diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-22 12:41:44 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-22 12:41:44 +0200 |
commit | 46e364dbfebee49f65ffa92a66279df6a408e4f0 (patch) | |
tree | e1292cf9d0803277b6ec9a9e9d13460dd4cef5db | |
parent | 09bbb2892da80efac4451e46683f9361d59cefd5 (diff) | |
download | busybox-w32-46e364dbfebee49f65ffa92a66279df6a408e4f0.tar.gz busybox-w32-46e364dbfebee49f65ffa92a66279df6a408e4f0.tar.bz2 busybox-w32-46e364dbfebee49f65ffa92a66279df6a408e4f0.zip |
mkfs_ext2: code shrink
function old new delta
mkfs_ext2_main 2505 2492 -13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/mkfs_ext2.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index ea35e5287..d89f9460e 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c | |||
@@ -201,7 +201,6 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
201 | uint32_t inode_table_blocks; | 201 | uint32_t inode_table_blocks; |
202 | uint32_t lost_and_found_blocks; | 202 | uint32_t lost_and_found_blocks; |
203 | time_t timestamp; | 203 | time_t timestamp; |
204 | unsigned opts; | ||
205 | const char *label = ""; | 204 | const char *label = ""; |
206 | struct stat st; | 205 | struct stat st; |
207 | struct ext2_super_block *sb; // superblock | 206 | struct ext2_super_block *sb; // superblock |
@@ -210,8 +209,10 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
210 | struct ext2_dir *dir; | 209 | struct ext2_dir *dir; |
211 | uint8_t *buf; | 210 | uint8_t *buf; |
212 | 211 | ||
212 | // using global "option_mask32" instead of local "opts": | ||
213 | // we are register starved here | ||
213 | opt_complementary = "-1:b+:m+:i+"; | 214 | opt_complementary = "-1:b+:m+:i+"; |
214 | opts = getopt32(argv, "cl:b:f:i:I:J:G:N:m:o:g:L:M:O:r:E:T:U:jnqvFS", | 215 | /*opts =*/ getopt32(argv, "cl:b:f:i:I:J:G:N:m:o:g:L:M:O:r:E:T:U:jnqvFS", |
215 | NULL, &bs, NULL, &bpi, &user_inodesize, NULL, NULL, NULL, | 216 | NULL, &bs, NULL, &bpi, &user_inodesize, NULL, NULL, NULL, |
216 | &reserved_percent, NULL, NULL, &label, NULL, NULL, NULL, NULL, NULL, NULL); | 217 | &reserved_percent, NULL, NULL, &label, NULL, NULL, NULL, NULL, NULL, NULL); |
217 | argv += optind; // argv[0] -- device | 218 | argv += optind; // argv[0] -- device |
@@ -219,7 +220,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
219 | // check the device is a block device | 220 | // check the device is a block device |
220 | xmove_fd(xopen(argv[0], O_WRONLY), fd); | 221 | xmove_fd(xopen(argv[0], O_WRONLY), fd); |
221 | fstat(fd, &st); | 222 | fstat(fd, &st); |
222 | if (!S_ISBLK(st.st_mode) && !(opts & OPT_F)) | 223 | if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_F)) |
223 | bb_error_msg_and_die("not a block device"); | 224 | bb_error_msg_and_die("not a block device"); |
224 | 225 | ||
225 | // check if it is mounted | 226 | // check if it is mounted |
@@ -233,7 +234,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
233 | kilobytes = xatoull(argv[1]); | 234 | kilobytes = xatoull(argv[1]); |
234 | // seek past end fails on block devices but works on files | 235 | // seek past end fails on block devices but works on files |
235 | if (lseek(fd, kilobytes * 1024 - 1, SEEK_SET) != (off_t)-1) { | 236 | if (lseek(fd, kilobytes * 1024 - 1, SEEK_SET) != (off_t)-1) { |
236 | if (!(opts & OPT_n)) | 237 | if (!(option_mask32 & OPT_n)) |
237 | xwrite(fd, "", 1); // file grows if needed | 238 | xwrite(fd, "", 1); // file grows if needed |
238 | } | 239 | } |
239 | //else { | 240 | //else { |
@@ -248,7 +249,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
248 | bytes_per_inode = 4096; | 249 | bytes_per_inode = 4096; |
249 | if (kilobytes < 3*1024) | 250 | if (kilobytes < 3*1024) |
250 | bytes_per_inode = 8192; | 251 | bytes_per_inode = 8192; |
251 | if (opts & OPT_i) | 252 | if (option_mask32 & OPT_i) |
252 | bytes_per_inode = bpi; | 253 | bytes_per_inode = bpi; |
253 | 254 | ||
254 | // Determine block size and inode size | 255 | // Determine block size and inode size |
@@ -267,7 +268,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
267 | while ((kilobytes >> 22) >= blocksize) | 268 | while ((kilobytes >> 22) >= blocksize) |
268 | blocksize *= 2; | 269 | blocksize *= 2; |
269 | } | 270 | } |
270 | if (opts & OPT_b) | 271 | if (option_mask32 & OPT_b) |
271 | blocksize = bs; | 272 | blocksize = bs; |
272 | if (blocksize < EXT2_MIN_BLOCK_SIZE | 273 | if (blocksize < EXT2_MIN_BLOCK_SIZE |
273 | || blocksize > EXT2_MAX_BLOCK_SIZE | 274 | || blocksize > EXT2_MAX_BLOCK_SIZE |
@@ -276,7 +277,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
276 | bb_error_msg_and_die("blocksize %u is bad", blocksize); | 277 | bb_error_msg_and_die("blocksize %u is bad", blocksize); |
277 | } | 278 | } |
278 | // Do we have custom inode size? | 279 | // Do we have custom inode size? |
279 | if (opts & OPT_I) { | 280 | if (option_mask32 & OPT_I) { |
280 | if (user_inodesize < sizeof(*inode) | 281 | if (user_inodesize < sizeof(*inode) |
281 | || user_inodesize > blocksize | 282 | || user_inodesize > blocksize |
282 | || (user_inodesize & (user_inodesize - 1)) // not power of 2 | 283 | || (user_inodesize & (user_inodesize - 1)) // not power of 2 |
@@ -432,7 +433,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
432 | } | 433 | } |
433 | bb_putchar('\n'); | 434 | bb_putchar('\n'); |
434 | 435 | ||
435 | if (opts & OPT_n) { | 436 | if (option_mask32 & OPT_n) { |
436 | if (ENABLE_FEATURE_CLEAN_UP) | 437 | if (ENABLE_FEATURE_CLEAN_UP) |
437 | close(fd); | 438 | close(fd); |
438 | return EXIT_SUCCESS; | 439 | return EXIT_SUCCESS; |