diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-20 17:04:55 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-20 17:04:55 +0200 |
commit | 82d6433abe251d8d7a43417af392b638f868afe5 (patch) | |
tree | a83c1ad9ff094ea924febac292d7dafbf31cf830 | |
parent | cbeb4528247cca8eb1aa6c5d7e43778ea6de1762 (diff) | |
download | busybox-w32-82d6433abe251d8d7a43417af392b638f868afe5.tar.gz busybox-w32-82d6433abe251d8d7a43417af392b638f868afe5.tar.bz2 busybox-w32-82d6433abe251d8d7a43417af392b638f868afe5.zip |
mkfs_ext2: fixes for small image generation. images up to ~8M are ok now
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/mkfs_ext2.c | 7 | ||||
-rwxr-xr-x | 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) | |||
256 | if (nblocks != kilobytes) | 256 | if (nblocks != kilobytes) |
257 | bb_error_msg_and_die("block count doesn't fit in 32 bits"); | 257 | bb_error_msg_and_die("block count doesn't fit in 32 bits"); |
258 | #define kilobytes kilobytes_unused_after_this | 258 | #define kilobytes kilobytes_unused_after_this |
259 | if (blocksize < PAGE_SIZE) | 259 | //compat problem |
260 | nblocks &= ~((PAGE_SIZE >> blocksize_log2)-1); | 260 | // if (blocksize < PAGE_SIZE) |
261 | // nblocks &= ~((PAGE_SIZE >> blocksize_log2)-1); | ||
261 | // Experimentally, standard mke2fs won't work on images smaller than 60k | 262 | // Experimentally, standard mke2fs won't work on images smaller than 60k |
262 | if (nblocks < 60) | 263 | if (nblocks < 60) |
263 | bb_error_msg_and_die("need >= 60 blocks"); | 264 | bb_error_msg_and_die("need >= 60 blocks"); |
@@ -307,7 +308,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
307 | { | 308 | { |
308 | // N.B. e2fsprogs does as follows! | 309 | // N.B. e2fsprogs does as follows! |
309 | // ninodes is the total number of inodes (files) in the file system | 310 | // ninodes is the total number of inodes (files) in the file system |
310 | uint32_t ninodes = nblocks_full / (blocksize >= 4096 ? 1 : 4096 / blocksize); | 311 | uint32_t ninodes = ((uint64_t) nblocks_full * blocksize) / bytes_per_inode; |
311 | uint32_t overhead, remainder; | 312 | uint32_t overhead, remainder; |
312 | if (ninodes < EXT2_GOOD_OLD_FIRST_INO+1) | 313 | if (ninodes < EXT2_GOOD_OLD_FIRST_INO+1) |
313 | ninodes = EXT2_GOOD_OLD_FIRST_INO+1; | 314 | 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 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | run_test() { # params: mke2fs_invocation image_name | 3 | system_mke2fs='/sbin/mke2fs' |
4 | bbox_mke2fs='./busybox mke2fs' | ||
5 | |||
6 | gen_image() { # params: mke2fs_invocation image_name | ||
4 | >$2 | 7 | >$2 |
5 | dd seek=$((kilobytes-1)) bs=1K count=1 </dev/zero of=$2 >/dev/null 2>&1 || exit 1 | 8 | dd seek=$((kilobytes-1)) bs=1K count=1 </dev/zero of=$2 >/dev/null 2>&1 || exit 1 |
6 | $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1 | 9 | $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1 |
10 | |||
11 | #off | sed 's/inodes, [0-9]* blocks/inodes, N blocks/' \ | ||
12 | |||
7 | cat $2.raw_out \ | 13 | cat $2.raw_out \ |
8 | | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \ | 14 | | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \ |
9 | | grep -v '^Maximum filesystem' \ | 15 | | grep -v '^Maximum filesystem' \ |
@@ -11,7 +17,6 @@ run_test() { # params: mke2fs_invocation image_name | |||
11 | | grep -v '^Writing superblocks and filesystem accounting information' \ | 17 | | grep -v '^Writing superblocks and filesystem accounting information' \ |
12 | | grep -v '^This filesystem will be automatically checked every' \ | 18 | | grep -v '^This filesystem will be automatically checked every' \ |
13 | | grep -v '^180 days, whichever comes first' \ | 19 | | grep -v '^180 days, whichever comes first' \ |
14 | | sed 's/inodes, [0-9]* blocks/inodes, N blocks/' \ | ||
15 | | sed 's/blocks* unused./blocks unused/' \ | 20 | | sed 's/blocks* unused./blocks unused/' \ |
16 | | sed 's/block groups*/block groups/' \ | 21 | | sed 's/block groups*/block groups/' \ |
17 | | sed 's/ *$//' \ | 22 | | sed 's/ *$//' \ |
@@ -23,32 +28,52 @@ run_test() { # params: mke2fs_invocation image_name | |||
23 | test_mke2fs() { | 28 | test_mke2fs() { |
24 | echo Testing $kilobytes | 29 | echo Testing $kilobytes |
25 | 30 | ||
26 | run_test '/sbin/mke2fs' image_std || return 1 | 31 | gen_image "$system_mke2fs" image_std || return 1 |
27 | run_test './busybox mke2fs' image_bb || return 1 | 32 | gen_image "$bbox_mke2fs" image_bb || return 1 |
28 | 33 | ||
29 | diff -ua image_bb.out image_std.out >image.out.diff || { | 34 | diff -ua image_bb.out image_std.out >image.out.diff || { |
30 | cat image.out.diff | 35 | cat image.out.diff |
31 | return 1 | 36 | return 1 |
32 | } | 37 | } |
33 | 38 | ||
34 | e2fsck -f -n image_bb >/dev/null 2>&1 || { | 39 | e2fsck -f -n image_bb >image_bb_e2fsck.out 2>&1 || { |
35 | echo "e2fsck error on image_bb" | 40 | echo "e2fsck error on image_bb" |
36 | e2fsck -f -n image_bb | 41 | cat image_bb_e2fsck.out |
37 | exit 1 | 42 | exit 1 |
38 | } | 43 | } |
39 | } | 44 | } |
40 | 45 | ||
41 | # kilobytes=60 is the minimal allowed size | 46 | # -:bbox +:standard |
47 | |||
48 | # kilobytes=60 is the minimal allowed size. | ||
49 | # | ||
50 | # kilobytes=8378 is the first value where we differ from std: | ||
51 | # +warning: 185 blocks unused | ||
52 | # Filesystem label= | ||
53 | # OS type: Linux | ||
54 | # Block size=1024 (log=0) | ||
55 | # Fragment size=1024 (log=0) | ||
56 | # -2096 inodes, 8378 blocks | ||
57 | # +2096 inodes, 8193 blocks | ||
58 | # 418 blocks reserved for the super user | ||
59 | # First data block=1 | ||
60 | # -2 block groups | ||
61 | # +1 block groups | ||
62 | # 8192 blocks per group, 8192 fragments per group | ||
63 | # -1048 inodes per group | ||
64 | # -Superblock backups stored on blocks: | ||
65 | # -8193 | ||
66 | # +2096 inodes per group | ||
67 | # | ||
42 | kilobytes=60 | 68 | kilobytes=60 |
43 | while true; do | 69 | while true; do |
44 | test_mke2fs #|| exit 1 | 70 | test_mke2fs || exit 1 |
45 | : $((kilobytes++)) | 71 | : $((kilobytes++)) |
46 | test $kilobytes = 200 && break | 72 | test $kilobytes = 300000 && break |
47 | done | 73 | done |
48 | exit | 74 | exit |
49 | 75 | ||
50 | # Specific sizes with known differences: | 76 | # Specific sizes with known differences: |
51 | # -:bbox +:standard | ||
52 | 77 | ||
53 | # -6240 inodes, 24908 blocks | 78 | # -6240 inodes, 24908 blocks |
54 | # +6240 inodes, 24577 blocks | 79 | # +6240 inodes, 24577 blocks |