Fixes so "make allnoconfig" works again.
[oweals/busybox.git] / util-linux / fsck_minix.c
index 9a53a705e60a11ec3a9123c189ffd2b227fd7fe3..f6d7deaab6fc6f99bdad2f2e866befe75164af9b 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 /*
- * 09.11.91  -  made the first rudimetary functions
+ * 09.11.91  -  made the first rudimentary functions
  *
  * 10.11.91  -  updated, does checking, no repairs yet.
  *             Sent out to the mailing-list for testing.
  * 01.07.96  - Fixed the v2 fs stuff to use the right #defines and such
  *            for modern libcs (janl@math.uio.no, Nicolai Langfeldt)
  *
- * 02.07.96  - Added C bit fiddling routines from rmk@ecs.soton.ac.uk 
+ * 02.07.96  - Added C bit fiddling routines from rmk@ecs.soton.ac.uk
  *             (Russell King).  He made them for ARM.  It would seem
  *            that the ARM is powerful enough to do this in C whereas
  *             i386 and m64k must use assembly to get it fast >:-)
- *            This should make minix fsck systemindependent.
+ *            This should make minix fsck system-independent.
  *            (janl@math.uio.no, Nicolai Langfeldt)
  *
  * 04.11.96  - Added minor fixes from Andreas Schwab to avoid compiler
- *             warnings.  Added mc68k bitops from 
+ *             warnings.  Added mc68k bitops from
  *            Joerg Dorchain <dorchain@mpi-sb.mpg.de>.
  *
  * 06.11.96  - Added v2 code submitted by Joerg Dorchain, but written by
@@ -73,7 +73,7 @@
  * unless you can be sure nobody is writing to it (and remember that the
  * kernel can write to it when it searches for files).
  *
- * Usuage: fsck [-larvsm] device
+ * Usage: fsck [-larvsm] device
  *     -l for a listing of all the filenames
  *     -a for automatic repairs (not implemented)
  *     -r for repairs (interactive) (not implemented)
@@ -83,7 +83,7 @@
  *     -f force filesystem check even if filesystem marked as valid
  *
  * The device may be a block device or a image of one, but this isn't
- * enforced (but it's not much fun on a character device :-). 
+ * enforced (but it's not much fun on a character device :-).
  */
 
 #include <stdio.h>
 #include <sys/param.h>
 #include "busybox.h"
 
- typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-
-
 static const int MINIX_ROOT_INO = 1;
 static const int MINIX_LINK_MAX = 250;
 static const int MINIX2_LINK_MAX = 65530;
@@ -130,13 +124,13 @@ static const int MINIX_V2 = 0x0002;               /* minix V2 fs */
  * Note the 8-bit gid and atime and ctime.
  */
 struct minix_inode {
-       u16 i_mode;
-       u16 i_uid;
-       u32 i_size;
-       u32 i_time;
-       u8  i_gid;
-       u8  i_nlinks;
-       u16 i_zone[9];
+       uint16_t i_mode;
+       uint16_t i_uid;
+       uint32_t i_size;
+       uint32_t i_time;
+       uint8_t  i_gid;
+       uint8_t  i_nlinks;
+       uint16_t i_zone[9];
 };
 
 /*
@@ -146,35 +140,35 @@ struct minix_inode {
  * now 16-bit. The inode is now 64 bytes instead of 32.
  */
 struct minix2_inode {
-       u16 i_mode;
-       u16 i_nlinks;
-       u16 i_uid;
-       u16 i_gid;
-       u32 i_size;
-       u32 i_atime;
-       u32 i_mtime;
-       u32 i_ctime;
-       u32 i_zone[10];
+       uint16_t i_mode;
+       uint16_t i_nlinks;
+       uint16_t i_uid;
+       uint16_t i_gid;
+       uint32_t i_size;
+       uint32_t i_atime;
+       uint32_t i_mtime;
+       uint32_t i_ctime;
+       uint32_t i_zone[10];
 };
 
 /*
  * minix super-block data on disk
  */
 struct minix_super_block {
-       u16 s_ninodes;
-       u16 s_nzones;
-       u16 s_imap_blocks;
-       u16 s_zmap_blocks;
-       u16 s_firstdatazone;
-       u16 s_log_zone_size;
-       u32 s_max_size;
-       u16 s_magic;
-       u16 s_state;
-       u32 s_zones;
+       uint16_t s_ninodes;
+       uint16_t s_nzones;
+       uint16_t s_imap_blocks;
+       uint16_t s_zmap_blocks;
+       uint16_t s_firstdatazone;
+       uint16_t s_log_zone_size;
+       uint32_t s_max_size;
+       uint16_t s_magic;
+       uint16_t s_state;
+       uint32_t s_zones;
 };
 
 struct minix_dir_entry {
-       u16 inode;
+       uint16_t inode;
        char name[0];
 };
 
