Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/fsck_minix.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/fsck_minix.c
r1765 r2725 5 5 * (C) 1991, 1992 Linus Torvalds. 6 6 * 7 * Licensed under GPLv2, see file LICENSE in this tarball for details.7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 9 … … 30 30 * 31 31 * Sat Mar 6 18:59:42 1993, faith@cs.unc.edu: Output namelen with 32 * super -block information32 * superblock information 33 33 * 34 34 * Sat Oct 9 11:17:11 1993, faith@cs.unc.edu: make exit status conform … … 65 65 * Andreas Schwab. 66 66 * 67 * 1999-02-22 Arkadiusz Mi ¶kiewicz <misiek@misiek.eu.org>67 * 1999-02-22 Arkadiusz Mickiewicz <misiek@misiek.eu.org> 68 68 * - added Native Language Support 69 69 * … … 80 80 * -r for repairs (interactive) (not implemented) 81 81 * -v for verbose (tells how many files) 82 * -s for super -block info82 * -s for superblock info 83 83 * -m for minix-like "mode not cleared" warnings 84 84 * -f force filesystem check even if filesystem marked as valid … … 95 95 #define BLKGETSIZE _IO(0x12,96) /* return device size */ 96 96 #endif 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 }; 97 104 98 105 enum { … … 108 115 }; 109 116 117 110 118 #if !ENABLE_FEATURE_MINIX2 111 119 enum { version2 = 0 }; … … 114 122 enum { MAX_DEPTH = 32 }; 115 123 124 enum { dev_fd = 3 }; 125 116 126 struct globals { 117 int dev_fd;118 127 #if ENABLE_FEATURE_MINIX2 119 128 smallint version2; 120 129 #endif 121 smallint repair, automatic, verbose, list, show, warn_mode, force;122 130 smallint changed; /* is filesystem modified? */ 123 131 smallint errors_uncorrected; /* flag if some error was not corrected */ … … 125 133 smallint dirsize; 126 134 smallint namelen; 127 c har *device_name;135 const char *device_name; 128 136 int directory, regular, blockdev, chardev, links, symlinks, total; 129 137 char *inode_buffer; … … 141 149 /* Bigger stuff */ 142 150 struct termios sv_termios; 143 char super _block_buffer[BLOCK_SIZE];151 char superblock_buffer[BLOCK_SIZE]; 144 152 char add_zone_ind_blk[BLOCK_SIZE]; 145 153 char add_zone_dind_blk[BLOCK_SIZE]; 146 USE_FEATURE_MINIX2(char add_zone_tind_blk[BLOCK_SIZE];)154 IF_FEATURE_MINIX2(char add_zone_tind_blk[BLOCK_SIZE];) 147 155 char check_file_blk[BLOCK_SIZE]; 148 156 … … 150 158 char current_name[MAX_DEPTH * MINIX_NAME_MAX]; 151 159 }; 152 153 160 #define G (*ptr_to_globals) 154 #define dev_fd (G.dev_fd )155 161 #if ENABLE_FEATURE_MINIX2 156 162 #define version2 (G.version2 ) 157 163 #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 164 #define changed (G.changed ) 166 165 #define errors_uncorrected (G.errors_uncorrected ) … … 184 183 #define name_component (G.name_component ) 185 184 #define sv_termios (G.sv_termios ) 186 #define super _block_buffer (G.super_block_buffer )185 #define superblock_buffer (G.superblock_buffer ) 187 186 #define add_zone_ind_blk (G.add_zone_ind_blk ) 188 187 #define add_zone_dind_blk (G.add_zone_dind_blk ) … … 191 190 #define current_name (G.current_name ) 192 191 #define INIT_G() do { \ 193 PTR_TO_GLOBALS = xzalloc(sizeof(G)); \192 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 194 193 dirsize = 16; \ 195 194 namelen = 14; \ … … 199 198 } while (0) 200 199 200 201 #define OPTION_STR "larvsmf" 202 enum { 203 OPT_l = (1 << 0), 204 OPT_a = (1 << 1), 205 OPT_r = (1 << 2), 206 OPT_v = (1 << 3), 207 OPT_s = (1 << 4), 208 OPT_w = (1 << 5), 209 OPT_f = (1 << 6), 210 }; 211 #define OPT_list (option_mask32 & OPT_l) 212 #define OPT_automatic (option_mask32 & OPT_a) 213 #define OPT_repair (option_mask32 & OPT_r) 214 #define OPT_verbose (option_mask32 & OPT_v) 215 #define OPT_show (option_mask32 & OPT_s) 216 #define OPT_warn_mode (option_mask32 & OPT_w) 217 #define OPT_force (option_mask32 & OPT_f) 218 /* non-automatic repairs requested? */ 219 #define OPT_manual ((option_mask32 & (OPT_a|OPT_r)) == OPT_r) 220 221 201 222 #define Inode1 (((struct minix1_inode *) inode_buffer)-1) 202 223 #define Inode2 (((struct minix2_inode *) inode_buffer)-1) 203 224 204 #define Super (*(struct minix_super _block *)(super_block_buffer))225 #define Super (*(struct minix_superblock *)(superblock_buffer)) 205 226 206 227 #if ENABLE_FEATURE_MINIX2 … … 223 244 } 224 245 225 #if ENABLE_FEATURE_MINIX2 226 #define INODE_BLOCKS div_roundup(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ 227 : MINIX1_INODES_PER_BLOCK)) 246 #if !ENABLE_FEATURE_MINIX2 247 #define INODE_BLOCKS div_roundup(INODES, MINIX1_INODES_PER_BLOCK) 228 248 #else 229 #define INODE_BLOCKS div_roundup(INODES, MINIX1_INODES_PER_BLOCK) 230 #endif 231 232 #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) 233 #define NORM_FIRSTZONE (2 + IMAPS + ZMAPS + INODE_BLOCKS) 249 #define INODE_BLOCKS div_roundup(INODES, \ 250 (version2 ? MINIX2_INODES_PER_BLOCK : MINIX1_INODES_PER_BLOCK)) 251 #endif 252 253 #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) 254 #define NORM_FIRSTZONE (2 + IMAPS + ZMAPS + INODE_BLOCKS) 234 255 235 256 /* Before you ask "where they come from?": */ … … 268 289 #endif 269 290 270 static void die(const char *str) ATTRIBUTE_NORETURN;291 static void die(const char *str) NORETURN; 271 292 static void die(const char *str) 272 293 { 273 294 if (termios_set) 274 tcsetattr (0, TCSANOW,&sv_termios);295 tcsetattr_stdin_TCSANOW(&sv_termios); 275 296 bb_error_msg_and_die("%s", str); 276 297 } … … 307 328 int c; 308 329 309 if (! repair) {310 puts("");330 if (!OPT_repair) { 331 bb_putchar('\n'); 311 332 errors_uncorrected = 1; 312 333 return 0; 313 334 } 314 if ( automatic) {315 puts("");335 if (OPT_automatic) { 336 bb_putchar('\n'); 316 337 if (!def) 317 338 errors_uncorrected = 1; … … 320 341 printf(def ? "%s (y/n)? " : "%s (n/y)? ", string); 321 342 for (;;) { 322 fflush (stdout);343 fflush_all(); 323 344 c = getchar(); 324 345 if (c == EOF) { … … 327 348 return def; 328 349 } 329 c = toupper(c); 330 if (c == 'Y') { 350 if (c == '\n') 351 break; 352 c |= 0x20; /* tolower */ 353 if (c == 'y') { 331 354 def = 1; 332 355 break; 333 } else if (c == 'N') { 356 } 357 if (c == 'n') { 334 358 def = 0; 335 359 break; 336 } else if (c == ' ' || c == '\n') 337 break; 360 } 338 361 } 339 362 if (def) … … 353 376 static void check_mount(void) 354 377 { 355 FILE *f; 356 struct mntent *mnt; 357 int cont; 358 int fd; 359 360 f = setmntent(MOUNTED, "r"); 361 if (f == NULL) 362 return; 363 while ((mnt = getmntent(f)) != NULL) 364 if (strcmp(device_name, mnt->mnt_fsname) == 0) 365 break; 366 endmntent(f); 367 if (!mnt) 368 return; 369 370 /* 371 * If the root is mounted read-only, then /etc/mtab is 372 * probably not correct; so we won't issue a warning based on 373 * it. 374 */ 375 fd = open(MOUNTED, O_RDWR); 376 if (fd < 0 && errno == EROFS) 377 return; 378 close(fd); 379 380 printf("%s is mounted. ", device_name); 381 cont = 0; 382 if (isatty(0) && isatty(1)) 383 cont = ask("Do you really want to continue", 0); 384 if (!cont) { 385 printf("Check aborted\n"); 386 exit(0); 378 if (find_mount_point(device_name, 0)) { 379 int cont; 380 #if ENABLE_FEATURE_MTAB_SUPPORT 381 /* 382 * If the root is mounted read-only, then /etc/mtab is 383 * probably not correct; so we won't issue a warning based on 384 * it. 385 */ 386 int fd = open(bb_path_mtab_file, O_RDWR); 387 388 if (fd < 0 && errno == EROFS) 389 return; 390 close(fd); 391 #endif 392 printf("%s is mounted. ", device_name); 393 cont = 0; 394 if (isatty(0) && isatty(1)) 395 cont = ask("Do you really want to continue", 0); 396 if (!cont) { 397 printf("Check aborted\n"); 398 exit(EXIT_SUCCESS); 399 } 387 400 } 388 401 } … … 424 437 * read-block reads block nr into the buffer at addr. 425 438 */ 426 static void read_block(unsigned nr, char*addr)439 static void read_block(unsigned nr, void *addr) 427 440 { 428 441 if (!nr) { … … 430 443 return; 431 444 } 432 if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET)) { 433 printf("%s: cannot seek to block in file '%s'\n", 434 bb_msg_read_error, current_name); 435 errors_uncorrected = 1; 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); 445 xlseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET); 446 if (BLOCK_SIZE != full_read(dev_fd, addr, BLOCK_SIZE)) { 447 printf("%s: bad block %u in file '%s'\n", 448 bb_msg_read_error, nr, current_name); 440 449 errors_uncorrected = 1; 441 450 memset(addr, 0, BLOCK_SIZE); … … 446 455 * write_block writes block nr to disk. 447 456 */ 448 static void write_block(unsigned nr, char*addr)457 static void write_block(unsigned nr, void *addr) 449 458 { 450 459 if (!nr) … … 456 465 return; 457 466 } 458 if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET)) 459 die("seek failed in write_block"); 460 if (BLOCK_SIZE != write(dev_fd, addr, BLOCK_SIZE)) { 461 printf("%s: bad block in file '%s'\n", 462 bb_msg_write_error, current_name); 467 xlseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET); 468 if (BLOCK_SIZE != full_write(dev_fd, addr, BLOCK_SIZE)) { 469 printf("%s: bad block %u in file '%s'\n", 470 bb_msg_write_error, nr, current_name); 463 471 errors_uncorrected = 1; 464 472 } … … 473 481 { 474 482 uint16_t ind[BLOCK_SIZE >> 1]; 475 uint16_t dind[BLOCK_SIZE >> 1];476 483 int block, result; 477 484 smallint blk_chg; … … 482 489 if (blknr < 512) { 483 490 block = check_zone_nr(inode->i_zone + 7, &changed); 484 read_block(block, (char *) ind); 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; 491 goto common; 490 492 } 491 493 blknr -= 512; 492 494 block = check_zone_nr(inode->i_zone + 8, &changed); 493 read_block(block, (char *) dind);495 read_block(block, ind); /* double indirect */ 494 496 blk_chg = 0; 495 result = check_zone_nr( dind + (blknr / 512), &blk_chg);497 result = check_zone_nr(&ind[blknr / 512], &blk_chg); 496 498 if (blk_chg) 497 write_block(block, (char *) dind);499 write_block(block, ind); 498 500 block = result; 499 read_block(block, (char *) ind); 501 common: 502 read_block(block, ind); 500 503 blk_chg = 0; 501 result = check_zone_nr( ind + (blknr % 512), &blk_chg);504 result = check_zone_nr(&ind[blknr % 512], &blk_chg); 502 505 if (blk_chg) 503 write_block(block, (char *)ind);506 write_block(block, ind); 504 507 return result; 505 508 } … … 509 512 { 510 513 uint32_t ind[BLOCK_SIZE >> 2]; 511 uint32_t dind[BLOCK_SIZE >> 2];512 uint32_t tind[BLOCK_SIZE >> 2];513 514 int block, result; 514 515 smallint blk_chg; … … 519 520 if (blknr < 256) { 520 521 block = check_zone_nr2(inode->i_zone + 7, &changed); 521 read_block(block, (char *) ind); 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; 522 goto common2; 527 523 } 528 524 blknr -= 256; 529 if (blknr >=256 * 256) {525 if (blknr < 256 * 256) { 530 526 block = check_zone_nr2(inode->i_zone + 8, &changed); 531 read_block(block, (char *) dind); 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; 527 goto common1; 543 528 } 544 529 blknr -= 256 * 256; 545 530 block = check_zone_nr2(inode->i_zone + 9, &changed); 546 read_block(block, (char *) tind);531 read_block(block, ind); /* triple indirect */ 547 532 blk_chg = 0; 548 result = check_zone_nr2( tind + blknr / (256 * 256), &blk_chg);533 result = check_zone_nr2(&ind[blknr / (256 * 256)], &blk_chg); 549 534 if (blk_chg) 550 write_block(block, (char *) tind);535 write_block(block, ind); 551 536 block = result; 552 read_block(block, (char *) dind); 537 common1: 538 read_block(block, ind); /* double indirect */ 553 539 blk_chg = 0; 554 result = check_zone_nr2( dind + (blknr / 256) % 256, &blk_chg);540 result = check_zone_nr2(&ind[(blknr / 256) % 256], &blk_chg); 555 541 if (blk_chg) 556 write_block(block, (char *) dind);542 write_block(block, ind); 557 543 block = result; 558 read_block(block, (char *) ind); 544 common2: 545 read_block(block, ind); 559 546 blk_chg = 0; 560 result = check_zone_nr2( ind + blknr % 256, &blk_chg);547 result = check_zone_nr2(&ind[blknr % 256], &blk_chg); 561 548 if (blk_chg) 562 write_block(block, (char *)ind);549 write_block(block, ind); 563 550 return result; 564 551 } 565 552 #endif 566 553 567 static void write_super _block(void)554 static void write_superblock(void) 568 555 { 569 556 /* … … 576 563 Super.s_state &= ~MINIX_ERROR_FS; 577 564 578 if (BLOCK_SIZE != lseek(dev_fd, BLOCK_SIZE, SEEK_SET)) 579 die("seek failed in write_super_block"); 580 if (BLOCK_SIZE != write(dev_fd, super_block_buffer, BLOCK_SIZE)) 581 die("cannot write super-block"); 565 xlseek(dev_fd, BLOCK_SIZE, SEEK_SET); 566 if (BLOCK_SIZE != full_write(dev_fd, superblock_buffer, BLOCK_SIZE)) 567 die("can't write superblock"); 582 568 } 583 569 584 570 static void write_tables(void) 585 571 { 586 write_super _block();572 write_superblock(); 587 573 588 574 if (IMAPS * BLOCK_SIZE != write(dev_fd, inode_map, IMAPS * BLOCK_SIZE)) 589 die("can not write inode map");575 die("can't write inode map"); 590 576 if (ZMAPS * BLOCK_SIZE != write(dev_fd, zone_map, ZMAPS * BLOCK_SIZE)) 591 die("can not write zone map");577 die("can't write zone map"); 592 578 if (INODE_BUFFER_SIZE != write(dev_fd, inode_buffer, INODE_BUFFER_SIZE)) 593 die("can not write inodes");579 die("can't write inodes"); 594 580 } 595 581 … … 619 605 static void read_superblock(void) 620 606 { 621 if (BLOCK_SIZE != lseek(dev_fd, BLOCK_SIZE, SEEK_SET)) 622 die("seek failed"); 623 if (BLOCK_SIZE != read(dev_fd, super_block_buffer, BLOCK_SIZE)) 624 die("cannot read super block"); 607 xlseek(dev_fd, BLOCK_SIZE, SEEK_SET); 608 if (BLOCK_SIZE != full_read(dev_fd, superblock_buffer, BLOCK_SIZE)) 609 die("can't read superblock"); 625 610 /* already initialized to: 626 611 namelen = 14; … … 641 626 #endif 642 627 } else 643 die("bad magic number in super -block");628 die("bad magic number in superblock"); 644 629 if (ZONESIZE != 0 || BLOCK_SIZE != 1024) 645 630 die("only 1k blocks/zones supported"); 646 631 if (IMAPS * BLOCK_SIZE * 8 < INODES + 1) 647 die("bad s_imap_blocks field in super -block");632 die("bad s_imap_blocks field in superblock"); 648 633 if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1) 649 die("bad s_zmap_blocks field in super -block");634 die("bad s_zmap_blocks field in superblock"); 650 635 } 651 636 … … 658 643 zone_count = xmalloc(ZONES); 659 644 if (IMAPS * BLOCK_SIZE != read(dev_fd, inode_map, IMAPS * BLOCK_SIZE)) 660 die("can not read inode map");645 die("can't read inode map"); 661 646 if (ZMAPS * BLOCK_SIZE != read(dev_fd, zone_map, ZMAPS * BLOCK_SIZE)) 662 die("can not read zone map");647 die("can't read zone map"); 663 648 if (INODE_BUFFER_SIZE != read(dev_fd, inode_buffer, INODE_BUFFER_SIZE)) 664 die("can not read inodes");649 die("can't read inodes"); 665 650 if (NORM_FIRSTZONE != FIRSTZONE) { 666 651 printf("warning: firstzone!=norm_firstzone\n"); … … 668 653 } 669 654 get_dirsize(); 670 if ( show) {655 if (OPT_show) { 671 656 printf("%u inodes\n" 672 657 "%u blocks\n" … … 686 671 } 687 672 688 static struct minix1_inode *get_inode(unsigned nr) 689 { 690 struct minix1_inode *inode; 691 692 if (!nr || nr > INODES) 693 return NULL; 673 static void get_inode_common(unsigned nr, uint16_t i_mode) 674 { 694 675 total++; 695 inode = Inode1 + nr;696 676 if (!inode_count[nr]) { 697 677 if (!inode_in_use(nr)) { 698 678 printf("Inode %d is marked as 'unused', but it is used " 699 679 "for file '%s'\n", nr, current_name); 700 if ( repair) {680 if (OPT_repair) { 701 681 if (ask("Mark as 'in use'", 1)) 702 682 mark_inode(nr); … … 705 685 } 706 686 } 707 if (S_ISDIR(i node->i_mode))687 if (S_ISDIR(i_mode)) 708 688 directory++; 709 else if (S_ISREG(i node->i_mode))689 else if (S_ISREG(i_mode)) 710 690 regular++; 711 else if (S_ISCHR(i node->i_mode))691 else if (S_ISCHR(i_mode)) 712 692 chardev++; 713 else if (S_ISBLK(i node->i_mode))693 else if (S_ISBLK(i_mode)) 714 694 blockdev++; 715 else if (S_ISLNK(i node->i_mode))695 else if (S_ISLNK(i_mode)) 716 696 symlinks++; 717 else if (S_ISSOCK(i node->i_mode));718 else if (S_ISFIFO(i node->i_mode));697 else if (S_ISSOCK(i_mode)); 698 else if (S_ISFIFO(i_mode)); 719 699 else { 720 printf("%s has mode %05o\n", current_name, inode->i_mode); 721 } 722 700 printf("%s has mode %05o\n", current_name, i_mode); 701 } 723 702 } else 724 703 links++; … … 728 707 errors_uncorrected = 1; 729 708 } 730 return inode; 731 } 732 733 #if ENABLE_FEATURE_MINIX2 734 static struct minix2_inode *get_inode2(unsigned nr) 735 { 736 struct minix2_inode *inode; 709 } 710 711 static struct minix1_inode *get_inode(unsigned nr) 712 { 713 struct minix1_inode *inode; 737 714 738 715 if (!nr || nr > INODES) 739 716 return NULL; 740 total++; 717 inode = Inode1 + nr; 718 get_inode_common(nr, inode->i_mode); 719 return inode; 720 } 721 722 #if ENABLE_FEATURE_MINIX2 723 static struct minix2_inode *get_inode2(unsigned nr) 724 { 725 struct minix2_inode *inode; 726 727 if (!nr || nr > INODES) 728 return NULL; 741 729 inode = Inode2 + nr; 742 if (!inode_count[nr]) { 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 } 730 get_inode_common(nr, inode->i_mode); 775 731 return inode; 776 732 } … … 797 753 #endif 798 754 799 static int add_zone(uint16_t *znr, smallint *corrected) 800 { 801 int result; 802 int block; 803 804 result = 0; 805 block = check_zone_nr(znr, corrected); 755 static int add_zone_common(int block, smallint *corrected) 756 { 806 757 if (!block) 807 758 return 0; … … 810 761 current_name); 811 762 if (ask("Clear", 1)) { 812 *znr = 0;813 763 block = 0; 814 764 *corrected = 1; 815 return 0;765 return -1; /* "please zero out *znr" */ 816 766 } 817 767 } … … 827 777 } 828 778 779 static int add_zone(uint16_t *znr, smallint *corrected) 780 { 781 int block; 782 783 block = check_zone_nr(znr, corrected); 784 block = add_zone_common(block, corrected); 785 if (block == -1) { 786 *znr = 0; 787 block = 0; 788 } 789 return block; 790 } 791 829 792 #if ENABLE_FEATURE_MINIX2 830 793 static int add_zone2(uint32_t *znr, smallint *corrected) 831 794 { 832 int result;833 795 int block; 834 796 835 result = 0;836 797 block = check_zone_nr2(znr, corrected); 837 if (!block) 838 return 0; 839 if (zone_count[block]) { 840 printf("Already used block is reused in file '%s'. ", 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 } 855 if (!++zone_count[block]) 856 zone_count[block]--; 798 block = add_zone_common(block, corrected); 799 if (block == -1) { 800 *znr = 0; 801 block = 0; 802 } 857 803 return block; 858 804 } … … 952 898 return; 953 899 inode = Inode1 + i; 954 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 955 !S_ISLNK(inode->i_mode)) return; 900 if (!S_ISDIR(inode->i_mode) 901 && !S_ISREG(inode->i_mode) 902 && !S_ISLNK(inode->i_mode) 903 ) { 904 return; 905 } 956 906 for (i = 0; i < 7; i++) 957 907 add_zone(i + inode->i_zone, &changed); … … 1019 969 return; 1020 970 push_filename(name); 1021 if ( list) {1022 if ( verbose)971 if (OPT_list) { 972 if (OPT_verbose) 1023 973 printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); 1024 974 printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : ""); … … 1069 1019 return; 1070 1020 push_filename(name); 1071 if ( list) {1072 if ( verbose)1021 if (OPT_list) { 1022 if (OPT_verbose) 1073 1023 printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); 1074 1024 printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : ""); … … 1119 1069 char buffer[BLOCK_SIZE]; 1120 1070 1121 if (BLOCK_SIZE * i != lseek(dev_fd, BLOCK_SIZE * i, SEEK_SET)) 1122 die("seek failed in bad_zone"); 1123 return (BLOCK_SIZE != read(dev_fd, buffer, BLOCK_SIZE)); 1071 xlseek(dev_fd, BLOCK_SIZE * i, SEEK_SET); 1072 return (BLOCK_SIZE != full_read(dev_fd, buffer, BLOCK_SIZE)); 1124 1073 } 1125 1074 … … 1129 1078 1130 1079 for (i = 1; i <= INODES; i++) { 1131 if ( warn_mode && Inode1[i].i_mode && !inode_in_use(i)) {1080 if (OPT_warn_mode && Inode1[i].i_mode && !inode_in_use(i)) { 1132 1081 printf("Inode %d has non-zero mode. ", i); 1133 1082 if (ask("Clear", 1)) { … … 1181 1130 1182 1131 for (i = 1; i <= INODES; i++) { 1183 if ( warn_mode && Inode2[i].i_mode && !inode_in_use(i)) {1132 if (OPT_warn_mode && Inode2[i].i_mode && !inode_in_use(i)) { 1184 1133 printf("Inode %d has non-zero mode. ", i); 1185 1134 if (ask("Clear", 1)) { … … 1250 1199 #endif 1251 1200 1252 int fsck_minix_main(int argc, char **argv) ;1253 int fsck_minix_main(int argc , char **argv)1201 int fsck_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1202 int fsck_minix_main(int argc UNUSED_PARAM, char **argv) 1254 1203 { 1255 1204 struct termios tmp; … … 1260 1209 INIT_G(); 1261 1210 1262 if (INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE) 1263 die("bad inode size"); 1264 #if ENABLE_FEATURE_MINIX2 1265 if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) 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 1309 check_mount(); /* trying to check a mounted filesystem? */ 1310 if (repair && !automatic) { 1211 opt_complementary = "=1:ar"; /* one argument; -a assumes -r */ 1212 getopt32(argv, OPTION_STR); 1213 argv += optind; 1214 device_name = argv[0]; 1215 1216 check_mount(); /* trying to check a mounted filesystem? */ 1217 if (OPT_manual) { 1311 1218 if (!isatty(0) || !isatty(1)) 1312 1219 die("need terminal for interactive repairs"); 1313 1220 } 1314 dev_fd = xopen(device_name, repair ? O_RDWR : O_RDONLY);1221 xmove_fd(xopen(device_name, OPT_repair ? O_RDWR : O_RDONLY), dev_fd); 1315 1222 1316 1223 /*sync(); paranoia? */ … … 1326 1233 1327 1234 if (!(Super.s_state & MINIX_ERROR_FS) 1328 && (Super.s_state & MINIX_VALID_FS) && ! force1235 && (Super.s_state & MINIX_VALID_FS) && !OPT_force 1329 1236 ) { 1330 if ( repair)1237 if (OPT_repair) 1331 1238 printf("%s is clean, check is skipped\n", device_name); 1332 1239 return 0; 1333 } else if ( force)1240 } else if (OPT_force) 1334 1241 printf("Forcing filesystem check on %s\n", device_name); 1335 else if ( repair)1242 else if (OPT_repair) 1336 1243 printf("Filesystem on %s is dirty, needs checking\n", 1337 1244 device_name); … … 1339 1246 read_tables(); 1340 1247 1341 if ( repair && !automatic) {1248 if (OPT_manual) { 1342 1249 tcgetattr(0, &sv_termios); 1343 1250 tmp = sv_termios; 1344 1251 tmp.c_lflag &= ~(ICANON | ECHO); 1345 tcsetattr (0, TCSANOW,&tmp);1252 tcsetattr_stdin_TCSANOW(&tmp); 1346 1253 termios_set = 1; 1347 1254 } … … 1355 1262 } 1356 1263 1357 if ( verbose) {1264 if (OPT_verbose) { 1358 1265 int i, free_cnt; 1359 1266 … … 1384 1291 printf("FILE SYSTEM HAS BEEN CHANGED\n"); 1385 1292 sync(); 1386 } else if ( repair)1387 write_super _block();1388 1389 if ( repair && !automatic)1390 tcsetattr (0, TCSANOW,&sv_termios);1293 } else if (OPT_repair) 1294 write_superblock(); 1295 1296 if (OPT_manual) 1297 tcsetattr_stdin_TCSANOW(&sv_termios); 1391 1298 1392 1299 if (changed)
Note:
See TracChangeset
for help on using the changeset viewer.