]> git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/fsck.c
817be97da4829c49b530b868519d20d31fbefe0e
[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 #include "monotonic.h"
58
59 #define XALLOC_EXIT_CODE FSCK_EX_ERROR
60 #include "xalloc.h"
61
62 #ifndef DEFAULT_FSTYPE
63 # define DEFAULT_FSTYPE "ext2"
64 #endif
65
66 #define MAX_DEVICES 32
67 #define MAX_ARGS 32
68
69 #define FSCK_RUNTIME_DIRNAME "/run/fsck"
70
71 static const char *ignored_types[] = {
72 "ignore",
73 "iso9660",
74 "sw",
75 NULL
76 };
77
78 static const char *really_wanted[] = {
79 "minix",
80 "ext2",
81 "ext3",
82 "ext4",
83 "ext4dev",
84 "jfs",
85 "reiserfs"
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 char *tp;
455 struct libmnt_cache *cache = mnt_table_get_cache(fstab);
456
457 tp = mnt_get_fstype(device, &ambi, cache);
458 if (!ambi)
459 mnt_fs_set_fstype(fs, tp);
460 if (!cache)
461 free(tp);
462 }
463 }
464
465 static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
466 const char *filename, int line)
467 {
468 warnx(_("%s: parse error at line %d -- ignore"), filename, line);
469 return 0;
470 }
471
472 /*
473 * Load the filesystem database from /etc/fstab
474 */
475 static void load_fs_info(void)
476 {
477 const char *path;
478
479 fstab = mnt_new_table();
480 if (!fstab)
481 err(FSCK_EX_ERROR, ("failed to initialize libmount table"));
482
483 mnt_table_set_parser_errcb(fstab, parser_errcb);
484 mnt_table_set_cache(fstab, mntcache);
485
486 errno = 0;
487
488 /*
489 * Let's follow libmount defauls if $FSTAB_FILE is not specified
490 */
491 path = getenv("FSTAB_FILE");
492
493 if (mnt_table_parse_fstab(fstab, path)) {
494 if (!path)
495 path = mnt_get_fstab_path();
496
497 /* don't print error when there is no fstab at all */
498 if (access(path, F_OK) == 0) {
499 if (errno)
500 warn(_("%s: failed to parse fstab"), path);
501 else
502 warnx(_("%s: failed to parse fstab"), path);
503 }
504 }
505 }
506
507 /*
508 * Lookup filesys in /etc/fstab and return the corresponding entry.
509 * The @path has to be real path (no TAG) by mnt_resolve_spec().
510 */
511 static struct libmnt_fs *lookup(char *path)
512 {
513 struct libmnt_fs *fs;
514
515 if (!path)
516 return NULL;
517
518 fs = mnt_table_find_srcpath(fstab, path, MNT_ITER_FORWARD);
519 if (!fs) {
520 /*
521 * Maybe mountpoint has been specified on fsck command line.
522 * Yeah, crazy feature...
523 *
524 * Note that mnt_table_find_target() may canonicalize paths in
525 * the fstab to support symlinks. This is really unwanted,
526 * because readlink() on mountpoints may trigger automounts.
527 *
528 * So, disable the cache and compare the paths as strings
529 * without care about symlinks...
530 */
531 mnt_table_set_cache(fstab, NULL);
532 fs = mnt_table_find_target(fstab, path, MNT_ITER_FORWARD);
533 mnt_table_set_cache(fstab, mntcache);
534 }
535 return fs;
536 }
537
538 /* Find fsck program for a given fs type. */
539 static char *find_fsck(const char *type)
540 {
541 char *s;
542 const char *tpl;
543 static char prog[256];
544 char *p = xstrdup(fsck_path);
545 struct stat st;
546
547 /* Are we looking for a program or just a type? */
548 tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
549
550 for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
551 sprintf(prog, tpl, s, type);
552 if (stat(prog, &st) == 0)
553 break;
554 }
555 free(p);
556
557 return(s ? prog : NULL);
558 }
559
560 static int progress_active(void)
561 {
562 struct fsck_instance *inst;
563
564 for (inst = instance_list; inst; inst = inst->next) {
565 if (inst->flags & FLAG_DONE)
566 continue;
567 if (inst->flags & FLAG_PROGRESS)
568 return 1;
569 }
570 return 0;
571 }
572
573 /*
574 * Process run statistics for finished fsck instances.
575 *
576 * If report_stats is 0, do nothing, otherwise print a selection of
577 * interesting rusage statistics as well as elapsed wallclock time.
578 */
579 static void print_stats(struct fsck_instance *inst)
580 {
581 struct timeval delta;
582
583 if (!inst || !report_stats || noexecute)
584 return;
585
586 timersub(&inst->end_time, &inst->start_time, &delta);
587
588 fprintf(stdout, "%s: status %d, rss %ld, "
589 "real %ld.%06ld, user %d.%06d, sys %d.%06d\n",
590 fs_get_device(inst->fs),
591 inst->exit_status,
592 inst->rusage.ru_maxrss,
593 delta.tv_sec, delta.tv_usec,
594 (int)inst->rusage.ru_utime.tv_sec,
595 (int)inst->rusage.ru_utime.tv_usec,
596 (int)inst->rusage.ru_stime.tv_sec,
597 (int)inst->rusage.ru_stime.tv_usec);
598 }
599
600 /*
601 * Execute a particular fsck program, and link it into the list of
602 * child processes we are waiting for.
603 */
604 static int execute(const char *progname, const char *progpath,
605 const char *type, struct libmnt_fs *fs, int interactive)
606 {
607 char *argv[80];
608 int argc, i;
609 struct fsck_instance *inst, *p;
610 pid_t pid;
611
612 inst = xcalloc(1, sizeof(*inst));
613
614 argv[0] = xstrdup(progname);
615 argc = 1;
616
617 for (i=0; i <num_args; i++)
618 argv[argc++] = xstrdup(args[i]);
619
620 if (progress) {
621 if ((strcmp(type, "ext2") == 0) ||
622 (strcmp(type, "ext3") == 0) ||
623 (strcmp(type, "ext4") == 0) ||
624 (strcmp(type, "ext4dev") == 0)) {
625 char tmp[80];
626
627 tmp[0] = 0;
628 if (!progress_active()) {
629 snprintf(tmp, 80, "-C%d", progress_fd);
630 inst->flags |= FLAG_PROGRESS;
631 } else if (progress_fd)
632 snprintf(tmp, 80, "-C%d", progress_fd * -1);
633 if (tmp[0])
634 argv[argc++] = xstrdup(tmp);
635 }
636 }
637
638 argv[argc++] = xstrdup(fs_get_device(fs));
639 argv[argc] = 0;
640
641 if (verbose || noexecute) {
642 const char *tgt = mnt_fs_get_target(fs);
643
644 if (!tgt)
645 tgt = fs_get_device(fs);
646 printf("[%s (%d) -- %s] ", progpath, num_running, tgt);
647 for (i=0; i < argc; i++)
648 printf("%s ", argv[i]);
649 printf("\n");
650 }
651
652 mnt_ref_fs(fs);
653 inst->fs = fs;
654 inst->lock = -1;
655
656 if (lockdisk)
657 lock_disk(inst);
658
659 /* Fork and execute the correct program. */
660 if (noexecute)
661 pid = -1;
662 else if ((pid = fork()) < 0) {
663 warn(_("fork failed"));
664 free_instance(inst);
665 return errno;
666 } else if (pid == 0) {
667 if (!interactive)
668 close(0);
669 execv(progpath, argv);
670 err(FSCK_EX_ERROR, _("%s: execute failed"), progpath);
671 }
672
673 for (i=0; i < argc; i++)
674 free(argv[i]);
675
676 inst->pid = pid;
677 inst->prog = xstrdup(progname);
678 inst->type = xstrdup(type);
679 gettime_monotonic(&inst->start_time);
680 inst->next = NULL;
681
682 /*
683 * Find the end of the list, so we add the instance on at the end.
684 */
685 for (p = instance_list; p && p->next; p = p->next);
686
687 if (p)
688 p->next = inst;
689 else
690 instance_list = inst;
691
692 return 0;
693 }
694
695 /*
696 * Send a signal to all outstanding fsck child processes
697 */
698 static int kill_all(int signum)
699 {
700 struct fsck_instance *inst;
701 int n = 0;
702
703 for (inst = instance_list; inst; inst = inst->next) {
704 if (inst->flags & FLAG_DONE)
705 continue;
706 kill(inst->pid, signum);
707 n++;
708 }
709 return n;
710 }
711
712 /*
713 * Wait for one child process to exit; when it does, unlink it from
714 * the list of executing child processes, and return it.
715 */
716 static struct fsck_instance *wait_one(int flags)
717 {
718 int status = 0;
719 int sig;
720 struct fsck_instance *inst, *inst2, *prev;
721 pid_t pid;
722 struct rusage rusage;
723
724 if (!instance_list)
725 return NULL;
726
727 if (noexecute) {
728 inst = instance_list;
729 prev = 0;
730 #ifdef RANDOM_DEBUG
731 while (inst->next && (random() & 1)) {
732 prev = inst;
733 inst = inst->next;
734 }
735 #endif
736 inst->exit_status = 0;
737 goto ret_inst;
738 }
739
740 /*
741 * gcc -Wall fails saving throw against stupidity
742 * (inst and prev are thought to be uninitialized variables)
743 */
744 inst = prev = NULL;
745
746 do {
747 pid = wait4(-1, &status, flags, &rusage);
748 if (cancel_requested && !kill_sent) {
749 kill_all(SIGTERM);
750 kill_sent++;
751 }
752 if ((pid == 0) && (flags & WNOHANG))
753 return NULL;
754 if (pid < 0) {
755 if ((errno == EINTR) || (errno == EAGAIN))
756 continue;
757 if (errno == ECHILD) {
758 warnx(_("wait: no more child process?!?"));
759 return NULL;
760 }
761 warn(_("waitpid failed"));
762 continue;
763 }
764 for (prev = 0, inst = instance_list;
765 inst;
766 prev = inst, inst = inst->next) {
767 if (inst->pid == pid)
768 break;
769 }
770 } while (!inst);
771
772 if (WIFEXITED(status))
773 status = WEXITSTATUS(status);
774 else if (WIFSIGNALED(status)) {
775 sig = WTERMSIG(status);
776 if (sig == SIGINT) {
777 status = FSCK_EX_UNCORRECTED;
778 } else {
779 warnx(_("Warning... %s for device %s exited "
780 "with signal %d."),
781 inst->prog, fs_get_device(inst->fs), sig);
782 status = FSCK_EX_ERROR;
783 }
784 } else {
785 warnx(_("%s %s: status is %x, should never happen."),
786 inst->prog, fs_get_device(inst->fs), status);
787 status = FSCK_EX_ERROR;
788 }
789
790 inst->exit_status = status;
791 inst->flags |= FLAG_DONE;
792 gettime_monotonic(&inst->end_time);
793 memcpy(&inst->rusage, &rusage, sizeof(struct rusage));
794
795 if (progress && (inst->flags & FLAG_PROGRESS) &&
796 !progress_active()) {
797 for (inst2 = instance_list; inst2; inst2 = inst2->next) {
798 if (inst2->flags & FLAG_DONE)
799 continue;
800 if (strcmp(inst2->type, "ext2") &&
801 strcmp(inst2->type, "ext3") &&
802 strcmp(inst2->type, "ext4") &&
803 strcmp(inst2->type, "ext4dev"))
804 continue;
805 /*
806 * If we've just started the fsck, wait a tiny
807 * bit before sending the kill, to give it
808 * time to set up the signal handler
809 */
810 if (inst2->start_time.tv_sec < time(0) + 2) {
811 if (fork() == 0) {
812 sleep(1);
813 kill(inst2->pid, SIGUSR1);
814 exit(FSCK_EX_OK);
815 }
816 } else
817 kill(inst2->pid, SIGUSR1);
818 inst2->flags |= FLAG_PROGRESS;
819 break;
820 }
821 }
822 ret_inst:
823 if (prev)
824 prev->next = inst->next;
825 else
826 instance_list = inst->next;
827
828 print_stats(inst);
829
830 if (verbose > 1)
831 printf(_("Finished with %s (exit status %d)\n"),
832 fs_get_device(inst->fs), inst->exit_status);
833 num_running--;
834 return inst;
835 }
836
837 #define FLAG_WAIT_ALL 0
838 #define FLAG_WAIT_ATLEAST_ONE 1
839 /*
840 * Wait until all executing child processes have exited; return the
841 * logical OR of all of their exit code values.
842 */
843 static int wait_many(int flags)
844 {
845 struct fsck_instance *inst;
846 int global_status = 0;
847 int wait_flags = 0;
848
849 while ((inst = wait_one(wait_flags))) {
850 global_status |= inst->exit_status;
851 free_instance(inst);
852 #ifdef RANDOM_DEBUG
853 if (noexecute && (flags & WNOHANG) && !(random() % 3))
854 break;
855 #endif
856 if (flags & FLAG_WAIT_ATLEAST_ONE)
857 wait_flags = WNOHANG;
858 }
859 return global_status;
860 }
861
862 /*
863 * Run the fsck program on a particular device
864 *
865 * If the type is specified using -t, and it isn't prefixed with "no"
866 * (as in "noext2") and only one filesystem type is specified, then
867 * use that type regardless of what is specified in /etc/fstab.
868 *
869 * If the type isn't specified by the user, then use either the type
870 * specified in /etc/fstab, or DEFAULT_FSTYPE.
871 */
872 static int fsck_device(struct libmnt_fs *fs, int interactive)
873 {
874 char progname[80], *progpath;
875 const char *type;
876 int retval;
877
878 fs_interpret_type(fs);
879
880 type = mnt_fs_get_fstype(fs);
881
882 if (type && strcmp(type, "auto") != 0)
883 ;
884 else if (fstype && strncmp(fstype, "no", 2) &&
885 strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) &&
886 !strchr(fstype, ','))
887 type = fstype;
888 else
889 type = DEFAULT_FSTYPE;
890
891 sprintf(progname, "fsck.%s", type);
892 progpath = find_fsck(progname);
893 if (progpath == NULL) {
894 if (fs_check_required(type)) {
895 retval = ENOENT;
896 goto err;
897 }
898 return 0;
899 }
900
901 num_running++;
902 retval = execute(progname, progpath, type, fs, interactive);
903 if (retval) {
904 num_running--;
905 goto err;
906 }
907 return 0;
908 err:
909 warnx(_("error %d (%m) while executing fsck.%s for %s"),
910 retval, type, fs_get_device(fs));
911 return FSCK_EX_ERROR;
912 }
913
914
915 /*
916 * Deal with the fsck -t argument.
917 */
918 struct fs_type_compile {
919 char **list;
920 int *type;
921 int negate;
922 } fs_type_compiled;
923
924 #define FS_TYPE_NORMAL 0
925 #define FS_TYPE_OPT 1
926 #define FS_TYPE_NEGOPT 2
927
928 static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
929 {
930 char *cp, *list, *s;
931 int num = 2;
932 int negate, first_negate = 1;
933
934 if (fs_type) {
935 for (cp=fs_type; *cp; cp++) {
936 if (*cp == ',')
937 num++;
938 }
939 }
940
941 cmp->list = xcalloc(num, sizeof(char *));
942 cmp->type = xcalloc(num, sizeof(int));
943 cmp->negate = 0;
944
945 if (!fs_type)
946 return;
947
948 list = xstrdup(fs_type);
949 num = 0;
950 s = strtok(list, ",");
951 while(s) {
952 negate = 0;
953 if (strncmp(s, "no", 2) == 0) {
954 s += 2;
955 negate = 1;
956 } else if (*s == '!') {
957 s++;
958 negate = 1;
959 }
960 if (strcmp(s, "loop") == 0)
961 /* loop is really short-hand for opts=loop */
962 goto loop_special_case;
963 else if (strncmp(s, "opts=", 5) == 0) {
964 s += 5;
965 loop_special_case:
966 cmp->type[num] = negate ? FS_TYPE_NEGOPT : FS_TYPE_OPT;
967 } else {
968 if (first_negate) {
969 cmp->negate = negate;
970 first_negate = 0;
971 }
972 if ((negate && !cmp->negate) ||
973 (!negate && cmp->negate)) {
974 errx(FSCK_EX_USAGE,
975 _("Either all or none of the filesystem types passed to -t must be prefixed\n"
976 "with 'no' or '!'."));
977 }
978 }
979
980 cmp->list[num++] = xstrdup(s);
981 s = strtok(NULL, ",");
982 }
983 free(list);
984 }
985
986 /*
987 * This function returns true if a particular option appears in a
988 * comma-delimited options list
989 */
990 static int opt_in_list(const char *opt, const char *optlist)
991 {
992 char *list, *s;
993
994 if (!optlist)
995 return 0;
996 list = xstrdup(optlist);
997
998 s = strtok(list, ",");
999 while(s) {
1000 if (strcmp(s, opt) == 0) {
1001 free(list);
1002 return 1;
1003 }
1004 s = strtok(NULL, ",");
1005 }
1006 free(list);
1007 return 0;
1008 }
1009
1010 /* See if the filesystem matches the criteria given by the -t option */
1011 static int fs_match(struct libmnt_fs *fs, struct fs_type_compile *cmp)
1012 {
1013 int n, ret = 0, checked_type = 0;
1014 char *cp;
1015
1016 if (cmp->list == 0 || cmp->list[0] == 0)
1017 return 1;
1018
1019 for (n=0; (cp = cmp->list[n]); n++) {
1020 switch (cmp->type[n]) {
1021 case FS_TYPE_NORMAL:
1022 {
1023 const char *type = mnt_fs_get_fstype(fs);
1024
1025 checked_type++;
1026 if (type && strcmp(cp, type) == 0)
1027 ret = 1;
1028 break;
1029 }
1030 case FS_TYPE_NEGOPT:
1031 if (opt_in_list(cp, mnt_fs_get_options(fs)))
1032 return 0;
1033 break;
1034 case FS_TYPE_OPT:
1035 if (!opt_in_list(cp, mnt_fs_get_options(fs)))
1036 return 0;
1037 break;
1038 }
1039 }
1040 if (checked_type == 0)
1041 return 1;
1042 return (cmp->negate ? !ret : ret);
1043 }
1044
1045 /*
1046 * Check if a device exists
1047 */
1048 static int device_exists(const char *device)
1049 {
1050 struct stat st;
1051
1052 if (stat(device, &st) == -1)
1053 return 0;
1054 if (!S_ISBLK(st.st_mode))
1055 return 0;
1056 return 1;
1057 }
1058
1059 static int fs_ignored_type(struct libmnt_fs *fs)
1060 {
1061 const char **ip, *type;
1062
1063 if (mnt_fs_is_netfs(fs) || mnt_fs_is_pseudofs(fs) || mnt_fs_is_swaparea(fs))
1064 return 1;
1065
1066 type = mnt_fs_get_fstype(fs);
1067
1068 for(ip = ignored_types; type && *ip; ip++) {
1069 if (strcmp(type, *ip) == 0)
1070 return 1;
1071 }
1072
1073 return 0;
1074 }
1075
1076 /* Check if we should ignore this filesystem. */
1077 static int ignore(struct libmnt_fs *fs)
1078 {
1079 const char *type;
1080
1081 /*
1082 * If the pass number is 0, ignore it.
1083 */
1084 if (mnt_fs_get_passno(fs) == 0)
1085 return 1;
1086
1087 /*
1088 * If this is a bind mount, ignore it.
1089 */
1090 if (opt_in_list("bind", mnt_fs_get_options(fs))) {
1091 warnx(_("%s: skipping bad line in /etc/fstab: "
1092 "bind mount with nonzero fsck pass number"),
1093 mnt_fs_get_target(fs));
1094 return 1;
1095 }
1096
1097 /*
1098 * ignore devices that don't exist and have the "nofail" mount option
1099 */
1100 if (!device_exists(fs_get_device(fs))) {
1101 if (opt_in_list("nofail", mnt_fs_get_options(fs))) {
1102 if (verbose)
1103 printf(_("%s: skipping nonexistent device\n"),
1104 fs_get_device(fs));
1105 return 1;
1106 }
1107 if (verbose)
1108 printf(_("%s: nonexistent device (\"nofail\" fstab "
1109 "option may be used to skip this device)\n"),
1110 fs_get_device(fs));
1111 }
1112
1113 fs_interpret_type(fs);
1114
1115 /*
1116 * If a specific fstype is specified, and it doesn't match,
1117 * ignore it.
1118 */
1119 if (!fs_match(fs, &fs_type_compiled))
1120 return 1;
1121
1122 type = mnt_fs_get_fstype(fs);
1123 if (!type) {
1124 if (verbose)
1125 printf(_("%s: skipping unknown filesystem type\n"),
1126 fs_get_device(fs));
1127 return 1;
1128 }
1129
1130 /* Are we ignoring this type? */
1131 if (fs_ignored_type(fs))
1132 return 1;
1133
1134
1135
1136 /* See if the <fsck.fs> program is available. */
1137 if (find_fsck(type) == NULL) {
1138 if (fs_check_required(type))
1139 warnx(_("cannot check %s: fsck.%s not found"),
1140 fs_get_device(fs), type);
1141 return 1;
1142 }
1143
1144 /* We can and want to check this file system type. */
1145 return 0;
1146 }
1147
1148 static int count_slaves(dev_t disk)
1149 {
1150 DIR *dir;
1151 struct dirent *dp;
1152 char dirname[PATH_MAX];
1153 int count = 0;
1154
1155 snprintf(dirname, sizeof(dirname),
1156 "/sys/dev/block/%u:%u/slaves/",
1157 major(disk), minor(disk));
1158
1159 if (!(dir = opendir(dirname)))
1160 return -1;
1161
1162 while ((dp = readdir(dir)) != 0) {
1163 #ifdef _DIRENT_HAVE_D_TYPE
1164 if (dp->d_type != DT_UNKNOWN && dp->d_type != DT_LNK)
1165 continue;
1166 #endif
1167 if (dp->d_name[0] == '.' &&
1168 ((dp->d_name[1] == 0) ||
1169 ((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
1170 continue;
1171
1172 count++;
1173 }
1174
1175 closedir(dir);
1176 return count;
1177 }
1178
1179 /*
1180 * Returns TRUE if a partition on the same disk is already being
1181 * checked.
1182 */
1183 static int disk_already_active(struct libmnt_fs *fs)
1184 {
1185 struct fsck_instance *inst;
1186 dev_t disk;
1187
1188 if (force_all_parallel)
1189 return 0;
1190
1191 if (instance_list && fs_is_stacked(instance_list->fs))
1192 /* any instance for a stacked device is already running */
1193 return 1;
1194
1195 disk = fs_get_disk(fs, 1);
1196
1197 /*
1198 * If we don't know the base device, assume that the device is
1199 * already active if there are any fsck instances running.
1200 *
1201 * Don't check a stacked device with any other disk too.
1202 */
1203 if (!disk || fs_is_stacked(fs))
1204 return (instance_list != 0);
1205
1206 for (inst = instance_list; inst; inst = inst->next) {
1207 dev_t idisk = fs_get_disk(inst->fs, 0);
1208
1209 if (!idisk || disk == idisk)
1210 return 1;
1211 }
1212
1213 return 0;
1214 }
1215
1216 /* Check all file systems, using the /etc/fstab table. */
1217 static int check_all(void)
1218 {
1219 int not_done_yet = 1;
1220 int passno = 1;
1221 int pass_done;
1222 int status = FSCK_EX_OK;
1223
1224 struct libmnt_fs *fs;
1225 struct libmnt_iter *itr = mnt_new_iter(MNT_ITER_FORWARD);
1226
1227 if (!itr)
1228 err(FSCK_EX_ERROR, _("failed to allocate iterator"));
1229
1230 /*
1231 * Do an initial scan over the filesystem; mark filesystems
1232 * which should be ignored as done, and resolve any "auto"
1233 * filesystem types (done as a side-effect of calling ignore()).
1234 */
1235 while (mnt_table_next_fs(fstab, itr, &fs) == 0) {
1236 if (ignore(fs)) {
1237 fs_set_done(fs);
1238 continue;
1239 }
1240 }
1241
1242 if (verbose)
1243 fputs(_("Checking all file systems.\n"), stdout);
1244
1245 /*
1246 * Find and check the root filesystem.
1247 */
1248 if (!parallel_root) {
1249 fs = mnt_table_find_target(fstab, "/", MNT_ITER_FORWARD);
1250 if (fs) {
1251 if (!skip_root &&
1252 !fs_is_done(fs) &&
1253 !(ignore_mounted && is_mounted(fs))) {
1254 status |= fsck_device(fs, 1);
1255 status |= wait_many(FLAG_WAIT_ALL);
1256 if (status > FSCK_EX_NONDESTRUCT) {
1257 mnt_free_iter(itr);
1258 return status;
1259 }
1260 }
1261 fs_set_done(fs);
1262 }
1263 }
1264
1265 /*
1266 * This is for the bone-headed user who enters the root
1267 * filesystem twice. Skip root will skep all root entries.
1268 */
1269 if (skip_root) {
1270 mnt_reset_iter(itr, MNT_ITER_FORWARD);
1271
1272 while(mnt_table_next_fs(fstab, itr, &fs) == 0) {
1273 const char *tgt = mnt_fs_get_target(fs);
1274
1275 if (tgt && strcmp(tgt, "/") == 0)
1276 fs_set_done(fs);
1277 }
1278 }
1279
1280 while (not_done_yet) {
1281 not_done_yet = 0;
1282 pass_done = 1;
1283
1284 mnt_reset_iter(itr, MNT_ITER_FORWARD);
1285
1286 while(mnt_table_next_fs(fstab, itr, &fs) == 0) {
1287
1288 if (cancel_requested)
1289 break;
1290 if (fs_is_done(fs))
1291 continue;
1292 /*
1293 * If the filesystem's pass number is higher
1294 * than the current pass number, then we don't
1295 * do it yet.
1296 */
1297 if (mnt_fs_get_passno(fs) > passno) {
1298 not_done_yet++;
1299 continue;
1300 }
1301 if (ignore_mounted && is_mounted(fs)) {
1302 fs_set_done(fs);
1303 continue;
1304 }
1305 /*
1306 * If a filesystem on a particular device has
1307 * already been spawned, then we need to defer
1308 * this to another pass.
1309 */
1310 if (disk_already_active(fs)) {
1311 pass_done = 0;
1312 continue;
1313 }
1314 /*
1315 * Spawn off the fsck process
1316 */
1317 status |= fsck_device(fs, serialize);
1318 fs_set_done(fs);
1319
1320 /*
1321 * Only do one filesystem at a time, or if we
1322 * have a limit on the number of fsck's extant
1323 * at one time, apply that limit.
1324 */
1325 if (serialize ||
1326 (max_running && (num_running >= max_running))) {
1327 pass_done = 0;
1328 break;
1329 }
1330 }
1331 if (cancel_requested)
1332 break;
1333 if (verbose > 1)
1334 printf(_("--waiting-- (pass %d)\n"), passno);
1335
1336 status |= wait_many(pass_done ? FLAG_WAIT_ALL :
1337 FLAG_WAIT_ATLEAST_ONE);
1338 if (pass_done) {
1339 if (verbose > 1)
1340 printf("----------------------------------\n");
1341 passno++;
1342 } else
1343 not_done_yet++;
1344 }
1345
1346 if (cancel_requested && !kill_sent) {
1347 kill_all(SIGTERM);
1348 kill_sent++;
1349 }
1350
1351 status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
1352 mnt_free_iter(itr);
1353 return status;
1354 }
1355
1356 static void __attribute__((__noreturn__)) usage(FILE *out)
1357 {
1358 fputs(USAGE_HEADER, out);
1359 fprintf(out, _(" %s [options] -- [fs-options] [<filesystem> ...]\n"),
1360 program_invocation_short_name);
1361
1362 fputs(USAGE_SEPARATOR, out);
1363 fputs(_("Check and repair a Linux filesystem.\n"), out);
1364
1365 fputs(USAGE_OPTIONS, out);
1366 fputs(_(" -A check all filesystems\n"), out);
1367 fputs(_(" -C [<fd>] display progress bar; file descriptor is for GUIs\n"), out);
1368 fputs(_(" -l lock the device to guarantee exclusive access\n"), out);
1369 fputs(_(" -M do not check mounted filesystems\n"), out);
1370 fputs(_(" -N do not execute, just show what would be done\n"), out);
1371 fputs(_(" -P check filesystems in parallel, including root\n"), out);
1372 fputs(_(" -R skip root filesystem; useful only with '-A'\n"), out);
1373 fputs(_(" -r report statistics for each device checked\n"), out);
1374 fputs(_(" -s serialize the checking operations\n"), out);
1375 fputs(_(" -T do not show the title on startup\n"), out);
1376 fputs(_(" -t <type> specify filesystem types to be checked;\n"
1377 " <type> is allowed to be a comma-separated list\n"), out);
1378 fputs(_(" -V explain what is being done\n"), out);
1379 fputs(_(" -? display this help and exit\n"), out);
1380
1381 fputs(USAGE_SEPARATOR, out);
1382 fputs(_("See the specific fsck.* commands for available fs-options."), out);
1383 fprintf(out, USAGE_MAN_TAIL("fsck(8)"));
1384
1385 exit(out == stderr ? FSCK_EX_USAGE : FSCK_EX_OK);
1386 }
1387
1388 static void signal_cancel(int sig __attribute__((__unused__)))
1389 {
1390 cancel_requested++;
1391 }
1392
1393 static void parse_argv(int argc, char *argv[])
1394 {
1395 int i, j;
1396 char *arg, *dev, *tmp = 0;
1397 char options[128];
1398 int opt = 0;
1399 int opts_for_fsck = 0;
1400 struct sigaction sa;
1401
1402 /*
1403 * Set up signal action
1404 */
1405 memset(&sa, 0, sizeof(struct sigaction));
1406 sa.sa_handler = signal_cancel;
1407 sigaction(SIGINT, &sa, 0);
1408 sigaction(SIGTERM, &sa, 0);
1409
1410 num_devices = 0;
1411 num_args = 0;
1412 instance_list = 0;
1413
1414 for (i=1; i < argc; i++) {
1415 arg = argv[i];
1416 if (!arg)
1417 continue;
1418 if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
1419 if (num_devices >= MAX_DEVICES)
1420 errx(FSCK_EX_ERROR, _("too many devices"));
1421
1422 dev = mnt_resolve_spec(arg, mntcache);
1423
1424 if (!dev && strchr(arg, '=')) {
1425 /*
1426 * Check to see if we failed because
1427 * /proc/partitions isn't found.
1428 */
1429 if (access(_PATH_PROC_PARTITIONS, R_OK) < 0) {
1430 warn(_("cannot open %s"),
1431 _PATH_PROC_PARTITIONS);
1432 errx(FSCK_EX_ERROR, _("Is /proc mounted?"));
1433 }
1434 /*
1435 * Check to see if this is because
1436 * we're not running as root
1437 */
1438 if (geteuid())
1439 errx(FSCK_EX_ERROR,
1440 _("must be root to scan for matching filesystems: %s"),
1441 arg);
1442 else
1443 errx(FSCK_EX_ERROR,
1444 _("couldn't find matching filesystem: %s"),
1445 arg);
1446 }
1447 devices[num_devices++] = dev ? dev : xstrdup(arg);
1448 continue;
1449 }
1450 if (arg[0] != '-' || opts_for_fsck) {
1451 if (num_args >= MAX_ARGS)
1452 errx(FSCK_EX_ERROR, _("too many arguments"));
1453 args[num_args++] = xstrdup(arg);
1454 continue;
1455 }
1456 for (j=1; arg[j]; j++) {
1457 if (opts_for_fsck) {
1458 options[++opt] = arg[j];
1459 continue;
1460 }
1461 switch (arg[j]) {
1462 case 'A':
1463 doall = 1;
1464 break;
1465 case 'C':
1466 progress = 1;
1467 if (arg[j+1]) { /* -C<fd> */
1468 progress_fd = string_to_int(arg+j+1);
1469 if (progress_fd < 0)
1470 progress_fd = 0;
1471 else
1472 goto next_arg;
1473 } else if (i+1 < argc && *argv[i+1] != '-') { /* -C <fd> */
1474 progress_fd = string_to_int(argv[i+1]);
1475 if (progress_fd < 0)
1476 progress_fd = 0;
1477 else {
1478 ++i;
1479 goto next_arg;
1480 }
1481 }
1482 break;
1483 case 'l':
1484 lockdisk = 1;
1485 break;
1486 case 'V':
1487 verbose++;
1488 break;
1489 case 'N':
1490 noexecute = 1;
1491 break;
1492 case 'R':
1493 skip_root = 1;
1494 break;
1495 case 'T':
1496 notitle = 1;
1497 break;
1498 case 'M':
1499 ignore_mounted = 1;
1500 break;
1501 case 'P':
1502 parallel_root = 1;
1503 break;
1504 case 'r':
1505 report_stats = 1;
1506 break;
1507 case 's':
1508 serialize = 1;
1509 break;
1510 case 't':
1511 tmp = 0;
1512 if (fstype)
1513 usage(stderr);
1514 if (arg[j+1])
1515 tmp = arg+j+1;
1516 else if ((i+1) < argc)
1517 tmp = argv[++i];
1518 else
1519 usage(stderr);
1520 fstype = xstrdup(tmp);
1521 compile_fs_type(fstype, &fs_type_compiled);
1522 goto next_arg;
1523 case '-':
1524 opts_for_fsck++;
1525 break;
1526 case '?':
1527 usage(stdout);
1528 break;
1529 default:
1530 options[++opt] = arg[j];
1531 break;
1532 }
1533 }
1534 next_arg:
1535 if (opt) {
1536 options[0] = '-';
1537 options[++opt] = '\0';
1538 if (num_args >= MAX_ARGS)
1539 errx(FSCK_EX_ERROR, _("too many arguments"));
1540 args[num_args++] = xstrdup(options);
1541 opt = 0;
1542 }
1543 }
1544 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1545 force_all_parallel++;
1546 if ((tmp = getenv("FSCK_MAX_INST")))
1547 max_running = atoi(tmp);
1548 }
1549
1550 int main(int argc, char *argv[])
1551 {
1552 int i, status = 0;
1553 int interactive = 0;
1554 char *oldpath = getenv("PATH");
1555 struct libmnt_fs *fs;
1556
1557 setvbuf(stdout, NULL, _IONBF, BUFSIZ);
1558 setvbuf(stderr, NULL, _IONBF, BUFSIZ);
1559
1560 setlocale(LC_MESSAGES, "");
1561 setlocale(LC_CTYPE, "");
1562 bindtextdomain(PACKAGE, LOCALEDIR);
1563 textdomain(PACKAGE);
1564 atexit(close_stdout);
1565
1566 mnt_init_debug(0); /* init libmount debug mask */
1567 mntcache = mnt_new_cache(); /* no fatal error if failed */
1568
1569 parse_argv(argc, argv);
1570
1571 if (!notitle)
1572 printf(UTIL_LINUX_VERSION);
1573
1574 load_fs_info();
1575
1576 /* Update our search path to include uncommon directories. */
1577 if (oldpath) {
1578 fsck_path = xmalloc (strlen (fsck_prefix_path) + 1 +
1579 strlen (oldpath) + 1);
1580 strcpy (fsck_path, fsck_prefix_path);
1581 strcat (fsck_path, ":");
1582 strcat (fsck_path, oldpath);
1583 } else {
1584 fsck_path = xstrdup(fsck_prefix_path);
1585 }
1586
1587 if ((num_devices == 1) || (serialize))
1588 interactive = 1;
1589
1590 if (lockdisk && (doall || num_devices > 1)) {
1591 warnx(_("the -l option can be used with one "
1592 "device only -- ignore"));
1593 lockdisk = 0;
1594 }
1595
1596 /* If -A was specified ("check all"), do that! */
1597 if (doall)
1598 return check_all();
1599
1600 if (num_devices == 0) {
1601 serialize++;
1602 interactive++;
1603 return check_all();
1604 }
1605 for (i = 0 ; i < num_devices; i++) {
1606 if (cancel_requested) {
1607 if (!kill_sent) {
1608 kill_all(SIGTERM);
1609 kill_sent++;
1610 }
1611 break;
1612 }
1613 fs = lookup(devices[i]);
1614 if (!fs)
1615 fs = add_dummy_fs(devices[i]);
1616 else if (fs_ignored_type(fs))
1617 continue;
1618 if (ignore_mounted && is_mounted(fs))
1619 continue;
1620 status |= fsck_device(fs, interactive);
1621 if (serialize ||
1622 (max_running && (num_running >= max_running))) {
1623 struct fsck_instance *inst;
1624
1625 inst = wait_one(0);
1626 if (inst) {
1627 status |= inst->exit_status;
1628 free_instance(inst);
1629 }
1630 if (verbose > 1)
1631 printf("----------------------------------\n");
1632 }
1633 }
1634 status |= wait_many(FLAG_WAIT_ALL);
1635 free(fsck_path);
1636 mnt_unref_cache(mntcache);
1637 mnt_unref_table(fstab);
1638 mnt_unref_table(mtab);
1639 return status;
1640 }