@@ -197,7 +191,7 @@ static const int ROOT_INO = 1;
 
 #define UPPER(size,n) ((size+((n)-1))/(n))
 #define INODE_SIZE (sizeof(struct minix_inode))
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 #define INODE_SIZE2 (sizeof(struct minix2_inode))
 #define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \
                                    : MINIX_INODES_PER_BLOCK))
@@ -238,7 +232,7 @@ static char super_block_buffer[BLOCK_SIZE];
 
 #define Super (*(struct minix_super_block *)super_block_buffer)
 #define INODES ((unsigned long)Super.s_ninodes)
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 #define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones))
 #else
 #define ZONES ((unsigned long)(Super.s_nzones))
@@ -258,7 +252,7 @@ static unsigned char *inode_count = NULL;
 static unsigned char *zone_count = NULL;
 
 static void recursive_check(unsigned int ino);
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void recursive_check2(unsigned int ino);
 #endif
 
@@ -285,7 +279,7 @@ static void leave(int status)
 
 static void die(const char *str)
 {
-       error_msg("%s", str);
+       bb_error_msg("%s", str);
        leave(8);
 }
 
@@ -414,7 +408,7 @@ static int check_zone_nr(unsigned short *nr, int *corrected)
        return 0;
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static int check_zone_nr2(unsigned int *nr, int *corrected)
 {
        if (!*nr)
@@ -521,7 +515,7 @@ static int map_block(struct minix_inode *inode, unsigned int blknr)
        return result;
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static int map_block2(struct minix2_inode *inode, unsigned int blknr)
 {
        unsigned int ind[BLOCK_SIZE >> 2];
@@ -619,7 +613,7 @@ static void get_dirsize(void)
        char blk[BLOCK_SIZE];
        int size;
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
        if (version2)
                block = Inode2[ROOT_INO].i_zone[0];
        else
@@ -650,7 +644,7 @@ static void read_superblock(void)
                namelen = 30;
                dirsize = 32;
                version2 = 0;
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
        } else if (MAGIC == MINIX2_SUPER_MAGIC) {
                namelen = 14;
                dirsize = 16;
@@ -701,7 +695,7 @@ static void read_tables(void)
        }
 }
 
-struct minix_inode *get_inode(unsigned int nr)
+static struct minix_inode *get_inode(unsigned int nr)
 {
        struct minix_inode *inode;
 
@@ -748,8 +742,8 @@ struct minix_inode *get_inode(unsigned int nr)
        return inode;
 }
 
