Whamcloud - gitweb
e2fsck: use proper types for variables
authorAndreas Dilger <adilger@whamcloud.com>
Fri, 7 Feb 2020 01:09:39 +0000 (18:09 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 29 Feb 2020 23:26:38 +0000 (18:26 -0500)
Use ext2_ino_t instead of ino_t for referencing inode numbers.
Use loff_t for for file offsets, and dgrp_t for group numbers.

Cast products to ssize_t before multiplication to avoid overflow.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: Shilong Wang <wshilong@ddn.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/dx_dirinfo.c
e2fsck/e2fsck.h
e2fsck/rehash.c
e2fsck/super.c
lib/ext2fs/imager.c
misc/create_inode.c
misc/dumpe2fs.c
misc/e2fuzz.c
misc/e2image.c
misc/tune2fs.c

index 89672b7..f0f6084 100644 (file)
@@ -138,7 +138,7 @@ void e2fsck_free_dx_dir_info(e2fsck_t ctx)
 /*
  * Return the count of number of directories in the dx_dir_info structure
  */
-int e2fsck_get_num_dx_dirinfo(e2fsck_t ctx)
+ext2_ino_t e2fsck_get_num_dx_dirinfo(e2fsck_t ctx)
 {
        return ctx->dx_dir_info_count;
 }
@@ -146,10 +146,10 @@ int e2fsck_get_num_dx_dirinfo(e2fsck_t ctx)
 /*
  * A simple interator function
  */
-struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control)
+struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, ext2_ino_t *control)
 {
        if (*control >= ctx->dx_dir_info_count)
                return 0;
 
-       return(ctx->dx_dir_info + (*control)++);
+       return ctx->dx_dir_info + (*control)++;
 }
index 253f8b5..5e7db42 100644 (file)
@@ -235,12 +235,12 @@ struct e2fsck_struct {
        char    *problem_log_fn;
        int     flags;          /* E2fsck internal flags */
        int     options;
-       int     blocksize;      /* blocksize */
+       unsigned blocksize;     /* blocksize */
        blk64_t use_superblock; /* sb requested by user */
        blk64_t superblock;     /* sb used to open fs */
        blk64_t num_blocks;     /* Total number of blocks */
-       blk64_t free_blocks;
-       ino_t   free_inodes;
+       blk64_t free_blocks;
+       ext2_ino_t free_inodes;
        int     mount_flags;
        int     openfs_flags;
        blkid_cache blkid;      /* blkid cache */
@@ -478,8 +478,9 @@ extern void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino,
                              struct ext2_inode *inode, int num_blocks);
 extern struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino);
 extern void e2fsck_free_dx_dir_info(e2fsck_t ctx);
-extern int e2fsck_get_num_dx_dirinfo(e2fsck_t ctx);
-extern struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control);
+extern ext2_ino_t e2fsck_get_num_dx_dirinfo(e2fsck_t ctx);
+extern struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx,
+                                                  ext2_ino_t *control);
 
 /* ea_refcount.c */
 typedef __u64 ea_key_t;
index 54bc680..4864ef1 100644 (file)
@@ -83,7 +83,7 @@ struct fill_dir_struct {
        int max_array, num_array;
        unsigned int dir_size;
        int compress;
-       ino_t parent;
+       ext2_ino_t parent;
        ext2_ino_t dir;
 };
 
index 18affcf..e1c3f93 100644 (file)
@@ -595,7 +595,7 @@ void check_super_block(e2fsck_t ctx)
        blk64_t should_be;
        struct problem_context  pctx;
        blk64_t free_blocks = 0;
-       ino_t   free_inodes = 0;
+       ext2_ino_t free_inodes = 0;
        int     csum_flag, clear_test_fs_flag;
 
        inodes_per_block = EXT2_INODES_PER_BLOCK(fs->super);
