- rc = write(fd, buf, pages * BLOCKSIZE);
- if (rc != pages * BLOCKSIZE) {
- printf("Write error %s\n", strerror(errno));
- return 1;
+ if (action == O_WRONLY || action == O_RDWR) {
+ if (lseek64(fd, seek, SEEK_SET) < 0) {
+ printf("lseek64 failed: %s\n", strerror(errno));
+ return 1;
+ }
+
+ rc = write(fd, wbuf, len);
+ if (rc != len) {
+ printf("Write error %s (rc = %d, len = %ld)\n",
+ strerror(errno), rc, len);
+ return 1;
+ }
+ }
+
+ if (action == O_RDONLY || action == O_RDWR) {
+ char *rbuf;
+
+ if (lseek64(fd, seek, SEEK_SET) < 0) {
+ printf("Cannot seek %s\n", strerror(errno));
+ return 1;
+ }
+
+ rbuf =mmap(0,len,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0,0);
+ if (rbuf == MAP_FAILED) {
+ printf("No memory %s\n", strerror(errno));
+ return 1;
+ }
+
+ rc = read(fd, rbuf, len);
+ if (rc != len) {
+ printf("Read error: %s rc = %d\n",strerror(errno),rc);
+ return 1;
+ }
+
+ if (memcmp(wbuf, rbuf, len)) {
+ printf("Data mismatch\n");
+ return 1;
+ }