-#ifdef BB_FEATURE_MINIX2
-struct minix2_inode *get_inode2(unsigned int nr)
+#ifdef CONFIG_FEATURE_MINIX2
+static struct minix2_inode *get_inode2(unsigned int nr)
 {
        struct minix2_inode *inode;
 
@@ -804,7 +798,7 @@ static void check_root(void)
                die("root inode isn't a directory");
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void check_root2(void)
 {
        struct minix2_inode *inode = Inode2 + ROOT_INO;
@@ -847,7 +841,7 @@ static int add_zone(unsigned short *znr, int *corrected)
        return block;
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static int add_zone2(unsigned int *znr, int *corrected)
 {
        int result;
@@ -898,7 +892,7 @@ static void add_zone_ind(unsigned short *znr, int *corrected)
                write_block(block, blk);
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void add_zone_ind2(unsigned int *znr, int *corrected)
 {
        static char blk[BLOCK_SIZE];
@@ -932,7 +926,7 @@ static void add_zone_dind(unsigned short *znr, int *corrected)
                write_block(block, blk);
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void add_zone_dind2(unsigned int *znr, int *corrected)
 {
        static char blk[BLOCK_SIZE];
@@ -983,7 +977,7 @@ static void check_zones(unsigned int i)
        add_zone_dind(8 + inode->i_zone, &changed);
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void check_zones2(unsigned int i)
 {
        struct minix2_inode *inode;
@@ -1068,7 +1062,7 @@ static void check_file(struct minix_inode *dir, unsigned int offset)
        return;
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void check_file2(struct minix2_inode *dir, unsigned int offset)
 {
        static char blk[BLOCK_SIZE];
@@ -1149,7 +1143,7 @@ static void recursive_check(unsigned int ino)
                check_file(dir, offset);
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void recursive_check2(unsigned int ino)
 {
        struct minix2_inode *dir;
@@ -1227,7 +1221,7 @@ static void check_counts(void)
        }
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void check_counts2(void)
 {
        int i;
@@ -1289,7 +1283,7 @@ static void check(void)
        check_counts();
 }
 
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
 static void check2(void)
 {
        memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count));
@@ -1311,18 +1305,16 @@ static void alloc_name_list(void)
                name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1);
 }
 
-#ifdef BB_FEATURE_CLEAN_UP
+#ifdef CONFIG_FEATURE_CLEAN_UP
 /* execute this atexit() to deallocate name_list[] */
 /* piptigger was here */
 static void free_name_list(void)
 {
        int i;
 
-       if (name_list) { 
+       if (name_list) {
                for (i = 0; i < MAX_DEPTH; i++) {
-                       if (name_list[i]) {
-                               free(name_list[i]);
-                       }
+                       free(name_list[i]);
                }
                free(name_list);
        }
@@ -1336,7 +1328,7 @@ extern int fsck_minix_main(int argc, char **argv)
        int retcode = 0;
 
        alloc_name_list();
-#ifdef BB_FEATURE_CLEAN_UP
+#ifdef CONFIG_FEATURE_CLEAN_UP
        /* Don't bother to free memory.  Exit does
         * that automagically, so we can save a few bytes */
        atexit(free_name_list);
@@ -1344,7 +1336,7 @@ extern int fsck_minix_main(int argc, char **argv)
 
        if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
                die("bad inode size");
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
        if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
                die("bad v2 inode size");
 #endif
@@ -1352,7 +1344,7 @@ extern int fsck_minix_main(int argc, char **argv)
                argv++;
                if (argv[0][0] != '-') {
                        if (device_name)
-                               show_usage();
+                               bb_show_usage();
                        else
                                device_name = argv[0];
                } else
@@ -1382,11 +1374,11 @@ extern int fsck_minix_main(int argc, char **argv)
                                        force = 1;
                                        break;
                                default:
-                                       show_usage();
+                                       bb_show_usage();
                                }
        }
        if (!device_name)
-               show_usage();
+               bb_show_usage();
        check_mount();                          /* trying to check a mounted filesystem? */
        if (repair && !automatic) {
                if (!isatty(0) || !isatty(1))
@@ -1404,10 +1396,10 @@ extern int fsck_minix_main(int argc, char **argv)
        /*
         * Determine whether or not we should continue with the checking.
         * This is based on the status of the filesystem valid and error
-        * flags and whether or not the -f switch was specified on the 
+        * flags and whether or not the -f switch was specified on the
         * command line.
         */
-       printf("%s, %s\n", applet_name, program_version);
+       printf("%s, %s\n", bb_applet_name, program_version);
        if (!(Super.s_state & MINIX_ERROR_FS) &&
                (Super.s_state & MINIX_VALID_FS) && !force) {
                if (repair)
@@ -1428,7 +1420,7 @@ extern int fsck_minix_main(int argc, char **argv)
                tcsetattr(0, TCSANOW, &tmp);
                termios_set = 1;
        }
-#ifdef BB_FEATURE_MINIX2
+#ifdef CONFIG_FEATURE_MINIX2
        if (version2) {
                check_root2();
                check2();
@@ -1439,18 +1431,18 @@ extern int fsck_minix_main(int argc, char **argv)
                check();
        }
        if (verbose) {
-               int i, free;
+               int i, free_cnt;
 
-               for (i = 1, free = 0; i <= INODES; i++)
+               for (i = 1, free_cnt = 0; i <= INODES; i++)
                        if (!inode_in_use(i))
-                               free++;
-               printf("\n%6ld inodes used (%ld%%)\n", (INODES - free),
-                          100 * (INODES - free) / INODES);
-               for (i = FIRSTZONE, free = 0; i < ZONES; i++)
+                               free_cnt++;
+               printf("\n%6ld inodes used (%ld%%)\n", (INODES - free_cnt),
+                          100 * (INODES - free_cnt) / INODES);
+               for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++)
                        if (!zone_in_use(i))
-                               free++;
-               printf("%6ld zones used (%ld%%)\n", (ZONES - free),
-                          100 * (ZONES - free) / ZONES);
+                               free_cnt++;
+               printf("%6ld zones used (%ld%%)\n", (ZONES - free_cnt),
+                          100 * (ZONES - free_cnt) / ZONES);
                printf("\n%6d regular files\n"
                           "%6d directories\n"
                           "%6d character device files\n"