aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Dilger <adilger@whamcloud.com>2020-02-06 18:09:39 -0700
committerTheodore Ts'o <tytso@mit.edu>2020-02-29 18:26:38 -0500
commit382ed4a1c2b60acb9db7631e86dda207bde6076e (patch)
treec41e4d4412123c5d789f650179f07f4aeea865e0
parent74fbba1ff1074333eedaa3ed46597294641bf6b8 (diff)
downloade2fsprogs-382ed4a1c2b60acb9db7631e86dda207bde6076e.tar.gz
e2fsck: use proper types for variables
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>
-rw-r--r--e2fsck/dx_dirinfo.c6
-rw-r--r--e2fsck/e2fsck.h11
-rw-r--r--e2fsck/rehash.c2
-rw-r--r--e2fsck/super.c2
-rw-r--r--lib/ext2fs/imager.c34
-rw-r--r--misc/create_inode.c2
-rw-r--r--misc/dumpe2fs.c2
-rw-r--r--misc/e2fuzz.c8
-rw-r--r--misc/e2image.c2
-rw-r--r--misc/tune2fs.c2
10 files changed, 38 insertions, 33 deletions
diff --git a/e2fsck/dx_dirinfo.c b/e2fsck/dx_dirinfo.c
index 89672b753..f0f6084dd 100644
--- a/e2fsck/dx_dirinfo.c
+++ b/e2fsck/dx_dirinfo.c
@@ -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)++;
}
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index 253f8b582..5e7db42c2 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -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;
diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
index 54bc68038..4864ef1d5 100644
--- a/e2fsck/rehash.c
+++ b/e2fsck/rehash.c
@@ -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;
};
diff --git a/e2fsck/super.c b/e2fsck/super.c
index 18affcf72..e1c3f9357 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -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);
diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c
index 20bb99aea..ed0989adb 100644
--- a/lib/ext2fs/imager.c
+++ b/lib/ext2fs/imager.c
@@ -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;
diff --git a/misc/create_inode.c b/misc/create_inode.c
index 5161d5e39..1d9a596e1 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -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;
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index a6e135034..72f323e0b 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -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)
diff --git a/misc/e2fuzz.c b/misc/e2fuzz.c
index 8576d4eea..7c0f776fe 100644
--- a/misc/e2fuzz.c
+++ b/misc/e2fuzz.c
@@ -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
diff --git a/misc/e2image.c b/misc/e2image.c
index 56183ad6f..892c5371e 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -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)),
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 923fbb7a1..39cf85877 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -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) {