X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=fsck_minix.c;h=9a53a705e60a11ec3a9123c189ffd2b227fd7fe3;hb=8bb7df49c24de71f28b47eb2e3b86fb5b2e9d42a;hp=c3c493fd2fe8345bf86f488b6dd4712132a08afc;hpb=bc0aed79a8c7bb24c32a21533893fdad660b7292;p=oweals%2Fbusybox.git diff --git a/fsck_minix.c b/fsck_minix.c index c3c493fd2..9a53a705e 100644 --- a/fsck_minix.c +++ b/fsck_minix.c @@ -86,7 +86,6 @@ * enforced (but it's not much fun on a character device :-). */ -#include "internal.h" #include #include #include @@ -96,8 +95,8 @@ #include #include #include -#include #include +#include "busybox.h" typedef unsigned char u8; @@ -105,24 +104,24 @@ typedef unsigned short u16; typedef unsigned int u32; -#define MINIX_ROOT_INO 1 -#define MINIX_LINK_MAX 250 -#define MINIX2_LINK_MAX 65530 +static const int MINIX_ROOT_INO = 1; +static const int MINIX_LINK_MAX = 250; +static const int MINIX2_LINK_MAX = 65530; -#define MINIX_I_MAP_SLOTS 8 -#define MINIX_Z_MAP_SLOTS 64 -#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ -#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ -#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */ -#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */ -#define MINIX_VALID_FS 0x0001 /* Clean fs. */ -#define MINIX_ERROR_FS 0x0002 /* fs has errors. */ +static const int MINIX_I_MAP_SLOTS = 8; +static const int MINIX_Z_MAP_SLOTS = 64; +static const int MINIX_SUPER_MAGIC = 0x137F; /* original minix fs */ +static const int MINIX_SUPER_MAGIC2 = 0x138F; /* minix fs, 30 char names */ +static const int MINIX2_SUPER_MAGIC = 0x2468; /* minix V2 fs */ +static const int MINIX2_SUPER_MAGIC2 = 0x2478; /* minix V2 fs, 30 char names */ +static const int MINIX_VALID_FS = 0x0001; /* Clean fs. */ +static const int MINIX_ERROR_FS = 0x0002; /* fs has errors. */ #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode))) #define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode))) -#define MINIX_V1 0x0001 /* original minix fs */ -#define MINIX_V2 0x0002 /* minix V2 fs */ +static const int MINIX_V1 = 0x0001; /* original minix fs */ +static const int MINIX_V2 = 0x0002; /* minix V2 fs */ #define INODE_VERSION(inode) inode->i_sb->u.minix_sb.s_version @@ -186,12 +185,6 @@ struct minix_dir_entry { #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode))) -#define MINIX_VALID_FS 0x0001 /* Clean fs. */ -#define MINIX_ERROR_FS 0x0002 /* fs has errors. */ - -#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ -#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ - #ifndef BLKGETSIZE #define BLKGETSIZE _IO(0x12,96) /* return device size */ #endif @@ -200,7 +193,7 @@ struct minix_dir_entry { #define volatile #endif -#define ROOT_INO 1 +static const int ROOT_INO = 1; #define UPPER(size,n) ((size+((n)-1))/(n)) #define INODE_SIZE (sizeof(struct minix_inode)) @@ -232,7 +225,7 @@ static struct termios termios; static int termios_set = 0; /* File-name data */ -#define MAX_DEPTH 32 +static const int MAX_DEPTH = 32; static int name_depth = 0; // static char name_list[MAX_DEPTH][BUFSIZ + 1]; static char **name_list = NULL; @@ -269,8 +262,12 @@ static void recursive_check(unsigned int ino); static void recursive_check2(unsigned int ino); #endif -#define inode_in_use(x) (isset(inode_map,(x))) -#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1)) +static inline int bit(char * a,unsigned int i) +{ + return (a[i >> 3] & (1<<(i & 7))) != 0; +} +#define inode_in_use(x) (bit(inode_map,(x))) +#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1)) #define mark_inode(x) (setbit(inode_map,(x)),changed=1) #define unmark_inode(x) (clrbit(inode_map,(x)),changed=1) @@ -286,14 +283,9 @@ static void leave(int status) exit(status); } -static void show_usage(void) -{ - usage(fsck_minix_usage); -} - static void die(const char *str) { - errorMsg("%s\n", str); + error_msg("%s", str); leave(8); } @@ -1319,7 +1311,7 @@ static void alloc_name_list(void) name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1); } -#if 0 +#ifdef BB_FEATURE_CLEAN_UP /* execute this atexit() to deallocate name_list[] */ /* piptigger was here */ static void free_name_list(void) @@ -1344,9 +1336,11 @@ extern int fsck_minix_main(int argc, char **argv) int retcode = 0; alloc_name_list(); +#ifdef BB_FEATURE_CLEAN_UP /* Don't bother to free memory. Exit does * that automagically, so we can save a few bytes */ - //atexit(free_name_list); + atexit(free_name_list); +#endif if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) die("bad inode size"); @@ -1399,8 +1393,10 @@ extern int fsck_minix_main(int argc, char **argv) die("need terminal for interactive repairs"); } IN = open(device_name, repair ? O_RDWR : O_RDONLY); - if (IN < 0) - die("unable to open '%s'"); + if (IN < 0){ + fprintf(stderr,"unable to open device '%s'.\n",device_name); + leave(8); + } for (count = 0; count < 3; count++) sync(); read_superblock();