diff options
author | Theodore Ts'o <tytso@mit.edu> | 2006-08-30 03:08:13 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2006-08-30 03:08:13 -0400 |
commit | a8862d9e90d0d94761ba28dbbf9674308fd7d7c0 (patch) | |
tree | 5fdfe5d2e83ac3c8c579b2579eb7dd76ee33f7b7 /resize | |
parent | 5830d6be9c33e23bb20c339036083e6e4fa6795e (diff) | |
download | e2fsprogs-a8862d9e90d0d94761ba28dbbf9674308fd7d7c0.tar.gz |
Fix potential 2**32-1 overflow by using e2p_percent()
Add a new functiom, e2p_percent(), which correct calculates the percentage
of a number based on a given percentage, without worrying about overflow
issues. This is used where we calculate the number of reserved blocks using
a percentage of the total number of blocks in a filesystem.
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 'resize')
-rw-r--r-- | resize/ChangeLog | 4 | ||||
-rw-r--r-- | resize/online.c | 3 | ||||
-rw-r--r-- | resize/resize2fs.c | 4 |
3 files changed, 8 insertions, 3 deletions
diff --git a/resize/ChangeLog b/resize/ChangeLog index dea9ba62..b1c0794b 100644 --- a/resize/ChangeLog +++ b/resize/ChangeLog @@ -1,5 +1,9 @@ 2006-08-30 Theodore Tso <tytso@mit.edu> + * resize2fs.c (adjust_fs_info), online.c (online_resize_fs): Use + e2p_percent to properly calculate the number of reserved + blocks without worrying about overflow. + * resize2fs.c (ext2fs_calculate_summary_stats): Fix potential overflow problems when the number of blocks is close to 2**31. diff --git a/resize/online.c b/resize/online.c index 45262b12..7701150d 100644 --- a/resize/online.c +++ b/resize/online.c @@ -107,7 +107,8 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, sb->s_first_data_block - (i * sb->s_blocks_per_group); } - input.reserved_blocks = input.blocks_count * r_frac / 100; + input.reserved_blocks = e2p_percent(r_frac, + input.blocks_count); #if 0 printf("new block bitmap is at 0x%04x\n", input.block_bitmap); diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 74b517b7..7d3bde90 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -245,8 +245,8 @@ retry: */ blk = old_fs->super->s_r_blocks_count * 100 / old_fs->super->s_blocks_count; - fs->super->s_r_blocks_count = ((fs->super->s_blocks_count * blk) - / 100); + fs->super->s_r_blocks_count = e2p_percent(blk, + fs->super->s_blocks_count); /* * Adjust the bitmaps for size |