diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-17 23:13:31 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-17 23:13:31 +0200 |
commit | 45887751827cb6316218536937ac846b1b062661 (patch) | |
tree | 0323abd66015b5dbfb1de7c2c8274056590255cc /util-linux/mkfs_ext2.c | |
parent | 823b4e6f260137bcd72a8b96587ef85a9bd7eac7 (diff) | |
download | busybox-w32-45887751827cb6316218536937ac846b1b062661.tar.gz busybox-w32-45887751827cb6316218536937ac846b1b062661.tar.bz2 busybox-w32-45887751827cb6316218536937ac846b1b062661.zip |
mkfs_ext2: shrink
function old new delta
has_super 28 25 -3
mkfs_ext2_main 2011 1980 -31
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mkfs_ext2.c')
-rw-r--r-- | util-linux/mkfs_ext2.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 0f5e0148f..e4c3e171e 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c | |||
@@ -95,14 +95,14 @@ static bool is_power_of(uint32_t x, uint16_t n) | |||
95 | return (z == (int)z); | 95 | return (z == (int)z); |
96 | } | 96 | } |
97 | 97 | ||
98 | static bool has_super(uint32_t x) | 98 | static uint32_t has_super(uint32_t x) |
99 | { | 99 | { |
100 | return (0 == x || 1 == x || is_power_of(x, 3) || is_power_of(x, 5) || is_power_of(x, 7)); | 100 | return (0 == x || 1 == x || is_power_of(x, 3) || is_power_of(x, 5) || is_power_of(x, 7)); |
101 | } | 101 | } |
102 | 102 | ||
103 | #else | 103 | #else |
104 | 104 | ||
105 | static bool has_super(uint32_t x) | 105 | static uint32_t has_super(uint32_t x) |
106 | { | 106 | { |
107 | static const uint32_t supers[] = { | 107 | static const uint32_t supers[] = { |
108 | 0, 1, 3, 5, 7, 9, 25, 27, 49, 81, 125, 243, 343, 625, 729, | 108 | 0, 1, 3, 5, 7, 9, 25, 27, 49, 81, 125, 243, 343, 625, 729, |
@@ -112,7 +112,8 @@ static bool has_super(uint32_t x) | |||
112 | 48828125, 129140163, 244140625, 282475249, 387420489, | 112 | 48828125, 129140163, 244140625, 282475249, 387420489, |
113 | 1162261467, 1220703125, 1977326743, 3486784401/* >2^31 */, | 113 | 1162261467, 1220703125, 1977326743, 3486784401/* >2^31 */, |
114 | }; | 114 | }; |
115 | for (int i = sizeof(supers)/sizeof(supers[0]); --i >= 0; ) | 115 | unsigned i; |
116 | for (i = ARRAY_SIZE(supers); --i >= 0;) | ||
116 | if (x == supers[i]) | 117 | if (x == supers[i]) |
117 | return 1; | 118 | return 1; |
118 | return 0; | 119 | return 0; |
@@ -358,7 +359,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
358 | i < ngroups; | 359 | i < ngroups; |
359 | i++, pos += nblocks_per_group, n -= nblocks_per_group | 360 | i++, pos += nblocks_per_group, n -= nblocks_per_group |
360 | ) { | 361 | ) { |
361 | uint32_t overhead = pos + has_super(i) * (1/*sb*/ + gdtsz + rgdtsz); | 362 | uint32_t overhead = pos + (has_super(i) ? (1/*sb*/ + gdtsz + rgdtsz) : 0); |
362 | gd[i].bg_block_bitmap = overhead + 0; | 363 | gd[i].bg_block_bitmap = overhead + 0; |
363 | gd[i].bg_inode_bitmap = overhead + 1; | 364 | gd[i].bg_inode_bitmap = overhead + 1; |
364 | gd[i].bg_inode_table = overhead + 2; | 365 | gd[i].bg_inode_table = overhead + 2; |
@@ -384,19 +385,21 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
384 | // dump filesystem skeleton structures | 385 | // dump filesystem skeleton structures |
385 | buf = xmalloc(blocksize); | 386 | buf = xmalloc(blocksize); |
386 | for (i = 0, pos = first_data_block; i < ngroups; i++, pos += nblocks_per_group) { | 387 | for (i = 0, pos = first_data_block; i < ngroups; i++, pos += nblocks_per_group) { |
387 | uint32_t overhead = has_super(i) * (1/*sb*/ + gdtsz + rgdtsz); | 388 | uint32_t overhead = has_super(i) ? (1/*sb*/ + gdtsz + rgdtsz) : 0; |
388 | uint32_t start;// = has_super(i) * (1/*sb*/ + gdtsz + rgdtsz); | 389 | uint32_t start;// = has_super(i) ? (1/*sb*/ + gdtsz + rgdtsz) : 0; |
389 | uint32_t end; | 390 | uint32_t end; |
390 | 391 | ||
391 | // dump superblock and group descriptors and their backups | 392 | // dump superblock and group descriptors and their backups |
392 | if (overhead) { // N.B. in fact, we want (has_super(i)) condition, but it is equal to (overhead != 0) and is cheaper | 393 | if (overhead) { // N.B. in fact, we want (has_super(i)) condition, but it is equal to (overhead != 0) and is cheaper |
393 | //bb_info_msg("SUPER@[%d]", pos); | 394 | //bb_info_msg("SUPER@[%d]", pos); |
394 | // N.B. 1024 byte blocks are special | 395 | // N.B. 1024 byte blocks are special |
395 | PUT(blocksize * pos + 1024 * (0 == i && 0 == first_data_block), sb, blocksize); | 396 | PUT(blocksize * pos + ((0 == i && 0 == first_data_block) ? 1024 : 0), sb, blocksize); |
396 | PUT(blocksize * pos + blocksize, gd, (gdtsz + rgdtsz) * blocksize); | 397 | PUT(blocksize * pos + blocksize, gd, (gdtsz + rgdtsz) * blocksize); |
397 | } | 398 | } |
398 | 399 | ||
399 | start = overhead + 1/*bbmp*/ + 1/*ibmp*/ + itsz + (0 == i) * 2; // +2: /, /lost+found | 400 | start = overhead + 1/*bbmp*/ + 1/*ibmp*/ + itsz; |
401 | if (i == 0) | ||
402 | start += 2; // for / and /lost+found | ||
400 | end = nblocks_per_group - (start + gd[i].bg_free_blocks_count); | 403 | end = nblocks_per_group - (start + gd[i].bg_free_blocks_count); |
401 | // mark preallocated blocks as allocated | 404 | // mark preallocated blocks as allocated |
402 | allocate(buf, blocksize, start, end); | 405 | allocate(buf, blocksize, start, end); |