diff options
author | Theodore Ts'o <tytso@mit.edu> | 2006-08-30 01:57:00 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2006-08-30 01:57:00 -0400 |
commit | 69022e029f3273b3b860bf701219cd3fe615f76b (patch) | |
tree | 81ecd1b770fe3a4d8e0c325ce78bc6f0c17c927b /misc/filefrag.c | |
parent | a3e025c7493b58ec88b775f26a41e4205a6a2c9f (diff) | |
download | e2fsprogs-69022e029f3273b3b860bf701219cd3fe615f76b.tar.gz |
Fix potential 2**32-1 overflow problems by ext2fs_div_ceil()
Add a new function, ext2fs_div_ceil(), which correctly calculates a division
of two unsigned integer where the result is always rounded up the next
largest integer. This is used everywhere where we might have
previously caused an overflow when the number of blocks
or inodes is too close to 2**32-1.
Based on patches from Eric Sandeen, but generalized to use this new function
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Eric Sandeen <esandeen@redhat.com>
Diffstat (limited to 'misc/filefrag.c')
-rw-r--r-- | misc/filefrag.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/misc/filefrag.c b/misc/filefrag.c index 0719d4ce..df900602 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -47,6 +47,13 @@ int verbose = 0; #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ #define EXT3_IOC_GETFLAGS _IOR('f', 1, long) +static unsigned int div_ceil(unsigned int a, unsigned int b) +{ + if (!a) + return 0; + return ((a - 1) / b) + 1; +} + static unsigned long get_bmap(int fd, unsigned long block) { int ret; @@ -105,7 +112,7 @@ static void frag_report(const char *filename) if (verbose) { printf("Filesystem type is: %x\n", fsinfo.f_type); } - cylgroups = (fsinfo.f_blocks + fsinfo.f_bsize*8-1) / fsinfo.f_bsize*8; + cylgroups = div_ceil(fsinfo.f_blocks, fsinfo.f_bsize*8); if (verbose) { printf("Filesystem cylinder groups is approximately %ld\n", cylgroups); |