diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-03 00:41:53 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-03 00:41:53 +0000 |
| commit | 9c290aa3172b2fbed0ca98ad05f27a5bd39c3e47 (patch) | |
| tree | 49abbb6f56ba9da551a3a7d97e19c5f020f8aeeb /util-linux | |
| parent | 563790c6550fda801db6704b25dc8c1b076fbd34 (diff) | |
| download | busybox-w32-9c290aa3172b2fbed0ca98ad05f27a5bd39c3e47.tar.gz busybox-w32-9c290aa3172b2fbed0ca98ad05f27a5bd39c3e47.tar.bz2 busybox-w32-9c290aa3172b2fbed0ca98ad05f27a5bd39c3e47.zip | |
fsck_minix: optimizations. ~130 bytes
git-svn-id: svn://busybox.net/trunk/busybox@17134 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/fsck_minix.c | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 9e885dc27..44bcd332f 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c | |||
| @@ -122,7 +122,11 @@ struct minix2_inode { | |||
| 122 | uint32_t i_zone[10]; | 122 | uint32_t i_zone[10]; |
| 123 | }; | 123 | }; |
| 124 | 124 | ||
| 125 | /* Believe it or not, but mount.h has this one */ | ||
| 126 | #undef BLOCK_SIZE | ||
| 125 | enum { | 127 | enum { |
| 128 | BLOCK_SIZE = 1024, | ||
| 129 | |||
| 126 | MINIX_ROOT_INO = 1, | 130 | MINIX_ROOT_INO = 1, |
| 127 | MINIX_LINK_MAX = 250, | 131 | MINIX_LINK_MAX = 250, |
| 128 | MINIX2_LINK_MAX = 65530, | 132 | MINIX2_LINK_MAX = 65530, |
| @@ -190,7 +194,7 @@ enum { ROOT_INO = 1 }; | |||
| 190 | 194 | ||
| 191 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) | 195 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) |
| 192 | 196 | ||
| 193 | static char *program_version = "1.2 - 11/11/96"; | 197 | #define PROGRAM_VERSION "1.2 - 11/11/96" |
| 194 | static char *device_name; | 198 | static char *device_name; |
| 195 | static int IN; | 199 | static int IN; |
| 196 | static smallint repair, automatic, verbose, list, show, warn_mode, force; | 200 | static smallint repair, automatic, verbose, list, show, warn_mode, force; |
| @@ -335,7 +339,8 @@ static int ask(const char *string, int def) | |||
| 335 | printf(def ? "%s (y/n)? " : "%s (n/y)? ", string); | 339 | printf(def ? "%s (y/n)? " : "%s (n/y)? ", string); |
| 336 | for (;;) { | 340 | for (;;) { |
| 337 | fflush(stdout); | 341 | fflush(stdout); |
| 338 | if ((c = getchar()) == EOF) { | 342 | c = getchar(); |
| 343 | if (c == EOF) { | ||
| 339 | if (!def) | 344 | if (!def) |
| 340 | errors_uncorrected = 1; | 345 | errors_uncorrected = 1; |
| 341 | return def; | 346 | return def; |
| @@ -371,7 +376,8 @@ static void check_mount(void) | |||
| 371 | int cont; | 376 | int cont; |
| 372 | int fd; | 377 | int fd; |
| 373 | 378 | ||
| 374 | if ((f = setmntent(MOUNTED, "r")) == NULL) | 379 | f = setmntent(MOUNTED, "r"); |
| 380 | if (f == NULL) | ||
| 375 | return; | 381 | return; |
| 376 | while ((mnt = getmntent(f)) != NULL) | 382 | while ((mnt = getmntent(f)) != NULL) |
| 377 | if (strcmp(device_name, mnt->mnt_fsname) == 0) | 383 | if (strcmp(device_name, mnt->mnt_fsname) == 0) |
| @@ -388,8 +394,7 @@ static void check_mount(void) | |||
| 388 | fd = open(MOUNTED, O_RDWR); | 394 | fd = open(MOUNTED, O_RDWR); |
| 389 | if (fd < 0 && errno == EROFS) | 395 | if (fd < 0 && errno == EROFS) |
| 390 | return; | 396 | return; |
| 391 | else | 397 | close(fd); |
| 392 | close(fd); | ||
| 393 | 398 | ||
| 394 | printf("%s is mounted. ", device_name); | 399 | printf("%s is mounted. ", device_name); |
| 395 | cont = 0; | 400 | cont = 0; |
| @@ -585,16 +590,14 @@ static void write_super_block(void) | |||
| 585 | * are uncorrected errors. The filesystem valid flag is | 590 | * are uncorrected errors. The filesystem valid flag is |
| 586 | * unconditionally set if we get this far. | 591 | * unconditionally set if we get this far. |
| 587 | */ | 592 | */ |
| 588 | Super.s_state |= MINIX_VALID_FS; | 593 | Super.s_state |= MINIX_VALID_FS | MINIX_ERROR_FS; |
| 589 | if (errors_uncorrected) | 594 | if (!errors_uncorrected) |
| 590 | Super.s_state |= MINIX_ERROR_FS; | ||
| 591 | else | ||
| 592 | Super.s_state &= ~MINIX_ERROR_FS; | 595 | Super.s_state &= ~MINIX_ERROR_FS; |
| 593 | 596 | ||
| 594 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) | 597 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) |
| 595 | die("seek failed in write_super_block"); | 598 | die("seek failed in write_super_block"); |
| 596 | if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) | 599 | if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) |
| 597 | die("unable to write super-block"); | 600 | die("cannot write super-block"); |
| 598 | } | 601 | } |
| 599 | 602 | ||
| 600 | static void write_tables(void) | 603 | static void write_tables(void) |
| @@ -602,11 +605,11 @@ static void write_tables(void) | |||
| 602 | write_super_block(); | 605 | write_super_block(); |
| 603 | 606 | ||
| 604 | if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE)) | 607 | if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE)) |
| 605 | die("unable to write inode map"); | 608 | die("cannot write inode map"); |
| 606 | if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE)) | 609 | if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE)) |
| 607 | die("unable to write zone map"); | 610 | die("cannot write zone map"); |
| 608 | if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE)) | 611 | if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE)) |
| 609 | die("unable to write inodes"); | 612 | die("cannot write inodes"); |
| 610 | } | 613 | } |
| 611 | 614 | ||
| 612 | static void get_dirsize(void) | 615 | static void get_dirsize(void) |
| @@ -637,7 +640,7 @@ static void read_superblock(void) | |||
| 637 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) | 640 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) |
| 638 | die("seek failed"); | 641 | die("seek failed"); |
| 639 | if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE)) | 642 | if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE)) |
| 640 | die("unable to read super block"); | 643 | die("cannot read super block"); |
| 641 | /* already initialized to: | 644 | /* already initialized to: |
| 642 | namelen = 14; | 645 | namelen = 14; |
| 643 | dirsize = 16; | 646 | dirsize = 16; |
| @@ -673,11 +676,11 @@ static void read_tables(void) | |||
| 673 | inode_count = xmalloc(INODES + 1); | 676 | inode_count = xmalloc(INODES + 1); |
| 674 | zone_count = xmalloc(ZONES); | 677 | zone_count = xmalloc(ZONES); |
| 675 | if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) | 678 | if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) |
| 676 | die("unable to read inode map"); | 679 | die("cannot read inode map"); |
| 677 | if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) | 680 | if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) |
| 678 | die("unable to read zone map"); | 681 | die("cannot read zone map"); |
| 679 | if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE)) | 682 | if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE)) |
| 680 | die("unable to read inodes"); | 683 | die("cannot read inodes"); |
| 681 | if (NORM_FIRSTZONE != FIRSTZONE) { | 684 | if (NORM_FIRSTZONE != FIRSTZONE) { |
| 682 | printf("warning: firstzone!=norm_firstzone\n"); | 685 | printf("warning: firstzone!=norm_firstzone\n"); |
| 683 | errors_uncorrected = 1; | 686 | errors_uncorrected = 1; |
| @@ -1024,18 +1027,16 @@ static void check_file(struct minix_inode *dir, unsigned int offset) | |||
| 1024 | inode = get_inode(ino); | 1027 | inode = get_inode(ino); |
| 1025 | pop_filename(); | 1028 | pop_filename(); |
| 1026 | if (!offset) { | 1029 | if (!offset) { |
| 1027 | if (!inode || strcmp(".", name)) { | 1030 | if (inode && LONE_CHAR(name, '.')) |
| 1028 | printf("%s: bad directory: '.' isn't first\n", current_name); | ||
| 1029 | errors_uncorrected = 1; | ||
| 1030 | } else | ||
| 1031 | return; | 1031 | return; |
| 1032 | printf("%s: bad directory: '.' isn't first\n", current_name); | ||
| 1033 | errors_uncorrected = 1; | ||
| 1032 | } | 1034 | } |
| 1033 | if (offset == dirsize) { | 1035 | if (offset == dirsize) { |
| 1034 | if (!inode || strcmp("..", name)) { | 1036 | if (inode && strcmp("..", name) == 0) |
| 1035 | printf("%s: bad directory: '..' isn't second\n", current_name); | ||
| 1036 | errors_uncorrected = 1; | ||
| 1037 | } else | ||
| 1038 | return; | 1037 | return; |
| 1038 | printf("%s: bad directory: '..' isn't second\n", current_name); | ||
| 1039 | errors_uncorrected = 1; | ||
| 1039 | } | 1040 | } |
| 1040 | if (!inode) | 1041 | if (!inode) |
| 1041 | return; | 1042 | return; |
| @@ -1077,18 +1078,16 @@ static void check_file2(struct minix2_inode *dir, unsigned int offset) | |||
| 1077 | inode = get_inode2(ino); | 1078 | inode = get_inode2(ino); |
| 1078 | pop_filename(); | 1079 | pop_filename(); |
| 1079 | if (!offset) { | 1080 | if (!offset) { |
| 1080 | if (!inode || strcmp(".", name)) { | 1081 | if (inode && LONE_CHAR(name, '.')) |
| 1081 | printf("%s: bad directory: '.' isn't first\n", current_name); | ||
| 1082 | errors_uncorrected = 1; | ||
| 1083 | } else | ||
| 1084 | return; | 1082 | return; |
| 1083 | printf("%s: bad directory: '.' isn't first\n", current_name); | ||
| 1084 | errors_uncorrected = 1; | ||
| 1085 | } | 1085 | } |
| 1086 | if (offset == dirsize) { | 1086 | if (offset == dirsize) { |
| 1087 | if (!inode || strcmp("..", name)) { | 1087 | if (inode && strcmp("..", name) == 0) |
| 1088 | printf("%s: bad directory: '..' isn't second\n", current_name); | ||
| 1089 | errors_uncorrected = 1; | ||
| 1090 | } else | ||
| 1091 | return; | 1088 | return; |
| 1089 | printf("%s: bad directory: '..' isn't second\n", current_name); | ||
| 1090 | errors_uncorrected = 1; | ||
| 1092 | } | 1091 | } |
| 1093 | if (!inode) | 1092 | if (!inode) |
| 1094 | return; | 1093 | return; |
| @@ -1141,7 +1140,7 @@ static void recursive_check2(unsigned int ino) | |||
| 1141 | 1140 | ||
| 1142 | static int bad_zone(int i) | 1141 | static int bad_zone(int i) |
| 1143 | { | 1142 | { |
| 1144 | char buffer[1024]; | 1143 | char buffer[BLOCK_SIZE]; |
| 1145 | 1144 | ||
| 1146 | if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET)) | 1145 | if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET)) |
| 1147 | die("seek failed in bad_zone"); | 1146 | die("seek failed in bad_zone"); |
| @@ -1276,6 +1275,8 @@ int fsck_minix_main(int argc, char **argv) | |||
| 1276 | struct termios tmp; | 1275 | struct termios tmp; |
| 1277 | int retcode = 0; | 1276 | int retcode = 0; |
| 1278 | 1277 | ||
| 1278 | xfunc_exitcode = 8; | ||
| 1279 | |||
| 1279 | alloc_current_name(); | 1280 | alloc_current_name(); |
| 1280 | #ifdef CONFIG_FEATURE_CLEAN_UP | 1281 | #ifdef CONFIG_FEATURE_CLEAN_UP |
| 1281 | /* Don't bother to free memory. Exit does | 1282 | /* Don't bother to free memory. Exit does |
| @@ -1289,15 +1290,14 @@ int fsck_minix_main(int argc, char **argv) | |||
| 1289 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) | 1290 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) |
| 1290 | die("bad v2 inode size"); | 1291 | die("bad v2 inode size"); |
| 1291 | #endif | 1292 | #endif |
| 1292 | while (argc-- > 1) { | 1293 | while (--argc != 0) { |
| 1293 | argv++; | 1294 | argv++; |
| 1294 | if (argv[0][0] != '-') { | 1295 | if (argv[0][0] != '-') { |
| 1295 | if (device_name) | 1296 | if (device_name) |
| 1296 | bb_show_usage(); | 1297 | bb_show_usage(); |
| 1297 | else | 1298 | device_name = argv[0]; |
| 1298 | device_name = argv[0]; | 1299 | } else { |
| 1299 | } else | 1300 | while (*++argv[0]) { |
| 1300 | while (*++argv[0]) | ||
| 1301 | switch (argv[0][0]) { | 1301 | switch (argv[0][0]) { |
| 1302 | case 'l': | 1302 | case 'l': |
| 1303 | list = 1; | 1303 | list = 1; |
| @@ -1325,9 +1325,12 @@ int fsck_minix_main(int argc, char **argv) | |||
| 1325 | default: | 1325 | default: |
| 1326 | bb_show_usage(); | 1326 | bb_show_usage(); |
| 1327 | } | 1327 | } |
| 1328 | } | ||
| 1329 | } | ||
| 1328 | } | 1330 | } |
| 1329 | if (!device_name) | 1331 | if (!device_name) |
| 1330 | bb_show_usage(); | 1332 | bb_show_usage(); |
| 1333 | |||
| 1331 | check_mount(); /* trying to check a mounted filesystem? */ | 1334 | check_mount(); /* trying to check a mounted filesystem? */ |
| 1332 | if (repair && !automatic) { | 1335 | if (repair && !automatic) { |
| 1333 | if (!isatty(0) || !isatty(1)) | 1336 | if (!isatty(0) || !isatty(1)) |
| @@ -1335,10 +1338,9 @@ int fsck_minix_main(int argc, char **argv) | |||
| 1335 | } | 1338 | } |
| 1336 | IN = open(device_name, repair ? O_RDWR : O_RDONLY); | 1339 | IN = open(device_name, repair ? O_RDWR : O_RDONLY); |
| 1337 | if (IN < 0) { | 1340 | if (IN < 0) { |
| 1338 | printf("unable to open device '%s'\n", device_name); | 1341 | bb_error_msg_and_die("cannot open device '%s'", device_name); |
| 1339 | leave(8); | ||
| 1340 | } | 1342 | } |
| 1341 | sync(); /* paranoia? */ | 1343 | /*sync(); paranoia? */ |
| 1342 | read_superblock(); | 1344 | read_superblock(); |
| 1343 | 1345 | ||
| 1344 | /* | 1346 | /* |
| @@ -1347,13 +1349,14 @@ int fsck_minix_main(int argc, char **argv) | |||
| 1347 | * flags and whether or not the -f switch was specified on the | 1349 | * flags and whether or not the -f switch was specified on the |
| 1348 | * command line. | 1350 | * command line. |
| 1349 | */ | 1351 | */ |
| 1350 | printf("%s, %s\n", applet_name, program_version); | 1352 | printf("%s, "PROGRAM_VERSION"\n", applet_name); |
| 1353 | |||
| 1351 | if (!(Super.s_state & MINIX_ERROR_FS) | 1354 | if (!(Super.s_state & MINIX_ERROR_FS) |
| 1352 | && (Super.s_state & MINIX_VALID_FS) && !force | 1355 | && (Super.s_state & MINIX_VALID_FS) && !force |
| 1353 | ) { | 1356 | ) { |
| 1354 | if (repair) | 1357 | if (repair) |
| 1355 | printf("%s is clean, check is skipped\n", device_name); | 1358 | printf("%s is clean, check is skipped\n", device_name); |
| 1356 | return retcode; | 1359 | return 0; |
| 1357 | } else if (force) | 1360 | } else if (force) |
| 1358 | printf("Forcing filesystem check on %s\n", device_name); | 1361 | printf("Forcing filesystem check on %s\n", device_name); |
| 1359 | else if (repair) | 1362 | else if (repair) |
