From: Theodore Ts'o Date: Tue, 17 Jun 2008 23:58:29 +0000 (-0400) Subject: mke2fs, tune2fs, resize2fs: Use floating point to calculate percentages X-Git-Tag: v1.40.11~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ff8ece57d46a9419fc60057547810824881bb45;p=thirdparty%2Fe2fsprogs.git mke2fs, tune2fs, resize2fs: Use floating point to calculate percentages When calculating the number reserved blocks, use floating point for better accuracy, since for big filesystems it really makes a difference. In addition, mke2fs and tune2fs accepts a floating point number from the user, so they should provide that level of accuracy. Addresses-Debian-Bug: #452639 Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/mke2fs.c b/misc/mke2fs.c index cf5e918e4..10ac78206 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1562,8 +1562,8 @@ static void PRS(int argc, char *argv[]) /* * Calculate number of blocks to reserve */ - fs_param.s_r_blocks_count = e2p_percent(reserved_ratio, - fs_param.s_blocks_count); + fs_param.s_r_blocks_count = (unsigned int) (reserved_ratio * + fs_param.s_blocks_count / 100.0); } int main (int argc, char *argv[]) diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 4e731f5cc..4c8a8342c 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -973,8 +973,8 @@ int main (int argc, char ** argv) printf (_("Setting interval between checks to %lu seconds\n"), interval); } if (m_flag) { - sb->s_r_blocks_count = e2p_percent(reserved_ratio, - sb->s_blocks_count); + sb->s_r_blocks_count = (unsigned int) (reserved_ratio * + sb->s_blocks_count / 100.0); ext2fs_mark_super_dirty(fs); printf (_("Setting reserved blocks percentage to %g%% (%u blocks)\n"), reserved_ratio, sb->s_r_blocks_count); diff --git a/resize/online.c b/resize/online.c index fc1f7a200..419d489bd 100644 --- a/resize/online.c +++ b/resize/online.c @@ -27,9 +27,10 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, unsigned long new_desc_blocks; ext2_filsys new_fs; errcode_t retval; + double percent; dgrp_t i; blk_t size; - int fd, r_frac, overhead; + int fd, overhead; printf(_("Filesystem at %s is mounted on %s; " "on-line resizing required\n"), fs->device_name, mtpt); @@ -80,7 +81,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, exit(1); } - r_frac = ext2fs_div_ceil(100 * sb->s_r_blocks_count, sb->s_blocks_count); + percent = (sb->s_r_blocks_count * 100.0) / sb->s_blocks_count; retval = ext2fs_read_bitmaps(fs); if (retval) @@ -127,8 +128,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 = e2p_percent(r_frac, - input.blocks_count); + input.reserved_blocks = (blk_t) (percent * input.blocks_count + / 100.0); #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 6dec3eb27..c6cadb85b 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -188,6 +188,7 @@ errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, blk_t new_size) unsigned int meta_bg, meta_bg_size; int has_super; unsigned long long new_inodes; /* u64 to check for overflow */ + double percent; fs->super->s_blocks_count = new_size; @@ -251,10 +252,10 @@ retry: /* * Adjust the number of reserved blocks */ - blk = (__u64)old_fs->super->s_r_blocks_count * 100 / + percent = (old_fs->super->s_r_blocks_count * 100.0) / old_fs->super->s_blocks_count; - fs->super->s_r_blocks_count = e2p_percent(blk, - fs->super->s_blocks_count); + fs->super->s_r_blocks_count = (unsigned int) (percent * + fs->super->s_blocks_count / 100.0); /* * Adjust the bitmaps for size diff --git a/tests/r_move_itable/expect b/tests/r_move_itable/expect index e5145531d..823cd33fd 100644 --- a/tests/r_move_itable/expect +++ b/tests/r_move_itable/expect @@ -25,7 +25,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 1248 Block count: 9985 -Reserved block count: 399 +Reserved block count: 497 Free blocks: 8704 Free inodes: 1237 First block: 1 @@ -326,7 +326,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 2496 Block count: 19969 -Reserved block count: 599 +Reserved block count: 993 Free blocks: 18325 Free inodes: 2485 First block: 1 @@ -863,7 +863,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 3744 Block count: 29953 -Reserved block count: 599 +Reserved block count: 1489 Free blocks: 27946 Free inodes: 3733 First block: 1 @@ -1636,7 +1636,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 5024 Block count: 40000 -Reserved block count: 400 +Reserved block count: 1988 Free blocks: 37624 Free inodes: 5013 First block: 1 diff --git a/tests/r_resize_inode/expect b/tests/r_resize_inode/expect index 129cdc408..bcc13e57b 100644 --- a/tests/r_resize_inode/expect +++ b/tests/r_resize_inode/expect @@ -23,7 +23,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 16384 Block count: 65536 -Reserved block count: 2621 +Reserved block count: 3276 Free blocks: 61023 Free inodes: 16373 First block: 1 @@ -471,7 +471,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 4096 Block count: 16384 -Reserved block count: 655 +Reserved block count: 819 Free blocks: 14277 Free inodes: 4085 First block: 1 @@ -628,7 +628,7 @@ Errors behavior: Continue Filesystem OS type: Linux Inode count: 41472 Block count: 165536 -Reserved block count: 4966 +Reserved block count: 8274 Free blocks: 157175 Free inodes: 41461 First block: 1