]> git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/fsck.c
fsck: use private lock file rather than whole-disk directly
[thirdparty/util-linux.git] / disk-utils / fsck.c
1 /*
2 * fsck --- 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
7 * parallel execution.
8 *
9 * Written by Theodore Ts'o, <tytso@mit.edu>
10 *
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.
18 *
19 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
20 * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o.
21 *
22 * Copyright (C) 2009-2014 Karel Zak <kzak@redhat.com>
23 *
24 * This file may be redistributed under the terms of the GNU Public
25 * License.
26 */
27
28 #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */
29
30 #include <sys/types.h>
31 #include <sys/wait.h>
32 #include <sys/stat.h>
33 #include <sys/file.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <stdio.h>
37 #include <ctype.h>
38 #include <string.h>
39 #include <time.h>
40 #include <stdlib.h>
41 #include <paths.h>
42 #include <unistd.h>
43 #include <errno.h>
44 #include <signal.h>
45 #include <dirent.h>
46 #include <sys/resource.h>
47 #include <sys/time.h>
48 #include <blkid.h>
49 #include <libmount.h>
50
51 #include "nls.h"
52 #include "pathnames.h"
53 #include "exitcodes.h"
54 #include "c.h"
55 #include "closestream.h"
56 #include "fileutils.h"
57
58 #define XALLOC_EXIT_CODE FSCK_EX_ERROR
59 #include "xalloc.h"
60
61 #ifndef DEFAULT_FSTYPE
62 # define DEFAULT_FSTYPE "ext2"
63 #endif
64
65 #define MAX_DEVICES 32
66 #define MAX_ARGS 32
67
68 #define FSCK_RUNTIME_DIRNAME "/run/fsck"
69
70 static const char *ignored_types[] = {
71 "ignore",
72 "iso9660",
73 "sw",
74 NULL
75 };
76
77 static const char *really_wanted[] = {
78 "minix",
79 "ext2",
80 "ext3",
81 "ext4",
82 "ext4dev",
83 "jfs",
84 "reiserfs",
85 "xiafs"
86 };
87
88 /*
89 * Internal structure for mount tabel entries.
90 */
91 struct fsck_fs_data
92 {
93 const char *device;
94 dev_t disk;
95 unsigned int stacked:1,
96 done:1,
97 eval_device:1;
98 };
99
100 /*
101 * Structure to allow exit codes to be stored
102 */
103 struct fsck_instance {
104 int pid;
105 int flags; /* FLAG_{DONE|PROGRESS} */
106
107 int lock; /* flock()ed lockpath file descriptor or -1 */
108 char *lockpath; /* /run/fsck/<diskname>.lock or NULL */
109
110 int exit_status;
111 struct timeval start_time;
112 struct timeval end_time;
113 char * prog;
114 char * type;
115
116 struct rusage rusage;
117 struct libmnt_fs *fs;
118 struct fsck_instance *next;
119 };
120
121 #define FLAG_DONE 1
122 #define FLAG_PROGRESS 2
123
124 /*
125 * Global variables for options
126 */
127 static char *devices[MAX_DEVICES];
128 static char *args[MAX_ARGS];
129 static int num_devices, num_args;
130
131 static int lockdisk;
132 static int verbose;
133 static int doall;
134 static int noexecute;
135 static int serialize;
136 static int skip_root;
137 static int ignore_mounted;
138 static int notitle;
139 static int parallel_root;
140 static int progress;
141 static int progress_fd;
142 static int force_all_parallel;
143 static int report_stats;
144
145 static int num_running;
146 static int max_running;
147
148 static volatile int cancel_requested;
149 static int kill_sent;
150 static char *fstype;
151 static struct fsck_instance *instance_list;
152
153 static const char fsck_prefix_path[] = FS_SEARCH_PATH;
154 static char *fsck_path;
155
156 /* parsed fstab and mtab */
157 static struct libmnt_table *fstab, *mtab;
158 static struct libmnt_cache *mntcache;
159
160 static int count_slaves(dev_t disk);
161
162 static int string_to_int(const char *s)
163 {
164 long l;
165 char *p;
166
167 l = strtol(s, &p, 0);
168 if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX)
169 return -1;
170 else
171 return (int) l;
172 }
173
174 /* Do we really really want to check this fs? */
175 static int fs_check_required(const char *type)
176 {
177 size_t i;
178
179 for(i = 0; i < ARRAY_SIZE(really_wanted); i++) {
180 if (strcmp(type, really_wanted[i]) == 0)
181 return 1;
182 }
183
184 return 0;
185 }
186
187 static int is_mounted(struct libmnt_fs *fs)
188 {
189 int rc;
190 const char *src;
191
192 src = mnt_fs_get_source(fs);
193 if (!src)
194 return 0;
195 if (!mntcache)
196 mntcache = mnt_new_cache();
197 if (!mtab) {
198 mtab = mnt_new_table();
199 if (!mtab)
200 err(FSCK_EX_ERROR, ("failed to initialize libmount table"));
201 mnt_table_set_cache(mtab, mntcache);
202 mnt_table_parse_mtab(mtab, NULL);
203 }
204
205 rc = mnt_table_find_source(mtab, src, MNT_ITER_BACKWARD) ? 1 : 0;
206 if (verbose) {
207 if (rc)
208 printf(_("%s is mounted\n"), src);
209 else
210 printf(_("%s is not mounted\n"), src);
211 }
212 return rc;
213 }
214
215 static int ignore(struct libmnt_fs *);
216
217 static struct fsck_fs_data *fs_create_data(struct libmnt_fs *fs)
218 {
219 struct fsck_fs_data *data = mnt_fs_get_userdata(fs);
220
221 if (!data) {
222 data = xcalloc(1, sizeof(*data));
223 mnt_fs_set_userdata(fs, data);
224 }
225 return data;
226 }
227
228 /*
229 * fs from fstab might contains real device name as well as symlink,
230 * LABEL or UUID, this function returns canonicalized result.
231 */
232 static const char *fs_get_device(struct libmnt_fs *fs)
233 {
234 struct fsck_fs_data *data = mnt_fs_get_userdata(fs);
235
236 if (!data || !data->eval_device) {
237 const char *spec = mnt_fs_get_source(fs);
238
239 if (!data)
240 data = fs_create_data(fs);
241
242 data->eval_device = 1;
243 data->device = mnt_resolve_spec(spec, mnt_table_get_cache(fstab));
244 if (!data->device)
245 data->device = xstrdup(spec);
246 }
247
248 return data->device;
249 }
250
251 static dev_t fs_get_disk(struct libmnt_fs *fs, int check)
252 {
253 struct fsck_fs_data *data;
254 const char *device;
255 struct stat st;
256
257 data = mnt_fs_get_userdata(fs);
258 if (data && data->disk)
259 return data->disk;
260
261 if (!check)
262 return 0;
263
264 if (mnt_fs_is_netfs(fs) || mnt_fs_is_pseudofs(fs))
265 return 0;
266
267 device = fs_get_device(fs);
268 if (!device)
269 return 0;
270
271 data = fs_create_data(fs);
272
273 if (!stat(device, &st) &&
274 !blkid_devno_to_wholedisk(st.st_rdev, NULL, 0, &data->disk)) {
275
276 if (data->disk)
277 data->stacked = count_slaves(data->disk) > 0 ? 1 : 0;
278 return data->disk;
279 }
280 return 0;
281 }
282
283 static int fs_is_stacked(struct libmnt_fs *fs)
284 {
285 struct fsck_fs_data *data = mnt_fs_get_userdata(fs);
286 return data ? data->stacked : 0;
287 }
288
289 static int fs_is_done(struct libmnt_fs *fs)
290 {
291 struct fsck_fs_data *data = mnt_fs_get_userdata(fs);
292 return data ? data->done : 0;
293 }
294
295 static void fs_set_done(struct libmnt_fs *fs)
296 {
297 struct fsck_fs_data *data = fs_create_data(fs);
298
299 if (data)
300 data->done = 1;
301 }
302
303 static int is_irrotational_disk(dev_t disk)
304 {
305 char path[PATH_MAX];
306 FILE *f;
307 int rc, x;
308
309
310 rc = snprintf(path, sizeof(path),
311 "/sys/dev/block/%d:%d/queue/rotational",
312 major(disk), minor(disk));
313
314 if (rc < 0 || (unsigned int) (rc + 1) > sizeof(path))
315 return 0;
316
317 f = fopen(path, "r");
318 if (!f)
319 return 0;
320
321 rc = fscanf(f, "%d", &x);
322 if (rc != 1) {
323 if (ferror(f))
324 warn(_("cannot read %s"), path);
325 else
326 warnx(_("parse error: %s"), path);
327 }
328 fclose(f);
329
330 return rc == 1 ? !x : 0;
331 }
332
333 static void lock_disk(struct fsck_instance *inst)
334 {
335 dev_t disk = fs_get_disk(inst->fs, 1);
336 char *diskpath = NULL, *diskname;
337
338 inst->lock = -1;
339
340 if (!disk || is_irrotational_disk(disk))
341 goto done;
342
343 diskpath = blkid_devno_to_devname(disk);
344 if (!diskpath)
345 goto done;
346
347 if (access(FSCK_RUNTIME_DIRNAME, F_OK) != 0) {
348 int rc = mkdir(FSCK_RUNTIME_DIRNAME,
349 S_IWUSR|
350 S_IRUSR|S_IRGRP|S_IROTH|
351 S_IXUSR|S_IXGRP|S_IXOTH);
352 if (rc && errno != EEXIST) {
353 warn(_("cannot create directory %s"),
354 FSCK_RUNTIME_DIRNAME);
355 goto done;
356 }
357 }
358
359 diskname = stripoff_last_component(diskpath);
360 if (!diskname)
361 diskname = diskpath;
362
363 xasprintf(&inst->lockpath, FSCK_RUNTIME_DIRNAME "/%s.lock", diskname);
364
365 if (verbose)
366 printf(_("Locking disk by %s ... "), inst->lockpath);
367
368 inst->lock = open(inst->lockpath, O_RDONLY|O_CREAT|O_CLOEXEC,
369 S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH);
370 if (inst->lock >= 0) {
371 int rc = -1;
372
373 /* inform users that we're waiting on the lock */
374 if (verbose &&
375 (rc = flock(inst->lock, LOCK_EX | LOCK_NB)) != 0 &&
376 errno == EWOULDBLOCK)
377 printf(_("(waiting) "));
378
379 if (rc != 0 && flock(inst->lock, LOCK_EX) != 0) {
380 close(inst->lock); /* failed */
381 inst->lock = -1;
382 }
383 }
384
385 if (verbose)
386 /* TRANSLATORS: These are followups to "Locking disk...". */
387 printf("%s.\n", inst->lock >= 0 ? _("succeeded") : _("failed"));
388
389
390 done:
391 if (inst->lock < 0) {
392 free(inst->lockpath);
393 inst->lockpath = NULL;
394 }
395 free(diskpath);
396 return;
397 }
398
399 static void unlock_disk(struct fsck_instance *inst)
400 {
401 if (inst->lock < 0)
402 return;
403
404 if (verbose)
405 printf(_("Unlocking %s.\n"), inst->lockpath);
406
407 close(inst->lock); /* unlock */
408 unlink(inst->lockpath);
409
410 free(inst->lockpath);
411
412 inst->lock = -1;
413 inst->lockpath = NULL;
414 }
415
416 static void free_instance(struct fsck_instance *i)
417 {
418 if (lockdisk)
419 unlock_disk(i);
420 free(i->prog);
421 free(i->lockpath);
422 mnt_unref_fs(i->fs);
423 free(i);
424 return;
425 }
426
427 static struct libmnt_fs *add_dummy_fs(const char *device)
428 {
429 struct libmnt_fs *fs = mnt_new_fs();
430
431 if (fs && mnt_fs_set_source(fs, device) == 0 &&
432 mnt_table_add_fs(fstab, fs) == 0) {
433 mnt_unref_fs(fs);
434 return fs;
435 }
436
437 mnt_unref_fs(fs);
438 err(FSCK_EX_ERROR, _("failed to setup description for %s"), device);
439 }
440
441 static void fs_interpret_type(struct libmnt_fs *fs)
442 {
443 const char *device;
444 const char *type = mnt_fs_get_fstype(fs);
445
446 if (type && strcmp(type, "auto") != 0)
447 return;
448
449 mnt_fs_set_fstype(fs, NULL);
450
451 device = fs_get_device(fs);
452 if (device) {
453 int ambi = 0;
454
455 type = mnt_get_fstype(device, &ambi, mnt_table_get_cache(fstab));
456 if (!ambi)
457 mnt_fs_set_fstype(fs, type);
458 }
459 }
460
461 static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
462 const char *filename, int line)
463 {
464 warnx(_("%s: parse error at line %d -- ignore"), filename, line);
465 return 0;
466 }
467
468 /*
469 * Load the filesystem database from /etc/fstab
470 */
471 static void load_fs_info(void)
472 {
473 const char *path;
474
475 fstab = mnt_new_table();
476 if (!fstab)
477 err(FSCK_EX_ERROR, ("failed to initialize libmount table"));
478
479 mnt_table_set_parser_errcb(fstab, parser_errcb);
480 mnt_table_set_cache(fstab, mntcache);
481
482 errno = 0;
483
484 /*
485 * Let's follow libmount defauls if $FSTAB_FILE is not specified
486 */
487 path = getenv("FSTAB_FILE");
488
489 if (mnt_table_parse_fstab(fstab, path)) {
490 if (!path)
491 path = mnt_get_fstab_path();
492
493 /* don't print error when there is no fstab at all */
494 if (access(path, F_OK) == 0) {
495 if (errno)
496 warn(_("%s: failed to parse fstab"), path);
497 else
498 warnx(_("%s: failed to parse fstab"), path);
499 }
500 }
501 }
502
503 /*
504 * Lookup filesys in /etc/fstab and return the corresponding entry.
505 * The @path has to be real path (no TAG) by mnt_resolve_spec().
506 */
507 static struct libmnt_fs *lookup(char *path)
508 {
509 struct libmnt_fs *fs;
510
511 if (!path)
512 return NULL;
513
514 fs = mnt_table_find_srcpath(fstab, path, MNT_ITER_FORWARD);
515 if (!fs) {
516 /*
517 * Maybe mountpoint has been specified on fsck command line.
518 * Yeah, crazy feature...
519 *
520 * Note that mnt_table_find_target() may canonicalize paths in
521 * the fstab to support symlinks. This is really unwanted,
522 * because readlink() on mountpoints may trigger automounts.
523 *
524 * So, disable the cache and compare the paths as strings
525 * without care about symlinks...
526 */
527 mnt_table_set_cache(fstab, NULL);
528 fs = mnt_table_find_target(fstab, path, MNT_ITER_FORWARD);
529 mnt_table_set_cache(fstab, mntcache);
530 }
531 return fs;
532 }
533
534 /* Find fsck program for a given fs type. */
535 static char *find_fsck(const char *type)
536 {
537 char *s;
538 const char *tpl;
539 static char prog[256];
540 char *p = xstrdup(fsck_path);
541 struct stat st;
542
543 /* Are we looking for a program or just a type? */
544 tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
545
546 for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
547 sprintf(prog, tpl, s, type);
548 if (stat(prog, &st) == 0)
549 break;
550 }
551 free(p);
552
553 return(s ? prog : NULL);
554 }
555
556 static int progress_active(void)
557 {
558 struct fsck_instance *inst;
559
560 for (inst = instance_list; inst; inst = inst->next) {
561 if (inst->flags & FLAG_DONE)
562 continue;
563 if (inst->flags & FLAG_PROGRESS)
564 return 1;
565 }
566 return 0;
567 }
568
569 /*
570 * Process run statistics for finished fsck instances.
571 *
572 * If report_stats is 0, do nothing, otherwise print a selection of
573 * interesting rusage statistics as well as elapsed wallclock time.
574 */
575 static void print_stats(struct fsck_instance *inst)
576 {
577 double time_diff;
578
579 if (!inst || !report_stats || noexecute)
580 return;
581
582 time_diff = (inst->end_time.tv_sec - inst->start_time.tv_sec)
583 + (inst->end_time.tv_usec - inst->start_time.tv_usec) / 1E6;
584
585 fprintf(stdout, "%s: status %d, rss %ld, "
586 "real %f, user %d.%06d, sys %d.%06d\n",
587 fs_get_device(inst->fs),
588 inst->exit_status,
589 inst->rusage.ru_maxrss,
590 time_diff,
591 (int)inst->rusage.ru_utime.tv_sec,
592 (int)inst->rusage.ru_utime.tv_usec,
593 (int)inst->rusage.ru_stime.tv_sec,
594 (int)inst->rusage.ru_stime.tv_usec);
595 }
596
597 /*
598 * Execute a particular fsck program, and link it into the list of
599 * child processes we are waiting for.
600 */
601 static int execute(const char *progname, const char *progpath,
602 const char *type, struct libmnt_fs *fs, int interactive)
603 {
604 char *argv[80];
605 int argc, i;
606 struct fsck_instance *inst, *p;
607 pid_t pid;
608
609 inst = xcalloc(1, sizeof(*inst));
610
611 argv[0] = xstrdup(progname);
612 argc = 1;
613
614 for (i=0; i <num_args; i++)
615 argv[argc++] = xstrdup(args[i]);
616
617 if (progress) {
618 if ((strcmp(type, "ext2") == 0) ||
619 (strcmp(type, "ext3") == 0) ||
620 (strcmp(type, "ext4") == 0) ||
621 (strcmp(type, "ext4dev") == 0)) {
622 char tmp[80];
623
624 tmp[0] = 0;
625 if (!progress_active()) {
626 snprintf(tmp, 80, "-C%d", progress_fd);
627 inst->flags |= FLAG_PROGRESS;
628 } else if (progress_fd)
629 snprintf(tmp, 80, "-C%d", progress_fd * -1);
630 if (tmp[0])
631 argv[argc++] = xstrdup(tmp);
632 }
633 }
634
635 argv[argc++] = xstrdup(fs_get_device(fs));
636 argv[argc] = 0;
637
638 if (verbose || noexecute) {
639 const char *tgt = mnt_fs_get_target(fs);
640
641 if (!tgt)
642 tgt = fs_get_device(fs);
643 printf("[%s (%d) -- %s] ", progpath, num_running, tgt);
644 for (i=0; i < argc; i++)
645 printf("%s ", argv[i]);
646 printf("\n");
647 }
648
649 mnt_ref_fs(fs);
650 inst->fs = fs;
651 inst->lock = -1;
652
653 if (lockdisk)
654 lock_disk(inst);
655
656 /* Fork and execute the correct program. */
657 if (noexecute)
658 pid = -1;
659 else if ((pid = fork()) < 0) {
660 warn(_("fork failed"));
661 free_instance(inst);
662 return errno;
663 } else if (pid == 0) {
664 if (!interactive)
665 close(0);
666 execv(progpath, argv);
667 err(FSCK_EX_ERROR, _("%s: execute failed"), progpath);
668 }
669
670 for (i=0; i < argc; i++)
671 free(argv[i]);
672
673 inst->pid = pid;
674 inst->prog = xstrdup(progname);
675 inst->type = xstrdup(type);
676 gettimeofday(&inst->start_time, NULL);
677 inst->next = NULL;
678
679 /*
680 * Find the end of the list, so we add the instance on at the end.
681 */
682 for (p = instance_list; p && p->next; p = p->next);
683
684 if (p)
685 p->next = inst;
686 else
687 instance_list = inst;
688
689 return 0;
690 }
691
692 /*
693 * Send a signal to all outstanding fsck child processes
694 */
695 static int kill_all(int signum)
696 {
697 struct fsck_instance *inst;
698 int n = 0;
699
700 for (inst = instance_list; inst; inst = inst->next) {
701 if (inst->flags & FLAG_DONE)
702 continue;
703 kill(inst->pid, signum);
704 n++;
705 }
706 return n;
707 }
708
709 /*
710 * Wait for one child process to exit; when it does, unlink it from
711 * the list of executing child processes, and return it.
712 */
713 static struct fsck_instance *wait_one(int flags)
714 {
715 int status;
716 int sig;
717 struct fsck_instance *inst, *inst2, *prev;
718 pid_t pid;
719 struct rusage rusage;
720
721 if (!instance_list)
722 return NULL;
723
724 if (noexecute) {
725 inst = instance_list;
726 prev = 0;
727 #ifdef RANDOM_DEBUG
728 while (inst->next && (random() & 1)) {
729 prev = inst;
730 inst = inst->next;
731 }
732 #endif
733 inst->exit_status = 0;
734 goto ret_inst;
735 }
736
737 /*
738 * gcc -Wall fails saving throw against stupidity
739 * (inst and prev are thought to be uninitialized variables)
740 */
741 inst = prev = NULL;
742
743 do {
744 pid = wait4(-1, &status, flags, &rusage);
745 if (cancel_requested && !kill_sent) {
746 kill_all(SIGTERM);
747 kill_sent++;
748 }
749 if ((pid == 0) && (flags & WNOHANG))
750 return NULL;
751 if (pid < 0) {
752 if ((errno == EINTR) || (errno == EAGAIN))
753 continue;
754 if (errno == ECHILD) {
755 warnx(_("wait: no more child process?!?"));
756 return NULL;
757 }
758 warn(_("waitpid failed"));
759 continue;
760 }
761 for (prev = 0, inst = instance_list;
762 inst;
763 prev = inst, inst = inst->next) {
764 if (inst->pid == pid)
765 break;
766 }
767 } while (!inst);
768
769 if (WIFEXITED(status))
770 status = WEXITSTATUS(status);
771 else if (WIFSIGNALED(status)) {
772 sig = WTERMSIG(status);
773 if (sig == SIGINT) {
774 status = FSCK_EX_UNCORRECTED;
775 } else {
776 warnx(_("Warning... %s for device %s exited "
777 "with signal %d."),
778 inst->prog, fs_get_device(inst->fs), sig);
779 status = FSCK_EX_ERROR;
780 }
781 } else {
782 warnx(_("%s %s: status is %x, should never happen."),
783 inst->prog, fs_get_device(inst->fs), status);
784 status = FSCK_EX_ERROR;
785 }
786
787 inst->exit_status = status;
788 inst->flags |= FLAG_DONE;
789 gettimeofday(&inst->end_time, NULL);
790 memcpy(&inst->rusage, &rusage, sizeof(struct rusage));
791
792 if (progress && (inst->flags & FLAG_PROGRESS) &&
793 !progress_active()) {
794 for (inst2 = instance_list; inst2; inst2 = inst2->next) {
795 if (inst2->flags & FLAG_DONE)
796 continue;
797 if (strcmp(inst2->type, "ext2") &&
798 strcmp(inst2->type, "ext3") &&
799 strcmp(inst2->type, "ext4") &&
800 strcmp(inst2->type, "ext4dev"))
801 continue;
802 /*
803 * If we've just started the fsck, wait a tiny
804 * bit before sending the kill, to give it
805 * time to set up the signal handler
806 */
807 if (inst2->start_time.tv_sec < time(0) + 2) {
808 if (fork() == 0) {
809 sleep(1);
810 kill(inst2->pid, SIGUSR1);
811 exit(FSCK_EX_OK);
812 }
813 } else
814 kill(inst2->pid, SIGUSR1);
815 inst2->flags |= FLAG_PROGRESS;
816 break;
817 }
818 }
819 ret_inst:
820 if (prev)
821 prev->next = inst->next;
822 else
823 instance_list = inst->next;
824
825 print_stats(inst);
826
827 if (verbose > 1)
828 printf(_("Finished with %s (exit status %d)\n"),
829 fs_get_device(inst->fs), inst->exit_status);
830 num_running--;
831 return inst;
832 }
833
834 #define FLAG_WAIT_ALL 0
835 #define FLAG_WAIT_ATLEAST_ONE 1
836 /*
837 * Wait until all executing child processes have exited; return the
838 * logical OR of all of their exit code values.
839 */
840 static int wait_many(int flags)
841 {
842 struct fsck_instance *inst;
843 int global_status = 0;
844 int wait_flags = 0;
845
846 while ((inst = wait_one(wait_flags))) {
847 global_status |= inst->exit_status;
848 free_instance(inst);
849 #ifdef RANDOM_DEBUG
850 if (noexecute && (flags & WNOHANG) && !(random() % 3))
851 break;
852 #endif
853 if (flags & FLAG_WAIT_ATLEAST_ONE)
854 wait_flags = WNOHANG;
855 }
856 return global_status;
857 }
858
859 /*
860 * Run the fsck program on a particular device
861 *
862 * If the type is specified using -t, and it isn't prefixed with "no"
863 * (as in "noext2") and only one filesystem type is specified, then
864 * use that type regardless of what is specified in /etc/fstab.
865 *
866 * If the type isn't specified by the user, then use either the type
867 * specified in /etc/fstab, or DEFAULT_FSTYPE.
868 */
869 static int fsck_device(struct libmnt_fs *fs, int interactive)
870 {
871 char progname[80], *progpath;
872 const char *type;
873 int retval;
874
875 fs_interpret_type(fs);
876
877 type = mnt_fs_get_fstype(fs);
878
879 if (type && strcmp(type, "auto") != 0)
880 ;
881 else if (fstype && strncmp(fstype, "no", 2) &&
882 strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) &&
883 !strchr(fstype, ','))
884 type = fstype;
885 else
886 type = DEFAULT_FSTYPE;
887
888 sprintf(progname, "fsck.%s", type);
889 progpath = find_fsck(progname);
890 if (progpath == NULL) {
891 if (fs_check_required(type)) {
892 retval = ENOENT;
893 goto err;
894 }
895 return 0;
896 }
897
898 num_running++;
899 retval = execute(progname, progpath, type, fs, interactive);
900 if (retval) {
901 num_running--;
902 goto err;
903 }
904 return 0;
905 err:
906 warnx(_("error %d (%m) while executing fsck.%s for %s"),
907 retval, type, fs_get_device(fs));
908 return FSCK_EX_ERROR;
909 }
910
911
912 /*
913 * Deal with the fsck -t argument.
914 */
915 struct fs_type_compile {
916 char **list;
917 int *type;
918 int negate;
919 } fs_type_compiled;
920
921 #define FS_TYPE_NORMAL 0
922 #define FS_TYPE_OPT 1
923 #define FS_TYPE_NEGOPT 2
924
925 static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
926 {
927 char *cp, *list, *s;
928 int num = 2;
929 int negate, first_negate = 1;
930
931 if (fs_type) {
932 for (cp=fs_type; *cp; cp++) {
933 if (*cp == ',')
934 num++;
935 }
936 }
937
938 cmp->list = xcalloc(num, sizeof(char *));
939 cmp->type = xcalloc(num, sizeof(int));
940 cmp->negate = 0;
941
942 if (!fs_type)
943 return;
944
945 list = xstrdup(fs_type);
946 num = 0;
947 s = strtok(list, ",");
948 while(s) {
949 negate = 0;
950 if (strncmp(s, "no", 2) == 0) {
951 s += 2;
952 negate = 1;
953 } else if (*s == '!') {
954 s++;
955 negate = 1;
956 }
957 if (strcmp(s, "loop") == 0)
958 /* loop is really short-hand for opts=loop */
959 goto loop_special_case;
960 else if (strncmp(s, "opts=", 5) == 0) {
961 s += 5;
962 loop_special_case:
963 cmp->type[num] = negate ? FS_TYPE_NEGOPT : FS_TYPE_OPT;
964 } else {
965 if (first_negate) {
966 cmp->negate = negate;
967 first_negate = 0;
968 }
969 if ((negate && !cmp->negate) ||
970 (!negate && cmp->negate)) {
971 errx(FSCK_EX_USAGE,
972 _("Either all or none of the filesystem types passed to -t must be prefixed\n"
973 "with 'no' or '!'."));
974 }
975 }
976
977 cmp->list[num++] = xstrdup(s);
978 s = strtok(NULL, ",");
979 }
980 free(list);
981 }
982
983 /*
984 * This function returns true if a particular option appears in a
985 * comma-delimited options list
986 */
987 static int opt_in_list(const char *opt, const char *optlist)
988 {
989 char *list, *s;
990
991 if (!optlist)
992 return 0;
993 list = xstrdup(optlist);
994
995 s = strtok(list, ",");
996 while(s) {
997 if (strcmp(s, opt) == 0) {
998 free(list);
999 return 1;
1000 }
1001 s = strtok(NULL, ",");
1002 }
1003 free(list);
1004 return 0;
1005 }
1006
1007 /* See if the filesystem matches the criteria given by the -t option */
1008 static int fs_match(struct libmnt_fs *fs, struct fs_type_compile *cmp)
1009 {
1010 int n, ret = 0, checked_type = 0;
1011 char *cp;
1012
1013 if (cmp->list == 0 || cmp->list[0] == 0)
1014 return 1;
1015
1016 for (n=0; (cp = cmp->list[n]); n++) {
1017 switch (cmp->type[n]) {
1018 case FS_TYPE_NORMAL:
1019 {
1020 const char *type = mnt_fs_get_fstype(fs);
1021
1022 checked_type++;
1023 if (type && strcmp(cp, type) == 0)
1024 ret = 1;
1025 break;
1026 }
1027 case FS_TYPE_NEGOPT:
1028 if (opt_in_list(cp, mnt_fs_get_options(fs)))
1029 return 0;
1030 break;
1031 case FS_TYPE_OPT:
1032 if (!opt_in_list(cp, mnt_fs_get_options(fs)))
1033 return 0;
1034 break;
1035 }
1036 }
1037 if (checked_type == 0)
1038 return 1;
1039 return (cmp->negate ? !ret : ret);
1040 }
1041
1042 /*
1043 * Check if a device exists
1044 */
1045 static int device_exists(const char *device)
1046 {
1047 struct stat st;
1048
1049 if (stat(device, &st) == -1)
1050 return 0;
1051 if (!S_ISBLK(st.st_mode))
1052 return 0;
1053 return 1;
1054 }
1055
1056 static int fs_ignored_type(struct libmnt_fs *fs)
1057 {
1058 const char **ip, *type;
1059
1060 if (mnt_fs_is_netfs(fs) || mnt_fs_is_pseudofs(fs) || mnt_fs_is_swaparea(fs))
1061 return 1;
1062
1063 type = mnt_fs_get_fstype(fs);
1064
1065 for(ip = ignored_types; type && *ip; ip++) {
1066 if (strcmp(type, *ip) == 0)
1067 return 1;
1068 }
1069
1070 return 0;
1071 }
1072
1073 /* Check if we should ignore this filesystem. */
1074 static int ignore(struct libmnt_fs *fs)
1075 {
1076 const char *type;
1077
1078 /*
1079 * If the pass number is 0, ignore it.
1080 */
1081 if (mnt_fs_get_passno(fs) == 0)
1082 return 1;
1083
1084 /*
1085 * If this is a bind mount, ignore it.
1086 */
1087 if (opt_in_list("bind", mnt_fs_get_options(fs))) {
1088 warnx(_("%s: skipping bad line in /etc/fstab: "
1089 "bind mount with nonzero fsck pass number"),
1090 mnt_fs_get_target(fs));
1091 return 1;
1092 }
1093
1094 /*
1095 * ignore devices that don't exist and have the "nofail" mount option
1096 */
1097 if (!device_exists(fs_get_device(fs))) {
1098 if (opt_in_list("nofail", mnt_fs_get_options(fs))) {
1099 if (verbose)
1100 printf(_("%s: skipping nonexistent device\n"),
1101 fs_get_device(fs));
1102 return 1;
1103 }
1104 if (verbose)
1105 printf(_("%s: nonexistent device (\"nofail\" fstab "
1106 "option may be used to skip this device)\n"),
1107 fs_get_device(fs));
1108 }
1109
1110 fs_interpret_type(fs);
1111
1112 /*
1113 * If a specific fstype is specified, and it doesn't match,
1114 * ignore it.
1115 */
1116 if (!fs_match(fs, &fs_type_compiled))
1117 return 1;
1118
1119 type = mnt_fs_get_fstype(fs);
1120 if (!type) {
1121 if (verbose)
1122 printf(_("%s: skipping unknown filesystem type\n"),
1123 fs_get_device(fs));
1124 return 1;
1125 }
1126
1127 /* Are we ignoring this type? */
1128 if (fs_ignored_type(fs))
1129 return 1;
1130
1131
1132
1133 /* See if the <fsck.fs> program is available. */
1134 if (find_fsck(type) == NULL) {
1135 if (fs_check_required(type))
1136 warnx(_("cannot check %s: fsck.%s not found"),
1137 fs_get_device(fs), type);
1138 return 1;
1139 }
1140
1141 /* We can and want to check this file system type. */
1142 return 0;
1143 }
1144
1145 static int count_slaves(dev_t disk)
1146 {
1147 DIR *dir;
1148 struct dirent *dp;
1149 char dirname[PATH_MAX];
1150 int count = 0;
1151
1152 snprintf(dirname, sizeof(dirname),
1153 "/sys/dev/block/%u:%u/slaves/",
1154 major(disk), minor(disk));
1155
1156 if (!(dir = opendir(dirname)))
1157 return -1;
1158
1159 while ((dp = readdir(dir)) != 0) {
1160 #ifdef _DIRENT_HAVE_D_TYPE
1161 if (dp->d_type != DT_UNKNOWN && dp->d_type != DT_LNK)
1162 continue;
1163 #endif
1164 if (dp->d_name[0] == '.' &&
1165 ((dp->d_name[1] == 0) ||
1166 ((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
1167 continue;
1168
1169 count++;
1170 }
1171
1172 closedir(dir);
1173 return count;
1174 }
1175
1176 /*
1177 * Returns TRUE if a partition on the same disk is already being
1178 * checked.
1179 */
1180 static int disk_already_active(struct libmnt_fs *fs)
1181 {
1182 struct fsck_instance *inst;
1183 dev_t disk;
1184
1185 if (force_all_parallel)
1186 return 0;
1187
1188 if (instance_list && fs_is_stacked(instance_list->fs))
1189 /* any instance for a stacked device is already running */
1190 return 1;
1191
1192 disk = fs_get_disk(fs, 1);
1193
1194 /*
1195 * If we don't know the base device, assume that the device is
1196 * already active if there are any fsck instances running.
1197 *
1198 * Don't check a stacked device with any other disk too.
1199 */
1200 if (!disk || fs_is_stacked(fs))
1201 return (instance_list != 0);
1202
1203 for (inst = instance_list; inst; inst = inst->next) {
1204 dev_t idisk = fs_get_disk(inst->fs, 0);
1205
1206 if (!idisk || disk == idisk)
1207 return 1;
1208 }
1209
1210 return 0;
1211 }
1212
1213 /* Check all file systems, using the /etc/fstab table. */
1214 static int check_all(void)
1215 {
1216 int not_done_yet = 1;
1217 int passno = 1;
1218 int pass_done;
1219 int status = FSCK_EX_OK;
1220
1221 struct libmnt_fs *fs;
1222 struct libmnt_iter *itr = mnt_new_iter(MNT_ITER_FORWARD);
1223
1224 if (!itr)
1225 err(FSCK_EX_ERROR, _("failed to allocate iterator"));
1226
1227 /*
1228 * Do an initial scan over the filesystem; mark filesystems
1229 * which should be ignored as done, and resolve any "auto"
1230 * filesystem types (done as a side-effect of calling ignore()).
1231 */
1232 while (mnt_table_next_fs(fstab, itr, &fs) == 0) {
1233 if (ignore(fs)) {
1234 fs_set_done(fs);
1235 continue;
1236 }
1237 }
1238
1239 if (verbose)
1240 fputs(_("Checking all file systems.\n"), stdout);
1241
1242 /*
1243 * Find and check the root filesystem.
1244 */
1245 if (!parallel_root) {
1246 fs = mnt_table_find_target(fstab, "/", MNT_ITER_FORWARD);
1247 if (fs) {
1248 if (!skip_root &&
1249 !fs_is_done(fs) &&
1250 !(ignore_mounted && is_mounted(fs))) {
1251 status |= fsck_device(fs, 1);
1252 status |= wait_many(FLAG_WAIT_ALL);
1253 if (status > FSCK_EX_NONDESTRUCT) {
1254 mnt_free_iter(itr);
1255 return status;
1256 }
1257 }
1258 fs_set_done(fs);
1259 }
1260 }
1261
1262 /*
1263 * This is for the bone-headed user who enters the root
1264 * filesystem twice. Skip root will skep all root entries.
1265 */
1266 if (skip_root) {
1267 mnt_reset_iter(itr, MNT_ITER_FORWARD);
1268
1269 while(mnt_table_next_fs(fstab, itr, &fs) == 0) {
1270 const char *tgt = mnt_fs_get_target(fs);
1271
1272 if (tgt && strcmp(tgt, "/") == 0)
1273 fs_set_done(fs);
1274 }
1275 }
1276
1277 while (not_done_yet) {
1278 not_done_yet = 0;
1279 pass_done = 1;
1280
1281 mnt_reset_iter(itr, MNT_ITER_FORWARD);
1282
1283 while(mnt_table_next_fs(fstab, itr, &fs) == 0) {
1284
1285 if (cancel_requested)
1286 break;
1287 if (fs_is_done(fs))
1288 continue;
1289 /*
1290 * If the filesystem's pass number is higher
1291 * than the current pass number, then we don't
1292 * do it yet.
1293 */
1294 if (mnt_fs_get_passno(fs) > passno) {
1295 not_done_yet++;
1296 continue;
1297 }
1298 if (ignore_mounted && is_mounted(fs)) {
1299 fs_set_done(fs);
1300 continue;
1301 }
1302 /*
1303 * If a filesystem on a particular device has
1304 * already been spawned, then we need to defer
1305 * this to another pass.
1306 */
1307 if (disk_already_active(fs)) {
1308 pass_done = 0;
1309 continue;
1310 }
1311 /*
1312 * Spawn off the fsck process
1313 */
1314 status |= fsck_device(fs, serialize);
1315 fs_set_done(fs);
1316
1317 /*
1318 * Only do one filesystem at a time, or if we
1319 * have a limit on the number of fsck's extant
1320 * at one time, apply that limit.
1321 */
1322 if (serialize ||
1323 (max_running && (num_running >= max_running))) {
1324 pass_done = 0;
1325 break;
1326 }
1327 }
1328 if (cancel_requested)
1329 break;
1330 if (verbose > 1)
1331 printf(_("--waiting-- (pass %d)\n"), passno);
1332
1333 status |= wait_many(pass_done ? FLAG_WAIT_ALL :
1334 FLAG_WAIT_ATLEAST_ONE);
1335 if (pass_done) {
1336 if (verbose > 1)
1337 printf("----------------------------------\n");
1338 passno++;
1339 } else
1340 not_done_yet++;
1341 }
1342
1343 if (cancel_requested && !kill_sent) {
1344 kill_all(SIGTERM);
1345 kill_sent++;
1346 }
1347
1348 status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
1349 mnt_free_iter(itr);
1350 return status;
1351 }
1352
1353 static void __attribute__((__noreturn__)) usage(FILE *out)
1354 {
1355 fputs(USAGE_HEADER, out);
1356 fprintf(out, _(" %s [options] -- [fs-options] [<filesystem> ...]\n"),
1357 program_invocation_short_name);
1358
1359 fputs(USAGE_OPTIONS, out);
1360 fputs(_(" -A check all filesystems\n"), out);
1361 fputs(_(" -C [<fd>] display progress bar; file descriptor is for GUIs\n"), out);
1362 fputs(_(" -l lock the device to guarantee exclusive access\n"), out);
1363 fputs(_(" -M do not check mounted filesystems\n"), out);
1364 fputs(_(" -N do not execute, just show what would be done\n"), out);
1365 fputs(_(" -P check filesystems in parallel, including root\n"), out);
1366 fputs(_(" -R skip root filesystem; useful only with '-A'\n"), out);
1367 fputs(_(" -r report statistics for each device checked\n"), out);
1368 fputs(_(" -s serialize the checking operations\n"), out);
1369 fputs(_(" -T do not show the title on startup\n"), out);
1370 fputs(_(" -t <type> specify filesystem types to be checked;\n"
1371 " <type> is allowed to be a comma-separated list\n"), out);
1372 fputs(_(" -V explain what is being done\n"), out);
1373 fputs(_(" -? display this help and exit\n"), out);
1374
1375 fputs(USAGE_SEPARATOR, out);
1376 fputs(_("See the specific fsck.* commands for available fs-options."), out);
1377 fprintf(out, USAGE_MAN_TAIL("fsck(8)"));
1378
1379 exit(out == stderr ? FSCK_EX_USAGE : FSCK_EX_OK);
1380 }
1381
1382 static void signal_cancel(int sig __attribute__((__unused__)))
1383 {
1384 cancel_requested++;
1385 }
1386
1387 static void parse_argv(int argc, char *argv[])
1388 {
1389 int i, j;
1390 char *arg, *dev, *tmp = 0;
1391 char options[128];
1392 int opt = 0;
1393 int opts_for_fsck = 0;
1394 struct sigaction sa;
1395
1396 /*
1397 * Set up signal action
1398 */
1399 memset(&sa, 0, sizeof(struct sigaction));
1400 sa.sa_handler = signal_cancel;
1401 sigaction(SIGINT, &sa, 0);
1402 sigaction(SIGTERM, &sa, 0);
1403
1404 num_devices = 0;
1405 num_args = 0;
1406 instance_list = 0;
1407
1408 for (i=1; i < argc; i++) {
1409 arg = argv[i];
1410 if (!arg)
1411 continue;
1412 if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
1413 if (num_devices >= MAX_DEVICES)
1414 errx(FSCK_EX_ERROR, _("too many devices"));
1415
1416 dev = mnt_resolve_spec(arg, mntcache);
1417
1418 if (!dev && strchr(arg, '=')) {
1419 /*
1420 * Check to see if we failed because
1421 * /proc/partitions isn't found.
1422 */
1423 if (access(_PATH_PROC_PARTITIONS, R_OK) < 0) {
1424 warn(_("cannot open %s"),
1425 _PATH_PROC_PARTITIONS);
1426 errx(FSCK_EX_ERROR, _("Is /proc mounted?"));
1427 }
1428 /*
1429 * Check to see if this is because
1430 * we're not running as root
1431 */
1432 if (geteuid())
1433 errx(FSCK_EX_ERROR,
1434 _("must be root to scan for matching filesystems: %s"),
1435 arg);
1436 else
1437 errx(FSCK_EX_ERROR,
1438 _("couldn't find matching filesystem: %s"),
1439 arg);
1440 }
1441 devices[num_devices++] = dev ? dev : xstrdup(arg);
1442 continue;
1443 }
1444 if (arg[0] != '-' || opts_for_fsck) {
1445 if (num_args >= MAX_ARGS)
1446 errx(FSCK_EX_ERROR, _("too many arguments"));
1447 args[num_args++] = xstrdup(arg);
1448 continue;
1449 }
1450 for (j=1; arg[j]; j++) {
1451 if (opts_for_fsck) {
1452 options[++opt] = arg[j];
1453 continue;
1454 }
1455 switch (arg[j]) {
1456 case 'A':
1457 doall = 1;
1458 break;
1459 case 'C':
1460 progress = 1;
1461 if (arg[j+1]) {
1462 progress_fd = string_to_int(arg+j+1);
1463 if (progress_fd < 0)
1464 progress_fd = 0;
1465 else
1466 goto next_arg;
1467 } else if ((i+1) < argc &&
1468 !strncmp(argv[i+1], "-", 1) == 0) {
1469 progress_fd = string_to_int(argv[i]);
1470 if (progress_fd < 0)
1471 progress_fd = 0;
1472 else {
1473 ++i;
1474 goto next_arg;
1475 }
1476 }
1477 break;
1478 case 'l':
1479 lockdisk = 1;
1480 break;
1481 case 'V':
1482 verbose++;
1483 break;
1484 case 'N':
1485 noexecute = 1;
1486 break;
1487 case 'R':
1488 skip_root = 1;
1489 break;
1490 case 'T':
1491 notitle = 1;
1492 break;
1493 case 'M':
1494 ignore_mounted = 1;
1495 break;
1496 case 'P':
1497 parallel_root = 1;
1498 break;
1499 case 'r':
1500 report_stats = 1;
1501 break;
1502 case 's':
1503 serialize = 1;
1504 break;
1505 case 't':
1506 tmp = 0;
1507 if (fstype)
1508 usage(stderr);
1509 if (arg[j+1])
1510 tmp = arg+j+1;
1511 else if ((i+1) < argc)
1512 tmp = argv[++i];
1513 else
1514 usage(stderr);
1515 fstype = xstrdup(tmp);
1516 compile_fs_type(fstype, &fs_type_compiled);
1517 goto next_arg;
1518 case '-':
1519 opts_for_fsck++;
1520 break;
1521 case '?':
1522 usage(stdout);
1523 break;
1524 default:
1525 options[++opt] = arg[j];
1526 break;
1527 }
1528 }
1529 next_arg:
1530 if (opt) {
1531 options[0] = '-';
1532 options[++opt] = '\0';
1533 if (num_args >= MAX_ARGS)
1534 errx(FSCK_EX_ERROR, _("too many arguments"));
1535 args[num_args++] = xstrdup(options);
1536 opt = 0;
1537 }
1538 }
1539 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1540 force_all_parallel++;
1541 if ((tmp = getenv("FSCK_MAX_INST")))
1542 max_running = atoi(tmp);
1543 }
1544
1545 int main(int argc, char *argv[])
1546 {
1547 int i, status = 0;
1548 int interactive = 0;
1549 char *oldpath = getenv("PATH");
1550 struct libmnt_fs *fs;
1551
1552 setvbuf(stdout, NULL, _IONBF, BUFSIZ);
1553 setvbuf(stderr, NULL, _IONBF, BUFSIZ);
1554
1555 setlocale(LC_MESSAGES, "");
1556 setlocale(LC_CTYPE, "");
1557 bindtextdomain(PACKAGE, LOCALEDIR);
1558 textdomain(PACKAGE);
1559 atexit(close_stdout);
1560
1561 mnt_init_debug(0); /* init libmount debug mask */
1562 mntcache = mnt_new_cache(); /* no fatal error if failed */
1563
1564 parse_argv(argc, argv);
1565
1566 if (!notitle)
1567 printf(UTIL_LINUX_VERSION);
1568
1569 load_fs_info();
1570
1571 /* Update our search path to include uncommon directories. */
1572 if (oldpath) {
1573 fsck_path = xmalloc (strlen (fsck_prefix_path) + 1 +
1574 strlen (oldpath) + 1);
1575 strcpy (fsck_path, fsck_prefix_path);
1576 strcat (fsck_path, ":");
1577 strcat (fsck_path, oldpath);
1578 } else {
1579 fsck_path = xstrdup(fsck_prefix_path);
1580 }
1581
1582 if ((num_devices == 1) || (serialize))
1583 interactive = 1;
1584
1585 if (lockdisk && (doall || num_devices > 1)) {
1586 warnx(_("the -l option can be used with one "
1587 "device only -- ignore"));
1588 lockdisk = 0;
1589 }
1590
1591 /* If -A was specified ("check all"), do that! */
1592 if (doall)
1593 return check_all();
1594
1595 if (num_devices == 0) {
1596 serialize++;
1597 interactive++;
1598 return check_all();
1599 }
1600 for (i = 0 ; i < num_devices; i++) {
1601 if (cancel_requested) {
1602 if (!kill_sent) {
1603 kill_all(SIGTERM);
1604 kill_sent++;
1605 }
1606 break;
1607 }
1608 fs = lookup(devices[i]);
1609 if (!fs)
1610 fs = add_dummy_fs(devices[i]);
1611 else if (fs_ignored_type(fs))
1612 continue;
1613 if (ignore_mounted && is_mounted(fs))
1614 continue;
1615 status |= fsck_device(fs, interactive);
1616 if (serialize ||
1617 (max_running && (num_running >= max_running))) {
1618 struct fsck_instance *inst;
1619
1620 inst = wait_one(0);
1621 if (inst) {
1622 status |= inst->exit_status;
1623 free_instance(inst);
1624 }
1625 if (verbose > 1)
1626 printf("----------------------------------\n");
1627 }
1628 }
1629 status |= wait_many(FLAG_WAIT_ALL);
1630 free(fsck_path);
1631 mnt_unref_cache(mntcache);
1632 mnt_unref_table(fstab);
1633 mnt_unref_table(mtab);
1634 return status;
1635 }