Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

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

    r821 r1770  
    33 * fsck.c - a file system consistency checker for Linux.
    44 *
    5  * (C) 1991, 1992 Linus Torvalds. This file may be redistributed
    6  * as per the GNU copyleft.
     5 * (C) 1991, 1992 Linus Torvalds.
     6 *
     7 * Licensed under GPLv2, see file LICENSE in this tarball for details.
    78 */
    89
     
    8788 */
    8889
    89 #include <stdio.h>
    90 #include <errno.h>
    91 #include <unistd.h>
    92 #include <string.h>
    93 #include <fcntl.h>
    94 #include <ctype.h>
    95 #include <stdlib.h>
    96 #include <termios.h>
    9790#include <mntent.h>
    98 #include <sys/param.h>
    99 #include "busybox.h"
    100 
    101 /*
    102  * This is the original minix inode layout on disk.
    103  * Note the 8-bit gid and atime and ctime.
    104  */
    105 struct minix_inode {
    106     uint16_t i_mode;
    107     uint16_t i_uid;
    108     uint32_t i_size;
    109     uint32_t i_time;
    110     uint8_t  i_gid;
    111     uint8_t  i_nlinks;
    112     uint16_t i_zone[9];
    113 };
    114 
    115 /*
    116  * The new minix inode has all the time entries, as well as
    117  * long block numbers and a third indirect block (7+1+1+1
    118  * instead of 7+1+1). Also, some previously 8-bit values are
    119  * now 16-bit. The inode is now 64 bytes instead of 32.
    120  */
    121 struct minix2_inode {
    122     uint16_t i_mode;
    123     uint16_t i_nlinks;
    124     uint16_t i_uid;
    125     uint16_t i_gid;
    126     uint32_t i_size;
    127     uint32_t i_atime;
    128     uint32_t i_mtime;
    129     uint32_t i_ctime;
    130     uint32_t i_zone[10];
    131 };
     91#include "libbb.h"
     92#include "minix.h"
     93
     94#ifndef BLKGETSIZE
     95#define BLKGETSIZE _IO(0x12,96)    /* return device size */
     96#endif
    13297
    13398enum {
    134     MINIX_ROOT_INO = 1,
    135     MINIX_LINK_MAX = 250,
     99#ifdef UNUSED
     100    MINIX1_LINK_MAX = 250,
    136101    MINIX2_LINK_MAX = 65530,
    137 
    138102    MINIX_I_MAP_SLOTS = 8,
    139103    MINIX_Z_MAP_SLOTS = 64,
    140     MINIX_SUPER_MAGIC = 0x137F,     /* original minix fs */
    141     MINIX_SUPER_MAGIC2 = 0x138F,        /* minix fs, 30 char names */
    142     MINIX2_SUPER_MAGIC = 0x2468,        /* minix V2 fs */
    143     MINIX2_SUPER_MAGIC2 = 0x2478,       /* minix V2 fs, 30 char names */
    144     MINIX_VALID_FS = 0x0001,        /* Clean fs. */
    145     MINIX_ERROR_FS = 0x0002,        /* fs has errors. */
    146 
    147     MINIX_INODES_PER_BLOCK = ((BLOCK_SIZE)/(sizeof (struct minix_inode))),
    148     MINIX2_INODES_PER_BLOCK = ((BLOCK_SIZE)/(sizeof (struct minix2_inode))),
    149 
    150     MINIX_V1 = 0x0001,      /* original minix fs */
    151     MINIX_V2 = 0x0002       /* minix V2 fs */
     104    MINIX_V1 = 0x0001,      /* original minix fs */
     105    MINIX_V2 = 0x0002,      /* minix V2 fs */
     106#endif
     107    MINIX_NAME_MAX = 255,         /* # chars in a file name */
    152108};
    153109
    154 #define INODE_VERSION(inode)    inode->i_sb->u.minix_sb.s_version
    155 
    156 /*
    157  * minix super-block data on disk
    158  */
    159 struct minix_super_block {
    160     uint16_t s_ninodes;
    161     uint16_t s_nzones;
    162     uint16_t s_imap_blocks;
    163     uint16_t s_zmap_blocks;
    164     uint16_t s_firstdatazone;
    165     uint16_t s_log_zone_size;
    166     uint32_t s_max_size;
    167     uint16_t s_magic;
    168     uint16_t s_state;
    169     uint32_t s_zones;
     110#if !ENABLE_FEATURE_MINIX2
     111enum { version2 = 0 };
     112#endif
     113
     114enum { MAX_DEPTH = 32 };
     115
     116struct globals {
     117    int dev_fd;
     118#if ENABLE_FEATURE_MINIX2
     119    smallint version2;
     120#endif
     121    smallint repair, automatic, verbose, list, show, warn_mode, force;
     122    smallint changed;  /* is filesystem modified? */
     123    smallint errors_uncorrected;  /* flag if some error was not corrected */
     124    smallint termios_set;
     125    smallint dirsize;
     126    smallint namelen;
     127    char *device_name;
     128    int directory, regular, blockdev, chardev, links, symlinks, total;
     129    char *inode_buffer;
     130
     131    char *inode_map;
     132    char *zone_map;
     133
     134    unsigned char *inode_count;
     135    unsigned char *zone_count;
     136
     137    /* File-name data */
     138    int name_depth;
     139    char *name_component[MAX_DEPTH+1];
     140
     141    /* Bigger stuff */
     142    struct termios sv_termios;
     143    char super_block_buffer[BLOCK_SIZE];
     144    char add_zone_ind_blk[BLOCK_SIZE];
     145    char add_zone_dind_blk[BLOCK_SIZE];
     146    USE_FEATURE_MINIX2(char add_zone_tind_blk[BLOCK_SIZE];)
     147    char check_file_blk[BLOCK_SIZE];
     148
     149    /* File-name data */
     150    char current_name[MAX_DEPTH * MINIX_NAME_MAX];
    170151};
    171152
    172 struct minix_dir_entry {
    173     uint16_t inode;
    174     char name[0];
    175 };
    176 
    177 
    178 #define NAME_MAX         255   /* # chars in a file name */
    179 
    180 #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
    181 
    182 #ifndef BLKGETSIZE
    183 #define BLKGETSIZE _IO(0x12,96)    /* return device size */
    184 #endif
    185 
    186 #ifndef __linux__
    187 #define volatile
    188 #endif
    189 
    190 enum { ROOT_INO = 1 };
    191 
    192 #define UPPER(size,n) ((size+((n)-1))/(n))
    193 #define INODE_SIZE (sizeof(struct minix_inode))
    194 #ifdef CONFIG_FEATURE_MINIX2
    195 #define INODE_SIZE2 (sizeof(struct minix2_inode))
    196 #define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \
    197                     : MINIX_INODES_PER_BLOCK))
     153#define G (*ptr_to_globals)
     154#define dev_fd             (G.dev_fd             )
     155#if ENABLE_FEATURE_MINIX2
     156#define version2           (G.version2           )
     157#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            )
     166#define errors_uncorrected (G.errors_uncorrected )
     167#define termios_set        (G.termios_set        )
     168#define dirsize            (G.dirsize            )
     169#define namelen            (G.namelen            )
     170#define device_name        (G.device_name        )
     171#define directory          (G.directory          )
     172#define regular            (G.regular            )
     173#define blockdev           (G.blockdev           )
     174#define chardev            (G.chardev            )
     175#define links              (G.links              )
     176#define symlinks           (G.symlinks           )
     177#define total              (G.total              )
     178#define inode_buffer       (G.inode_buffer       )
     179#define inode_map          (G.inode_map          )
     180#define zone_map           (G.zone_map           )
     181#define inode_count        (G.inode_count        )
     182#define zone_count         (G.zone_count         )
     183#define name_depth         (G.name_depth         )
     184#define name_component     (G.name_component     )
     185#define sv_termios         (G.sv_termios         )
     186#define super_block_buffer (G.super_block_buffer )
     187#define add_zone_ind_blk   (G.add_zone_ind_blk   )
     188#define add_zone_dind_blk  (G.add_zone_dind_blk  )
     189#define add_zone_tind_blk  (G.add_zone_tind_blk  )
     190#define check_file_blk     (G.check_file_blk     )
     191#define current_name       (G.current_name       )
     192#define INIT_G() do { \
     193    PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
     194    dirsize = 16; \
     195    namelen = 14; \
     196    current_name[0] = '/'; \
     197    /*current_name[1] = '\0';*/ \
     198    name_component[0] = &current_name[0]; \
     199} while (0)
     200
     201#define Inode1 (((struct minix1_inode *) inode_buffer)-1)
     202#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
     203
     204#define Super (*(struct minix_super_block *)(super_block_buffer))
     205
     206#if ENABLE_FEATURE_MINIX2
     207# define ZONES    ((unsigned)(version2 ? Super.s_zones : Super.s_nzones))
    198208#else
    199 #define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK))
    200 #endif
     209# define ZONES    ((unsigned)(Super.s_nzones))
     210#endif
     211#define INODES    ((unsigned)Super.s_ninodes)
     212#define IMAPS     ((unsigned)Super.s_imap_blocks)
     213#define ZMAPS     ((unsigned)Super.s_zmap_blocks)
     214#define FIRSTZONE ((unsigned)Super.s_firstdatazone)
     215#define ZONESIZE  ((unsigned)Super.s_log_zone_size)
     216#define MAXSIZE   ((unsigned)Super.s_max_size)
     217#define MAGIC     (Super.s_magic)
     218
     219/* gcc likes this more (code is smaller) than macro variant */
     220static ALWAYS_INLINE unsigned div_roundup(unsigned size, unsigned n)
     221{
     222    return (size + n-1) / n;
     223}
     224
     225#if ENABLE_FEATURE_MINIX2
     226#define INODE_BLOCKS div_roundup(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \
     227                    : MINIX1_INODES_PER_BLOCK))
     228#else
     229#define INODE_BLOCKS div_roundup(INODES, MINIX1_INODES_PER_BLOCK)
     230#endif
     231
    201232#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE)
    202 
    203 #define BITS_PER_BLOCK (BLOCK_SIZE<<3)
    204 
    205 static char *program_version = "1.2 - 11/11/96";
    206 static char *device_name;
    207 static int IN;
    208 static int repair, automatic, verbose, list, show, warn_mode, force;
    209 static int directory, regular, blockdev, chardev, links, symlinks, total;
    210 
    211 static int changed;         /* flags if the filesystem has been changed */
    212 static int errors_uncorrected;  /* flag if some error was not corrected */
    213 static int dirsize = 16;
    214 static int namelen = 14;
    215 static struct termios termios;
    216 static int termios_set;
    217 
    218 static char *inode_buffer;
    219 #define Inode (((struct minix_inode *) inode_buffer)-1)
    220 #define Inode2 (((struct minix2_inode *) inode_buffer)-1)
    221 static char super_block_buffer[BLOCK_SIZE];
    222 
    223 #define Super (*(struct minix_super_block *)super_block_buffer)
    224 #define INODES ((unsigned long)Super.s_ninodes)
    225 #ifdef CONFIG_FEATURE_MINIX2
    226 static int version2;
    227 #define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones))
    228 #else
    229 #define ZONES ((unsigned long)(Super.s_nzones))
    230 #endif
    231 #define IMAPS ((unsigned long)Super.s_imap_blocks)
    232 #define ZMAPS ((unsigned long)Super.s_zmap_blocks)
    233 #define FIRSTZONE ((unsigned long)Super.s_firstdatazone)
    234 #define ZONESIZE ((unsigned long)Super.s_log_zone_size)
    235 #define MAXSIZE ((unsigned long)Super.s_max_size)
    236 #define MAGIC (Super.s_magic)
    237 #define NORM_FIRSTZONE (2+IMAPS+ZMAPS+INODE_BLOCKS)
    238 
    239 static char *inode_map;
    240 static char *zone_map;
    241 
    242 static unsigned char *inode_count;
    243 static unsigned char *zone_count;
    244 
    245 static void recursive_check(unsigned int ino);
    246 #ifdef CONFIG_FEATURE_MINIX2
    247 static void recursive_check2(unsigned int ino);
    248 #endif
    249 
    250 static inline int bit(char *a, unsigned int i)
    251 {
    252       return (a[i >> 3] & (1<<(i & 7))) != 0;
    253 }
    254 #define inode_in_use(x) (bit(inode_map,(x)))
    255 #define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
    256 
    257 #define mark_inode(x) (setbit(inode_map,(x)),changed=1)
    258 #define unmark_inode(x) (clrbit(inode_map,(x)),changed=1)
    259 
    260 #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1),changed=1)
    261 #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1),changed=1)
    262 
    263 static void leave(int) ATTRIBUTE_NORETURN;
    264 static void leave(int status)
     233#define NORM_FIRSTZONE    (2 + IMAPS + ZMAPS + INODE_BLOCKS)
     234
     235/* Before you ask "where they come from?": */
     236/* setbit/clrbit are supplied by sys/param.h */
     237
     238static int minix_bit(const char *a, unsigned i)
     239{
     240    return (a[i >> 3] & (1<<(i & 7)));
     241}
     242
     243static void minix_setbit(char *a, unsigned i)
     244{
     245    setbit(a, i);
     246    changed = 1;
     247}
     248static void minix_clrbit(char *a, unsigned i)
     249{
     250    clrbit(a, i);
     251    changed = 1;
     252}
     253
     254/* Note: do not assume 0/1, it is 0/nonzero */
     255#define zone_in_use(x)  (minix_bit(zone_map,(x)-FIRSTZONE+1))
     256#define inode_in_use(x) (minix_bit(inode_map,(x)))
     257
     258#define mark_inode(x)   (minix_setbit(inode_map,(x)))
     259#define unmark_inode(x) (minix_clrbit(inode_map,(x)))
     260
     261#define mark_zone(x)    (minix_setbit(zone_map,(x)-FIRSTZONE+1))
     262#define unmark_zone(x)  (minix_clrbit(zone_map,(x)-FIRSTZONE+1))
     263
     264
     265static void recursive_check(unsigned ino);
     266#if ENABLE_FEATURE_MINIX2
     267static void recursive_check2(unsigned ino);
     268#endif
     269
     270static void die(const char *str) ATTRIBUTE_NORETURN;
     271static void die(const char *str)
    265272{
    266273    if (termios_set)
    267         tcsetattr(0, TCSANOW, &termios);
    268     exit(status);
    269 }
    270 
    271 static void die(const char *str)
    272 {
    273     bb_error_msg("%s", str);
    274     leave(8);
    275 }
    276 
    277 /* File-name data */
    278 enum { MAX_DEPTH = 32 };
    279 static int name_depth;
    280 static char *current_name;
    281 static char *name_component[MAX_DEPTH+1];
    282 
    283 /* Wed Feb  9 15:17:06 MST 2000 */
    284 /* dynamically allocate name_list (instead of making it static) */
    285 static inline void alloc_current_name(void)
    286 {
    287     current_name = xmalloc(MAX_DEPTH * (BUFSIZ + 1));
    288     current_name[0] = '/';
    289     current_name[1] = '\0';
    290     name_component[0] = &current_name[0];
    291 }
    292 
    293 #ifdef CONFIG_FEATURE_CLEAN_UP
    294 /* execute this atexit() to deallocate name_list[] */
    295 /* piptigger was here */
    296 static inline void free_current_name(void)
    297 {
    298     free(current_name);
    299 }
    300 #endif
     274        tcsetattr(0, TCSANOW, &sv_termios);
     275    bb_error_msg_and_die("%s", str);
     276}
    301277
    302278static void push_filename(const char *name)
     
    315291}
    316292
    317 static void pop_filename(void) {
     293static void pop_filename(void)
     294{
    318295    name_depth--;
    319296    if (name_depth < MAX_DEPTH) {
     
    331308
    332309    if (!repair) {
    333         printf("\n");
     310        puts("");
    334311        errors_uncorrected = 1;
    335312        return 0;
    336313    }
    337314    if (automatic) {
    338         printf("\n");
     315        puts("");
    339316        if (!def)
    340317            errors_uncorrected = 1;
     
    344321    for (;;) {
    345322        fflush(stdout);
    346         if ((c = getchar()) == EOF) {
     323        c = getchar();
     324        if (c == EOF) {
    347325            if (!def)
    348326                errors_uncorrected = 1;
     
    380358    int fd;
    381359
    382     if ((f = setmntent(MOUNTED, "r")) == NULL)
     360    f = setmntent(MOUNTED, "r");
     361    if (f == NULL)
    383362        return;
    384363    while ((mnt = getmntent(f)) != NULL)
     
    397376    if (fd < 0 && errno == EROFS)
    398377        return;
    399     else
    400         close(fd);
     378    close(fd);
    401379
    402380    printf("%s is mounted. ", device_name);
     
    408386        exit(0);
    409387    }
    410     return;
    411388}
    412389
     
    417394 * or a bad zone-number).
    418395 */
    419 static int check_zone_nr2(uint32_t *nr, int *corrected)
     396static int check_zone_nr2(uint32_t *nr, smallint *corrected)
    420397{
    421398    const char *msg;
     
    436413}
    437414
    438 static int check_zone_nr(uint16_t *nr, int *corrected)
     415static int check_zone_nr(uint16_t *nr, smallint *corrected)
    439416{
    440417    uint32_t nr32 = *nr;
     
    447424 * read-block reads block nr into the buffer at addr.
    448425 */
    449 static void read_block(unsigned int nr, char *addr)
     426static void read_block(unsigned nr, char *addr)
    450427{
    451428    if (!nr) {
     
    453430        return;
    454431    }
    455     if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) {
    456         printf("%s: unable to seek to block in file '%s'\n",
     432    if (BLOCK_SIZE * nr != lseek(dev_fd, BLOCK_SIZE * nr, SEEK_SET)) {
     433        printf("%s: cannot seek to block in file '%s'\n",
    457434                bb_msg_read_error, current_name);
    458435        errors_uncorrected = 1;
    459436        memset(addr, 0, BLOCK_SIZE);
    460     } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) {
     437    } else if (BLOCK_SIZE != read(dev_fd, addr, BLOCK_SIZE)) {
    461438        printf("%s: bad block in file '%s'\n",
    462439                bb_msg_read_error, current_name);
     
    469446 * write_block writes block nr to disk.
    470447 */
    471 static void write_block(unsigned int nr, char *addr)
     448static void write_block(unsigned nr, char *addr)
    472449{
    473450    if (!nr)
     
    479456        return;
    480457    }
    481     if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET))
    482         die("Seek failed in write_block");
    483     if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) {
     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)) {
    484461        printf("%s: bad block in file '%s'\n",
    485462                bb_msg_write_error, current_name);
     
    493470 * any indirect blocks with errors.
    494471 */
    495 static int map_block(struct minix_inode *inode, unsigned int blknr)
     472static int map_block(struct minix1_inode *inode, unsigned blknr)
    496473{
    497474    uint16_t ind[BLOCK_SIZE >> 1];
    498475    uint16_t dind[BLOCK_SIZE >> 1];
    499     int blk_chg, block, result;
     476    int block, result;
     477    smallint blk_chg;
    500478
    501479    if (blknr < 7)
     
    527505}
    528506
    529 #ifdef CONFIG_FEATURE_MINIX2
    530 static int map_block2(struct minix2_inode *inode, unsigned int blknr)
     507#if ENABLE_FEATURE_MINIX2
     508static int map_block2(struct minix2_inode *inode, unsigned blknr)
    531509{
    532510    uint32_t ind[BLOCK_SIZE >> 2];
    533511    uint32_t dind[BLOCK_SIZE >> 2];
    534512    uint32_t tind[BLOCK_SIZE >> 2];
    535     int blk_chg, block, result;
     513    int block, result;
     514    smallint blk_chg;
    536515
    537516    if (blknr < 7)
     
    593572     * unconditionally set if we get this far.
    594573     */
    595     Super.s_state |= MINIX_VALID_FS;
    596     if (errors_uncorrected)
    597         Super.s_state |= MINIX_ERROR_FS;
    598     else
     574    Super.s_state |= MINIX_VALID_FS | MINIX_ERROR_FS;
     575    if (!errors_uncorrected)
    599576        Super.s_state &= ~MINIX_ERROR_FS;
    600577
    601     if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
    602         die("Seek failed in write_super_block");
    603     if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE))
    604         die("Unable to write super-block");
     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");
    605582}
    606583
     
    609586    write_super_block();
    610587
    611     if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE))
    612         die("Unable to write inode map");
    613     if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE))
    614         die("Unable to write zone map");
    615     if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE))
    616         die("Unable to write inodes");
     588    if (IMAPS * BLOCK_SIZE != write(dev_fd, inode_map, IMAPS * BLOCK_SIZE))
     589        die("cannot write inode map");
     590    if (ZMAPS * BLOCK_SIZE != write(dev_fd, zone_map, ZMAPS * BLOCK_SIZE))
     591        die("cannot write zone map");
     592    if (INODE_BUFFER_SIZE != write(dev_fd, inode_buffer, INODE_BUFFER_SIZE))
     593        die("cannot write inodes");
    617594}
    618595
     
    623600    int size;
    624601
    625 #ifdef CONFIG_FEATURE_MINIX2
     602#if ENABLE_FEATURE_MINIX2
    626603    if (version2)
    627         block = Inode2[ROOT_INO].i_zone[0];
     604        block = Inode2[MINIX_ROOT_INO].i_zone[0];
    628605    else
    629606#endif
    630         block = Inode[ROOT_INO].i_zone[0];
     607        block = Inode1[MINIX_ROOT_INO].i_zone[0];
    631608    read_block(block, blk);
    632609    for (size = 16; size < BLOCK_SIZE; size <<= 1) {
     
    642619static void read_superblock(void)
    643620{
    644     if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET))
    645         die("Seek failed");
    646     if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE))
    647         die("Unable to read super block");
     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");
    648625    /* already initialized to:
    649626    namelen = 14;
     
    651628    version2 = 0;
    652629    */
    653     if (MAGIC == MINIX_SUPER_MAGIC) {
    654     } else if (MAGIC == MINIX_SUPER_MAGIC2) {
     630    if (MAGIC == MINIX1_SUPER_MAGIC) {
     631    } else if (MAGIC == MINIX1_SUPER_MAGIC2) {
    655632        namelen = 30;
    656633        dirsize = 32;
    657 #ifdef CONFIG_FEATURE_MINIX2
     634#if ENABLE_FEATURE_MINIX2
    658635    } else if (MAGIC == MINIX2_SUPER_MAGIC) {
    659636        version2 = 1;
     
    664641#endif
    665642    } else
    666         die("Bad magic number in super-block");
     643        die("bad magic number in super-block");
    667644    if (ZONESIZE != 0 || BLOCK_SIZE != 1024)
    668         die("Only 1k blocks/zones supported");
     645        die("only 1k blocks/zones supported");
    669646    if (IMAPS * BLOCK_SIZE * 8 < INODES + 1)
    670         die("Bad s_imap_blocks field in super-block");
     647        die("bad s_imap_blocks field in super-block");
    671648    if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1)
    672         die("Bad s_zmap_blocks field in super-block");
     649        die("bad s_zmap_blocks field in super-block");
    673650}
    674651
     
    680657    inode_count = xmalloc(INODES + 1);
    681658    zone_count = xmalloc(ZONES);
    682     if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE))
    683         die("Unable to read inode map");
    684     if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE))
    685         die("Unable to read zone map");
    686     if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE))
    687         die("Unable to read inodes");
     659    if (IMAPS * BLOCK_SIZE != read(dev_fd, inode_map, IMAPS * BLOCK_SIZE))
     660        die("cannot read inode map");
     661    if (ZMAPS * BLOCK_SIZE != read(dev_fd, zone_map, ZMAPS * BLOCK_SIZE))
     662        die("cannot read zone map");
     663    if (INODE_BUFFER_SIZE != read(dev_fd, inode_buffer, INODE_BUFFER_SIZE))
     664        die("cannot read inodes");
    688665    if (NORM_FIRSTZONE != FIRSTZONE) {
    689         printf("Warning: Firstzone!=Norm_firstzone\n");
     666        printf("warning: firstzone!=norm_firstzone\n");
    690667        errors_uncorrected = 1;
    691668    }
    692669    get_dirsize();
    693670    if (show) {
    694         printf("%ld inodes\n"
    695             "%ld blocks\n"
    696             "Firstdatazone=%ld (%ld)\n"
    697             "Zonesize=%d\n"
    698             "Maxsize=%ld\n"
    699             "Filesystem state=%d\n"
    700             "namelen=%d\n\n",
     671        printf("%u inodes\n"
     672            "%u blocks\n"
     673            "Firstdatazone=%u (%u)\n"
     674            "Zonesize=%u\n"
     675            "Maxsize=%u\n"
     676            "Filesystem state=%u\n"
     677            "namelen=%u\n\n",
    701678            INODES,
    702679            ZONES,
     
    709686}
    710687
    711 static struct minix_inode *get_inode(unsigned int nr)
    712 {
    713     struct minix_inode *inode;
     688static struct minix1_inode *get_inode(unsigned nr)
     689{
     690    struct minix1_inode *inode;
    714691
    715692    if (!nr || nr > INODES)
    716693        return NULL;
    717694    total++;
    718     inode = Inode + nr;
     695    inode = Inode1 + nr;
    719696    if (!inode_count[nr]) {
    720697        if (!inode_in_use(nr)) {
     
    724701                if (ask("Mark as 'in use'", 1))
    725702                    mark_inode(nr);
    726             } else {
    727                 errors_uncorrected = 1;
     703                else
     704                    errors_uncorrected = 1;
    728705            }
    729706        }
     
    754731}
    755732
    756 #ifdef CONFIG_FEATURE_MINIX2
    757 static struct minix2_inode *get_inode2(unsigned int nr)
     733#if ENABLE_FEATURE_MINIX2
     734static struct minix2_inode *get_inode2(unsigned nr)
    758735{
    759736    struct minix2_inode *inode;
     
    802779static void check_root(void)
    803780{
    804     struct minix_inode *inode = Inode + ROOT_INO;
     781    struct minix1_inode *inode = Inode1 + MINIX_ROOT_INO;
    805782
    806783    if (!inode || !S_ISDIR(inode->i_mode))
    807         die("Root inode isn't a directory");
    808 }
    809 
    810 #ifdef CONFIG_FEATURE_MINIX2
     784        die("root inode isn't a directory");
     785}
     786
     787#if ENABLE_FEATURE_MINIX2
    811788static void check_root2(void)
    812789{
    813     struct minix2_inode *inode = Inode2 + ROOT_INO;
     790    struct minix2_inode *inode = Inode2 + MINIX_ROOT_INO;
    814791
    815792    if (!inode || !S_ISDIR(inode->i_mode))
    816         die("Root inode isn't a directory");
    817 }
    818 #endif
    819 
    820 static int add_zone(uint16_t *znr, int *corrected)
     793        die("root inode isn't a directory");
     794}
     795#else
     796void check_root2(void);
     797#endif
     798
     799static int add_zone(uint16_t *znr, smallint *corrected)
    821800{
    822801    int result;
     
    848827}
    849828
    850 #ifdef CONFIG_FEATURE_MINIX2
    851 static int add_zone2(uint32_t *znr, int *corrected)
     829#if ENABLE_FEATURE_MINIX2
     830static int add_zone2(uint32_t *znr, smallint *corrected)
    852831{
    853832    int result;
     
    880859#endif
    881860
    882 static void add_zone_ind(uint16_t *znr, int *corrected)
    883 {
    884     static char blk[BLOCK_SIZE];
    885     int i, chg_blk = 0;
     861static void add_zone_ind(uint16_t *znr, smallint *corrected)
     862{
     863    int i;
    886864    int block;
     865    smallint chg_blk = 0;
    887866
    888867    block = add_zone(znr, corrected);
    889868    if (!block)
    890869        return;
    891     read_block(block, blk);
     870    read_block(block, add_zone_ind_blk);
    892871    for (i = 0; i < (BLOCK_SIZE >> 1); i++)
    893         add_zone(i + (uint16_t *) blk, &chg_blk);
     872        add_zone(i + (uint16_t *) add_zone_ind_blk, &chg_blk);
    894873    if (chg_blk)
    895         write_block(block, blk);
    896 }
    897 
    898 #ifdef CONFIG_FEATURE_MINIX2
    899 static void add_zone_ind2(uint32_t *znr, int *corrected)
    900 {
    901     static char blk[BLOCK_SIZE];
    902     int i, chg_blk = 0;
     874        write_block(block, add_zone_ind_blk);
     875}
     876
     877#if ENABLE_FEATURE_MINIX2
     878static void add_zone_ind2(uint32_t *znr, smallint *corrected)
     879{
     880    int i;
    903881    int block;
     882    smallint chg_blk = 0;
    904883
    905884    block = add_zone2(znr, corrected);
    906885    if (!block)
    907886        return;
    908     read_block(block, blk);
     887    read_block(block, add_zone_ind_blk);
    909888    for (i = 0; i < BLOCK_SIZE >> 2; i++)
    910         add_zone2(i + (uint32_t *) blk, &chg_blk);
     889        add_zone2(i + (uint32_t *) add_zone_ind_blk, &chg_blk);
    911890    if (chg_blk)
    912         write_block(block, blk);
    913 }
    914 #endif
    915 
    916 static void add_zone_dind(uint16_t *znr, int *corrected)
    917 {
    918     static char blk[BLOCK_SIZE];
    919     int i, blk_chg = 0;
     891        write_block(block, add_zone_ind_blk);
     892}
     893#endif
     894
     895static void add_zone_dind(uint16_t *znr, smallint *corrected)
     896{
     897    int i;
    920898    int block;
     899    smallint chg_blk = 0;
    921900
    922901    block = add_zone(znr, corrected);
    923902    if (!block)
    924903        return;
    925     read_block(block, blk);
     904    read_block(block, add_zone_dind_blk);
    926905    for (i = 0; i < (BLOCK_SIZE >> 1); i++)
    927         add_zone_ind(i + (uint16_t *) blk, &blk_chg);
    928     if (blk_chg)
    929         write_block(block, blk);
    930 }
    931 
    932 #ifdef CONFIG_FEATURE_MINIX2
    933 static void add_zone_dind2(uint32_t *znr, int *corrected)
    934 {
    935     static char blk[BLOCK_SIZE];
    936     int i, blk_chg = 0;
     906        add_zone_ind(i + (uint16_t *) add_zone_dind_blk, &chg_blk);
     907    if (chg_blk)
     908        write_block(block, add_zone_dind_blk);
     909}
     910
     911#if ENABLE_FEATURE_MINIX2
     912static void add_zone_dind2(uint32_t *znr, smallint *corrected)
     913{
     914    int i;
    937915    int block;
     916    smallint chg_blk = 0;
    938917
    939918    block = add_zone2(znr, corrected);
    940919    if (!block)
    941920        return;
    942     read_block(block, blk);
     921    read_block(block, add_zone_dind_blk);
    943922    for (i = 0; i < BLOCK_SIZE >> 2; i++)
    944         add_zone_ind2(i + (uint32_t *) blk, &blk_chg);
    945     if (blk_chg)
    946         write_block(block, blk);
    947 }
    948 
    949 static void add_zone_tind2(uint32_t *znr, int *corrected)
    950 {
    951     static char blk[BLOCK_SIZE];
    952     int i, blk_chg = 0;
     923        add_zone_ind2(i + (uint32_t *) add_zone_dind_blk, &chg_blk);
     924    if (chg_blk)
     925        write_block(block, add_zone_dind_blk);
     926}
     927
     928static void add_zone_tind2(uint32_t *znr, smallint *corrected)
     929{
     930    int i;
    953931    int block;
     932    smallint chg_blk = 0;
    954933
    955934    block = add_zone2(znr, corrected);
    956935    if (!block)
    957936        return;
    958     read_block(block, blk);
     937    read_block(block, add_zone_tind_blk);
    959938    for (i = 0; i < BLOCK_SIZE >> 2; i++)
    960         add_zone_dind2(i + (uint32_t *) blk, &blk_chg);
    961     if (blk_chg)
    962         write_block(block, blk);
    963 }
    964 #endif
    965 
    966 static void check_zones(unsigned int i)
    967 {
    968     struct minix_inode *inode;
     939        add_zone_dind2(i + (uint32_t *) add_zone_tind_blk, &chg_blk);
     940    if (chg_blk)
     941        write_block(block, add_zone_tind_blk);
     942}
     943#endif
     944
     945static void check_zones(unsigned i)
     946{
     947    struct minix1_inode *inode;
    969948
    970949    if (!i || i > INODES)
     
    972951    if (inode_count[i] > 1)     /* have we counted this file already? */
    973952        return;
    974     inode = Inode + i;
     953    inode = Inode1 + i;
    975954    if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
    976955        !S_ISLNK(inode->i_mode)) return;
     
    981960}
    982961
    983 #ifdef CONFIG_FEATURE_MINIX2
    984 static void check_zones2(unsigned int i)
     962#if ENABLE_FEATURE_MINIX2
     963static void check_zones2(unsigned i)
    985964{
    986965    struct minix2_inode *inode;
     
    1002981#endif
    1003982
    1004 static void check_file(struct minix_inode *dir, unsigned int offset)
    1005 {
    1006     static char blk[BLOCK_SIZE];
    1007     struct minix_inode *inode;
     983static void check_file(struct minix1_inode *dir, unsigned offset)
     984{
     985    struct minix1_inode *inode;
    1008986    int ino;
    1009987    char *name;
     
    1011989
    1012990    block = map_block(dir, offset / BLOCK_SIZE);
    1013     read_block(block, blk);
    1014     name = blk + (offset % BLOCK_SIZE) + 2;
     991    read_block(block, check_file_blk);
     992    name = check_file_blk + (offset % BLOCK_SIZE) + 2;
    1015993    ino = *(uint16_t *) (name - 2);
    1016994    if (ino > INODES) {
     
    1019997        if (ask("Remove", 1)) {
    1020998            *(uint16_t *) (name - 2) = 0;
    1021             write_block(block, blk);
     999            write_block(block, check_file_blk);
    10221000        }
    10231001        ino = 0;
     
    10271005    pop_filename();
    10281006    if (!offset) {
    1029         if (!inode || strcmp(".", name)) {
    1030             printf("%s: bad directory: '.' isn't first\n", current_name);
    1031             errors_uncorrected = 1;
    1032         } else
     1007        if (inode && LONE_CHAR(name, '.'))
    10331008            return;
     1009        printf("%s: bad directory: '.' isn't first\n", current_name);
     1010        errors_uncorrected = 1;
    10341011    }
    10351012    if (offset == dirsize) {
    1036         if (!inode || strcmp("..", name)) {
    1037             printf("%s: bad directory: '..' isn't second\n", current_name);
    1038             errors_uncorrected = 1;
    1039         } else
     1013        if (inode && strcmp("..", name) == 0)
    10401014            return;
     1015        printf("%s: bad directory: '..' isn't second\n", current_name);
     1016        errors_uncorrected = 1;
    10411017    }
    10421018    if (!inode)
     
    10521028        recursive_check(ino);
    10531029    pop_filename();
    1054     return;
    1055 }
    1056 
    1057 #ifdef CONFIG_FEATURE_MINIX2
    1058 static void check_file2(struct minix2_inode *dir, unsigned int offset)
    1059 {
    1060     static char blk[BLOCK_SIZE];
     1030}
     1031
     1032#if ENABLE_FEATURE_MINIX2
     1033static void check_file2(struct minix2_inode *dir, unsigned offset)
     1034{
    10611035    struct minix2_inode *inode;
    10621036    int ino;
     
    10651039
    10661040    block = map_block2(dir, offset / BLOCK_SIZE);
    1067     read_block(block, blk);
    1068     name = blk + (offset % BLOCK_SIZE) + 2;
     1041    read_block(block, check_file_blk);
     1042    name = check_file_blk + (offset % BLOCK_SIZE) + 2;
    10691043    ino = *(uint16_t *) (name - 2);
    10701044    if (ino > INODES) {
     
    10731047        if (ask("Remove", 1)) {
    10741048            *(uint16_t *) (name - 2) = 0;
    1075             write_block(block, blk);
     1049            write_block(block, check_file_blk);
    10761050        }
    10771051        ino = 0;
     
    10811055    pop_filename();
    10821056    if (!offset) {
    1083         if (!inode || strcmp(".", name)) {
    1084             printf("%s: bad directory: '.' isn't first\n", current_name);
    1085             errors_uncorrected = 1;
    1086         } else
     1057        if (inode && LONE_CHAR(name, '.'))
    10871058            return;
     1059        printf("%s: bad directory: '.' isn't first\n", current_name);
     1060        errors_uncorrected = 1;
    10881061    }
    10891062    if (offset == dirsize) {
    1090         if (!inode || strcmp("..", name)) {
    1091             printf("%s: bad directory: '..' isn't second\n", current_name);
    1092             errors_uncorrected = 1;
    1093         } else
     1063        if (inode && strcmp("..", name) == 0)
    10941064            return;
     1065        printf("%s: bad directory: '..' isn't second\n", current_name);
     1066        errors_uncorrected = 1;
    10951067    }
    10961068    if (!inode)
     
    11061078        recursive_check2(ino);
    11071079    pop_filename();
    1108     return;
    1109 }
    1110 #endif
    1111 
    1112 static void recursive_check(unsigned int ino)
    1113 {
    1114     struct minix_inode *dir;
    1115     unsigned int offset;
    1116 
    1117     dir = Inode + ino;
     1080}
     1081#endif
     1082
     1083static void recursive_check(unsigned ino)
     1084{
     1085    struct minix1_inode *dir;
     1086    unsigned offset;
     1087
     1088    dir = Inode1 + ino;
    11181089    if (!S_ISDIR(dir->i_mode))
    1119         die("Internal error");
     1090        die("internal error");
    11201091    if (dir->i_size < 2 * dirsize) {
    11211092        printf("%s: bad directory: size<32", current_name);
     
    11261097}
    11271098
    1128 #ifdef CONFIG_FEATURE_MINIX2
    1129 static void recursive_check2(unsigned int ino)
     1099#if ENABLE_FEATURE_MINIX2
     1100static void recursive_check2(unsigned ino)
    11301101{
    11311102    struct minix2_inode *dir;
    1132     unsigned int offset;
     1103    unsigned offset;
    11331104
    11341105    dir = Inode2 + ino;
    11351106    if (!S_ISDIR(dir->i_mode))
    1136         die("Internal error");
     1107        die("internal error");
    11371108    if (dir->i_size < 2 * dirsize) {
    11381109        printf("%s: bad directory: size<32", current_name);
     
    11461117static int bad_zone(int i)
    11471118{
    1148     char buffer[1024];
    1149 
    1150     if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET))
    1151         die("Seek failed in bad_zone");
    1152     return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE));
     1119    char buffer[BLOCK_SIZE];
     1120
     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));
    11531124}
    11541125
     
    11581129
    11591130    for (i = 1; i <= INODES; i++) {
    1160         if (warn_mode && Inode[i].i_mode && !inode_in_use(i)) {
     1131        if (warn_mode && Inode1[i].i_mode && !inode_in_use(i)) {
    11611132            printf("Inode %d has non-zero mode. ", i);
    11621133            if (ask("Clear", 1)) {
    1163                 Inode[i].i_mode = 0;
     1134                Inode1[i].i_mode = 0;
    11641135                changed = 1;
    11651136            }
     
    11781149                mark_inode(i);
    11791150        }
    1180         if (Inode[i].i_nlinks != inode_count[i]) {
     1151        if (Inode1[i].i_nlinks != inode_count[i]) {
    11811152            printf("Inode %d (mode=%07o), i_nlinks=%d, counted=%d. ",
    1182                    i, Inode[i].i_mode, Inode[i].i_nlinks, inode_count[i]);
     1153                i, Inode1[i].i_mode, Inode1[i].i_nlinks,
     1154                inode_count[i]);
    11831155            if (ask("Set i_nlinks to count", 1)) {
    1184                 Inode[i].i_nlinks = inode_count[i];
     1156                Inode1[i].i_nlinks = inode_count[i];
    11851157                changed = 1;
    11861158            }
     
    11881160    }
    11891161    for (i = FIRSTZONE; i < ZONES; i++) {
    1190         if (zone_in_use(i) == zone_count[i])
     1162        if ((zone_in_use(i) != 0) == zone_count[i])
    11911163            continue;
    11921164        if (!zone_count[i]) {
     
    12031175}
    12041176
    1205 #ifdef CONFIG_FEATURE_MINIX2
     1177#if ENABLE_FEATURE_MINIX2
    12061178static void check_counts2(void)
    12071179{
     
    12311203        if (Inode2[i].i_nlinks != inode_count[i]) {
    12321204            printf("Inode %d (mode=%07o), i_nlinks=%d, counted=%d. ",
    1233                    i, Inode2[i].i_mode, Inode2[i].i_nlinks,
    1234                    inode_count[i]);
     1205                i, Inode2[i].i_mode, Inode2[i].i_nlinks,
     1206                inode_count[i]);
    12351207            if (ask("Set i_nlinks to count", 1)) {
    12361208                Inode2[i].i_nlinks = inode_count[i];
     
    12401212    }
    12411213    for (i = FIRSTZONE; i < ZONES; i++) {
    1242         if (zone_in_use(i) == zone_count[i])
     1214        if ((zone_in_use(i) != 0) == zone_count[i])
    12431215            continue;
    12441216        if (!zone_count[i]) {
     
    12601232    memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count));
    12611233    memset(zone_count, 0, ZONES * sizeof(*zone_count));
    1262     check_zones(ROOT_INO);
    1263     recursive_check(ROOT_INO);
     1234    check_zones(MINIX_ROOT_INO);
     1235    recursive_check(MINIX_ROOT_INO);
    12641236    check_counts();
    12651237}
    12661238
    1267 #ifdef CONFIG_FEATURE_MINIX2
     1239#if ENABLE_FEATURE_MINIX2
    12681240static void check2(void)
    12691241{
    12701242    memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count));
    12711243    memset(zone_count, 0, ZONES * sizeof(*zone_count));
    1272     check_zones2(ROOT_INO);
    1273     recursive_check2(ROOT_INO);
     1244    check_zones2(MINIX_ROOT_INO);
     1245    recursive_check2(MINIX_ROOT_INO);
    12741246    check_counts2();
    12751247}
    1276 #endif
    1277 
     1248#else
     1249void check2(void);
     1250#endif
     1251
     1252int fsck_minix_main(int argc, char **argv);
    12781253int fsck_minix_main(int argc, char **argv)
    12791254{
     
    12811256    int retcode = 0;
    12821257
    1283     alloc_current_name();
    1284 #ifdef CONFIG_FEATURE_CLEAN_UP
    1285     /* Don't bother to free memory.  Exit does
    1286      * that automagically, so we can save a few bytes */
    1287     atexit(free_current_name);
    1288 #endif
    1289 
    1290     if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
    1291         die("Bad inode size");
    1292 #ifdef CONFIG_FEATURE_MINIX2
     1258    xfunc_error_retval = 8;
     1259
     1260    INIT_G();
     1261
     1262    if (INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE)
     1263        die("bad inode size");
     1264#if ENABLE_FEATURE_MINIX2
    12931265    if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
    1294         die("Bad v2 inode size");
    1295 #endif
    1296     while (argc-- > 1) {
     1266        die("bad v2 inode size");
     1267#endif
     1268    while (--argc != 0) {
    12971269        argv++;
    12981270        if (argv[0][0] != '-') {
    12991271            if (device_name)
    13001272                bb_show_usage();
    1301             else
    1302                 device_name = argv[0];
    1303         } else
    1304             while (*++argv[0])
     1273            device_name = argv[0];
     1274        } else {
     1275            while (*++argv[0]) {
    13051276                switch (argv[0][0]) {
    13061277                case 'l':
     
    13301301                    bb_show_usage();
    13311302                }
     1303            }
     1304        }
    13321305    }
    13331306    if (!device_name)
    13341307        bb_show_usage();
     1308
    13351309    check_mount();              /* trying to check a mounted filesystem? */
    13361310    if (repair && !automatic) {
    13371311        if (!isatty(0) || !isatty(1))
    1338             die("Need terminal for interactive repairs");
    1339     }
    1340     IN = open(device_name, repair ? O_RDWR : O_RDONLY);
    1341     if (IN < 0){
    1342         printf("Unable to open device '%s'\n", device_name);
    1343         leave(8);
    1344     }
    1345     sync(); /* paranoia? */
     1312            die("need terminal for interactive repairs");
     1313    }
     1314    dev_fd = xopen(device_name, repair ? O_RDWR : O_RDONLY);
     1315
     1316    /*sync(); paranoia? */
    13461317    read_superblock();
    13471318
     
    13521323     * command line.
    13531324     */
    1354     printf("%s, %s\n", bb_applet_name, program_version);
    1355     if (!(Super.s_state & MINIX_ERROR_FS) &&
    1356         (Super.s_state & MINIX_VALID_FS) && !force) {
     1325    printf("%s: %s\n", applet_name, bb_banner);
     1326
     1327    if (!(Super.s_state & MINIX_ERROR_FS)
     1328     && (Super.s_state & MINIX_VALID_FS) && !force
     1329    ) {
    13571330        if (repair)
    13581331            printf("%s is clean, check is skipped\n", device_name);
    1359         return retcode;
     1332        return 0;
    13601333    } else if (force)
    13611334        printf("Forcing filesystem check on %s\n", device_name);
     
    13671340
    13681341    if (repair && !automatic) {
    1369         tcgetattr(0, &termios);
    1370         tmp = termios;
     1342        tcgetattr(0, &sv_termios);
     1343        tmp = sv_termios;
    13711344        tmp.c_lflag &= ~(ICANON | ECHO);
    13721345        tcsetattr(0, TCSANOW, &tmp);
    13731346        termios_set = 1;
    13741347    }
    1375 #ifdef CONFIG_FEATURE_MINIX2
     1348
    13761349    if (version2) {
    13771350        check_root2();
    13781351        check2();
    1379     } else
    1380 #endif
    1381     {
     1352    } else {
    13821353        check_root();
    13831354        check();
    13841355    }
     1356
    13851357    if (verbose) {
    13861358        int i, free_cnt;
     
    13891361            if (!inode_in_use(i))
    13901362                free_cnt++;
    1391         printf("\n%6ld inodes used (%ld%%)\n", (INODES - free_cnt),
     1363        printf("\n%6u inodes used (%u%%)\n", (INODES - free_cnt),
    13921364               100 * (INODES - free_cnt) / INODES);
    13931365        for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++)
    13941366            if (!zone_in_use(i))
    13951367                free_cnt++;
    1396         printf("%6ld zones used (%ld%%)\n\n"
    1397                "%6d regular files\n"
    1398                "%6d directories\n"
    1399                "%6d character device files\n"
    1400                "%6d block device files\n"
    1401                "%6d links\n"
    1402                "%6d symbolic links\n"
     1368        printf("%6u zones used (%u%%)\n\n"
     1369               "%6u regular files\n"
     1370               "%6u directories\n"
     1371               "%6u character device files\n"
     1372               "%6u block device files\n"
     1373               "%6u links\n"
     1374               "%6u symbolic links\n"
    14031375               "------\n"
    1404                "%6d files\n",
     1376               "%6u files\n",
    14051377               (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES,
    14061378               regular, directory, chardev, blockdev,
     
    14161388
    14171389    if (repair && !automatic)
    1418         tcsetattr(0, TCSANOW, &termios);
     1390        tcsetattr(0, TCSANOW, &sv_termios);
    14191391
    14201392    if (changed)
Note: See TracChangeset for help on using the changeset viewer.