index 20bb99a..ed0989a 100644 (file)
@@ -61,19 +61,20 @@ static int check_zero_block(char *buf, int blocksize)
 
 errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
 {
-       unsigned int    group, left, c, d;
+       dgrp_t          group;
+       ssize_t         left, c, d;
        char            *buf, *cp;
        blk64_t         blk;
        ssize_t         actual;
        errcode_t       retval;
-       off_t           r;
+       loff_t          r;
 
        buf = malloc(fs->blocksize * BUF_BLOCKS);
        if (!buf)
                return ENOMEM;
 
        for (group = 0; group < fs->group_desc_count; group++) {
-               blk = ext2fs_inode_table_loc(fs, (unsigned)group);
+               blk = ext2fs_inode_table_loc(fs, group);
                if (!blk) {
                        retval = EXT2_ET_MISSING_INODE_TABLE;
                        goto errout;
@@ -107,23 +108,25 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
                                        continue;
                                }
                                /* Find non-zero blocks */
-                               for (d=1; d < c; d++) {
-                                       if (check_zero_block(cp + d*fs->blocksize, fs->blocksize))
+                               for (d = 1; d < c; d++) {
+                                       if (check_zero_block(cp +
+                                                            d * fs->blocksize,
+                                                            fs->blocksize))
                                                break;
                                }
                        skip_sparse:
-                               actual = write(fd, cp, fs->blocksize * d);
+                               actual = write(fd, cp, d * fs->blocksize);
                                if (actual == -1) {
                                        retval = errno;
                                        goto errout;
                                }
-                               if (actual != (ssize_t) (fs->blocksize * d)) {
+                               if (actual != d * fs->blocksize) {
                                        retval = EXT2_ET_SHORT_WRITE;
                                        goto errout;
                                }
                                blk += d;
                                left -= d;
-                               cp += fs->blocksize * d;
+                               cp += d * fs->blocksize;
                                c -= d;
                        }
                }
@@ -141,7 +144,8 @@ errout:
 errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
                                  int flags EXT2FS_ATTR((unused)))
 {
-       unsigned int    group, c, left;
+       dgrp_t          group;
+       ssize_t         c, left;
        char            *buf;
        blk64_t         blk;
        ssize_t         actual;
@@ -152,7 +156,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
                return ENOMEM;
 
        for (group = 0; group < fs->group_desc_count; group++) {
-               blk = ext2fs_inode_table_loc(fs, (unsigned)group);
+               blk = ext2fs_inode_table_loc(fs, group);
                if (!blk) {
                        retval = EXT2_ET_MISSING_INODE_TABLE;
                        goto errout;
@@ -167,7 +171,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
                                retval = errno;
                                goto errout;
                        }
-                       if (actual != (ssize_t) (fs->blocksize * c)) {
+                       if (actual != fs->blocksize * c) {
                                retval = EXT2_ET_SHORT_READ;
                                goto errout;
                        }
@@ -252,7 +256,7 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
        }
 #endif
 
-       actual = write(fd, cp, fs->blocksize * fs->desc_blocks);
+       actual = write(fd, cp, (ssize_t)fs->blocksize * fs->desc_blocks);
 
 
 #ifdef WORDS_BIGENDIAN
@@ -268,7 +272,7 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
                retval = errno;
                goto errout;
        }
-       if (actual != (ssize_t) (fs->blocksize * fs->desc_blocks)) {
+       if (actual != (ssize_t)fs->blocksize * fs->desc_blocks) {
                retval = EXT2_ET_SHORT_WRITE;
                goto errout;
        }
@@ -290,7 +294,7 @@ errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
        ssize_t         actual, size;
        errcode_t       retval;
 
-       size = fs->blocksize * (fs->group_desc_count + 1);
+       size = (ssize_t)fs->blocksize * (fs->group_desc_count + 1);
        buf = malloc(size);
        if (!buf)
                return ENOMEM;
@@ -314,7 +318,7 @@ errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
        memcpy(fs->super, buf, SUPERBLOCK_SIZE);
 
        memcpy(fs->group_desc, buf + fs->blocksize,
-              fs->blocksize * fs->group_desc_count);
+              (ssize_t)fs->blocksize * fs->group_desc_count);
 
        retval = 0;
 
index 5161d5e..1d9a596 100644 (file)
@@ -601,7 +601,7 @@ out:
        return err;
 }
 
-static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ino_t ino)
+static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ext2_ino_t ino)
 {
        int i;
 
index a6e1350..72f323e 100644 (file)
@@ -362,7 +362,7 @@ static void print_inline_journal_information(ext2_filsys fs)
        struct ext2_inode       inode;
        ext2_file_t             journal_file;
        errcode_t               retval;
-       ino_t                   ino = fs->super->s_journal_inum;
+       ext2_ino_t              ino = fs->super->s_journal_inum;
        char                    buf[1024];
 
        if (fs->flags & EXT2_FLAG_IMAGE_FILE)
index 8576d4e..7c0f776 100644 (file)
@@ -181,9 +181,9 @@ static int process_fs(const char *fsname)
        int flags, fd;
        ext2_filsys fs = NULL;
        ext2fs_block_bitmap corrupt_map;
-       off_t hsize, count, off, offset, corrupt_bytes;
+       loff_t hsize, count, off, offset, corrupt_bytes;
        unsigned char c;
-       off_t i;
+       loff_t i;
 
        /* If mounted rw, force dryrun mode */
        ret = ext2fs_check_if_mounted(fsname, &flags);
@@ -277,8 +277,8 @@ static int process_fs(const char *fsname)
                        c |= 0x80;
                if (verbose)
                        printf("Corrupting byte %lld in block %lld to 0x%x\n",
-                              (long long) off % fs->blocksize,
-                              (long long) off / fs->blocksize, c);
+                              off % fs->blocksize,
+                              off / fs->blocksize, c);
                if (dryrun)
                        continue;
 #ifdef HAVE_PWRITE64
index 56183ad..892c537 100644 (file)
@@ -312,7 +312,7 @@ struct process_block_struct {
  * structure, so there's no point in letting the ext2fs library read
  * the inode again.
  */
-static ino_t stashed_ino = 0;
+static ext2_ino_t stashed_ino = 0;
 static struct ext2_inode *stashed_inode;
 
 static errcode_t meta_get_blocks(ext2_filsys fs EXT2FS_ATTR((unused)),
index 923fbb7..39cf858 100644 (file)
@@ -365,7 +365,7 @@ static errcode_t remove_journal_inode(ext2_filsys fs)
 {
        struct ext2_inode       inode;
        errcode_t               retval;
-       ino_t                   ino = fs->super->s_journal_inum;
+       ext2_ino_t              ino = fs->super->s_journal_inum;
 
        retval = ext2fs_read_inode(fs, ino,  &inode);
        if (retval) {