]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
mke2fs, tune2fs, resize2fs: Use floating point to calculate percentages
authorTheodore Ts'o <tytso@mit.edu>
Tue, 17 Jun 2008 23:58:29 +0000 (19:58 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 18 Jun 2008 01:08:49 +0000 (21:08 -0400)
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" <tytso@mit.edu>
misc/mke2fs.c
misc/tune2fs.c
resize/online.c
resize/resize2fs.c
tests/r_move_itable/expect
tests/r_resize_inode/expect

index cf5e918e4e767b0414d213e25d96e8e9679f9120..10ac78206ad885c5ee620aacee5b6341589af86a 100644 (file)
@@ -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[])
index 4e731f5cc221d99f554f91283d8749324230f9c3..4c8a8342c09b8187acf6b1bd48578f7c70de12f5 100644 (file)
@@ -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);
index fc1f7a20096a44f9013bd6dbbb3d9fdab284eccc..419d489bd38397489177e39ed10784bc0b95f7e1 100644 (file)
@@ -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);
index 6dec3eb27578a2622854434eeb845b5d9611b773..c6cadb85b0766f506bc77a9b1e566ba6e78095ae 100644 (file)
@@ -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
index e5145531d696ff2ed8bb114df00b431e77df1b28..823cd33fd6de060092a4ce7d5c737aeb1c6d4152 100644 (file)
@@ -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
index 129cdc40814066a719a3df6de4bbd2c1566d0c9e..bcc13e57b9eace530f45ef19bfd53ae08f6cb143 100644 (file)
@@ -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