diff options
author | Rob Landley | 2006-04-29 20:05:17 +0000 |
---|---|---|
committer | Rob Landley | 2006-04-29 20:05:17 +0000 |
commit | 8a6254994ce56859f245120726f47bafa8281b2d (patch) | |
tree | 3f1e08a90fbddc01f2f7bf6f331521702a2b5c6d | |
parent | 9950cab8e0f51f2810b3d9a8d403fdfd98881235 (diff) | |
download | busybox-8a6254994ce56859f245120726f47bafa8281b2d.zip busybox-8a6254994ce56859f245120726f47bafa8281b2d.tar.gz |
Patch from Denis Vlasenko:
* Do not initialize globals to 0, it is done automatically
* unsigned short -> uint16_t, unsigned int -> uint32_t
where appropriate (did it ever work on Alphas?)
* triple sync() is silly - removed
* check_zone_nr uses check_zone_nr2 now
* remove trailing periods from messages, uppercase first letter
-rw-r--r-- | util-linux/fsck_minix.c | 167 |
1 files changed, 74 insertions, 93 deletions
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 350c957..b90ccc5 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c @@ -206,28 +206,26 @@ enum { ROOT_INO = 1 }; #define BITS_PER_BLOCK (BLOCK_SIZE<<3) static char *program_version = "1.2 - 11/11/96"; -static char *device_name = NULL; +static char *device_name; static int IN; -static int repair = 0, automatic = 0, verbose = 0, list = 0, show = - 0, warn_mode = 0, force = 0; -static int directory = 0, regular = 0, blockdev = 0, chardev = 0, links = - 0, symlinks = 0, total = 0; +static int repair, automatic, verbose, list, show, warn_mode, force; +static int directory, regular, blockdev, chardev, links, symlinks, total; -static int changed = 0; /* flags if the filesystem has been changed */ -static int errors_uncorrected = 0; /* flag if some error was not corrected */ +static int changed; /* flags if the filesystem has been changed */ +static int errors_uncorrected; /* flag if some error was not corrected */ static int dirsize = 16; static int namelen = 14; -static int version2 = 0; +static int version2; static struct termios termios; -static int termios_set = 0; +static int termios_set; /* File-name data */ enum { MAX_DEPTH = 32 }; -static int name_depth = 0; +static int name_depth; // static char name_list[MAX_DEPTH][BUFSIZ + 1]; -static char **name_list = NULL; +static char **name_list; -static char *inode_buffer = NULL; +static char *inode_buffer; #define Inode (((struct minix_inode *) inode_buffer)-1) #define Inode2 (((struct minix2_inode *) inode_buffer)-1) @@ -251,8 +249,8 @@ static char super_block_buffer[BLOCK_SIZE]; static char *inode_map; static char *zone_map; -static unsigned char *inode_count = NULL; -static unsigned char *zone_count = NULL; +static unsigned char *inode_count; +static unsigned char *zone_count; static void recursive_check(unsigned int ino); #ifdef CONFIG_FEATURE_MINIX2 @@ -375,12 +373,11 @@ static void check_mount(void) close(fd); printf("%s is mounted. ", device_name); + cont = 0; if (isatty(0) && isatty(1)) cont = ask("Do you really want to continue", 0); - else - cont = 0; if (!cont) { - printf("check aborted.\n"); + printf("Check aborted\n"); exit(0); } return; @@ -392,7 +389,7 @@ static void check_mount(void) * if an error was corrected, and returns the zone (0 for no zone * or a bad zone-number). */ -static int check_zone_nr(unsigned short *nr, int *corrected) +static int check_zone_nr2(uint32_t *nr, int *corrected) { if (!*nr) return 0; @@ -411,26 +408,13 @@ static int check_zone_nr(unsigned short *nr, int *corrected) return 0; } -#ifdef CONFIG_FEATURE_MINIX2 -static int check_zone_nr2(unsigned int *nr, int *corrected) +static int check_zone_nr(uint16_t *nr, int *corrected) { - if (!*nr) - return 0; - if (*nr < FIRSTZONE) - printf("Zone nr < FIRSTZONE in file `"); - else if (*nr >= ZONES) - printf("Zone nr >= ZONES in file `"); - else - return *nr; - print_current_name(); - printf("'."); - if (ask("Remove block", 1)) { - *nr = 0; - *corrected = 1; - } - return 0; + uint32_t nr32 = *nr; + int r = check_zone_nr2(&nr32, corrected); + *nr = (uint16_t)nr32; + return r; } -#endif /* * read-block reads block nr into the buffer at addr. @@ -445,14 +429,14 @@ static void read_block(unsigned int nr, char *addr) printf("Read error: unable to seek to block in file '"); print_current_name(); printf("'\n"); - memset(addr, 0, BLOCK_SIZE); errors_uncorrected = 1; + memset(addr, 0, BLOCK_SIZE); } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { printf("Read error: bad block in file '"); print_current_name(); printf("'\n"); - memset(addr, 0, BLOCK_SIZE); errors_uncorrected = 1; + memset(addr, 0, BLOCK_SIZE); } } @@ -480,14 +464,14 @@ static void write_block(unsigned int nr, char *addr) } /* - * map-block calculates the absolute block nr of a block in a file. + * map_block calculates the absolute block nr of a block in a file. * It sets 'changed' if the inode has needed changing, and re-writes * any indirect blocks with errors. */ static int map_block(struct minix_inode *inode, unsigned int blknr) { - unsigned short ind[BLOCK_SIZE >> 1]; - unsigned short dind[BLOCK_SIZE >> 1]; + uint16_t ind[BLOCK_SIZE >> 1]; + uint16_t dind[BLOCK_SIZE >> 1]; int blk_chg, block, result; if (blknr < 7) @@ -521,9 +505,9 @@ static int map_block(struct minix_inode *inode, unsigned int blknr) #ifdef CONFIG_FEATURE_MINIX2 static int map_block2(struct minix2_inode *inode, unsigned int blknr) { - unsigned int ind[BLOCK_SIZE >> 2]; - unsigned int dind[BLOCK_SIZE >> 2]; - unsigned int tind[BLOCK_SIZE >> 2]; + uint32_t ind[BLOCK_SIZE >> 2]; + uint32_t dind[BLOCK_SIZE >> 2]; + uint32_t tind[BLOCK_SIZE >> 2]; int blk_chg, block, result; if (blknr < 7) @@ -594,8 +578,6 @@ static void write_super_block(void) die("seek failed in write_super_block"); if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) die("unable to write super-block"); - - return; } static void write_tables(void) @@ -639,18 +621,15 @@ static void read_superblock(void) die("seek failed"); if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE)) die("unable to read super block"); + namelen = 14; + dirsize = 16; + version2 = 0; if (MAGIC == MINIX_SUPER_MAGIC) { - namelen = 14; - dirsize = 16; - version2 = 0; } else if (MAGIC == MINIX_SUPER_MAGIC2) { namelen = 30; dirsize = 32; - version2 = 0; #ifdef CONFIG_FEATURE_MINIX2 } else if (MAGIC == MINIX2_SUPER_MAGIC) { - namelen = 14; - dirsize = 16; version2 = 1; } else if (MAGIC == MINIX2_SUPER_MAGIC2) { namelen = 30; @@ -688,13 +667,20 @@ static void read_tables(void) } get_dirsize(); if (show) { - printf("%ld inodes\n", INODES); - printf("%ld blocks\n", ZONES); - printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE); - printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE); - printf("Maxsize=%ld\n", MAXSIZE); - printf("Filesystem state=%d\n", Super.s_state); - printf("namelen=%d\n\n", namelen); + printf("%ld inodes\n" + "%ld blocks\n" + "Firstdatazone=%ld (%ld)\n" + "Zonesize=%d\n" + "Maxsize=%ld\n" + "Filesystem state=%d\n" + "namelen=%d\n\n", + INODES, + ZONES, + FIRSTZONE, NORM_FIRSTZONE, + BLOCK_SIZE << ZONESIZE, + MAXSIZE, + Super.s_state, + namelen); } } @@ -738,7 +724,7 @@ static struct minix_inode *get_inode(unsigned int nr) } else links++; if (!++inode_count[nr]) { - printf("Warning: inode count too big.\n"); + printf("Warning: inode count too big\n"); inode_count[nr]--; errors_uncorrected = 1; } @@ -785,7 +771,7 @@ static struct minix2_inode *get_inode2(unsigned int nr) } else links++; if (!++inode_count[nr]) { - printf("Warning: inode count too big.\n"); + printf("Warning: inode count too big\n"); inode_count[nr]--; errors_uncorrected = 1; } @@ -811,7 +797,7 @@ static void check_root2(void) } #endif -static int add_zone(unsigned short *znr, int *corrected) +static int add_zone(uint16_t *znr, int *corrected) { int result; int block; @@ -828,10 +814,9 @@ static int add_zone(unsigned short *znr, int *corrected) *znr = 0; block = 0; *corrected = 1; + return 0; } } - if (!block) - return 0; if (!zone_in_use(block)) { printf("Block %d in file `", block); print_current_name(); @@ -845,7 +830,7 @@ static int add_zone(unsigned short *znr, int *corrected) } #ifdef CONFIG_FEATURE_MINIX2 -static int add_zone2(unsigned int *znr, int *corrected) +static int add_zone2(uint32_t *znr, int *corrected) { int result; int block; @@ -862,10 +847,9 @@ static int add_zone2(unsigned int *znr, int *corrected) *znr = 0; block = 0; *corrected = 1; + return 0; } } - if (!block) - return 0; if (!zone_in_use(block)) { printf("Block %d in file `", block); print_current_name(); @@ -879,7 +863,7 @@ static int add_zone2(unsigned int *znr, int *corrected) } #endif -static void add_zone_ind(unsigned short *znr, int *corrected) +static void add_zone_ind(uint16_t *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, chg_blk = 0; @@ -890,13 +874,13 @@ static void add_zone_ind(unsigned short *znr, int *corrected) return; read_block(block, blk); for (i = 0; i < (BLOCK_SIZE >> 1); i++) - add_zone(i + (unsigned short *) blk, &chg_blk); + add_zone(i + (uint16_t *) blk, &chg_blk); if (chg_blk) write_block(block, blk); } #ifdef CONFIG_FEATURE_MINIX2 -static void add_zone_ind2(unsigned int *znr, int *corrected) +static void add_zone_ind2(uint32_t *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, chg_blk = 0; @@ -907,13 +891,13 @@ static void add_zone_ind2(unsigned int *znr, int *corrected) return; read_block(block, blk); for (i = 0; i < BLOCK_SIZE >> 2; i++) - add_zone2(i + (unsigned int *) blk, &chg_blk); + add_zone2(i + (uint32_t *) blk, &chg_blk); if (chg_blk) write_block(block, blk); } #endif -static void add_zone_dind(unsigned short *znr, int *corrected) +static void add_zone_dind(uint16_t *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, blk_chg = 0; @@ -924,13 +908,13 @@ static void add_zone_dind(unsigned short *znr, int *corrected) return; read_block(block, blk); for (i = 0; i < (BLOCK_SIZE >> 1); i++) - add_zone_ind(i + (unsigned short *) blk, &blk_chg); + add_zone_ind(i + (uint16_t *) blk, &blk_chg); if (blk_chg) write_block(block, blk); } #ifdef CONFIG_FEATURE_MINIX2 -static void add_zone_dind2(unsigned int *znr, int *corrected) +static void add_zone_dind2(uint32_t *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, blk_chg = 0; @@ -941,12 +925,12 @@ static void add_zone_dind2(unsigned int *znr, int *corrected) return; read_block(block, blk); for (i = 0; i < BLOCK_SIZE >> 2; i++) - add_zone_ind2(i + (unsigned int *) blk, &blk_chg); + add_zone_ind2(i + (uint32_t *) blk, &blk_chg); if (blk_chg) write_block(block, blk); } -static void add_zone_tind2(unsigned int *znr, int *corrected) +static void add_zone_tind2(uint32_t *znr, int *corrected) { static char blk[BLOCK_SIZE]; int i, blk_chg = 0; @@ -957,7 +941,7 @@ static void add_zone_tind2(unsigned int *znr, int *corrected) return; read_block(block, blk); for (i = 0; i < BLOCK_SIZE >> 2; i++) - add_zone_dind2(i + (unsigned int *) blk, &blk_chg); + add_zone_dind2(i + (uint32_t *) blk, &blk_chg); if (blk_chg) write_block(block, blk); } @@ -1012,13 +996,13 @@ static void check_file(struct minix_inode *dir, unsigned int offset) block = map_block(dir, offset / BLOCK_SIZE); read_block(block, blk); name = blk + (offset % BLOCK_SIZE) + 2; - ino = *(unsigned short *) (name - 2); + ino = *(uint16_t *) (name - 2); if (ino > INODES) { print_current_name(); printf(" contains a bad inode number for file '"); printf("%.*s'.", namelen, name); if (ask(" Remove", 1)) { - *(unsigned short *) (name - 2) = 0; + *(uint16_t *) (name - 2) = 0; write_block(block, blk); } ino = 0; @@ -1077,13 +1061,13 @@ static void check_file2(struct minix2_inode *dir, unsigned int offset) block = map_block2(dir, offset / BLOCK_SIZE); read_block(block, blk); name = blk + (offset % BLOCK_SIZE) + 2; - ino = *(unsigned short *) (name - 2); + ino = *(uint16_t *) (name - 2); if (ino > INODES) { print_current_name(); printf(" contains a bad inode number for file '"); printf("%.*s'.", namelen, name); if (ask(" Remove", 1)) { - *(unsigned short *) (name - 2) = 0; + *(uint16_t *) (name - 2) = 0; write_block(block, blk); } ino = 0; @@ -1179,7 +1163,7 @@ static void check_counts(void) int i; for (i = 1; i <= INODES; i++) { - if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { + if (warn_mode && Inode[i].i_mode && !inode_in_use(i)) { printf("Inode %d mode not cleared.", i); if (ask("Clear", 1)) { Inode[i].i_mode = 0; @@ -1230,7 +1214,7 @@ static void check_counts2(void) int i; for (i = 1; i <= INODES; i++) { - if (!inode_in_use(i) && Inode2[i].i_mode && warn_mode) { + if (warn_mode && Inode2[i].i_mode && !inode_in_use(i)) { printf("Inode %d mode not cleared.", i); if (ask("Clear", 1)) { Inode2[i].i_mode = 0; @@ -1305,7 +1289,7 @@ static void alloc_name_list(void) name_list = xmalloc(sizeof(char *) * MAX_DEPTH); for (i = 0; i < MAX_DEPTH; i++) - name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1); + name_list[i] = xmalloc(sizeof(char) * (BUFSIZ + 1)); } #ifdef CONFIG_FEATURE_CLEAN_UP @@ -1327,7 +1311,6 @@ static void free_name_list(void) int fsck_minix_main(int argc, char **argv) { struct termios tmp; - int count; int retcode = 0; alloc_name_list(); @@ -1389,11 +1372,10 @@ int fsck_minix_main(int argc, char **argv) } IN = open(device_name, repair ? O_RDWR : O_RDONLY); if (IN < 0){ - fprintf(stderr,"unable to open device '%s'.\n",device_name); + fprintf(stderr,"unable to open device '%s'\n",device_name); leave(8); } - for (count = 0; count < 3; count++) - sync(); + sync(); /* paranoia? */ read_superblock(); /* @@ -1406,12 +1388,12 @@ int fsck_minix_main(int argc, char **argv) if (!(Super.s_state & MINIX_ERROR_FS) && (Super.s_state & MINIX_VALID_FS) && !force) { if (repair) - printf("%s is clean, no check.\n", device_name); + printf("%s is clean, no check\n", device_name); return retcode; } else if (force) - printf("Forcing filesystem check on %s.\n", device_name); + printf("Forcing filesystem check on %s\n", device_name); else if (repair) - printf("Filesystem on %s is dirty, needs checking.\n", + printf("Filesystem on %s is dirty, needs checking\n", device_name); read_tables(); @@ -1463,8 +1445,7 @@ int fsck_minix_main(int argc, char **argv) printf("----------------------------\n" "FILE SYSTEM HAS BEEN CHANGED\n" "----------------------------\n"); - for (count = 0; count < 3; count++) - sync(); + sync(); } else if (repair) write_super_block(); |