[parted-devel] [PATCH] Fix the mkfs final-group-block-too-short bug.

Jim Meyering jim at meyering.net
Tue Jun 12 15:30:10 UTC 2007


Ironically, after taking the time to record-as-failing the
existing mkfs problem, this morning I noticed the fix, then
in testing, found the off-by-one bug:

        Fix the mkfs final-group-block-too-short bug.
        mkfs would fail for certain sizes resulting in a final group-block
        that was too small to accommodate the minimum number of admin blocks.
        There was already work-around code for when a decremented "numgroups"
        was 1.  This change applies that work-around code for larger values of
        numgroups, too.  Also, there was an off-by-one error in the guard test
        that would allow a few too-small partition sizes to slip through and
        provoke the error (see tests/t2000-mkfs.sh for two examples).
        This change fixes that, too.

Signed-off-by: Jim Meyering <jim at meyering.net>
---
 libparted/fs/ext2/ext2_mkfs.c |    4 +-
 tests/t2000-mkfs.sh           |   49 ++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/libparted/fs/ext2/ext2_mkfs.c b/libparted/fs/ext2/ext2_mkfs.c
index 92261f6..0684115 100644
--- a/libparted/fs/ext2/ext2_mkfs.c
+++ b/libparted/fs/ext2/ext2_mkfs.c
@@ -565,12 +565,12 @@ struct ext2_fs *ext2_mkfs(struct ext2_dev_handle *handle,
                               &last_group_admin, &inodes_per_group);

 	int fs_too_small = 0;
-	if (last_group_admin >= last_group_blocks)
+	if (last_group_admin + 1 >= last_group_blocks)
           {
             numgroups--;
             if (numgroups == 0)
               fs_too_small = 1;
-            else if (numgroups == 1)
+            else
               {
 		numblocks -= last_group_blocks;
                 compute_block_counts (numblocks, numgroups, log_block_size,
diff --git a/tests/t2000-mkfs.sh b/tests/t2000-mkfs.sh
index 66a66a3..3fb1494 100755
--- a/tests/t2000-mkfs.sh
+++ b/tests/t2000-mkfs.sh
@@ -108,21 +108,44 @@ test_expect_success \

 #############################################################
 # Demonstrate 3-block-group failure for 16+MB EXT2 file system.
-# This test fails with at least parted-1.8.8.
+# This test would fail with parted-1.8.7.

 dev=loop-file

-test_expect_success \
-    "setup: create and label a device" \
-    'dd if=/dev/null of=$dev bs=1 seek=20M 2>/dev/null &&
-     parted -s $dev mklabel gpt'
-
-# FIXME: this test currently fails with the diagnostic "Error: Attempt
-# to write sectors 32772-32773 outside of partition on .../loop-file."
-# Eventually, when this bug is fixed, change to "test_expect_success"
-# and ensure that the output file is empty.
-test_expect_failure \
-    'try to create a file system with the offending size' \
-    'parted -s $dev mkpartfs primary ext2 0 16796160B >out 2>&1'
+mkfs()
+{
+  size=$1
+  test_expect_success \
+      "setup: create and label a device" \
+      'dd if=/dev/null of=$dev bs=1 seek=30M 2>/dev/null &&
+       parted -s $dev mklabel gpt'
+
+  test_expect_success \
+      "try to create an ext2 file system of size $size" \
+      'parted -s $dev mkpartfs primary ext2 0 ${size}B >out 2>&1'
+  test_expect_success 'check for empty output' '$compare out /dev/null'
+}
+
+
+# size in bytes  #block groups  last_group_blocks (in ext2_mkfs)
+mkfs   16795000 #  2              8191
+mkfs   16796000 #  2              8192
+mkfs   16796160 #  2 (was 3)         1
+mkfs   16797000 #  2 (was 3)         1
+mkfs   16798000 #  2 (was 3)         2
+# ...
+mkfs   17154000 #  2 (was 3)       350
+mkfs   17155000 #  2 (was 3)       351 last_group_admin == last_group_blocks
+mkfs   17156000 #  2 (was 3)       352
+mkfs   17157000 #  3               353
+mkfs   17158000 #  3               354
+# ...
+mkfs   25184000 #  3              8192
+mkfs   25185000 #  3 (was 4)         1 (last_group_admin = 387)
+mkfs   25186000 #  3 (was 4)         2 (last_group_admin = 387)
+# ...
+mkfs   25589000 #  3 (was 4)       394 (last_group_admin = 394)
+mkfs   25589000 #  3 (was 4)       395 (last_group_admin = 394)
+mkfs   25590000 #  4               396

 test_done



More information about the parted-devel mailing list