aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/fsck.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-26 02:51:29 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-26 02:51:29 +0000
commit0de9375ee6e766cf15942c6582c79b0ac6d310f5 (patch)
tree69a866577fc99e3e0c3153f486f22a2e675028a0 /e2fsprogs/fsck.c
parentc4f623ef2a7980a63de7c9f1d539a656b83f10e7 (diff)
downloadbusybox-w32-0de9375ee6e766cf15942c6582c79b0ac6d310f5.tar.gz
busybox-w32-0de9375ee6e766cf15942c6582c79b0ac6d310f5.tar.bz2
busybox-w32-0de9375ee6e766cf15942c6582c79b0ac6d310f5.zip
leftover of e2fsck surgery
Diffstat (limited to 'e2fsprogs/fsck.c')
-rw-r--r--e2fsprogs/fsck.c118
1 files changed, 36 insertions, 82 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index d59206ca2..396174ef5 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -27,7 +27,6 @@
27 */ 27 */
28 28
29#include "busybox.h" 29#include "busybox.h"
30/*#include "e2fs_lib.h"*/
31 30
32#define EXIT_OK 0 31#define EXIT_OK 0
33#define EXIT_NONDESTRUCT 1 32#define EXIT_NONDESTRUCT 1
@@ -41,9 +40,6 @@
41#define DEFAULT_FSTYPE "ext2" 40#define DEFAULT_FSTYPE "ext2"
42#endif 41#endif
43 42
44#define MAX_DEVICES 32
45#define MAX_ARGS 32
46
47/* 43/*
48 * Internal structure for mount tabel entries. 44 * Internal structure for mount tabel entries.
49 */ 45 */
@@ -76,7 +72,7 @@ struct fsck_instance {
76 struct fsck_instance *next; 72 struct fsck_instance *next;
77}; 73};
78 74
79static const char * const ignored_types[] = { 75static const char *const ignored_types[] = {
80 "ignore", 76 "ignore",
81 "iso9660", 77 "iso9660",
82 "nfs", 78 "nfs",
@@ -88,7 +84,8 @@ static const char * const ignored_types[] = {
88 NULL 84 NULL
89}; 85};
90 86
91static const char * const really_wanted[] = { 87#if 0
88static const char *const really_wanted[] = {
92 "minix", 89 "minix",
93 "ext2", 90 "ext2",
94 "ext3", 91 "ext3",
@@ -98,16 +95,15 @@ static const char * const really_wanted[] = {
98 "xfs", 95 "xfs",
99 NULL 96 NULL
100}; 97};
98#endif
101 99
102#define BASE_MD "/dev/md" 100#define BASE_MD "/dev/md"
103 101
104/* 102static volatile int cancel_requested;
105 * Global variables for options 103
106 */
107static char **devices; 104static char **devices;
108static char **args; 105static char **args;
109static int num_devices, num_args; 106static int num_devices, num_args;
110
111static int verbose; 107static int verbose;
112static int doall; 108static int doall;
113static int noexecute; 109static int noexecute;
@@ -121,13 +117,10 @@ static int progress_fd;
121static int force_all_parallel; 117static int force_all_parallel;
122static int num_running; 118static int num_running;
123static int max_running; 119static int max_running;
124static volatile int cancel_requested;
125static int kill_sent;
126static char *fstype; 120static char *fstype;
127static struct fs_info *filesys_info, *filesys_last; 121static struct fs_info *filesys_info;
122static struct fs_info *filesys_last;
128static struct fsck_instance *instance_list; 123static struct fsck_instance *instance_list;
129/*static char *fsck_path;*/
130/*static blkid_cache cache;*/
131 124
132#define FS_TYPE_FLAG_NORMAL 0 125#define FS_TYPE_FLAG_NORMAL 0
133#define FS_TYPE_FLAG_OPT 1 126#define FS_TYPE_FLAG_OPT 1
@@ -439,11 +432,10 @@ static void load_fs_info(const char *filename)
439 fclose(f); 432 fclose(f);
440 433
441 if (old_fstab) { 434 if (old_fstab) {
442 fputs("\007\007\007" 435 fputs("\007"
443 "WARNING: Your /etc/fstab does not contain the fsck passno\n" 436"WARNING: Your /etc/fstab does not contain the fsck passno field.\n"
444 " field. I will kludge around things for you, but you\n" 437"I will kludge around things for you, but you should fix\n"
445 " should fix your /etc/fstab file as soon as you can.\n\n", stderr); 438"your /etc/fstab file as soon as you can.\n\n", stderr);
446
447 for (fs = filesys_info; fs; fs = fs->next) { 439 for (fs = filesys_info; fs; fs = fs->next) {
448 fs->passno = 1; 440 fs->passno = 1;
449 } 441 }
@@ -455,10 +447,6 @@ static struct fs_info *lookup(char *filesys)
455{ 447{
456 struct fs_info *fs; 448 struct fs_info *fs;
457 449
458 /* No filesys name given. */
459 if (filesys == NULL)
460 return NULL;
461
462 for (fs = filesys_info; fs; fs = fs->next) { 450 for (fs = filesys_info; fs; fs = fs->next) {
463 if (strcmp(filesys, fs->device) == 0 451 if (strcmp(filesys, fs->device) == 0
464 || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0) 452 || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0)
@@ -469,29 +457,6 @@ static struct fs_info *lookup(char *filesys)
469 return fs; 457 return fs;
470} 458}
471 459
472#if 0
473/* Find fsck program for a given fs type. */
474static char *find_fsck(char *type)
475{
476 char *s;
477 const char *tpl;
478 char *p = xstrdup(fsck_path);
479 struct stat st;
480
481 /* Are we looking for a program or just a type? */
482 tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
483
484 for (s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
485 s = xasprintf(tpl, s, type);
486 if (stat(s, &st) == 0)
487 break;
488 free(s);
489 }
490 free(p);
491 return s;
492}
493#endif
494
495static int progress_active(void) 460static int progress_active(void)
496{ 461{
497 struct fsck_instance *inst; 462 struct fsck_instance *inst;
@@ -588,18 +553,21 @@ static int execute(const char *type, const char *device, const char *mntpt,
588/* 553/*
589 * Send a signal to all outstanding fsck child processes 554 * Send a signal to all outstanding fsck child processes
590 */ 555 */
591static int kill_all(int signum) 556static void kill_all_if_cancel_requested(void)
592{ 557{
558 static int kill_sent;
559
593 struct fsck_instance *inst; 560 struct fsck_instance *inst;
594 int n = 0; 561
562 if (!cancel_requested || kill_sent)
563 return;
595 564
596 for (inst = instance_list; inst; inst = inst->next) { 565 for (inst = instance_list; inst; inst = inst->next) {
597 if (inst->flags & FLAG_DONE) 566 if (inst->flags & FLAG_DONE)
598 continue; 567 continue;
599 kill(inst->pid, signum); 568 kill(inst->pid, SIGTERM);
600 n++;
601 } 569 }
602 return n; 570 kill_sent = 1;
603} 571}
604 572
605/* 573/*
@@ -637,14 +605,11 @@ static struct fsck_instance *wait_one(int flags)
637 605
638 do { 606 do {
639 pid = waitpid(-1, &status, flags); 607 pid = waitpid(-1, &status, flags);
640 if (cancel_requested && !kill_sent) { 608 kill_all_if_cancel_requested();
641 kill_all(SIGTERM); 609 if (pid == 0 && (flags & WNOHANG))
642 kill_sent++;
643 }
644 if ((pid == 0) && (flags & WNOHANG))
645 return NULL; 610 return NULL;
646 if (pid < 0) { 611 if (pid < 0) {
647 if ((errno == EINTR) || (errno == EAGAIN)) 612 if (errno == EINTR || errno == EAGAIN)
648 continue; 613 continue;
649 if (errno == ECHILD) { 614 if (errno == ECHILD) {
650 bb_error_msg("wait: no more child process?!?"); 615 bb_error_msg("wait: no more child process?!?");
@@ -704,7 +669,7 @@ static struct fsck_instance *wait_one(int flags)
704 break; 669 break;
705 } 670 }
706 } 671 }
707ret_inst: 672 ret_inst:
708 if (prev) 673 if (prev)
709 prev->next = inst->next; 674 prev->next = inst->next;
710 else 675 else
@@ -758,16 +723,16 @@ static void fsck_device(struct fs_info *fs, int interactive)
758 723
759 interpret_type(fs); 724 interpret_type(fs);
760 725
726 type = DEFAULT_FSTYPE;
761 if (strcmp(fs->type, "auto") != 0) 727 if (strcmp(fs->type, "auto") != 0)
762 type = fs->type; 728 type = fs->type;
763 else if (fstype 729 else if (fstype
764 && strncmp(fstype, "no", 2) 730 && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
765 && strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) 731 && strncmp(fstype, "opts=", 5) != 0
732 && strncmp(fstype, "loop", 4) != 0
766 && !strchr(fstype, ',') 733 && !strchr(fstype, ',')
767 ) 734 )
768 type = fstype; 735 type = fstype;
769 else
770 type = DEFAULT_FSTYPE;
771 736
772 num_running++; 737 num_running++;
773 retval = execute(type, fs->device, fs->mountpt, interactive); 738 retval = execute(type, fs->device, fs->mountpt, interactive);
@@ -1078,17 +1043,14 @@ static int check_all(void)
1078 } else 1043 } else
1079 not_done_yet++; 1044 not_done_yet++;
1080 } 1045 }
1081 if (cancel_requested && !kill_sent) { 1046 kill_all_if_cancel_requested();
1082 kill_all(SIGTERM);
1083 kill_sent++;
1084 }
1085 status |= wait_many(FLAG_WAIT_ATLEAST_ONE); 1047 status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
1086 return status; 1048 return status;
1087} 1049}
1088 1050
1089static void signal_cancel(int sig ATTRIBUTE_UNUSED) 1051static void signal_cancel(int sig ATTRIBUTE_UNUSED)
1090{ 1052{
1091 cancel_requested++; 1053 cancel_requested = 1;
1092} 1054}
1093 1055
1094static int string_to_int(const char *s) 1056static int string_to_int(const char *s)
@@ -1126,9 +1088,6 @@ static void parse_args(int argc, char *argv[])
1126 for (i = 1; i < argc; i++) { 1088 for (i = 1; i < argc; i++) {
1127 arg = argv[i]; 1089 arg = argv[i];
1128 if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) { 1090 if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
1129 if (num_devices >= MAX_DEVICES) {
1130 bb_error_msg_and_die("too many devices");
1131 }
1132#if 0 1091#if 0
1133 char *dev; 1092 char *dev;
1134 dev = blkid_get_devname(cache, arg, NULL); 1093 dev = blkid_get_devname(cache, arg, NULL);
@@ -1138,8 +1097,8 @@ static void parse_args(int argc, char *argv[])
1138 * /proc/partitions isn't found. 1097 * /proc/partitions isn't found.
1139 */ 1098 */
1140 if (access("/proc/partitions", R_OK) < 0) { 1099 if (access("/proc/partitions", R_OK) < 0) {
1141 bb_perror_msg_and_die("cannot open /proc/partitions " 1100 bb_perror_msg_and_die(
1142 "(is /proc mounted?)"); 1101"cannot open /proc/partitions (is /proc mounted?)");
1143 } 1102 }
1144 /* 1103 /*
1145 * Check to see if this is because 1104 * Check to see if this is because
@@ -1147,10 +1106,10 @@ static void parse_args(int argc, char *argv[])
1147 */ 1106 */
1148 if (geteuid()) 1107 if (geteuid())
1149 bb_error_msg_and_die( 1108 bb_error_msg_and_die(
1150 "must be root to scan for matching filesystems: %s\n", arg); 1109"must be root to scan for matching filesystems: %s\n", arg);
1151 else 1110 else
1152 bb_error_msg_and_die( 1111 bb_error_msg_and_die(
1153 "cannot find matching filesystem: %s", arg); 1112"cannot find matching filesystem: %s", arg);
1154 } 1113 }
1155 devices = xrealloc(devices, (num_devices+1) * sizeof(devices[0])); 1114 devices = xrealloc(devices, (num_devices+1) * sizeof(devices[0]));
1156 devices[num_devices++] = dev ? dev : xstrdup(arg); 1115 devices[num_devices++] = dev ? dev : xstrdup(arg);
@@ -1271,8 +1230,6 @@ int fsck_main(int argc, char *argv[])
1271 fstab = "/etc/fstab"; 1230 fstab = "/etc/fstab";
1272 load_fs_info(fstab); 1231 load_fs_info(fstab);
1273 1232
1274 /*fsck_path = e2fs_set_sbin_path();*/
1275
1276 if (num_devices == 1 || serialize) 1233 if (num_devices == 1 || serialize)
1277 interactive = 1; 1234 interactive = 1;
1278 1235
@@ -1286,12 +1243,9 @@ int fsck_main(int argc, char *argv[])
1286 return check_all(); 1243 return check_all();
1287 } 1244 }
1288 1245
1289 for (i = 0 ; i < num_devices; i++) { 1246 for (i = 0; i < num_devices; i++) {
1290 if (cancel_requested) { 1247 if (cancel_requested) {
1291 if (!kill_sent) { 1248 kill_all_if_cancel_requested();
1292 kill_all(SIGTERM);
1293 kill_sent++;
1294 }
1295 break; 1249 break;
1296 } 1250 }
1297 fs = lookup(devices[i]); 1251 fs = lookup(devices[i]);