- rc = read(fd, buf, blocks * st.st_blksize);
- if (rc != blocks * st.st_blksize) {
- printf("Read error: %s (rc = %d)\n", strerror(errno), rc);
- 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, buf, 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) {
+ if (lseek64(fd, seek, SEEK_SET) < 0) {
+ printf("Cannot seek %s\n", strerror(errno));
+ return 1;
+ }
+ /* reset all bytes to something nor 0x0 neither 0xab */
+ memset(buf, 0x5e, len);
+ rc = read(fd, buf, len);
+ if (rc != len) {
+ printf("Read error: %s rc = %d\n",strerror(errno),rc);
+ return 1;
+ }
+
+ if (check_bytes(buf, pad, len) != len) {
+ printf("Data mismatch\n");
+ return 1;
+ }