2 * pfsck --- A generic, parallelizing front-end for the fsck program.
3 * It will automatically try to run fsck programs in parallel if the
4 * devices are on separate spindles. It is based on the same ideas as
5 * the generic front end for fsck by David Engel and Fred van Kempen,
6 * but it has been completely rewritten from scratch to support
9 * Written by Theodore Ts'o, <tytso@mit.edu>
11 * Miquel van Smoorenburg (miquels@drinkel.ow.org) 20-Oct-1994:
12 * o Changed -t fstype to behave like with mount when -A (all file
13 * systems) or -M (like mount) is specified.
14 * o fsck looks if it can find the fsck.type program to decide
15 * if it should ignore the fs type. This way more fsck programs
16 * can be added without changing this front-end.
17 * o -R flag skip root file system.
19 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
20 * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o.
22 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
24 * This file may be redistributed under the terms of the GNU Public
28 #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */
30 #include <sys/types.h>
51 #include "pathnames.h"
52 #include "ismounted.h"
56 #define XALLOC_EXIT_CODE EXIT_ERROR
59 static const char *ignored_types[] = {
71 static const char *really_wanted[] = {
84 #define BASE_MD "/dev/md"
87 * Global variables for options
89 char *devices[MAX_DEVICES];
91 int num_devices, num_args;
99 int ignore_mounted = 0;
101 int parallel_root = 0;
104 int force_all_parallel = 0;
107 volatile int cancel_requested = 0;
110 struct fs_info *filesys_info = NULL, *filesys_last = NULL;
111 struct fsck_instance *instance_list;
112 const char fsck_prefix_path[] = FS_SEARCH_PATH;
115 static char *string_copy(const char *s)
121 ret = xmalloc(strlen(s)+1);
126 static int string_to_int(const char *s)
131 l = strtol(s, &p, 0);
132 if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX)
138 static int ignore(struct fs_info *);
140 static char *skip_over_blank(char *cp)
142 while (*cp && isspace(*cp))
147 static char *skip_over_word(char *cp)
149 while (*cp && !isspace(*cp))
154 static void strip_line(char *line)
159 p = line + strlen(line) - 1;
160 if ((*p == '\n') || (*p == '\r'))
167 static char *parse_word(char **buf)
175 word = skip_over_blank(word);
176 next = skip_over_word(word);
183 static void parse_escape(char *word)
191 for (p = word, q = word; *p; p++, q++) {
210 for (i = 0; i < 3; i++, p++) {
213 ac = (ac * 8) + (*p - '0');
221 static dev_t get_disk(const char *device)
226 if (!stat(device, &st) &&
227 !blkid_devno_to_wholedisk(st.st_rdev, NULL, 0, &disk))
233 static int is_irrotational_disk(dev_t disk)
239 rc = snprintf(path, sizeof(path),
240 "/sys/dev/block/%d:%d/queue/rotational",
241 major(disk), minor(disk));
243 if (rc < 0 || (unsigned int) (rc + 1) > sizeof(path))
246 f = fopen(path, "r");
250 rc = fscanf(f, "%d", &x);
253 warn(_("failed to read: %s"), path);
255 warnx(_("parse error: %s"), path);
259 return rc == 1 ? !x : 0;
262 static void lock_disk(struct fsck_instance *inst)
264 dev_t disk = inst->fs->disk ? inst->fs->disk : get_disk(inst->fs->device);
267 if (!disk || is_irrotational_disk(disk))
270 diskname = blkid_devno_to_devname(disk);
275 printf(_("Locking disk %s ... "), diskname);
277 inst->lock = open(diskname, O_CLOEXEC | O_RDONLY);
278 if (inst->lock >= 0) {
281 /* inform users that we're waiting on the lock */
283 (rc = flock(inst->lock, LOCK_EX | LOCK_NB)) != 0 &&
284 errno == EWOULDBLOCK)
285 printf(_("(waiting) "));
287 if (rc != 0 && flock(inst->lock, LOCK_EX) != 0) {
288 close(inst->lock); /* failed */
294 /* TRANSLATORS: These are followups to "Locking disk...". */
295 printf("%s.\n", inst->lock >= 0 ? _("succeeded") : _("failed"));
301 static void unlock_disk(struct fsck_instance *inst)
303 if (inst->lock >= 0) {
304 /* explicitly unlock, don't rely on close(), maybe some library
305 * (e.g. liblkid) has still open the device.
307 flock(inst->lock, LOCK_UN);
314 static void free_instance(struct fsck_instance *i)
323 static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
324 const char *type, const char *opts,
325 int freq, int passno)
329 fs = xmalloc(sizeof(struct fs_info));
331 fs->device = string_copy(device);
332 fs->mountpt = string_copy(mntpnt);
333 fs->type = string_copy(type);
334 fs->opts = string_copy(opts ? opts : "");
345 filesys_last->next = fs;
353 static int parse_fstab_line(char *line, struct fs_info **ret_fs)
355 char *dev, *device, *mntpnt, *type, *opts, *freq, *passno, *cp;
362 device = parse_word(&cp);
363 if (!device || *device == '#')
364 return 0; /* Ignore blank lines and comments */
365 mntpnt = parse_word(&cp);
366 type = parse_word(&cp);
367 opts = parse_word(&cp);
368 freq = parse_word(&cp);
369 passno = parse_word(&cp);
371 if (!mntpnt || !type)
374 parse_escape(device);
375 parse_escape(mntpnt);
379 parse_escape(passno);
381 dev = fsprobe_get_devname_by_spec(device);
385 if (strchr(type, ','))
388 fs = create_fs_device(device, mntpnt, type ? type : "auto", opts,
389 freq ? atoi(freq) : -1,
390 passno ? atoi(passno) : -1);
399 static void interpret_type(struct fs_info *fs)
403 if (strcmp(fs->type, "auto") != 0)
405 t = fsprobe_get_fstype_by_devname(fs->device);
413 * Load the filesystem database from /etc/fstab
415 static void load_fs_info(const char *filename)
423 if ((f = fopen(filename, "r")) == NULL) {
424 warn(_("WARNING: couldn't open %s"), filename);
429 if (!fgets(buf, sizeof(buf), f))
431 buf[sizeof(buf)-1] = 0;
432 if (parse_fstab_line(buf, &fs) < 0) {
433 warnx(_("WARNING: bad format "
434 "on line %d of %s"), lineno, filename);
447 if (old_fstab && filesys_info) {
449 "WARNING: Your /etc/fstab does not contain the fsck passno\n"
450 " field. I will kludge around things for you, but you\n"
451 " should fix your /etc/fstab file as soon as you can.\n"));
453 for (fs = filesys_info; fs; fs = fs->next) {
459 /* Lookup filesys in /etc/fstab and return the corresponding entry. */
460 static struct fs_info *lookup(char *filesys)
464 /* No filesys name given. */
468 for (fs = filesys_info; fs; fs = fs->next) {
469 if (!strcmp(filesys, fs->device) ||
470 (fs->mountpt && !strcmp(filesys, fs->mountpt)))
477 /* Find fsck program for a given fs type. */
478 static char *find_fsck(char *type)
482 static char prog[256];
483 char *p = string_copy(fsck_path);
486 /* Are we looking for a program or just a type? */
487 tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
489 for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
490 sprintf(prog, tpl, s, type);
491 if (stat(prog, &st) == 0) break;
494 return(s ? prog : NULL);
497 static int progress_active(NOARGS)
499 struct fsck_instance *inst;
501 for (inst = instance_list; inst; inst = inst->next) {
502 if (inst->flags & FLAG_DONE)
504 if (inst->flags & FLAG_PROGRESS)
511 * Execute a particular fsck program, and link it into the list of
512 * child processes we are waiting for.
514 static int execute(const char *type, struct fs_info *fs, int interactive)
516 char *s, *argv[80], prog[80];
518 struct fsck_instance *inst, *p;
521 inst = xmalloc(sizeof(struct fsck_instance));
522 memset(inst, 0, sizeof(struct fsck_instance));
524 sprintf(prog, "fsck.%s", type);
525 argv[0] = string_copy(prog);
528 for (i=0; i <num_args; i++)
529 argv[argc++] = string_copy(args[i]);
532 if ((strcmp(type, "ext2") == 0) ||
533 (strcmp(type, "ext3") == 0) ||
534 (strcmp(type, "ext4") == 0) ||
535 (strcmp(type, "ext4dev") == 0)) {
539 if (!progress_active()) {
540 snprintf(tmp, 80, "-C%d", progress_fd);
541 inst->flags |= FLAG_PROGRESS;
542 } else if (progress_fd)
543 snprintf(tmp, 80, "-C%d", progress_fd * -1);
545 argv[argc++] = string_copy(tmp);
549 argv[argc++] = string_copy(fs->device);
554 warnx(_("%s: not found"), prog);
559 if (verbose || noexecute) {
560 printf("[%s (%d) -- %s] ", s, num_running,
561 fs->mountpt ? fs->mountpt : fs->device);
562 for (i=0; i < argc; i++)
563 printf("%s ", argv[i]);
574 /* Fork and execute the correct program. */
577 else if ((pid = fork()) < 0) {
581 } else if (pid == 0) {
584 (void) execv(s, argv);
590 for (i=0; i < argc; i++)
594 inst->prog = string_copy(prog);
595 inst->type = string_copy(type);
596 inst->start_time = time(0);
600 * Find the end of the list, so we add the instance on at the end.
602 for (p = instance_list; p && p->next; p = p->next);
607 instance_list = inst;
613 * Send a signal to all outstanding fsck child processes
615 static int kill_all(int signum)
617 struct fsck_instance *inst;
620 for (inst = instance_list; inst; inst = inst->next) {
621 if (inst->flags & FLAG_DONE)
623 kill(inst->pid, signum);
630 * Wait for one child process to exit; when it does, unlink it from
631 * the list of executing child processes, and return it.
633 static struct fsck_instance *wait_one(int flags)
637 struct fsck_instance *inst, *inst2, *prev;
644 inst = instance_list;
647 while (inst->next && (random() & 1)) {
652 inst->exit_status = 0;
657 * gcc -Wall fails saving throw against stupidity
658 * (inst and prev are thought to be uninitialized variables)
663 pid = waitpid(-1, &status, flags);
664 if (cancel_requested && !kill_sent) {
668 if ((pid == 0) && (flags & WNOHANG))
671 if ((errno == EINTR) || (errno == EAGAIN))
673 if (errno == ECHILD) {
674 warnx(_("wait: no more child process?!?"));
680 for (prev = 0, inst = instance_list;
682 prev = inst, inst = inst->next) {
683 if (inst->pid == pid)
688 if (WIFEXITED(status))
689 status = WEXITSTATUS(status);
690 else if (WIFSIGNALED(status)) {
691 sig = WTERMSIG(status);
693 status = EXIT_UNCORRECTED;
695 warnx(_("Warning... %s for device %s exited "
697 inst->prog, inst->fs->device, sig);
701 warnx(_("%s %s: status is %x, should never happen."),
702 inst->prog, inst->fs->device, status);
705 inst->exit_status = status;
706 inst->flags |= FLAG_DONE;
707 if (progress && (inst->flags & FLAG_PROGRESS) &&
708 !progress_active()) {
709 for (inst2 = instance_list; inst2; inst2 = inst2->next) {
710 if (inst2->flags & FLAG_DONE)
712 if (strcmp(inst2->type, "ext2") &&
713 strcmp(inst2->type, "ext3") &&
714 strcmp(inst2->type, "ext4") &&
715 strcmp(inst2->type, "ext4dev"))
718 * If we've just started the fsck, wait a tiny
719 * bit before sending the kill, to give it
720 * time to set up the signal handler
722 if (inst2->start_time < time(0)+2) {
725 kill(inst2->pid, SIGUSR1);
729 kill(inst2->pid, SIGUSR1);
730 inst2->flags |= FLAG_PROGRESS;
736 prev->next = inst->next;
738 instance_list = inst->next;
740 printf(_("Finished with %s (exit status %d)\n"),
741 inst->fs->device, inst->exit_status);
746 #define FLAG_WAIT_ALL 0
747 #define FLAG_WAIT_ATLEAST_ONE 1
749 * Wait until all executing child processes have exited; return the
750 * logical OR of all of their exit code values.
752 static int wait_many(int flags)
754 struct fsck_instance *inst;
755 int global_status = 0;
758 while ((inst = wait_one(wait_flags))) {
759 global_status |= inst->exit_status;
762 if (noexecute && (flags & WNOHANG) && !(random() % 3))
765 if (flags & FLAG_WAIT_ATLEAST_ONE)
766 wait_flags = WNOHANG;
768 return global_status;
772 * Run the fsck program on a particular device
774 * If the type is specified using -t, and it isn't prefixed with "no"
775 * (as in "noext2") and only one filesystem type is specified, then
776 * use that type regardless of what is specified in /etc/fstab.
778 * If the type isn't specified by the user, then use either the type
779 * specified in /etc/fstab, or DEFAULT_FSTYPE.
781 static int fsck_device(struct fs_info *fs, int interactive)
788 if (strcmp(fs->type, "auto") != 0)
790 else if (fstype && strncmp(fstype, "no", 2) &&
791 strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) &&
792 !strchr(fstype, ','))
795 type = DEFAULT_FSTYPE;
798 retval = execute(type, fs, interactive);
800 warnx(_("error %d while executing fsck.%s for %s"),
801 retval, type, fs->device);
810 * Deal with the fsck -t argument.
812 struct fs_type_compile {
818 #define FS_TYPE_NORMAL 0
819 #define FS_TYPE_OPT 1
820 #define FS_TYPE_NEGOPT 2
822 static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
826 int negate, first_negate = 1;
829 for (cp=fs_type; *cp; cp++) {
835 cmp->list = xmalloc(num * sizeof(char *));
836 cmp->type = xmalloc(num * sizeof(int));
837 memset(cmp->list, 0, num * sizeof(char *));
838 memset(cmp->type, 0, num * sizeof(int));
844 list = string_copy(fs_type);
846 s = strtok(list, ",");
849 if (strncmp(s, "no", 2) == 0) {
852 } else if (*s == '!') {
856 if (strcmp(s, "loop") == 0)
857 /* loop is really short-hand for opts=loop */
858 goto loop_special_case;
859 else if (strncmp(s, "opts=", 5) == 0) {
862 cmp->type[num] = negate ? FS_TYPE_NEGOPT : FS_TYPE_OPT;
865 cmp->negate = negate;
868 if ((negate && !cmp->negate) ||
869 (!negate && cmp->negate)) {
871 _("Either all or none of the filesystem types passed to -t must be prefixed\n"
872 "with 'no' or '!'."));
876 printf("Adding %s to list (type %d).\n", s, cmp->type[num]);
878 cmp->list[num++] = string_copy(s);
879 s = strtok(NULL, ",");
885 * This function returns true if a particular option appears in a
886 * comma-delimited options list
888 static int opt_in_list(const char *opt, char *optlist)
894 list = string_copy(optlist);
896 s = strtok(list, ",");
898 if (strcmp(s, opt) == 0) {
902 s = strtok(NULL, ",");
908 /* See if the filesystem matches the criteria given by the -t option */
909 static int fs_match(struct fs_info *fs, struct fs_type_compile *cmp)
911 int n, ret = 0, checked_type = 0;
914 if (cmp->list == 0 || cmp->list[0] == 0)
917 for (n=0; (cp = cmp->list[n]); n++) {
918 switch (cmp->type[n]) {
921 if (strcmp(cp, fs->type) == 0) {
926 if (opt_in_list(cp, fs->opts))
930 if (!opt_in_list(cp, fs->opts))
935 if (checked_type == 0)
937 return (cmp->negate ? !ret : ret);
941 * Check if a device exists
943 static int device_exists(const char *device)
947 if (stat(device, &st) == -1)
950 if (!S_ISBLK(st.st_mode))
956 /* Check if we should ignore this filesystem. */
957 static int ignore(struct fs_info *fs)
963 * If the pass number is 0, ignore it.
969 * If this is a bind mount, ignore it.
971 if (opt_in_list("bind", fs->opts)) {
972 warnx(_("%s: skipping bad line in /etc/fstab: "
973 "bind mount with nonzero fsck pass number"),
979 * ignore devices that don't exist and have the "nofail" mount option
981 if (!device_exists(fs->device)) {
982 if (opt_in_list("nofail", fs->opts)) {
984 printf(_("%s: skipping nonexistent device\n"),
989 printf(_("%s: nonexistent device (\"nofail\" fstab "
990 "option may be used to skip this device)\n"),
997 * If a specific fstype is specified, and it doesn't match,
1000 if (!fs_match(fs, &fs_type_compiled)) return 1;
1002 /* Are we ignoring this type? */
1003 for(ip = ignored_types; *ip; ip++)
1004 if (strcmp(fs->type, *ip) == 0) return 1;
1006 /* Do we really really want to check this fs? */
1007 for(ip = really_wanted; *ip; ip++)
1008 if (strcmp(fs->type, *ip) == 0) {
1013 /* See if the <fsck.fs> program is available. */
1014 if (find_fsck(fs->type) == NULL) {
1016 warnx(_("cannot check %s: fsck.%s not found"),
1017 fs->device, fs->type);
1021 /* We can and want to check this file system type. */
1025 static int count_slaves(dev_t disk)
1029 char dirname[PATH_MAX];
1032 snprintf(dirname, sizeof(dirname),
1033 "/sys/dev/block/%u:%u/slaves/",
1034 major(disk), minor(disk));
1036 if (!(dir = opendir(dirname)))
1039 while ((dp = readdir(dir)) != 0) {
1040 #ifdef _DIRENT_HAVE_D_TYPE
1041 if (dp->d_type != DT_UNKNOWN && dp->d_type != DT_LNK)
1044 if (dp->d_name[0] == '.' &&
1045 ((dp->d_name[1] == 0) ||
1046 ((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
1056 * Returns TRUE if a partition on the same disk is already being
1059 static int disk_already_active(struct fs_info *fs)
1061 struct fsck_instance *inst;
1063 if (force_all_parallel)
1066 if (instance_list && instance_list->fs->stacked)
1067 /* any instance for a stacked device is already running */
1071 fs->disk = get_disk(fs->device);
1073 fs->stacked = count_slaves(fs->disk);
1077 * If we don't know the base device, assume that the device is
1078 * already active if there are any fsck instances running.
1080 * Don't check a stacked device with any other disk too.
1082 if (!fs->disk || fs->stacked)
1083 return (instance_list != 0);
1085 for (inst = instance_list; inst; inst = inst->next) {
1086 if (!inst->fs->disk || fs->disk == inst->fs->disk)
1092 /* Check all file systems, using the /etc/fstab table. */
1093 static int check_all(NOARGS)
1095 struct fs_info *fs = NULL;
1096 int status = EXIT_OK;
1097 int not_done_yet = 1;
1102 fputs(_("Checking all file systems.\n"), stdout);
1105 * Do an initial scan over the filesystem; mark filesystems
1106 * which should be ignored as done, and resolve any "auto"
1107 * filesystem types (done as a side-effect of calling ignore()).
1109 for (fs = filesys_info; fs; fs = fs->next) {
1111 fs->flags |= FLAG_DONE;
1115 * Find and check the root filesystem.
1117 if (!parallel_root) {
1118 for (fs = filesys_info; fs; fs = fs->next) {
1119 if (!strcmp(fs->mountpt, "/"))
1123 if (!skip_root && !ignore(fs) &&
1124 !(ignore_mounted && is_mounted(fs->device))) {
1125 status |= fsck_device(fs, 1);
1126 status |= wait_many(FLAG_WAIT_ALL);
1127 if (status > EXIT_NONDESTRUCT)
1130 fs->flags |= FLAG_DONE;
1134 * This is for the bone-headed user who enters the root
1135 * filesystem twice. Skip root will skep all root entries.
1138 for (fs = filesys_info; fs; fs = fs->next)
1139 if (!strcmp(fs->mountpt, "/"))
1140 fs->flags |= FLAG_DONE;
1142 while (not_done_yet) {
1146 for (fs = filesys_info; fs; fs = fs->next) {
1147 if (cancel_requested)
1149 if (fs->flags & FLAG_DONE)
1152 * If the filesystem's pass number is higher
1153 * than the current pass number, then we don't
1156 if (fs->passno > passno) {
1160 if (ignore_mounted && is_mounted(fs->device)) {
1161 fs->flags |= FLAG_DONE;
1165 * If a filesystem on a particular device has
1166 * already been spawned, then we need to defer
1167 * this to another pass.
1169 if (disk_already_active(fs)) {
1174 * Spawn off the fsck process
1176 status |= fsck_device(fs, serialize);
1177 fs->flags |= FLAG_DONE;
1180 * Only do one filesystem at a time, or if we
1181 * have a limit on the number of fsck's extant
1182 * at one time, apply that limit.
1185 (max_running && (num_running >= max_running))) {
1190 if (cancel_requested)
1193 printf(_("--waiting-- (pass %d)\n"), passno);
1194 status |= wait_many(pass_done ? FLAG_WAIT_ALL :
1195 FLAG_WAIT_ATLEAST_ONE);
1198 printf("----------------------------------\n");
1203 if (cancel_requested && !kill_sent) {
1207 status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
1211 static void __attribute__((__noreturn__)) usage(void)
1213 printf(_("\nUsage:\n"
1214 " %s [fsck-options] [fs-options] [filesys ...]\n"),
1215 program_invocation_short_name);
1217 puts(_( "\nOptions:\n"
1218 " -A check all filesystems\n"
1219 " -R skip root filesystem; useful only with `-A'\n"
1220 " -M do not check mounted filesystems\n"
1221 " -t <type> specify filesystem types to be checked;\n"
1222 " type is allowed to be comma-separated list\n"
1223 " -P check filesystems in parallel, including root\n"
1224 " -s serialize fsck operations\n"
1225 " -l lock the device using flock()\n"
1226 " -N do not execute, just show what would be done\n"
1227 " -T do not show the title on startup\n"
1228 " -C <fd> display progress bar; file descriptor is for GUIs\n"
1229 " -V explain what is being done\n"
1230 " -? display this help and exit\n\n"
1231 "See fsck.* commands for fs-options."));
1236 static void signal_cancel(int sig FSCK_ATTR((unused)))
1241 static void PRS(int argc, char *argv[])
1244 char *arg, *dev, *tmp = 0;
1247 int opts_for_fsck = 0;
1248 struct sigaction sa;
1251 * Set up signal action
1253 memset(&sa, 0, sizeof(struct sigaction));
1254 sa.sa_handler = signal_cancel;
1255 sigaction(SIGINT, &sa, 0);
1256 sigaction(SIGTERM, &sa, 0);
1262 for (i=1; i < argc; i++) {
1266 if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
1267 if (num_devices >= MAX_DEVICES)
1268 errx(EXIT_ERROR, _("too many devices"));
1269 dev = fsprobe_get_devname_by_spec(arg);
1270 if (!dev && strchr(arg, '=')) {
1272 * Check to see if we failed because
1273 * /proc/partitions isn't found.
1275 if (access(_PATH_PROC_PARTITIONS, R_OK) < 0) {
1276 warn(_("couldn't open %s"),
1277 _PATH_PROC_PARTITIONS);
1278 errx(EXIT_ERROR, _("Is /proc mounted?"));
1281 * Check to see if this is because
1282 * we're not running as root
1286 _("must be root to scan for matching filesystems: %s"),
1290 _("couldn't find matching filesystem: %s"),
1293 devices[num_devices++] = dev ? dev : string_copy(arg);
1296 if (arg[0] != '-' || opts_for_fsck) {
1297 if (num_args >= MAX_ARGS)
1298 errx(EXIT_ERROR, _("too many arguments"));
1299 args[num_args++] = string_copy(arg);
1302 for (j=1; arg[j]; j++) {
1303 if (opts_for_fsck) {
1304 options[++opt] = arg[j];
1314 progress_fd = string_to_int(arg+j+1);
1315 if (progress_fd < 0)
1319 } else if ((i+1) < argc &&
1320 !strncmp(argv[i+1], "-", 1) == 0) {
1321 progress_fd = string_to_int(argv[i]);
1322 if (progress_fd < 0)
1360 else if ((i+1) < argc)
1364 fstype = string_copy(tmp);
1365 compile_fs_type(fstype, &fs_type_compiled);
1374 options[++opt] = arg[j];
1381 options[++opt] = '\0';
1382 if (num_args >= MAX_ARGS)
1383 errx(EXIT_ERROR, _("too many arguments"));
1384 args[num_args++] = string_copy(options);
1388 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1389 force_all_parallel++;
1390 if ((tmp = getenv("FSCK_MAX_INST")))
1391 max_running = atoi(tmp);
1394 int main(int argc, char *argv[])
1397 int interactive = 0;
1398 char *oldpath = getenv("PATH");
1402 setvbuf(stdout, NULL, _IONBF, BUFSIZ);
1403 setvbuf(stderr, NULL, _IONBF, BUFSIZ);
1405 setlocale(LC_MESSAGES, "");
1406 setlocale(LC_CTYPE, "");
1407 bindtextdomain(PACKAGE, LOCALEDIR);
1408 textdomain(PACKAGE);
1414 printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING);
1416 fstab = getenv("FSTAB_FILE");
1418 fstab = _PATH_MNTTAB;
1419 load_fs_info(fstab);
1421 /* Update our search path to include uncommon directories. */
1423 fsck_path = xmalloc (strlen (fsck_prefix_path) + 1 +
1424 strlen (oldpath) + 1);
1425 strcpy (fsck_path, fsck_prefix_path);
1426 strcat (fsck_path, ":");
1427 strcat (fsck_path, oldpath);
1429 fsck_path = string_copy(fsck_prefix_path);
1432 if ((num_devices == 1) || (serialize))
1435 if (lockdisk && (doall || num_devices > 1)) {
1436 warnx(_("the -l option can be used with one "
1437 "device only -- ignore"));
1441 /* If -A was specified ("check all"), do that! */
1445 if (num_devices == 0) {
1450 for (i = 0 ; i < num_devices; i++) {
1451 if (cancel_requested) {
1458 fs = lookup(devices[i]);
1460 fs = create_fs_device(devices[i], 0, "auto",
1465 if (ignore_mounted && is_mounted(fs->device))
1467 status |= fsck_device(fs, interactive);
1469 (max_running && (num_running >= max_running))) {
1470 struct fsck_instance *inst;
1474 status |= inst->exit_status;
1475 free_instance(inst);
1478 printf("----------------------------------\n");
1481 status |= wait_many(FLAG_WAIT_ALL);