Whamcloud - gitweb
e2fuzz: fix pwrite64/pwrite usage
authorDarrick J. Wong <darrick.wong@oracle.com>
Sun, 24 Aug 2014 23:55:42 +0000 (19:55 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 24 Aug 2014 23:55:42 +0000 (19:55 -0400)
Select pwrite64 or pwrite depending on what autoconf finds.  This
makes e2fuzz find a suitable pwrite variant regardless of platform.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/e2fuzz.c

index 741dd67..c08e3df 100644 (file)
@@ -32,15 +32,15 @@ static int metadata_only = 1;
 static unsigned long long user_corrupt_bytes = 0;
 static double user_corrupt_pct = 0.0;
 
-#ifndef HAVE_PWRITE
-ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
+#if !defined HAVE_PWRITE64 && !defined HAVE_PWRITE
+static ssize_t my_pwrite(int fd, const void *buf, size_t count, off_t offset)
 {
        if (lseek(fd, offset, SEEK_SET) < 0)
                return 0;
 
        return write(fd, buf, count);
 }
-#endif /* HAVE_PWRITE */
+#endif /* !defined HAVE_PWRITE64 && !defined HAVE_PWRITE */
 
 int getseed(void)
 {
@@ -277,10 +277,22 @@ int process_fs(const char *fsname)
                               off % fs->blocksize, off / fs->blocksize, c);
                if (dryrun)
                        continue;
+#ifdef HAVE_PWRITE64
+               if (pwrite64(fd, &c, sizeof(c), off) != sizeof(c)) {
+                       perror(fsname);
+                       goto fail3;
+               }
+#elif HAVE_PWRITE
                if (pwrite(fd, &c, sizeof(c), off) != sizeof(c)) {
                        perror(fsname);
                        goto fail3;
                }
+#else
+               if (my_pwrite(fd, &c, sizeof(c), off) != sizeof(c)) {
+                       perror(fsname);
+                       goto fail3;
+               }
+#endif
        }
        close(fd);