Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/util-linux/fsck_minix.c

    r1765 r2725  
    55 * (C) 1991, 1992 Linus Torvalds.
    66 *
    7  * Licensed under GPLv2, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2, see file LICENSE in this source tree.
    88 */
    99
     
    3030 *
    3131 * Sat Mar  6 18:59:42 1993, faith@cs.unc.edu: Output namelen with
    32  *                           super-block information
     32 *                           superblock information
    3333 *
    3434 * Sat Oct  9 11:17:11 1993, faith@cs.unc.edu: make exit status conform
     
    6565 *             Andreas Schwab.
    6666 *
    67  * 1999-02-22 Arkadiusz Mikiewicz <misiek@misiek.eu.org>
     67 * 1999-02-22 Arkadiusz Mickiewicz <misiek@misiek.eu.org>
    6868 * - added Native Language Support
    6969 *
     
    8080 *  -r for repairs (interactive) (not implemented)
    8181 *  -v for verbose (tells how many files)
    82  *  -s for super-block info
     82 *  -s for superblock info
    8383 *  -m for minix-like "mode not cleared" warnings
    8484 *  -f force filesystem check even if filesystem marked as valid
     
    9595#define BLKGETSIZE _IO(0x12,96)    /* return device size */
    9696#endif
     97
     98struct 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};
    97104
    98105enum {
     
    108115};
    109116
     117
    110118#if !ENABLE_FEATURE_MINIX2
    111119enum { version2 = 0 };
     
    114122enum { MAX_DEPTH = 32 };
    115123
     124enum { dev_fd = 3 };
     125
    116126struct globals {
    117     int dev_fd;
    118127#if ENABLE_FEATURE_MINIX2
    119128    smallint version2;
    120129#endif
    121     smallint repair, automatic, verbose, list, show, warn_mode, force;
    122130    smallint changed;  /* is filesystem modified? */
    123131    smallint errors_uncorrected;  /* flag if some error was not corrected */
     
    125133    smallint dirsize;
    126134    smallint namelen;
    127     char *device_name;
     135    const char *device_name;
    128136    int directory, regular, blockdev, chardev, links, symlinks, total;
    129137    char *inode_buffer;
     
    141149    /* Bigger stuff */
    142150    struct termios sv_termios;
    143     char super_block_buffer[BLOCK_SIZE];
     151    char superblock_buffer[BLOCK_SIZE];
    144152    char add_zone_ind_blk[BLOCK_SIZE];
    145153    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];)
    147155    char check_file_blk[BLOCK_SIZE];
    148156
     
    150158    char current_name[MAX_DEPTH * MINIX_NAME_MAX];
    151159};
    152 
    153160#define G (*ptr_to_globals)
    154 #define dev_fd             (G.dev_fd             )
    155161#if ENABLE_FEATURE_MINIX2
    156162#define version2           (G.version2           )
    157163#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              )
    165164#define changed            (G.changed            )
    166165#define errors_uncorrected (G.errors_uncorrected )
     
    184183#define name_component     (G.name_component     )
    185184#define sv_termios         (G.sv_termios         )
    186 #define super_block_buffer (G.super_block_buffer )
     185#define superblock_buffer  (G.superblock_buffer )
    187186#define add_zone_ind_blk   (G.add_zone_ind_blk   )
    188187#define add_zone_dind_blk  (G.add_zone_dind_blk  )
     
    191190#define current_name       (G.current_name       )
    192191#define INIT_G() do { \
    193     PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
     192    SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
    194193    dirsize = 16; \
    195194    namelen = 14; \
     
    199198} while (0)
    200199
     200
     201#define OPTION_STR "larvsmf"
     202enum {
     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
    201222#define Inode1 (((struct minix1_inode *) inode_buffer)-1)
    202223#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
    203224
    204 #define Super (*(struct minix_super_block *)(super_block_buffer))
     225#define Super (*(struct minix_superblock *)(superblock_buffer))
    205226
    206227#if ENABLE_FEATURE_MINIX2
     
    223244}
    224245
    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)
    228248#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)
    234255
    235256/* Before you ask "where they come from?": */
     
    268289#endif
    269290
    270 static void die(const char *str) ATTRIBUTE_NORETURN;
     291static void die(const char *str) NORETURN;
    271292static void die(const char *str)
    272293{
    273294    if (termios_set)
    274         tcsetattr(0, TCSANOW, &sv_termios);
     295        tcsetattr_stdin_TCSANOW(&sv_termios);
    275296    bb_error_msg_and_die("%s", str);
    276297}
     
    307328    int c;
    308329
    309     if (!repair) {
    310         puts("");
     330    if (!OPT_repair) {
     331        bb_putchar('\n');
    311332        errors_uncorrected = 1;
    312333        return 0;
    313334    }
    314     if (automatic) {
    315         puts("");
     335    if (OPT_automatic) {
     336        bb_putchar('\n');
    316337        if (!def)
    317338            errors_uncorrected = 1;
     
    320341    printf(def ? "%s (y/n)? " : "%s (n/y)? ", string);
    321342    for (;;) {
    322         fflush(stdout);
     343        fflush_all();
    323344        c = getchar();
    324345        if (c == EOF) {
     
    327348            return def;
    328349        }
    329         c = toupper(c);
    330         if (c == 'Y') {
     350        if (c == '\n')
     351            break;
     352        c |= 0x20; /* tolower */
     353        if (c == 'y') {
    331354            def = 1;
    332355            break;
    333         } else if (c == 'N') {
     356        }
     357        if (c == 'n') {
    334358            def = 0;
    335359            break;
    336         } else if (c == ' ' || c == '\n')
    337             break;
     360        }
    338361    }
    339362    if (def)
     
    353376static void check_mount(void)
    354377{
    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        }
    387400    }
    388401}
     
    424437 * read-block reads block nr into the buffer at addr.
    425438 */
    426 static void read_block(unsigned nr, char *addr)
     439static void read_block(unsigned nr, void *addr)
    427440{
    428441    if (!nr) {
     
    430443        return;
    431444    }
    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);
    440449        errors_uncorrected = 1;
    441450        memset(addr, 0, BLOCK_SIZE);
     
    446455 * write_block writes block nr to disk.
    447456 */
    448 static void write_block(unsigned nr, char *addr)
     457static void write_block(unsigned nr, void *addr)
    449458{
    450459    if (!nr)
     
    456465        return;
    457466    }
    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);
    463471        errors_uncorrected = 1;
    464472    }
     
    473481{
    474482    uint16_t ind[BLOCK_SIZE >> 1];
    475     uint16_t dind[BLOCK_SIZE >> 1];
    476483    int block, result;
    477484    smallint blk_chg;
     
    482489    if (blknr < 512) {
    483490        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;
    490492    }
    491493    blknr -= 512;
    492494    block = check_zone_nr(inode->i_zone + 8, &changed);
    493     read_block(block, (char *) dind);
     495    read_block(block, ind); /* double indirect */
    494496    blk_chg = 0;
    495     result = check_zone_nr(dind + (blknr / 512), &blk_chg);
     497    result = check_zone_nr(&ind[blknr / 512], &blk_chg);
    496498    if (blk_chg)
    497         write_block(block, (char *) dind);
     499        write_block(block, ind);
    498500    block = result;
    499     read_block(block, (char *) ind);
     501 common:
     502    read_block(block, ind);
    500503    blk_chg = 0;
    501     result = check_zone_nr(ind + (blknr % 512), &blk_chg);
     504    result = check_zone_nr(&ind[blknr % 512], &blk_chg);
    502505    if (blk_chg)
    503         write_block(block, (char *) ind);
     506        write_block(block, ind);
    504507    return result;
    505508}
     
    509512{
    510513    uint32_t ind[BLOCK_SIZE >> 2];
    511     uint32_t dind[BLOCK_SIZE >> 2];
    512     uint32_t tind[BLOCK_SIZE >> 2];
    513514    int block, result;
    514515    smallint blk_chg;
     
    519520    if (blknr < 256) {
    520521        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;
    527523    }
    528524    blknr -= 256;
    529     if (blknr >= 256 * 256) {
     525    if (blknr < 256 * 256) {
    530526        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;
    543528    }
    544529    blknr -= 256 * 256;
    545530    block = check_zone_nr2(inode->i_zone + 9, &changed);
    546     read_block(block, (char *) tind);
     531    read_block(block, ind); /* triple indirect */
    547532    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);
    549534    if (blk_chg)
    550         write_block(block, (char *) tind);
     535        write_block(block, ind);
    551536    block = result;
    552     read_block(block, (char *) dind);
     537 common1:
     538    read_block(block, ind); /* double indirect */
    553539    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);
    555541    if (blk_chg)
    556         write_block(block, (char *) dind);
     542        write_block(block, ind);
    557543    block = result;
    558     read_block(block, (char *) ind);
     544 common2:
     545    read_block(block, ind);
    559546    blk_chg = 0;
    560     result = check_zone_nr2(ind + blknr % 256, &blk_chg);
     547    result = check_zone_nr2(&ind[blknr % 256], &blk_chg);
    561548    if (blk_chg)
    562         write_block(block, (char *) ind);
     549        write_block(block, ind);
    563550    return result;
    564551}
    565552#endif
    566553
    567 static void write_super_block(void)
     554static void write_superblock(void)
    568555{
    569556    /*
     
    576563        Super.s_state &= ~MINIX_ERROR_FS;
    577564
    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");
    582568}
    583569
    584570static void write_tables(void)
    585571{
    586     write_super_block();
     572    write_superblock();
    587573
    588574    if (IMAPS * BLOCK_SIZE != write(dev_fd, inode_map, IMAPS * BLOCK_SIZE))
    589         die("cannot write inode map");
     575        die("can't write inode map");
    590576    if (ZMAPS * BLOCK_SIZE != write(dev_fd, zone_map, ZMAPS * BLOCK_SIZE))
    591         die("cannot write zone map");
     577        die("can't write zone map");
    592578    if (INODE_BUFFER_SIZE != write(dev_fd, inode_buffer, INODE_BUFFER_SIZE))
    593         die("cannot write inodes");
     579        die("can't write inodes");
    594580}
    595581
     
    619605static void read_superblock(void)
    620606{
    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");
    625610    /* already initialized to:
    626611    namelen = 14;
     
    641626#endif
    642627    } else
    643         die("bad magic number in super-block");
     628        die("bad magic number in superblock");
    644629    if (ZONESIZE != 0 || BLOCK_SIZE != 1024)
    645630        die("only 1k blocks/zones supported");
    646631    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");
    648633    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");
    650635}
    651636
     
    658643    zone_count = xmalloc(ZONES);
    659644    if (IMAPS * BLOCK_SIZE != read(dev_fd, inode_map, IMAPS * BLOCK_SIZE))
    660         die("cannot read inode map");
     645        die("can't read inode map");
    661646    if (ZMAPS * BLOCK_SIZE != read(dev_fd, zone_map, ZMAPS * BLOCK_SIZE))
    662         die("cannot read zone map");
     647        die("can't read zone map");
    663648    if (INODE_BUFFER_SIZE != read(dev_fd, inode_buffer, INODE_BUFFER_SIZE))
    664         die("cannot read inodes");
     649        die("can't read inodes");
    665650    if (NORM_FIRSTZONE != FIRSTZONE) {
    666651        printf("warning: firstzone!=norm_firstzone\n");
     
    668653    }
    669654    get_dirsize();
    670     if (show) {
     655    if (OPT_show) {
    671656        printf("%u inodes\n"
    672657            "%u blocks\n"
     
    686671}
    687672
    688 static struct minix1_inode *get_inode(unsigned nr)
    689 {
    690     struct minix1_inode *inode;
    691 
    692     if (!nr || nr > INODES)
    693         return NULL;
     673static void get_inode_common(unsigned nr, uint16_t i_mode)
     674{
    694675    total++;
    695     inode = Inode1 + nr;
    696676    if (!inode_count[nr]) {
    697677        if (!inode_in_use(nr)) {
    698678            printf("Inode %d is marked as 'unused', but it is used "
    699679                    "for file '%s'\n", nr, current_name);
    700             if (repair) {
     680            if (OPT_repair) {
    701681                if (ask("Mark as 'in use'", 1))
    702682                    mark_inode(nr);
     
    705685            }
    706686        }
    707         if (S_ISDIR(inode->i_mode))
     687        if (S_ISDIR(i_mode))
    708688            directory++;
    709         else if (S_ISREG(inode->i_mode))
     689        else if (S_ISREG(i_mode))
    710690            regular++;
    711         else if (S_ISCHR(inode->i_mode))
     691        else if (S_ISCHR(i_mode))
    712692            chardev++;
    713         else if (S_ISBLK(inode->i_mode))
     693        else if (S_ISBLK(i_mode))
    714694            blockdev++;
    715         else if (S_ISLNK(inode->i_mode))
     695        else if (S_ISLNK(i_mode))
    716696            symlinks++;
    717         else if (S_ISSOCK(inode->i_mode));
    718         else if (S_ISFIFO(inode->i_mode));
     697        else if (S_ISSOCK(i_mode));
     698        else if (S_ISFIFO(i_mode));
    719699        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        }
    723702    } else
    724703        links++;
     
    728707        errors_uncorrected = 1;
    729708    }
    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
     711static struct minix1_inode *get_inode(unsigned nr)
     712{
     713    struct minix1_inode *inode;
    737714
    738715    if (!nr || nr > INODES)
    739716        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
     723static struct minix2_inode *get_inode2(unsigned nr)
     724{
     725    struct minix2_inode *inode;
     726
     727    if (!nr || nr > INODES)
     728        return NULL;
    741729    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);
    775731    return inode;
    776732}
     
    797753#endif
    798754
    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);
     755static int add_zone_common(int block, smallint *corrected)
     756{
    806757    if (!block)
    807758        return 0;
     
    810761                current_name);
    811762        if (ask("Clear", 1)) {
    812             *znr = 0;
    813763            block = 0;
    814764            *corrected = 1;
    815             return 0;
     765            return -1; /* "please zero out *znr" */
    816766        }
    817767    }
     
    827777}
    828778
     779static 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
    829792#if ENABLE_FEATURE_MINIX2
    830793static int add_zone2(uint32_t *znr, smallint *corrected)
    831794{
    832     int result;
    833795    int block;
    834796
    835     result = 0;
    836797    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    }
    857803    return block;
    858804}
     
    952898        return;
    953899    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    }
    956906    for (i = 0; i < 7; i++)
    957907        add_zone(i + inode->i_zone, &changed);
     
    1019969        return;
    1020970    push_filename(name);
    1021     if (list) {
    1022         if (verbose)
     971    if (OPT_list) {
     972        if (OPT_verbose)
    1023973            printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks);
    1024974        printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : "");
     
    10691019        return;
    10701020    push_filename(name);
    1071     if (list) {
    1072         if (verbose)
     1021    if (OPT_list) {
     1022        if (OPT_verbose)
    10731023            printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks);
    10741024        printf("%s%s\n", current_name, S_ISDIR(inode->i_mode) ? ":" : "");
     
    11191069    char buffer[BLOCK_SIZE];
    11201070
    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));
    11241073}
    11251074
     
    11291078
    11301079    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)) {
    11321081            printf("Inode %d has non-zero mode. ", i);
    11331082            if (ask("Clear", 1)) {
     
    11811130
    11821131    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)) {
    11841133            printf("Inode %d has non-zero mode. ", i);
    11851134            if (ask("Clear", 1)) {
     
    12501199#endif
    12511200
    1252 int fsck_minix_main(int argc, char **argv);
    1253 int fsck_minix_main(int argc, char **argv)
     1201int fsck_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     1202int fsck_minix_main(int argc UNUSED_PARAM, char **argv)
    12541203{
    12551204    struct termios tmp;
     
    12601209    INIT_G();
    12611210
    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) {
    13111218        if (!isatty(0) || !isatty(1))
    13121219            die("need terminal for interactive repairs");
    13131220    }
    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);
    13151222
    13161223    /*sync(); paranoia? */
     
    13261233
    13271234    if (!(Super.s_state & MINIX_ERROR_FS)
    1328      && (Super.s_state & MINIX_VALID_FS) && !force
     1235     && (Super.s_state & MINIX_VALID_FS) && !OPT_force
    13291236    ) {
    1330         if (repair)
     1237        if (OPT_repair)
    13311238            printf("%s is clean, check is skipped\n", device_name);
    13321239        return 0;
    1333     } else if (force)
     1240    } else if (OPT_force)
    13341241        printf("Forcing filesystem check on %s\n", device_name);
    1335     else if (repair)
     1242    else if (OPT_repair)
    13361243        printf("Filesystem on %s is dirty, needs checking\n",
    13371244               device_name);
     
    13391246    read_tables();
    13401247
    1341     if (repair && !automatic) {
     1248    if (OPT_manual) {
    13421249        tcgetattr(0, &sv_termios);
    13431250        tmp = sv_termios;
    13441251        tmp.c_lflag &= ~(ICANON | ECHO);
    1345         tcsetattr(0, TCSANOW, &tmp);
     1252        tcsetattr_stdin_TCSANOW(&tmp);
    13461253        termios_set = 1;
    13471254    }
     
    13551262    }
    13561263
    1357     if (verbose) {
     1264    if (OPT_verbose) {
    13581265        int i, free_cnt;
    13591266
     
    13841291        printf("FILE SYSTEM HAS BEEN CHANGED\n");
    13851292        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);
    13911298
    13921299    if (changed)
Note: See TracChangeset for help on using the changeset viewer.