Whamcloud - gitweb
mke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF
[tools/e2fsprogs.git] / misc / e2fuzz.c
index 741dd67..685cdbe 100644 (file)
@@ -32,17 +32,18 @@ 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,
+                        ext2_loff_t offset)
 {
-       if (lseek(fd, offset, SEEK_SET) < 0)
+       if (ext2fs_llseek(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)
+static int getseed(void)
 {
        int r;
        int fd;
@@ -65,8 +66,11 @@ struct find_block {
        blk64_t corrupt_blocks;
 };
 
-int find_block_helper(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt,
-                     blk64_t ref_blk, int ref_offset, void *priv_data)
+static int find_block_helper(ext2_filsys fs EXT2FS_ATTR((unused)),
+                            blk64_t *blocknr, e2_blkcnt_t blockcnt,
+                            blk64_t ref_blk EXT2FS_ATTR((unused)),
+                            int ref_offset EXT2FS_ATTR((unused)),
+                            void *priv_data)
 {
        struct find_block *fb = (struct find_block *)priv_data;
 
@@ -78,8 +82,8 @@ int find_block_helper(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt,
        return 0;
 }
 
-errcode_t find_metadata_blocks(ext2_filsys fs, ext2fs_block_bitmap bmap,
-                              off_t *corrupt_bytes)
+static errcode_t find_metadata_blocks(ext2_filsys fs, ext2fs_block_bitmap bmap,
+                                     ext2_loff_t *corrupt_bytes)
 {
        dgrp_t i;
        blk64_t b, c;
@@ -160,10 +164,10 @@ out:
        return retval;
 }
 
-uint64_t rand_num(uint64_t min, uint64_t max)
+static uint64_t rand_num(uint64_t min, uint64_t max)
 {
        uint64_t x;
-       int i;
+       unsigned int i;
        uint8_t *px = (uint8_t *)&x;
 
        for (i = 0; i < sizeof(x); i++)
@@ -172,15 +176,14 @@ uint64_t rand_num(uint64_t min, uint64_t max)
        return min + (uint64_t)((double)(max - min) * (x / (UINT64_MAX + 1.0)));
 }
 
-int process_fs(const char *fsname)
+static int process_fs(const char *fsname)
 {
        errcode_t ret;
        int flags, fd;
        ext2_filsys fs = NULL;
        ext2fs_block_bitmap corrupt_map;
-       off_t hsize, count, off, offset, corrupt_bytes;
+       ext2_loff_t hsize, count, off, offset, corrupt_bytes, i;
        unsigned char c;
-       unsigned long i;
 
        /* If mounted rw, force dryrun mode */
        ret = ext2fs_check_if_mounted(fsname, &flags);
@@ -273,14 +276,27 @@ int process_fs(const char *fsname)
                if ((rand() % 2) && c < 128)
                        c |= 0x80;
                if (verbose)
-                       printf("Corrupting byte %jd in block %jd to 0x%x\n",
-                              off % fs->blocksize, off / fs->blocksize, c);
+                       printf("Corrupting byte %lld in block %lld to 0x%x\n",
+                              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);
 
@@ -302,7 +318,7 @@ fail:
        return 1;
 }
 
-void print_help(const char *progname)
+static void print_help(const char *progname)
 {
        printf("Usage: %s OPTIONS device\n", progname);
        printf("-b:     Corrupt this many bytes.\n");