aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-19 02:24:14 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-19 02:24:14 +0200
commitc4fb8c6ad52e8007c6fa07e40f043bb2e0c043d1 (patch)
treea6998c9070a15367c46d3caec1c80af5f0da7ea9
parent36647abcc393daf2ddd7876e6f24d9497c2a84a1 (diff)
downloadbusybox-w32-c4fb8c6ad52e8007c6fa07e40f043bb2e0c043d1.tar.gz
busybox-w32-c4fb8c6ad52e8007c6fa07e40f043bb2e0c043d1.tar.bz2
busybox-w32-c4fb8c6ad52e8007c6fa07e40f043bb2e0c043d1.zip
fsck: do not use statics
function old new delta fsck_main 1794 1812 +18 packed_usage 30662 30664 +2 kill_all_if_got_signal 60 62 +2 create_fs_device 158 160 +2 static.kill_sent 1 - -1 skip_root 1 - -1 serialize 1 - -1 parallel_root 1 - -1 noexecute 1 - -1 fs_type_negated 1 - -1 force_all_parallel 1 - -1 verbose 4 - -4 num_running 4 - -4 num_args 4 - -4 max_running 4 - -4 instance_list 4 - -4 fstype 4 - -4 fs_type_list 4 - -4 fs_type_flag 4 - -4 filesys_last 4 - -4 filesys_info 4 - -4 args 4 - -4 wait_one 309 300 -9 ignore 196 174 -22 ------------------------------------------------------------------------------ (add/remove: 0/18 grow/shrink: 4/2 up/down: 24/-82) Total: -58 bytes text data bss dec hex filename 938527 932 17448 956907 e99eb busybox_old 938487 932 17392 956811 e998b busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--e2fsprogs/fsck.c261
1 files changed, 133 insertions, 128 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index adaf0c538..627d2be31 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -46,7 +46,7 @@
46//kbuild:lib-$(CONFIG_FSCK) += fsck.o 46//kbuild:lib-$(CONFIG_FSCK) += fsck.o
47 47
48//usage:#define fsck_trivial_usage 48//usage:#define fsck_trivial_usage
49//usage: "[-ANPRTV] [-C FD] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..." 49//usage: "[-ANPRTV] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..."
50//usage:#define fsck_full_usage "\n\n" 50//usage:#define fsck_full_usage "\n\n"
51//usage: "Check and repair filesystems\n" 51//usage: "Check and repair filesystems\n"
52//usage: "\n -A Walk /etc/fstab and check all filesystems" 52//usage: "\n -A Walk /etc/fstab and check all filesystems"
@@ -55,7 +55,8 @@
55//usage: "\n -R With -A, skip the root filesystem" 55//usage: "\n -R With -A, skip the root filesystem"
56//usage: "\n -T Don't show title on startup" 56//usage: "\n -T Don't show title on startup"
57//usage: "\n -V Verbose" 57//usage: "\n -V Verbose"
58//usage: "\n -C n Write status information to specified filedescriptor" 58//DO_PROGRESS_INDICATOR is off:
59////usage: "\n -C FD Write status information to specified file descriptor"
59//usage: "\n -t TYPE List of filesystem types to check" 60//usage: "\n -t TYPE List of filesystem types to check"
60 61
61#include "libbb.h" 62#include "libbb.h"
@@ -136,35 +137,42 @@ static const char really_wanted[] ALIGN1 =
136 137
137#define BASE_MD "/dev/md" 138#define BASE_MD "/dev/md"
138 139
139static char **args; 140struct globals {
140static int num_args; 141 char **args;
141static int verbose; 142 int num_args;
143 int verbose;
142 144
143#define FS_TYPE_FLAG_NORMAL 0 145#define FS_TYPE_FLAG_NORMAL 0
144#define FS_TYPE_FLAG_OPT 1 146#define FS_TYPE_FLAG_OPT 1
145#define FS_TYPE_FLAG_NEGOPT 2 147#define FS_TYPE_FLAG_NEGOPT 2
146static char **fs_type_list; 148 char **fs_type_list;
147static uint8_t *fs_type_flag; 149 uint8_t *fs_type_flag;
148static smallint fs_type_negated; 150 smallint fs_type_negated;
149 151
150static smallint noexecute; 152 smallint noexecute;
151static smallint serialize; 153 smallint serialize;
152static smallint skip_root; 154 smallint skip_root;
153/* static smallint like_mount; */ 155 /* smallint like_mount; */
154static smallint parallel_root; 156 smallint parallel_root;
155static smallint force_all_parallel; 157 smallint force_all_parallel;
158 smallint kill_sent;
156 159
157#if DO_PROGRESS_INDICATOR 160#if DO_PROGRESS_INDICATOR
158static smallint progress; 161 smallint progress;
159static int progress_fd; 162 int progress_fd;
160#endif 163#endif
161 164
162static int num_running; 165 int num_running;
163static int max_running; 166 int max_running;
164static char *fstype; 167 char *fstype;
165static struct fs_info *filesys_info; 168 struct fs_info *filesys_info;
166static struct fs_info *filesys_last; 169 struct fs_info *filesys_last;
167static struct fsck_instance *instance_list; 170 struct fsck_instance *instance_list;
171} FIX_ALIASING;
172#define G (*(struct globals*)&bb_common_bufsiz1)
173#define INIT_G() do { \
174 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
175} while (0)
168 176
169/* 177/*
170 * Return the "base device" given a particular device; this is used to 178 * Return the "base device" given a particular device; this is used to
@@ -313,11 +321,11 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
313 /*fs->flags = 0; */ 321 /*fs->flags = 0; */
314 /*fs->next = NULL; */ 322 /*fs->next = NULL; */
315 323
316 if (!filesys_info) 324 if (!G.filesys_info)
317 filesys_info = fs; 325 G.filesys_info = fs;
318 else 326 else
319 filesys_last->next = fs; 327 G.filesys_last->next = fs;
320 filesys_last = fs; 328 G.filesys_last = fs;
321 329
322 return fs; 330 return fs;
323} 331}
@@ -327,6 +335,7 @@ static void load_fs_info(const char *filename)
327{ 335{
328 FILE *fstab; 336 FILE *fstab;
329 struct mntent mte; 337 struct mntent mte;
338 char buf[1024];
330 339
331 fstab = setmntent(filename, "r"); 340 fstab = setmntent(filename, "r");
332 if (!fstab) { 341 if (!fstab) {
@@ -335,7 +344,7 @@ static void load_fs_info(const char *filename)
335 } 344 }
336 345
337 // Loop through entries 346 // Loop through entries
338 while (getmntent_r(fstab, &mte, bb_common_bufsiz1, COMMON_BUFSIZE)) { 347 while (getmntent_r(fstab, &mte, buf, sizeof(buf))) {
339 //bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir, 348 //bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir,
340 // mte.mnt_type, mte.mnt_opts, 349 // mte.mnt_type, mte.mnt_opts,
341 // mte.mnt_passno); 350 // mte.mnt_passno);
@@ -351,7 +360,7 @@ static struct fs_info *lookup(char *filesys)
351{ 360{
352 struct fs_info *fs; 361 struct fs_info *fs;
353 362
354 for (fs = filesys_info; fs; fs = fs->next) { 363 for (fs = G.filesys_info; fs; fs = fs->next) {
355 if (strcmp(filesys, fs->device) == 0 364 if (strcmp(filesys, fs->device) == 0
356 || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0) 365 || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0)
357 ) 366 )
@@ -366,7 +375,7 @@ static int progress_active(void)
366{ 375{
367 struct fsck_instance *inst; 376 struct fsck_instance *inst;
368 377
369 for (inst = instance_list; inst; inst = inst->next) { 378 for (inst = G.instance_list; inst; inst = inst->next) {
370 if (inst->flags & FLAG_DONE) 379 if (inst->flags & FLAG_DONE)
371 continue; 380 continue;
372 if (inst->flags & FLAG_PROGRESS) 381 if (inst->flags & FLAG_PROGRESS)
@@ -382,19 +391,17 @@ static int progress_active(void)
382 */ 391 */
383static void kill_all_if_got_signal(void) 392static void kill_all_if_got_signal(void)
384{ 393{
385 static smallint kill_sent;
386
387 struct fsck_instance *inst; 394 struct fsck_instance *inst;
388 395
389 if (!bb_got_signal || kill_sent) 396 if (!bb_got_signal || G.kill_sent)
390 return; 397 return;
391 398
392 for (inst = instance_list; inst; inst = inst->next) { 399 for (inst = G.instance_list; inst; inst = inst->next) {
393 if (inst->flags & FLAG_DONE) 400 if (inst->flags & FLAG_DONE)
394 continue; 401 continue;
395 kill(inst->pid, SIGTERM); 402 kill(inst->pid, SIGTERM);
396 } 403 }
397 kill_sent = 1; 404 G.kill_sent = 1;
398} 405}
399 406
400/* 407/*
@@ -409,9 +416,9 @@ static int wait_one(int flags)
409 struct fsck_instance *inst, *prev; 416 struct fsck_instance *inst, *prev;
410 pid_t pid; 417 pid_t pid;
411 418
412 if (!instance_list) 419 if (!G.instance_list)
413 return -1; 420 return -1;
414 /* if (noexecute) { already returned -1; } */ 421 /* if (G.noexecute) { already returned -1; } */
415 422
416 while (1) { 423 while (1) {
417 pid = waitpid(-1, &status, flags); 424 pid = waitpid(-1, &status, flags);
@@ -429,7 +436,7 @@ static int wait_one(int flags)
429 continue; 436 continue;
430 } 437 }
431 prev = NULL; 438 prev = NULL;
432 inst = instance_list; 439 inst = G.instance_list;
433 do { 440 do {
434 if (inst->pid == pid) 441 if (inst->pid == pid)
435 goto child_died; 442 goto child_died;
@@ -439,9 +446,8 @@ static int wait_one(int flags)
439 } 446 }
440 child_died: 447 child_died:
441 448
442 if (WIFEXITED(status)) 449 status = WEXITSTATUS(status);
443 status = WEXITSTATUS(status); 450 if (WIFSIGNALED(status)) {
444 else if (WIFSIGNALED(status)) {
445 sig = WTERMSIG(status); 451 sig = WTERMSIG(status);
446 status = EXIT_UNCORRECTED; 452 status = EXIT_UNCORRECTED;
447 if (sig != SIGINT) { 453 if (sig != SIGINT) {
@@ -450,16 +456,12 @@ static int wait_one(int flags)
450 inst->prog, inst->device, sig); 456 inst->prog, inst->device, sig);
451 status = EXIT_ERROR; 457 status = EXIT_ERROR;
452 } 458 }
453 } else {
454 printf("%s %s: status is %x, should never happen\n",
455 inst->prog, inst->device, status);
456 status = EXIT_ERROR;
457 } 459 }
458 460
459#if DO_PROGRESS_INDICATOR 461#if DO_PROGRESS_INDICATOR
460 if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) { 462 if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) {
461 struct fsck_instance *inst2; 463 struct fsck_instance *inst2;
462 for (inst2 = instance_list; inst2; inst2 = inst2->next) { 464 for (inst2 = G.instance_list; inst2; inst2 = inst2->next) {
463 if (inst2->flags & FLAG_DONE) 465 if (inst2->flags & FLAG_DONE)
464 continue; 466 continue;
465 if (strcmp(inst2->type, "ext2") != 0 467 if (strcmp(inst2->type, "ext2") != 0
@@ -486,11 +488,11 @@ static int wait_one(int flags)
486 if (prev) 488 if (prev)
487 prev->next = inst->next; 489 prev->next = inst->next;
488 else 490 else
489 instance_list = inst->next; 491 G.instance_list = inst->next;
490 if (verbose > 1) 492 if (G.verbose > 1)
491 printf("Finished with %s (exit status %d)\n", 493 printf("Finished with %s (exit status %d)\n",
492 inst->device, status); 494 inst->device, status);
493 num_running--; 495 G.num_running--;
494 free_instance(inst); 496 free_instance(inst);
495 497
496 return status; 498 return status;
@@ -526,51 +528,51 @@ static void execute(const char *type, const char *device,
526 struct fsck_instance *inst; 528 struct fsck_instance *inst;
527 pid_t pid; 529 pid_t pid;
528 530
529 args[0] = xasprintf("fsck.%s", type); 531 G.args[0] = xasprintf("fsck.%s", type);
530 532
531#if DO_PROGRESS_INDICATOR 533#if DO_PROGRESS_INDICATOR
532 if (progress && !progress_active()) { 534 if (progress && !progress_active()) {
533 if (strcmp(type, "ext2") == 0 535 if (strcmp(type, "ext2") == 0
534 || strcmp(type, "ext3") == 0 536 || strcmp(type, "ext3") == 0
535 ) { 537 ) {
536 args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */ 538 G.args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */
537 inst->flags |= FLAG_PROGRESS; 539 inst->flags |= FLAG_PROGRESS;
538 } 540 }
539 } 541 }
540#endif 542#endif
541 543
542 args[num_args - 2] = (char*)device; 544 G.args[G.num_args - 2] = (char*)device;
543 /* args[num_args - 1] = NULL; - already is */ 545 /* G.args[G.num_args - 1] = NULL; - already is */
544 546
545 if (verbose || noexecute) { 547 if (G.verbose || G.noexecute) {
546 printf("[%s (%d) -- %s]", args[0], num_running, 548 printf("[%s (%d) -- %s]", G.args[0], G.num_running,
547 mntpt ? mntpt : device); 549 mntpt ? mntpt : device);
548 for (i = 0; args[i]; i++) 550 for (i = 0; G.args[i]; i++)
549 printf(" %s", args[i]); 551 printf(" %s", G.args[i]);
550 bb_putchar('\n'); 552 bb_putchar('\n');
551 } 553 }
552 554
553 /* Fork and execute the correct program. */ 555 /* Fork and execute the correct program. */
554 pid = -1; 556 pid = -1;
555 if (!noexecute) { 557 if (!G.noexecute) {
556 pid = spawn(args); 558 pid = spawn(G.args);
557 if (pid < 0) 559 if (pid < 0)
558 bb_simple_perror_msg(args[0]); 560 bb_simple_perror_msg(G.args[0]);
559 } 561 }
560 562
561#if DO_PROGRESS_INDICATOR 563#if DO_PROGRESS_INDICATOR
562 free(args[XXX]); 564 free(G.args[XXX]);
563#endif 565#endif
564 566
565 /* No child, so don't record an instance */ 567 /* No child, so don't record an instance */
566 if (pid <= 0) { 568 if (pid <= 0) {
567 free(args[0]); 569 free(G.args[0]);
568 return; 570 return;
569 } 571 }
570 572
571 inst = xzalloc(sizeof(*inst)); 573 inst = xzalloc(sizeof(*inst));
572 inst->pid = pid; 574 inst->pid = pid;
573 inst->prog = args[0]; 575 inst->prog = G.args[0];
574 inst->device = xstrdup(device); 576 inst->device = xstrdup(device);
575 inst->base_device = base_device(device); 577 inst->base_device = base_device(device);
576#if DO_PROGRESS_INDICATOR 578#if DO_PROGRESS_INDICATOR
@@ -579,8 +581,8 @@ static void execute(const char *type, const char *device,
579 581
580 /* Add to the list of running fsck's. 582 /* Add to the list of running fsck's.
581 * (was adding to the end, but adding to the front is simpler...) */ 583 * (was adding to the end, but adding to the front is simpler...) */
582 inst->next = instance_list; 584 inst->next = G.instance_list;
583 instance_list = inst; 585 G.instance_list = inst;
584} 586}
585 587
586/* 588/*
@@ -599,27 +601,27 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
599 601
600 if (strcmp(fs->type, "auto") != 0) { 602 if (strcmp(fs->type, "auto") != 0) {
601 type = fs->type; 603 type = fs->type;
602 if (verbose > 2) 604 if (G.verbose > 2)
603 bb_info_msg("using filesystem type '%s' %s", 605 bb_info_msg("using filesystem type '%s' %s",
604 type, "from fstab"); 606 type, "from fstab");
605 } else if (fstype 607 } else if (G.fstype
606 && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */ 608 && (G.fstype[0] != 'n' || G.fstype[1] != 'o') /* != "no" */
607 && !is_prefixed_with(fstype, "opts=") 609 && !is_prefixed_with(G.fstype, "opts=")
608 && !is_prefixed_with(fstype, "loop") 610 && !is_prefixed_with(G.fstype, "loop")
609 && !strchr(fstype, ',') 611 && !strchr(G.fstype, ',')
610 ) { 612 ) {
611 type = fstype; 613 type = G.fstype;
612 if (verbose > 2) 614 if (G.verbose > 2)
613 bb_info_msg("using filesystem type '%s' %s", 615 bb_info_msg("using filesystem type '%s' %s",
614 type, "from -t"); 616 type, "from -t");
615 } else { 617 } else {
616 type = "auto"; 618 type = "auto";
617 if (verbose > 2) 619 if (G.verbose > 2)
618 bb_info_msg("using filesystem type '%s' %s", 620 bb_info_msg("using filesystem type '%s' %s",
619 type, "(default)"); 621 type, "(default)");
620 } 622 }
621 623
622 num_running++; 624 G.num_running++;
623 execute(type, fs->device, fs->mountpt /*, interactive */); 625 execute(type, fs->device, fs->mountpt /*, interactive */);
624} 626}
625 627
@@ -632,13 +634,13 @@ static int device_already_active(char *device)
632 struct fsck_instance *inst; 634 struct fsck_instance *inst;
633 char *base; 635 char *base;
634 636
635 if (force_all_parallel) 637 if (G.force_all_parallel)
636 return 0; 638 return 0;
637 639
638#ifdef BASE_MD 640#ifdef BASE_MD
639 /* Don't check a soft raid disk with any other disk */ 641 /* Don't check a soft raid disk with any other disk */
640 if (instance_list 642 if (G.instance_list
641 && (is_prefixed_with(instance_list->device, BASE_MD) 643 && (is_prefixed_with(G.instance_list->device, BASE_MD)
642 || is_prefixed_with(device, BASE_MD)) 644 || is_prefixed_with(device, BASE_MD))
643 ) { 645 ) {
644 return 1; 646 return 1;
@@ -651,9 +653,9 @@ static int device_already_active(char *device)
651 * already active if there are any fsck instances running. 653 * already active if there are any fsck instances running.
652 */ 654 */
653 if (!base) 655 if (!base)
654 return (instance_list != NULL); 656 return (G.instance_list != NULL);
655 657
656 for (inst = instance_list; inst; inst = inst->next) { 658 for (inst = G.instance_list; inst; inst = inst->next) {
657 if (!inst->base_device || !strcmp(base, inst->base_device)) { 659 if (!inst->base_device || !strcmp(base, inst->base_device)) {
658 free(base); 660 free(base);
659 return 1; 661 return 1;
@@ -698,17 +700,17 @@ static int fs_match(struct fs_info *fs)
698 int n, ret, checked_type; 700 int n, ret, checked_type;
699 char *cp; 701 char *cp;
700 702
701 if (!fs_type_list) 703 if (!G.fs_type_list)
702 return 1; 704 return 1;
703 705
704 ret = 0; 706 ret = 0;
705 checked_type = 0; 707 checked_type = 0;
706 n = 0; 708 n = 0;
707 while (1) { 709 while (1) {
708 cp = fs_type_list[n]; 710 cp = G.fs_type_list[n];
709 if (!cp) 711 if (!cp)
710 break; 712 break;
711 switch (fs_type_flag[n]) { 713 switch (G.fs_type_flag[n]) {
712 case FS_TYPE_FLAG_NORMAL: 714 case FS_TYPE_FLAG_NORMAL:
713 checked_type++; 715 checked_type++;
714 if (strcmp(cp, fs->type) == 0) 716 if (strcmp(cp, fs->type) == 0)
@@ -728,7 +730,7 @@ static int fs_match(struct fs_info *fs)
728 if (checked_type == 0) 730 if (checked_type == 0)
729 return 1; 731 return 1;
730 732
731 return (fs_type_negated ? !ret : ret); 733 return (G.fs_type_negated ? !ret : ret);
732} 734}
733 735
734/* Check if we should ignore this filesystem. */ 736/* Check if we should ignore this filesystem. */
@@ -764,7 +766,7 @@ static int check_all(void)
764 smallint pass_done; 766 smallint pass_done;
765 int passno; 767 int passno;
766 768
767 if (verbose) 769 if (G.verbose)
768 puts("Checking all filesystems"); 770 puts("Checking all filesystems");
769 771
770 /* 772 /*
@@ -772,17 +774,17 @@ static int check_all(void)
772 * which should be ignored as done, and resolve any "auto" 774 * which should be ignored as done, and resolve any "auto"
773 * filesystem types (done as a side-effect of calling ignore()). 775 * filesystem types (done as a side-effect of calling ignore()).
774 */ 776 */
775 for (fs = filesys_info; fs; fs = fs->next) 777 for (fs = G.filesys_info; fs; fs = fs->next)
776 if (ignore(fs)) 778 if (ignore(fs))
777 fs->flags |= FLAG_DONE; 779 fs->flags |= FLAG_DONE;
778 780
779 /* 781 /*
780 * Find and check the root filesystem. 782 * Find and check the root filesystem.
781 */ 783 */
782 if (!parallel_root) { 784 if (!G.parallel_root) {
783 for (fs = filesys_info; fs; fs = fs->next) { 785 for (fs = G.filesys_info; fs; fs = fs->next) {
784 if (LONE_CHAR(fs->mountpt, '/')) { 786 if (LONE_CHAR(fs->mountpt, '/')) {
785 if (!skip_root && !ignore(fs)) { 787 if (!G.skip_root && !ignore(fs)) {
786 fsck_device(fs /*, 1*/); 788 fsck_device(fs /*, 1*/);
787 status |= wait_many(FLAG_WAIT_ALL); 789 status |= wait_many(FLAG_WAIT_ALL);
788 if (status > EXIT_NONDESTRUCT) 790 if (status > EXIT_NONDESTRUCT)
@@ -798,8 +800,8 @@ static int check_all(void)
798 * filesystem listed twice. 800 * filesystem listed twice.
799 * "Skip root" will skip _all_ root entries. 801 * "Skip root" will skip _all_ root entries.
800 */ 802 */
801 if (skip_root) 803 if (G.skip_root)
802 for (fs = filesys_info; fs; fs = fs->next) 804 for (fs = G.filesys_info; fs; fs = fs->next)
803 if (LONE_CHAR(fs->mountpt, '/')) 805 if (LONE_CHAR(fs->mountpt, '/'))
804 fs->flags |= FLAG_DONE; 806 fs->flags |= FLAG_DONE;
805 807
@@ -809,7 +811,7 @@ static int check_all(void)
809 not_done_yet = 0; 811 not_done_yet = 0;
810 pass_done = 1; 812 pass_done = 1;
811 813
812 for (fs = filesys_info; fs; fs = fs->next) { 814 for (fs = G.filesys_info; fs; fs = fs->next) {
813 if (bb_got_signal) 815 if (bb_got_signal)
814 break; 816 break;
815 if (fs->flags & FLAG_DONE) 817 if (fs->flags & FLAG_DONE)
@@ -835,7 +837,7 @@ static int check_all(void)
835 /* 837 /*
836 * Spawn off the fsck process 838 * Spawn off the fsck process
837 */ 839 */
838 fsck_device(fs /*, serialize*/); 840 fsck_device(fs /*, G.serialize*/);
839 fs->flags |= FLAG_DONE; 841 fs->flags |= FLAG_DONE;
840 842
841 /* 843 /*
@@ -843,8 +845,8 @@ static int check_all(void)
843 * have a limit on the number of fsck's extant 845 * have a limit on the number of fsck's extant
844 * at one time, apply that limit. 846 * at one time, apply that limit.
845 */ 847 */
846 if (serialize 848 if (G.serialize
847 || (max_running && (num_running >= max_running)) 849 || (G.num_running >= G.max_running)
848 ) { 850 ) {
849 pass_done = 0; 851 pass_done = 0;
850 break; 852 break;
@@ -852,12 +854,12 @@ static int check_all(void)
852 } 854 }
853 if (bb_got_signal) 855 if (bb_got_signal)
854 break; 856 break;
855 if (verbose > 1) 857 if (G.verbose > 1)
856 printf("--waiting-- (pass %d)\n", passno); 858 printf("--waiting-- (pass %d)\n", passno);
857 status |= wait_many(pass_done ? FLAG_WAIT_ALL : 859 status |= wait_many(pass_done ? FLAG_WAIT_ALL :
858 FLAG_WAIT_ATLEAST_ONE); 860 FLAG_WAIT_ATLEAST_ONE);
859 if (pass_done) { 861 if (pass_done) {
860 if (verbose > 1) 862 if (G.verbose > 1)
861 puts("----------------------------------"); 863 puts("----------------------------------");
862 passno++; 864 passno++;
863 } else 865 } else
@@ -885,9 +887,9 @@ static void compile_fs_type(char *fs_type)
885 s++; 887 s++;
886 } 888 }
887 889
888 fs_type_list = xzalloc(num * sizeof(fs_type_list[0])); 890 G.fs_type_list = xzalloc(num * sizeof(G.fs_type_list[0]));
889 fs_type_flag = xzalloc(num * sizeof(fs_type_flag[0])); 891 G.fs_type_flag = xzalloc(num * sizeof(G.fs_type_flag[0]));
890 fs_type_negated = -1; /* not yet known is it negated or not */ 892 G.fs_type_negated = -1; /* not yet known is it negated or not */
891 893
892 num = 0; 894 num = 0;
893 s = fs_type; 895 s = fs_type;
@@ -909,18 +911,18 @@ static void compile_fs_type(char *fs_type)
909 if (is_prefixed_with(s, "opts=")) { 911 if (is_prefixed_with(s, "opts=")) {
910 s += 5; 912 s += 5;
911 loop_special_case: 913 loop_special_case:
912 fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT; 914 G.fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
913 } else { 915 } else {
914 if (fs_type_negated == -1) 916 if (G.fs_type_negated == -1)
915 fs_type_negated = negate; 917 G.fs_type_negated = negate;
916 if (fs_type_negated != negate) 918 if (G.fs_type_negated != negate)
917 bb_error_msg_and_die( 919 bb_error_msg_and_die(
918"either all or none of the filesystem types passed to -t must be prefixed " 920"either all or none of the filesystem types passed to -t must be prefixed "
919"with 'no' or '!'"); 921"with 'no' or '!'");
920 } 922 }
921 comma = strchr(s, ','); 923 comma = strchrnul(s, ',');
922 fs_type_list[num++] = comma ? xstrndup(s, comma-s) : xstrdup(s); 924 G.fs_type_list[num++] = xstrndup(s, comma-s);
923 if (!comma) 925 if (*comma == '\0')
924 break; 926 break;
925 s = comma + 1; 927 s = comma + 1;
926 } 928 }
@@ -928,8 +930,8 @@ static void compile_fs_type(char *fs_type)
928 930
929static char **new_args(void) 931static char **new_args(void)
930{ 932{
931 args = xrealloc_vector(args, 2, num_args); 933 G.args = xrealloc_vector(G.args, 2, G.num_args);
932 return &args[num_args++]; 934 return &G.args[G.num_args++];
933} 935}
934 936
935int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 937int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -946,6 +948,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
946 smallint doall; 948 smallint doall;
947 smallint notitle; 949 smallint notitle;
948 950
951 INIT_G();
952
949 /* we want wait() to be interruptible */ 953 /* we want wait() to be interruptible */
950 signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); 954 signal_no_SA_RESTART_empty_mask(SIGINT, record_signo);
951 signal_no_SA_RESTART_empty_mask(SIGTERM, record_signo); 955 signal_no_SA_RESTART_empty_mask(SIGTERM, record_signo);
@@ -955,8 +959,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
955 opts_for_fsck = doall = notitle = 0; 959 opts_for_fsck = doall = notitle = 0;
956 devices = NULL; 960 devices = NULL;
957 num_devices = 0; 961 num_devices = 0;
958 new_args(); /* args[0] = NULL, will be replaced by fsck.<type> */ 962 new_args(); /* G.args[0] = NULL, will be replaced by fsck.<type> */
959 /* instance_list = NULL; - in bss, so already zeroed */ 963 /* G.instance_list = NULL; - in bss, so already zeroed */
960 964
961 while (*++argv) { 965 while (*++argv) {
962 int j; 966 int j;
@@ -1005,13 +1009,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
1005 goto next_arg; 1009 goto next_arg;
1006#endif 1010#endif
1007 case 'V': 1011 case 'V':
1008 verbose++; 1012 G.verbose++;
1009 break; 1013 break;
1010 case 'N': 1014 case 'N':
1011 noexecute = 1; 1015 G.noexecute = 1;
1012 break; 1016 break;
1013 case 'R': 1017 case 'R':
1014 skip_root = 1; 1018 G.skip_root = 1;
1015 break; 1019 break;
1016 case 'T': 1020 case 'T':
1017 notitle = 1; 1021 notitle = 1;
@@ -1020,13 +1024,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
1020 like_mount = 1; 1024 like_mount = 1;
1021 break; */ 1025 break; */
1022 case 'P': 1026 case 'P':
1023 parallel_root = 1; 1027 G.parallel_root = 1;
1024 break; 1028 break;
1025 case 's': 1029 case 's':
1026 serialize = 1; 1030 G.serialize = 1;
1027 break; 1031 break;
1028 case 't': 1032 case 't':
1029 if (fstype) 1033 if (G.fstype)
1030 bb_show_usage(); 1034 bb_show_usage();
1031 if (arg[++j]) 1035 if (arg[++j])
1032 tmp = &arg[j]; 1036 tmp = &arg[j];
@@ -1034,8 +1038,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
1034 tmp = *argv; 1038 tmp = *argv;
1035 else 1039 else
1036 bb_show_usage(); 1040 bb_show_usage();
1037 fstype = xstrdup(tmp); 1041 G.fstype = xstrdup(tmp);
1038 compile_fs_type(fstype); 1042 compile_fs_type(G.fstype);
1039 goto next_arg; 1043 goto next_arg;
1040 case '?': 1044 case '?':
1041 bb_show_usage(); 1045 bb_show_usage();
@@ -1056,12 +1060,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
1056 } 1060 }
1057 } 1061 }
1058 if (getenv("FSCK_FORCE_ALL_PARALLEL")) 1062 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1059 force_all_parallel = 1; 1063 G.force_all_parallel = 1;
1060 tmp = getenv("FSCK_MAX_INST"); 1064 tmp = getenv("FSCK_MAX_INST");
1065 G.max_running = INT_MAX;
1061 if (tmp) 1066 if (tmp)
1062 max_running = xatoi(tmp); 1067 G.max_running = xatoi(tmp);
1063 new_args(); /* args[num_args - 2] will be replaced by <device> */ 1068 new_args(); /* G.args[G.num_args - 2] will be replaced by <device> */
1064 new_args(); /* args[num_args - 1] is the last, NULL element */ 1069 new_args(); /* G.args[G.num_args - 1] is the last, NULL element */
1065 1070
1066 if (!notitle) 1071 if (!notitle)
1067 puts("fsck (busybox "BB_VER", "BB_BT")"); 1072 puts("fsck (busybox "BB_VER", "BB_BT")");
@@ -1073,10 +1078,10 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
1073 fstab = "/etc/fstab"; 1078 fstab = "/etc/fstab";
1074 load_fs_info(fstab); 1079 load_fs_info(fstab);
1075 1080
1076 /*interactive = (num_devices == 1) | serialize;*/ 1081 /*interactive = (num_devices == 1) | G.serialize;*/
1077 1082
1078 if (num_devices == 0) 1083 if (num_devices == 0)
1079 /*interactive =*/ serialize = doall = 1; 1084 /*interactive =*/ G.serialize = doall = 1;
1080 if (doall) 1085 if (doall)
1081 return check_all(); 1086 return check_all();
1082 1087
@@ -1092,13 +1097,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
1092 fs = create_fs_device(devices[i], "", "auto", NULL, -1); 1097 fs = create_fs_device(devices[i], "", "auto", NULL, -1);
1093 fsck_device(fs /*, interactive */); 1098 fsck_device(fs /*, interactive */);
1094 1099
1095 if (serialize 1100 if (G.serialize
1096 || (max_running && (num_running >= max_running)) 1101 || (G.num_running >= G.max_running)
1097 ) { 1102 ) {
1098 int exit_status = wait_one(0); 1103 int exit_status = wait_one(0);
1099 if (exit_status >= 0) 1104 if (exit_status >= 0)
1100 status |= exit_status; 1105 status |= exit_status;
1101 if (verbose > 1) 1106 if (G.verbose > 1)
1102 puts("----------------------------------"); 1107 puts("----------------------------------");
1103 } 1108 }
1104 } 1109 }