From 82d6433abe251d8d7a43417af392b638f868afe5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 20 Oct 2009 17:04:55 +0200 Subject: [PATCH] mkfs_ext2: fixes for small image generation. images up to ~8M are ok now Signed-off-by: Denys Vlasenko --- util-linux/mkfs_ext2.c | 7 +++--- util-linux/mkfs_ext2_test.sh | 45 ++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 5d5429f07..380312bca 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -256,8 +256,9 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) if (nblocks != kilobytes) bb_error_msg_and_die("block count doesn't fit in 32 bits"); #define kilobytes kilobytes_unused_after_this - if (blocksize < PAGE_SIZE) - nblocks &= ~((PAGE_SIZE >> blocksize_log2)-1); +//compat problem +// if (blocksize < PAGE_SIZE) +// nblocks &= ~((PAGE_SIZE >> blocksize_log2)-1); // Experimentally, standard mke2fs won't work on images smaller than 60k if (nblocks < 60) bb_error_msg_and_die("need >= 60 blocks"); @@ -307,7 +308,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) { // N.B. e2fsprogs does as follows! // ninodes is the total number of inodes (files) in the file system - uint32_t ninodes = nblocks_full / (blocksize >= 4096 ? 1 : 4096 / blocksize); + uint32_t ninodes = ((uint64_t) nblocks_full * blocksize) / bytes_per_inode; uint32_t overhead, remainder; if (ninodes < EXT2_GOOD_OLD_FIRST_INO+1) ninodes = EXT2_GOOD_OLD_FIRST_INO+1; diff --git a/util-linux/mkfs_ext2_test.sh b/util-linux/mkfs_ext2_test.sh index 1199852fa..4bc5f1ea9 100755 --- a/util-linux/mkfs_ext2_test.sh +++ b/util-linux/mkfs_ext2_test.sh @@ -1,9 +1,15 @@ #!/bin/sh -run_test() { # params: mke2fs_invocation image_name +system_mke2fs='/sbin/mke2fs' +bbox_mke2fs='./busybox mke2fs' + +gen_image() { # params: mke2fs_invocation image_name >$2 dd seek=$((kilobytes-1)) bs=1K count=1 /dev/null 2>&1 || exit 1 $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1 + +#off | sed 's/inodes, [0-9]* blocks/inodes, N blocks/' \ + cat $2.raw_out \ | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \ | grep -v '^Maximum filesystem' \ @@ -11,7 +17,6 @@ run_test() { # params: mke2fs_invocation image_name | grep -v '^Writing superblocks and filesystem accounting information' \ | grep -v '^This filesystem will be automatically checked every' \ | grep -v '^180 days, whichever comes first' \ - | sed 's/inodes, [0-9]* blocks/inodes, N blocks/' \ | sed 's/blocks* unused./blocks unused/' \ | sed 's/block groups*/block groups/' \ | sed 's/ *$//' \ @@ -23,32 +28,52 @@ run_test() { # params: mke2fs_invocation image_name test_mke2fs() { echo Testing $kilobytes - run_test '/sbin/mke2fs' image_std || return 1 - run_test './busybox mke2fs' image_bb || return 1 + gen_image "$system_mke2fs" image_std || return 1 + gen_image "$bbox_mke2fs" image_bb || return 1 diff -ua image_bb.out image_std.out >image.out.diff || { cat image.out.diff return 1 } - e2fsck -f -n image_bb >/dev/null 2>&1 || { + e2fsck -f -n image_bb >image_bb_e2fsck.out 2>&1 || { echo "e2fsck error on image_bb" - e2fsck -f -n image_bb + cat image_bb_e2fsck.out exit 1 } } -# kilobytes=60 is the minimal allowed size +# -:bbox +:standard + +# kilobytes=60 is the minimal allowed size. +# +# kilobytes=8378 is the first value where we differ from std: +# +warning: 185 blocks unused +# Filesystem label= +# OS type: Linux +# Block size=1024 (log=0) +# Fragment size=1024 (log=0) +# -2096 inodes, 8378 blocks +# +2096 inodes, 8193 blocks +# 418 blocks reserved for the super user +# First data block=1 +# -2 block groups +# +1 block groups +# 8192 blocks per group, 8192 fragments per group +# -1048 inodes per group +# -Superblock backups stored on blocks: +# -8193 +# +2096 inodes per group +# kilobytes=60 while true; do - test_mke2fs #|| exit 1 + test_mke2fs || exit 1 : $((kilobytes++)) - test $kilobytes = 200 && break + test $kilobytes = 300000 && break done exit # Specific sizes with known differences: -# -:bbox +:standard # -6240 inodes, 24908 blocks # +6240 inodes, 24577 blocks -- 2.25.1