From 7703a6ff27b154f2048c96fe0dc2f0297188768a Mon Sep 17 00:00:00 2001 From: Scott Long Date: Mon, 30 Dec 2013 01:16:08 +0000 Subject: Add the -R option to allow fsck_ffs to restart itself when too many critical errors have been detected in a particular run. Clean up the global state variables so that a restart can happen correctly. Separate the global variables in fsck_ffs and fsdb to their own file. This fixes header sharing with fscd. Correctly initialize, static-ize, and remove global variables as needed in dir.c. This fixes a problem with lost+found directories that was causing a segfault. Correctly initialize, static-ize, and remove global variables as needed in suj.c. Initialize the suj globals before allocating the disk object, not after. Also ensure that 'preen' mode doesn't conflict with 'restart' mode Submitted by: scottl, max Reviewed by: max, mckusick (earlier version) Obtained from: Netflix MFC after: 3 days --- sbin/fsck_ffs/main.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'sbin/fsck_ffs/main.c') diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c index 1a1c03bc7d85..08c7745727e4 100644 --- a/sbin/fsck_ffs/main.c +++ b/sbin/fsck_ffs/main.c @@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$"); #include "fsck.h" +int restarts; + static void usage(void) __dead2; static int argtoi(int flag, const char *req, const char *str, int base); static int checkfilesys(char *filesys); @@ -82,7 +84,7 @@ main(int argc, char *argv[]) sync(); skipclean = 1; inoopt = 0; - while ((ch = getopt(argc, argv, "b:Bc:CdEfFm:nprSyZ")) != -1) { + while ((ch = getopt(argc, argv, "b:Bc:CdEfFm:npRrSyZ")) != -1) { switch (ch) { case 'b': skipclean = 0; @@ -138,6 +140,9 @@ main(int argc, char *argv[]) ckclean++; break; + case 'R': + wantrestart = 1; + break; case 'r': inoopt++; break; @@ -186,8 +191,12 @@ main(int argc, char *argv[]) rlimit.rlim_cur = rlimit.rlim_max; (void)setrlimit(RLIMIT_DATA, &rlimit); } - while (argc-- > 0) - (void)checkfilesys(*argv++); + while (argc > 0) { + if (checkfilesys(*argv) == ERESTART) + continue; + argc--; + argv++; + } if (returntosingle) ret = 2; @@ -228,6 +237,8 @@ checkfilesys(char *filesys) iov = NULL; iovlen = 0; errmsg[0] = '\0'; + fsutilinit(); + fsckinit(); cdevname = filesys; if (debug && ckclean) @@ -550,8 +561,12 @@ checkfilesys(char *filesys) inostathead = NULL; if (fsmodified && !preen) printf("\n***** FILE SYSTEM WAS MODIFIED *****\n"); - if (rerun) + if (rerun) { + if (wantrestart && (restarts++ < 10) && + (preen || reply("RESTART"))) + return (ERESTART); printf("\n***** PLEASE RERUN FSCK *****\n"); + } if (chkdoreload(mntp) != 0) { if (!fsmodified) return (0); @@ -654,3 +669,15 @@ usage(void) getprogname()); exit(1); } + +void +infohandler(int sig __unused) +{ + got_siginfo = 1; +} + +void +alarmhandler(int sig __unused) +{ + got_sigalarm = 1; +} -- cgit v1.2.3