diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-17 08:32:26 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-17 08:32:26 +0000 |
commit | 9f153f610fe82528bcd0f976fd9ce2122c516b2d (patch) | |
tree | d16b02a2b0b6514034d9642b47f91b662c46e765 | |
parent | 3f165fa5b3b38fa4b321be94a97f06927f636fb1 (diff) | |
download | busybox-w32-9f153f610fe82528bcd0f976fd9ce2122c516b2d.tar.gz busybox-w32-9f153f610fe82528bcd0f976fd9ce2122c516b2d.tar.bz2 busybox-w32-9f153f610fe82528bcd0f976fd9ce2122c516b2d.zip |
fsck_minix: getopt32-ification; code shrink; reduce stack usage;
fix bug in map_block2: s/(blknr >= 256 * 256)/(blknr < 256 * 256)/
function old new delta
get_inode_common - 291 +291
add_zone_common - 205 +205
ask 229 215 -14
write_super_block 109 90 -19
write_block 653 629 -24
bad_zone 95 64 -31
read_block 241 198 -43
fsck_minix_main 3285 3195 -90
add_zone2 217 34 -183
add_zone 216 33 -183
recursive_check 1097 866 -231
recursive_check2 1340 956 -384
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/10 up/down: 496/-1202) Total: -706 bytes
text data bss dec hex filename
799349 661 7428 807438 c520e busybox_old
798437 661 7428 806526 c4e7e busybox_unstripped
-rw-r--r-- | archival/libunarchive/filter_accept_reject_list.c | 7 | ||||
-rw-r--r-- | archival/libunarchive/find_list_entry.c | 2 | ||||
-rw-r--r-- | util-linux/fsck_minix.c | 354 |
3 files changed, 139 insertions, 224 deletions
diff --git a/archival/libunarchive/filter_accept_reject_list.c b/archival/libunarchive/filter_accept_reject_list.c index bf983b5e8..439ba20ca 100644 --- a/archival/libunarchive/filter_accept_reject_list.c +++ b/archival/libunarchive/filter_accept_reject_list.c | |||
@@ -13,11 +13,14 @@ | |||
13 | */ | 13 | */ |
14 | char filter_accept_reject_list(archive_handle_t *archive_handle) | 14 | char filter_accept_reject_list(archive_handle_t *archive_handle) |
15 | { | 15 | { |
16 | const char *key = archive_handle->file_header->name; | 16 | const char *key; |
17 | const llist_t *reject_entry = find_list_entry2(archive_handle->reject, key); | 17 | const llist_t *reject_entry; |
18 | const llist_t *accept_entry; | 18 | const llist_t *accept_entry; |
19 | 19 | ||
20 | key = archive_handle->file_header->name; | ||
21 | |||
20 | /* If the key is in a reject list fail */ | 22 | /* If the key is in a reject list fail */ |
23 | reject_entry = find_list_entry2(archive_handle->reject, key); | ||
21 | if (reject_entry) { | 24 | if (reject_entry) { |
22 | return EXIT_FAILURE; | 25 | return EXIT_FAILURE; |
23 | } | 26 | } |
diff --git a/archival/libunarchive/find_list_entry.c b/archival/libunarchive/find_list_entry.c index f2741039d..754058953 100644 --- a/archival/libunarchive/find_list_entry.c +++ b/archival/libunarchive/find_list_entry.c | |||
@@ -38,7 +38,7 @@ const llist_t *find_list_entry2(const llist_t *list, const char *filename) | |||
38 | if (*c++ == '/') pattern_slash_cnt++; | 38 | if (*c++ == '/') pattern_slash_cnt++; |
39 | c = filename; | 39 | c = filename; |
40 | d = buf; | 40 | d = buf; |
41 | /* paranoia is better that buffer overflows */ | 41 | /* paranoia is better than buffer overflows */ |
42 | while (*c && d != buf + sizeof(buf)-1) { | 42 | while (*c && d != buf + sizeof(buf)-1) { |
43 | if (*c == '/' && --pattern_slash_cnt < 0) | 43 | if (*c == '/' && --pattern_slash_cnt < 0) |
44 | break; | 44 | break; |
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 62e4f08b6..63f915ac5 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c | |||
@@ -95,6 +95,13 @@ | |||
95 | #define BLKGETSIZE _IO(0x12,96) /* return device size */ | 95 | #define BLKGETSIZE _IO(0x12,96) /* return device size */ |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | struct BUG_bad_inode_size { | ||
99 | char BUG_bad_inode1_size[(INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE) ? -1 : 1]; | ||
100 | #if ENABLE_FEATURE_MINIX2 | ||
101 | char BUG_bad_inode2_size[(INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) ? -1 : 1]; | ||
102 | #endif | ||
103 | }; | ||
104 | |||
98 | enum { | 105 | enum { |
99 | #ifdef UNUSED | 106 | #ifdef UNUSED |
100 | MINIX1_LINK_MAX = 250, | 107 | MINIX1_LINK_MAX = 250, |
@@ -107,6 +114,7 @@ enum { | |||
107 | MINIX_NAME_MAX = 255, /* # chars in a file name */ | 114 | MINIX_NAME_MAX = 255, /* # chars in a file name */ |
108 | }; | 115 | }; |
109 | 116 | ||
117 | |||
110 | #if !ENABLE_FEATURE_MINIX2 | 118 | #if !ENABLE_FEATURE_MINIX2 |
111 | enum { version2 = 0 }; | 119 | enum { version2 = 0 }; |
112 | #endif | 120 | #endif |
@@ -118,13 +126,12 @@ struct globals { | |||
118 | #if ENABLE_FEATURE_MINIX2 | 126 | #if ENABLE_FEATURE_MINIX2 |
119 | smallint version2; | 127 | smallint version2; |
120 | #endif | 128 | #endif |
121 | smallint repair, automatic, verbose, list, show, warn_mode, force; | ||
122 | smallint changed; /* is filesystem modified? */ | 129 | smallint changed; /* is filesystem modified? */ |
123 | smallint errors_uncorrected; /* flag if some error was not corrected */ | 130 | smallint errors_uncorrected; /* flag if some error was not corrected */ |
124 | smallint termios_set; | 131 | smallint termios_set; |
125 | smallint dirsize; | 132 | smallint dirsize; |
126 | smallint namelen; | 133 | smallint namelen; |
127 | char *device_name; | 134 | const char *device_name; |
128 | int directory, regular, blockdev, chardev, links, symlinks, total; | 135 | int directory, regular, blockdev, chardev, links, symlinks, total; |
129 | char *inode_buffer; | 136 | char *inode_buffer; |
130 | 137 | ||
@@ -155,13 +162,6 @@ struct globals { | |||
155 | #if ENABLE_FEATURE_MINIX2 | 162 | #if ENABLE_FEATURE_MINIX2 |
156 | #define version2 (G.version2 ) | 163 | #define version2 (G.version2 ) |
157 | #endif | 164 | #endif |
158 | #define repair (G.repair ) | ||
159 | #define automatic (G.automatic ) | ||
160 | #define verbose (G.verbose ) | ||
161 | #define list (G.list ) | ||
162 | #define show (G.show ) | ||
163 | #define warn_mode (G.warn_mode ) | ||
164 | #define force (G.force ) | ||
165 | #define changed (G.changed ) | 165 | #define changed (G.changed ) |
166 | #define errors_uncorrected (G.errors_uncorrected ) | 166 | #define errors_uncorrected (G.errors_uncorrected ) |
167 | #define termios_set (G.termios_set ) | 167 | #define termios_set (G.termios_set ) |
@@ -198,6 +198,28 @@ struct globals { | |||
198 | name_component[0] = ¤t_name[0]; \ | 198 | name_component[0] = ¤t_name[0]; \ |
199 | } while (0) | 199 | } while (0) |
200 | 200 | ||
201 | |||
202 | #define OPTION_STR "larvsmf" | ||
203 | enum { | ||
204 | OPT_l = (1 << 0), | ||
205 | OPT_a = (1 << 1), | ||
206 | OPT_r = (1 << 2), | ||
207 | OPT_v = (1 << 3), | ||
208 | OPT_s = (1 << 4), | ||
209 | OPT_w = (1 << 5), | ||
210 | OPT_f = (1 << 6), | ||
211 | }; | ||
212 | #define OPT_list (option_mask32 & OPT_l) | ||
213 | #define OPT_automatic (option_mask32 & OPT_a) | ||
214 | #define OPT_repair (option_mask32 & OPT_r) | ||
215 | #define OPT_verbose (option_mask32 & OPT_v) | ||
216 | #define OPT_show (option_mask32 & OPT_s) | ||
217 | #define OPT_warn_mode (option_mask32 & OPT_w) | ||
218 | #define OPT_force (option_mask32 & OPT_f) | ||
219 | /* non-automatic repairs requested? */ | ||
220 | #define OPT_manual ((option_mask32 & (OPT_a|OPT_r)) == OPT_r) | ||
221 | |||
222 | |||
201 | #define Inode1 (((struct minix1_inode *) inode_buffer)-1) | 223 | #define Inode1 (((struct minix1_inode *) inode_buffer)-1) |
202 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) | 224 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) |
203 | 225 | ||
@@ -306,12 +328,12 @@ static int ask(const char *string, int def) | |||
306 | { | 328 | { |
307 | int c; | 329 | int c; |
308 | 330 | ||
309 | if (!repair) { | 331 | if (!OPT_repair) { |
310 | bb_putchar('\n'); | 332 | bb_putchar('\n'); |
311 | errors_uncorrected = 1; | 333 | errors_uncorrected = 1; |
312 | return 0; | 334 | return 0; |
313 | } | 335 | } |
314 | if (automatic) { | 336 | if (OPT_automatic) { |
315 | bb_putchar('\n'); | 337 | bb_putchar('\n'); |
316 | if (!def) | 338 | if (!def) |
317 | errors_uncorrected = 1; | 339 | errors_uncorrected = 1; |
@@ -423,20 +445,16 @@ static int check_zone_nr(uint16_t *nr, smallint *corrected) | |||
423 | /* | 445 | /* |
424 | * read-block reads block nr into the buffer at addr. | 446 | * read-block reads block nr into the buffer at addr. |
425 | */ | 447 | */ |
426 | static void read_block(unsigned nr, char *addr) | 448 | static void read_block(unsigned nr, void *addr) |
427 | { | 449 | { |
428 | if (!nr) { | 450 | if (!nr) { |
429 | memset(addr, 0, BLOCK_SIZE); | 451 | memset(addr, 0, BLOCK_SIZE); |
430 | return; | 452 | return; |
431 | } | 453 | } |
432 | if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET)) { | 454 | xlseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET); |
433 | printf("%s: cannot seek to block in file '%s'\n", | 455 | if (BLOCK_SIZE != full_read(dev_fd, addr, BLOCK_SIZE)) { |
434 | bb_msg_read_error, current_name); | 456 | printf("%s: bad block %u in file '%s'\n", |
435 | errors_uncorrected = 1; | 457 | bb_msg_read_error, nr, current_name); |
436 | memset(addr, 0, BLOCK_SIZE); | ||
437 | } else if (BLOCK_SIZE != read(dev_fd, addr, BLOCK_SIZE)) { | ||
438 | printf("%s: bad block in file '%s'\n", | ||
439 | bb_msg_read_error, current_name); | ||
440 | errors_uncorrected = 1; | 458 | errors_uncorrected = 1; |
441 | memset(addr, 0, BLOCK_SIZE); | 459 | memset(addr, 0, BLOCK_SIZE); |
442 | } | 460 | } |
@@ -445,7 +463,7 @@ static void read_block(unsigned nr, char *addr) | |||
445 | /* | 463 | /* |
446 | * write_block writes block nr to disk. | 464 | * write_block writes block nr to disk. |
447 | */ | 465 | */ |
448 | static void write_block(unsigned nr, char *addr) | 466 | static void write_block(unsigned nr, void *addr) |
449 | { | 467 | { |
450 | if (!nr) | 468 | if (!nr) |
451 | return; | 469 | return; |
@@ -455,11 +473,10 @@ static void write_block(unsigned nr, char *addr) | |||
455 | errors_uncorrected = 1; | 473 | errors_uncorrected = 1; |
456 | return; | 474 | return; |
457 | } | 475 | } |
458 | if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET)) | 476 | xlseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET); |
459 | die("seek failed in write_block"); | 477 | if (BLOCK_SIZE != full_write(dev_fd, addr, BLOCK_SIZE)) { |
460 | if (BLOCK_SIZE != write(dev_fd, addr, BLOCK_SIZE)) { | 478 | printf("%s: bad block %u in file '%s'\n", |
461 | printf("%s: bad block in file '%s'\n", | 479 | bb_msg_write_error, nr, current_name); |
462 | bb_msg_write_error, current_name); | ||
463 | errors_uncorrected = 1; | 480 | errors_uncorrected = 1; |
464 | } | 481 | } |
465 | } | 482 | } |
@@ -472,7 +489,6 @@ static void write_block(unsigned nr, char *addr) | |||
472 | static int map_block(struct minix1_inode *inode, unsigned blknr) | 489 | static int map_block(struct minix1_inode *inode, unsigned blknr) |
473 | { | 490 | { |
474 | uint16_t ind[BLOCK_SIZE >> 1]; | 491 | uint16_t ind[BLOCK_SIZE >> 1]; |
475 | uint16_t dind[BLOCK_SIZE >> 1]; | ||
476 | int block, result; | 492 | int block, result; |
477 | smallint blk_chg; | 493 | smallint blk_chg; |
478 | 494 | ||
@@ -481,26 +497,22 @@ static int map_block(struct minix1_inode *inode, unsigned blknr) | |||
481 | blknr -= 7; | 497 | blknr -= 7; |
482 | if (blknr < 512) { | 498 | if (blknr < 512) { |
483 | block = check_zone_nr(inode->i_zone + 7, &changed); | 499 | block = check_zone_nr(inode->i_zone + 7, &changed); |
484 | read_block(block, (char *) ind); | 500 | goto common; |
485 | blk_chg = 0; | ||
486 | result = check_zone_nr(blknr + ind, &blk_chg); | ||
487 | if (blk_chg) | ||
488 | write_block(block, (char *) ind); | ||
489 | return result; | ||
490 | } | 501 | } |
491 | blknr -= 512; | 502 | blknr -= 512; |
492 | block = check_zone_nr(inode->i_zone + 8, &changed); | 503 | block = check_zone_nr(inode->i_zone + 8, &changed); |
493 | read_block(block, (char *) dind); | 504 | read_block(block, ind); /* double indirect */ |
494 | blk_chg = 0; | 505 | blk_chg = 0; |
495 | result = check_zone_nr(dind + (blknr / 512), &blk_chg); | 506 | result = check_zone_nr(&ind[blknr / 512], &blk_chg); |
496 | if (blk_chg) | 507 | if (blk_chg) |
497 | write_block(block, (char *) dind); | 508 | write_block(block, ind); |
498 | block = result; | 509 | block = result; |
499 | read_block(block, (char *) ind); | 510 | common: |
511 | read_block(block, ind); | ||
500 | blk_chg = 0; | 512 | blk_chg = 0; |
501 | result = check_zone_nr(ind + (blknr % 512), &blk_chg); | 513 | result = check_zone_nr(&ind[blknr % 512], &blk_chg); |
502 | if (blk_chg) | 514 | if (blk_chg) |
503 | write_block(block, (char *) ind); | 515 | write_block(block, ind); |
504 | return result; | 516 | return result; |
505 | } | 517 | } |
506 | 518 | ||
@@ -508,8 +520,6 @@ static int map_block(struct minix1_inode *inode, unsigned blknr) | |||
508 | static int map_block2(struct minix2_inode *inode, unsigned blknr) | 520 | static int map_block2(struct minix2_inode *inode, unsigned blknr) |
509 | { | 521 | { |
510 | uint32_t ind[BLOCK_SIZE >> 2]; | 522 | uint32_t ind[BLOCK_SIZE >> 2]; |
511 | uint32_t dind[BLOCK_SIZE >> 2]; | ||
512 | uint32_t tind[BLOCK_SIZE >> 2]; | ||
513 | int block, result; | 523 | int block, result; |
514 | smallint blk_chg; | 524 | smallint blk_chg; |
515 | 525 | ||
@@ -518,48 +528,34 @@ static int map_block2(struct minix2_inode *inode, unsigned blknr) | |||
518 | blknr -= 7; | 528 | blknr -= 7; |
519 | if (blknr < 256) { | 529 | if (blknr < 256) { |
520 | block = check_zone_nr2(inode->i_zone + 7, &changed); | 530 | block = check_zone_nr2(inode->i_zone + 7, &changed); |
521 | read_block(block, (char *) ind); | 531 | goto common2; |
522 | blk_chg = 0; | ||
523 | result = check_zone_nr2(blknr + ind, &blk_chg); | ||
524 | if (blk_chg) | ||
525 | write_block(block, (char *) ind); | ||
526 | return result; | ||
527 | } | 532 | } |
528 | blknr -= 256; | 533 | blknr -= 256; |
529 | if (blknr >= 256 * 256) { | 534 | if (blknr < 256 * 256) { |
530 | block = check_zone_nr2(inode->i_zone + 8, &changed); | 535 | block = check_zone_nr2(inode->i_zone + 8, &changed); |
531 | read_block(block, (char *) dind); | 536 | goto common1; |
532 | blk_chg = 0; | ||
533 | result = check_zone_nr2(dind + blknr / 256, &blk_chg); | ||
534 | if (blk_chg) | ||
535 | write_block(block, (char *) dind); | ||
536 | block = result; | ||
537 | read_block(block, (char *) ind); | ||
538 | blk_chg = 0; | ||
539 | result = check_zone_nr2(ind + blknr % 256, &blk_chg); | ||
540 | if (blk_chg) | ||
541 | write_block(block, (char *) ind); | ||
542 | return result; | ||
543 | } | 537 | } |
544 | blknr -= 256 * 256; | 538 | blknr -= 256 * 256; |
545 | block = check_zone_nr2(inode->i_zone + 9, &changed); | 539 | block = check_zone_nr2(inode->i_zone + 9, &changed); |
546 | read_block(block, (char *) tind); | 540 | read_block(block, ind); /* triple indirect */ |
547 | blk_chg = 0; | 541 | blk_chg = 0; |
548 | result = check_zone_nr2(tind + blknr / (256 * 256), &blk_chg); | 542 | result = check_zone_nr2(&ind[blknr / (256 * 256)], &blk_chg); |
549 | if (blk_chg) | 543 | if (blk_chg) |
550 | write_block(block, (char *) tind); | 544 | write_block(block, ind); |
551 | block = result; | 545 | block = result; |
552 | read_block(block, (char *) dind); | 546 | common1: |
547 | read_block(block, ind); /* double indirect */ | ||
553 | blk_chg = 0; | 548 | blk_chg = 0; |
554 | result = check_zone_nr2(dind + (blknr / 256) % 256, &blk_chg); | 549 | result = check_zone_nr2(&ind[(blknr / 256) % 256], &blk_chg); |
555 | if (blk_chg) | 550 | if (blk_chg) |
556 | write_block(block, (char *) dind); | 551 | write_block(block, ind); |
557 | block = result; | 552 | block = result; |
558 | read_block(block, (char *) ind); | 553 | common2: |
554 | read_block(block, ind); | ||
559 | blk_chg = 0; | 555 | blk_chg = 0; |
560 | result = check_zone_nr2(ind + blknr % 256, &blk_chg); | 556 | result = check_zone_nr2(&ind[blknr % 256], &blk_chg); |
561 | if (blk_chg) | 557 | if (blk_chg) |
562 | write_block(block, (char *) ind); | 558 | write_block(block, ind); |
563 | return result; | 559 | return result; |
564 | } | 560 | } |
565 | #endif | 561 | #endif |
@@ -575,9 +571,8 @@ static void write_super_block(void) | |||
575 | if (!errors_uncorrected) | 571 | if (!errors_uncorrected) |
576 | Super.s_state &= ~MINIX_ERROR_FS; | 572 | Super.s_state &= ~MINIX_ERROR_FS; |
577 | 573 | ||
578 | if (BLOCK_SIZE != lseek(dev_fd, BLOCK_SIZE, SEEK_SET)) | 574 | xlseek(dev_fd, BLOCK_SIZE, SEEK_SET); |
579 | die("seek failed in write_super_block"); | 575 | if (BLOCK_SIZE != full_write(dev_fd, super_block_buffer, BLOCK_SIZE)) |
580 | if (BLOCK_SIZE != write(dev_fd, super_block_buffer, BLOCK_SIZE)) | ||
581 | die("cannot write super-block"); | 576 | die("cannot write super-block"); |
582 | } | 577 | } |
583 | 578 | ||
@@ -618,9 +613,8 @@ static void get_dirsize(void) | |||
618 | 613 | ||
619 | static void read_superblock(void) | 614 | static void read_superblock(void) |
620 | { | 615 | { |
621 | if (BLOCK_SIZE != lseek(dev_fd, BLOCK_SIZE, SEEK_SET)) | 616 | xlseek(dev_fd, BLOCK_SIZE, SEEK_SET); |
622 | die("seek failed"); | 617 | if (BLOCK_SIZE != full_read(dev_fd, super_block_buffer, BLOCK_SIZE)) |
623 | if (BLOCK_SIZE != read(dev_fd, super_block_buffer, BLOCK_SIZE)) | ||
624 | die("cannot read super block"); | 618 | die("cannot read super block"); |
625 | /* already initialized to: | 619 | /* already initialized to: |
626 | namelen = 14; | 620 | namelen = 14; |
@@ -667,7 +661,7 @@ static void read_tables(void) | |||
667 | errors_uncorrected = 1; | 661 | errors_uncorrected = 1; |
668 | } | 662 | } |
669 | get_dirsize(); | 663 | get_dirsize(); |
670 | if (show) { | 664 | if (OPT_show) { |
671 | printf("%u inodes\n" | 665 | printf("%u inodes\n" |
672 | "%u blocks\n" | 666 | "%u blocks\n" |
673 | "Firstdatazone=%u (%u)\n" | 667 | "Firstdatazone=%u (%u)\n" |
@@ -685,41 +679,35 @@ static void read_tables(void) | |||
685 | } | 679 | } |
686 | } | 680 | } |
687 | 681 | ||
688 | static struct minix1_inode *get_inode(unsigned nr) | 682 | static void get_inode_common(unsigned nr, uint16_t i_mode) |
689 | { | 683 | { |
690 | struct minix1_inode *inode; | ||
691 | |||
692 | if (!nr || nr > INODES) | ||
693 | return NULL; | ||
694 | total++; | 684 | total++; |
695 | inode = Inode1 + nr; | ||
696 | if (!inode_count[nr]) { | 685 | if (!inode_count[nr]) { |
697 | if (!inode_in_use(nr)) { | 686 | if (!inode_in_use(nr)) { |
698 | printf("Inode %d is marked as 'unused', but it is used " | 687 | printf("Inode %d is marked as 'unused', but it is used " |
699 | "for file '%s'\n", nr, current_name); | 688 | "for file '%s'\n", nr, current_name); |
700 | if (repair) { | 689 | if (OPT_repair) { |
701 | if (ask("Mark as 'in use'", 1)) | 690 | if (ask("Mark as 'in use'", 1)) |
702 | mark_inode(nr); | 691 | mark_inode(nr); |
703 | else | 692 | else |
704 | errors_uncorrected = 1; | 693 | errors_uncorrected = 1; |
705 | } | 694 | } |
706 | } | 695 | } |
707 | if (S_ISDIR(inode->i_mode)) | 696 | if (S_ISDIR(i_mode)) |
708 | directory++; | 697 | directory++; |
709 | else if (S_ISREG(inode->i_mode)) | 698 | else if (S_ISREG(i_mode)) |
710 | regular++; | 699 | regular++; |
711 | else if (S_ISCHR(inode->i_mode)) | 700 | else if (S_ISCHR(i_mode)) |
712 | chardev++; | 701 | chardev++; |
713 | else if (S_ISBLK(inode->i_mode)) | 702 | else if (S_ISBLK(i_mode)) |
714 | blockdev++; | 703 | blockdev++; |
715 | else if (S_ISLNK(inode->i_mode)) | 704 | else if (S_ISLNK(i_mode)) |
716 | symlinks++; | 705 | symlinks++; |
717 | else if (S_ISSOCK(inode->i_mode)); | 706 | else if (S_ISSOCK(i_mode)); |
718 | else if (S_ISFIFO(inode->i_mode)); | 707 | else if (S_ISFIFO(i_mode)); |
719 | else { | 708 | else { |
720 | printf("%s has mode %05o\n", current_name, inode->i_mode); | 709 | printf("%s has mode %05o\n", current_name, i_mode); |
721 | } | 710 | } |
722 | |||
723 | } else | 711 | } else |
724 | links++; | 712 | links++; |
725 | if (!++inode_count[nr]) { | 713 | if (!++inode_count[nr]) { |
@@ -727,6 +715,16 @@ static struct minix1_inode *get_inode(unsigned nr) | |||
727 | inode_count[nr]--; | 715 | inode_count[nr]--; |
728 | errors_uncorrected = 1; | 716 | errors_uncorrected = 1; |
729 | } | 717 | } |
718 | } | ||
719 | |||
720 | static struct minix1_inode *get_inode(unsigned nr) | ||
721 | { | ||
722 | struct minix1_inode *inode; | ||
723 | |||
724 | if (!nr || nr > INODES) | ||
725 | return NULL; | ||
726 | inode = Inode1 + nr; | ||
727 | get_inode_common(nr, inode->i_mode); | ||
730 | return inode; | 728 | return inode; |
731 | } | 729 | } |
732 | 730 | ||
@@ -737,41 +735,8 @@ static struct minix2_inode *get_inode2(unsigned nr) | |||
737 | 735 | ||
738 | if (!nr || nr > INODES) | 736 | if (!nr || nr > INODES) |
739 | return NULL; | 737 | return NULL; |
740 | total++; | ||
741 | inode = Inode2 + nr; | 738 | inode = Inode2 + nr; |
742 | if (!inode_count[nr]) { | 739 | get_inode_common(nr, inode->i_mode); |
743 | if (!inode_in_use(nr)) { | ||
744 | printf("Inode %d is marked as 'unused', but it is used " | ||
745 | "for file '%s'\n", nr, current_name); | ||
746 | if (repair) { | ||
747 | if (ask("Mark as 'in use'", 1)) | ||
748 | mark_inode(nr); | ||
749 | else | ||
750 | errors_uncorrected = 1; | ||
751 | } | ||
752 | } | ||
753 | if (S_ISDIR(inode->i_mode)) | ||
754 | directory++; | ||
755 | else if (S_ISREG(inode->i_mode)) | ||
756 | regular++; | ||
757 | else if (S_ISCHR(inode->i_mode)) | ||
758 | chardev++; | ||
759 | else if (S_ISBLK(inode->i_mode)) | ||
760 | blockdev++; | ||
761 | else if (S_ISLNK(inode->i_mode)) | ||
762 | symlinks++; | ||
763 | else if (S_ISSOCK(inode->i_mode)); | ||
764 | else if (S_ISFIFO(inode->i_mode)); | ||
765 | else { | ||
766 | printf("%s has mode %05o\n", current_name, inode->i_mode); | ||
767 | } | ||
768 | } else | ||
769 | links++; | ||
770 | if (!++inode_count[nr]) { | ||
771 | printf("Warning: inode count too big\n"); | ||
772 | inode_count[nr]--; | ||
773 | errors_uncorrected = 1; | ||
774 | } | ||
775 | return inode; | 740 | return inode; |
776 | } | 741 | } |
777 | #endif | 742 | #endif |
@@ -796,23 +761,17 @@ static void check_root2(void) | |||
796 | void check_root2(void); | 761 | void check_root2(void); |
797 | #endif | 762 | #endif |
798 | 763 | ||
799 | static int add_zone(uint16_t *znr, smallint *corrected) | 764 | static int add_zone_common(int block, smallint *corrected) |
800 | { | 765 | { |
801 | int result; | ||
802 | int block; | ||
803 | |||
804 | result = 0; | ||
805 | block = check_zone_nr(znr, corrected); | ||
806 | if (!block) | 766 | if (!block) |
807 | return 0; | 767 | return 0; |
808 | if (zone_count[block]) { | 768 | if (zone_count[block]) { |
809 | printf("Already used block is reused in file '%s'. ", | 769 | printf("Already used block is reused in file '%s'. ", |
810 | current_name); | 770 | current_name); |
811 | if (ask("Clear", 1)) { | 771 | if (ask("Clear", 1)) { |
812 | *znr = 0; | ||
813 | block = 0; | 772 | block = 0; |
814 | *corrected = 1; | 773 | *corrected = 1; |
815 | return 0; | 774 | return -1; /* "please zero out *znr" */ |
816 | } | 775 | } |
817 | } | 776 | } |
818 | if (!zone_in_use(block)) { | 777 | if (!zone_in_use(block)) { |
@@ -826,34 +785,30 @@ static int add_zone(uint16_t *znr, smallint *corrected) | |||
826 | return block; | 785 | return block; |
827 | } | 786 | } |
828 | 787 | ||
788 | static int add_zone(uint16_t *znr, smallint *corrected) | ||
789 | { | ||
790 | int block; | ||
791 | |||
792 | block = check_zone_nr(znr, corrected); | ||
793 | block = add_zone_common(block, corrected); | ||
794 | if (block == -1) { | ||
795 | *znr = 0; | ||
796 | block = 0; | ||
797 | } | ||
798 | return block; | ||
799 | } | ||
800 | |||
829 | #if ENABLE_FEATURE_MINIX2 | 801 | #if ENABLE_FEATURE_MINIX2 |
830 | static int add_zone2(uint32_t *znr, smallint *corrected) | 802 | static int add_zone2(uint32_t *znr, smallint *corrected) |
831 | { | 803 | { |
832 | int result; | ||
833 | int block; | 804 | int block; |
834 | 805 | ||
835 | result = 0; | ||
836 | block = check_zone_nr2(znr, corrected); | 806 | block = check_zone_nr2(znr, corrected); |
837 | if (!block) | 807 | block = add_zone_common(block, corrected); |
838 | return 0; | 808 | if (block == -1) { |
839 | if (zone_count[block]) { | 809 | *znr = 0; |
840 | printf("Already used block is reused in file '%s'. ", | 810 | block = 0; |
841 | current_name); | ||
842 | if (ask("Clear", 1)) { | ||
843 | *znr = 0; | ||
844 | block = 0; | ||
845 | *corrected = 1; | ||
846 | return 0; | ||
847 | } | ||
848 | } | ||
849 | if (!zone_in_use(block)) { | ||
850 | printf("Block %d in file '%s' is marked as 'unused'. ", | ||
851 | block, current_name); | ||
852 | if (ask("Correct", 1)) | ||
853 | mark_zone(block); | ||
854 | } | 811 | } |
855 | if (!++zone_count[block]) | ||
856 | zone_count[block]--; | ||
857 | return block; | 812 | return block; |
858 | } | 813 | } |
859 | #endif | 814 | #endif |
@@ -1018,8 +973,8 @@ static void check_file(struct minix1_inode *dir, unsigned offset) | |||
1018 | if (!inode) | 973 | if (!inode) |
1019 | return; | 974 | return; |
1020 | push_filename(name); | 975 | push_filename(name); |
1021 | if (list) { | 976 | if (OPT_list) { |
1022 | if (verbose) | 977 | if (OPT_verbose) |
1023 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); | 978 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); |
1024 | printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : ""); | 979 | printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : ""); |
1025 | } | 980 | } |
@@ -1068,8 +1023,8 @@ static void check_file2(struct minix2_inode *dir, unsigned offset) | |||
1068 | if (!inode) | 1023 | if (!inode) |
1069 | return; | 1024 | return; |
1070 | push_filename(name); | 1025 | push_filename(name); |
1071 | if (list) { | 1026 | if (OPT_list) { |
1072 | if (verbose) | 1027 | if (OPT_verbose) |
1073 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); | 1028 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); |
1074 | printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : ""); | 1029 | printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : ""); |
1075 | } | 1030 | } |
@@ -1118,9 +1073,8 @@ static int bad_zone(int i) | |||
1118 | { | 1073 | { |
1119 | char buffer[BLOCK_SIZE]; | 1074 | char buffer[BLOCK_SIZE]; |
1120 | 1075 | ||
1121 | if (BLOCK_SIZE * i != lseek(dev_fd, BLOCK_SIZE * i, SEEK_SET)) | 1076 | xlseek(dev_fd, BLOCK_SIZE * i, SEEK_SET); |
1122 | die("seek failed in bad_zone"); | 1077 | return (BLOCK_SIZE != full_read(dev_fd, buffer, BLOCK_SIZE)); |
1123 | return (BLOCK_SIZE != read(dev_fd, buffer, BLOCK_SIZE)); | ||
1124 | } | 1078 | } |
1125 | 1079 | ||
1126 | static void check_counts(void) | 1080 | static void check_counts(void) |
@@ -1128,7 +1082,7 @@ static void check_counts(void) | |||
1128 | int i; | 1082 | int i; |
1129 | 1083 | ||
1130 | for (i = 1; i <= INODES; i++) { | 1084 | for (i = 1; i <= INODES; i++) { |
1131 | if (warn_mode && Inode1[i].i_mode && !inode_in_use(i)) { | 1085 | if (OPT_warn_mode && Inode1[i].i_mode && !inode_in_use(i)) { |
1132 | printf("Inode %d has non-zero mode. ", i); | 1086 | printf("Inode %d has non-zero mode. ", i); |
1133 | if (ask("Clear", 1)) { | 1087 | if (ask("Clear", 1)) { |
1134 | Inode1[i].i_mode = 0; | 1088 | Inode1[i].i_mode = 0; |
@@ -1180,7 +1134,7 @@ static void check_counts2(void) | |||
1180 | int i; | 1134 | int i; |
1181 | 1135 | ||
1182 | for (i = 1; i <= INODES; i++) { | 1136 | for (i = 1; i <= INODES; i++) { |
1183 | if (warn_mode && Inode2[i].i_mode && !inode_in_use(i)) { | 1137 | if (OPT_warn_mode && Inode2[i].i_mode && !inode_in_use(i)) { |
1184 | printf("Inode %d has non-zero mode. ", i); | 1138 | printf("Inode %d has non-zero mode. ", i); |
1185 | if (ask("Clear", 1)) { | 1139 | if (ask("Clear", 1)) { |
1186 | Inode2[i].i_mode = 0; | 1140 | Inode2[i].i_mode = 0; |
@@ -1259,59 +1213,17 @@ int fsck_minix_main(int argc, char **argv) | |||
1259 | 1213 | ||
1260 | INIT_G(); | 1214 | INIT_G(); |
1261 | 1215 | ||
1262 | if (INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE) | 1216 | opt_complementary = "=1:ar"; /* one argument; -a assumes -r */ |
1263 | die("bad inode size"); | 1217 | getopt32(argv, OPTION_STR); |
1264 | #if ENABLE_FEATURE_MINIX2 | 1218 | argv += optind; |
1265 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) | 1219 | device_name = argv[0]; |
1266 | die("bad v2 inode size"); | ||
1267 | #endif | ||
1268 | while (--argc != 0) { | ||
1269 | argv++; | ||
1270 | if (argv[0][0] != '-') { | ||
1271 | if (device_name) | ||
1272 | bb_show_usage(); | ||
1273 | device_name = argv[0]; | ||
1274 | } else { | ||
1275 | while (*++argv[0]) { | ||
1276 | switch (argv[0][0]) { | ||
1277 | case 'l': | ||
1278 | list = 1; | ||
1279 | break; | ||
1280 | case 'a': | ||
1281 | automatic = 1; | ||
1282 | repair = 1; | ||
1283 | break; | ||
1284 | case 'r': | ||
1285 | automatic = 0; | ||
1286 | repair = 1; | ||
1287 | break; | ||
1288 | case 'v': | ||
1289 | verbose = 1; | ||
1290 | break; | ||
1291 | case 's': | ||
1292 | show = 1; | ||
1293 | break; | ||
1294 | case 'm': | ||
1295 | warn_mode = 1; | ||
1296 | break; | ||
1297 | case 'f': | ||
1298 | force = 1; | ||
1299 | break; | ||
1300 | default: | ||
1301 | bb_show_usage(); | ||
1302 | } | ||
1303 | } | ||
1304 | } | ||
1305 | } | ||
1306 | if (!device_name) | ||
1307 | bb_show_usage(); | ||
1308 | 1220 | ||
1309 | check_mount(); /* trying to check a mounted filesystem? */ | 1221 | check_mount(); /* trying to check a mounted filesystem? */ |
1310 | if (repair && !automatic) { | 1222 | if (OPT_manual) { |
1311 | if (!isatty(0) || !isatty(1)) | 1223 | if (!isatty(0) || !isatty(1)) |
1312 | die("need terminal for interactive repairs"); | 1224 | die("need terminal for interactive repairs"); |
1313 | } | 1225 | } |
1314 | dev_fd = xopen(device_name, repair ? O_RDWR : O_RDONLY); | 1226 | dev_fd = xopen(device_name, OPT_repair ? O_RDWR : O_RDONLY); |
1315 | 1227 | ||
1316 | /*sync(); paranoia? */ | 1228 | /*sync(); paranoia? */ |
1317 | read_superblock(); | 1229 | read_superblock(); |
@@ -1325,20 +1237,20 @@ int fsck_minix_main(int argc, char **argv) | |||
1325 | printf("%s: %s\n", applet_name, bb_banner); | 1237 | printf("%s: %s\n", applet_name, bb_banner); |
1326 | 1238 | ||
1327 | if (!(Super.s_state & MINIX_ERROR_FS) | 1239 | if (!(Super.s_state & MINIX_ERROR_FS) |
1328 | && (Super.s_state & MINIX_VALID_FS) && !force | 1240 | && (Super.s_state & MINIX_VALID_FS) && !OPT_force |
1329 | ) { | 1241 | ) { |
1330 | if (repair) | 1242 | if (OPT_repair) |
1331 | printf("%s is clean, check is skipped\n", device_name); | 1243 | printf("%s is clean, check is skipped\n", device_name); |
1332 | return 0; | 1244 | return 0; |
1333 | } else if (force) | 1245 | } else if (OPT_force) |
1334 | printf("Forcing filesystem check on %s\n", device_name); | 1246 | printf("Forcing filesystem check on %s\n", device_name); |
1335 | else if (repair) | 1247 | else if (OPT_repair) |
1336 | printf("Filesystem on %s is dirty, needs checking\n", | 1248 | printf("Filesystem on %s is dirty, needs checking\n", |
1337 | device_name); | 1249 | device_name); |
1338 | 1250 | ||
1339 | read_tables(); | 1251 | read_tables(); |
1340 | 1252 | ||
1341 | if (repair && !automatic) { | 1253 | if (OPT_manual) { |
1342 | tcgetattr(0, &sv_termios); | 1254 | tcgetattr(0, &sv_termios); |
1343 | tmp = sv_termios; | 1255 | tmp = sv_termios; |
1344 | tmp.c_lflag &= ~(ICANON | ECHO); | 1256 | tmp.c_lflag &= ~(ICANON | ECHO); |
@@ -1354,7 +1266,7 @@ int fsck_minix_main(int argc, char **argv) | |||
1354 | check(); | 1266 | check(); |
1355 | } | 1267 | } |
1356 | 1268 | ||
1357 | if (verbose) { | 1269 | if (OPT_verbose) { |
1358 | int i, free_cnt; | 1270 | int i, free_cnt; |
1359 | 1271 | ||
1360 | for (i = 1, free_cnt = 0; i <= INODES; i++) | 1272 | for (i = 1, free_cnt = 0; i <= INODES; i++) |
@@ -1383,10 +1295,10 @@ int fsck_minix_main(int argc, char **argv) | |||
1383 | write_tables(); | 1295 | write_tables(); |
1384 | printf("FILE SYSTEM HAS BEEN CHANGED\n"); | 1296 | printf("FILE SYSTEM HAS BEEN CHANGED\n"); |
1385 | sync(); | 1297 | sync(); |
1386 | } else if (repair) | 1298 | } else if (OPT_repair) |
1387 | write_super_block(); | 1299 | write_super_block(); |
1388 | 1300 | ||
1389 | if (repair && !automatic) | 1301 | if (OPT_manual) |
1390 | tcsetattr(0, TCSANOW, &sv_termios); | 1302 | tcsetattr(0, TCSANOW, &sv_termios); |
1391 | 1303 | ||
1392 | if (changed) | 1304 | if (changed) |