]>
git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - misc/fsck.c
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.
23 * This file may be redistributed under the terms of the GNU Public
28 #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */
31 #include <sys/types.h>
61 #include "../version.h"
62 #include "support/nls-enable.h"
64 #include "blkid/blkid.h"
67 #define _PATH_MNTTAB "/etc/fstab"
70 static const char *ignored_types
[] = {
82 static const char *really_wanted
[] = {
95 #define BASE_MD "/dev/md"
98 * Global variables for options
100 static char *devices
[MAX_DEVICES
];
101 static char *args
[MAX_ARGS
];
102 static int num_devices
, num_args
;
104 static int verbose
= 0;
105 static int doall
= 0;
106 static int noexecute
= 0;
107 static int serialize
= 0;
108 static int skip_root
= 0;
109 static int ignore_mounted
= 0;
110 static int notitle
= 0;
111 static int parallel_root
= 0;
112 static int progress
= 0;
113 static int progress_fd
= 0;
114 static int force_all_parallel
= 0;
115 static int num_running
= 0;
116 static int max_running
= 0;
117 static volatile int cancel_requested
= 0;
118 static int kill_sent
= 0;
119 static char *progname
;
120 static char *fstype
= NULL
;
121 static struct fs_info
*filesys_info
= NULL
, *filesys_last
= NULL
;
122 static struct fsck_instance
*instance_list
;
123 static const char *fsck_prefix_path
= "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
124 static char *fsck_path
= 0;
125 static blkid_cache cache
= NULL
;
127 static char *string_copy(const char *s
)
133 ret
= malloc(strlen(s
)+1);
139 static int string_to_int(const char *s
)
144 l
= strtol(s
, &p
, 0);
145 if (*p
|| l
== LONG_MIN
|| l
== LONG_MAX
|| l
< 0 || l
> INT_MAX
)
151 static int ignore(struct fs_info
*);
153 static char *skip_over_blank(char *cp
)
155 while (*cp
&& isspace(*cp
))
160 static char *skip_over_word(char *cp
)
162 while (*cp
&& !isspace(*cp
))
167 static void strip_line(char *line
)
172 p
= line
+ strlen(line
) - 1;
173 if ((*p
== '\n') || (*p
== '\r'))
180 static char *parse_word(char **buf
)
188 word
= skip_over_blank(word
);
189 next
= skip_over_word(word
);
196 static void parse_escape(char *word
)
204 for (p
= word
, q
= word
; *p
; p
++, q
++) {
223 for (i
= 0; i
< 3; i
++, p
++) {
226 ac
= (ac
* 8) + (*p
- '0');
234 static void free_instance(struct fsck_instance
*i
)
238 free(i
->base_device
);
243 static struct fs_info
*create_fs_device(const char *device
, const char *mntpnt
,
244 const char *type
, const char *opts
,
245 int freq
, int passno
)
249 if (!(fs
= malloc(sizeof(struct fs_info
))))
252 fs
->device
= string_copy(device
);
253 fs
->mountpt
= string_copy(mntpnt
);
254 fs
->type
= string_copy(type
);
255 fs
->opts
= string_copy(opts
? opts
: "");
264 filesys_last
->next
= fs
;
272 static int parse_fstab_line(char *line
, struct fs_info
**ret_fs
)
274 char *dev
, *device
, *mntpnt
, *type
, *opts
, *freq
, *passno
, *cp
;
281 device
= parse_word(&cp
);
282 if (!device
|| *device
== '#')
283 return 0; /* Ignore blank lines and comments */
284 mntpnt
= parse_word(&cp
);
285 type
= parse_word(&cp
);
286 opts
= parse_word(&cp
);
287 freq
= parse_word(&cp
);
288 passno
= parse_word(&cp
);
290 if (!mntpnt
|| !type
)
293 parse_escape(device
);
294 parse_escape(mntpnt
);
298 parse_escape(passno
);
300 dev
= blkid_get_devname(cache
, device
, NULL
);
304 if (strchr(type
, ','))
307 fs
= create_fs_device(device
, mntpnt
, type
? type
: "auto", opts
,
308 freq
? atoi(freq
) : -1,
309 passno
? atoi(passno
) : -1);
318 static void interpret_type(struct fs_info
*fs
)
322 if (strcmp(fs
->type
, "auto") != 0)
324 t
= blkid_get_tag_value(cache
, "TYPE", fs
->device
);
332 * Load the filesystem database from /etc/fstab
334 static void load_fs_info(const char *filename
)
342 if ((f
= fopen(filename
, "r")) == NULL
) {
343 fprintf(stderr
, _("WARNING: couldn't open %s: %s\n"),
344 filename
, strerror(errno
));
349 if (!fgets(buf
, sizeof(buf
), f
))
351 buf
[sizeof(buf
)-1] = 0;
352 if (parse_fstab_line(buf
, &fs
) < 0) {
353 fprintf(stderr
, _("WARNING: bad format "
354 "on line %d of %s\n"), lineno
, filename
);
367 if (old_fstab
&& filesys_info
) {
368 fputs("\007\007\007", stderr
);
370 "WARNING: Your /etc/fstab does not contain the fsck passno\n"
371 " field. I will kludge around things for you, but you\n"
372 " should fix your /etc/fstab file as soon as you can.\n\n"), stderr
);
374 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
380 /* Lookup filesys in /etc/fstab and return the corresponding entry. */
381 static struct fs_info
*lookup(char *filesys
)
385 /* No filesys name given. */
389 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
390 if (!strcmp(filesys
, fs
->device
) ||
391 (fs
->mountpt
&& !strcmp(filesys
, fs
->mountpt
)))
398 /* Find fsck program for a given fs type. */
399 static char *find_fsck(char *type
)
403 static char prog
[256];
404 char *p
= string_copy(fsck_path
);
407 /* Are we looking for a program or just a type? */
408 tpl
= (strncmp(type
, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
410 for(s
= strtok(p
, ":"); s
; s
= strtok(NULL
, ":")) {
411 if (snprintf(prog
, sizeof(prog
), tpl
, s
, type
) >= sizeof(prog
))
413 if (stat(prog
, &st
) == 0) break;
416 return(s
? prog
: NULL
);
419 static int progress_active(NOARGS
)
421 struct fsck_instance
*inst
;
423 for (inst
= instance_list
; inst
; inst
= inst
->next
) {
424 if (inst
->flags
& FLAG_DONE
)
426 if (inst
->flags
& FLAG_PROGRESS
)
433 * Execute a particular fsck program, and link it into the list of
434 * child processes we are waiting for.
436 static int execute(const char *type
, const char *device
, const char *mntpt
,
439 char *s
, *argv
[80], prog
[256];
441 struct fsck_instance
*inst
, *p
;
444 inst
= malloc(sizeof(struct fsck_instance
));
447 memset(inst
, 0, sizeof(struct fsck_instance
));
449 if (snprintf(prog
, sizeof(prog
), "fsck.%s", type
) >= sizeof(prog
))
451 argv
[0] = string_copy(prog
);
454 for (i
=0; i
<num_args
; i
++)
455 argv
[argc
++] = string_copy(args
[i
]);
458 if ((strcmp(type
, "ext2") == 0) ||
459 (strcmp(type
, "ext3") == 0) ||
460 (strcmp(type
, "ext4") == 0) ||
461 (strcmp(type
, "ext4dev") == 0)) {
465 if (!progress_active()) {
466 snprintf(tmp
, 80, "-C%d", progress_fd
);
467 inst
->flags
|= FLAG_PROGRESS
;
468 } else if (progress_fd
)
469 snprintf(tmp
, 80, "-C%d", progress_fd
* -1);
471 argv
[argc
++] = string_copy(tmp
);
475 argv
[argc
++] = string_copy(device
);
480 fprintf(stderr
, _("fsck: %s: not found\n"), prog
);
485 if (verbose
|| noexecute
) {
486 printf("[%s (%d) -- %s] ", s
, num_running
,
487 mntpt
? mntpt
: device
);
488 for (i
=0; i
< argc
; i
++)
489 printf("%s ", argv
[i
]);
493 /* Fork and execute the correct program. */
496 else if ((pid
= fork()) < 0) {
500 } else if (pid
== 0) {
503 (void) execv(s
, argv
);
509 for (i
=0; i
< argc
; i
++)
513 inst
->prog
= string_copy(prog
);
514 inst
->type
= string_copy(type
);
515 inst
->device
= string_copy(device
);
516 inst
->base_device
= base_device(device
);
517 inst
->start_time
= time(0);
521 * Find the end of the list, so we add the instance on at the end.
523 for (p
= instance_list
; p
&& p
->next
; p
= p
->next
);
528 instance_list
= inst
;
534 * Send a signal to all outstanding fsck child processes
536 static int kill_all(int signum
)
538 struct fsck_instance
*inst
;
541 for (inst
= instance_list
; inst
; inst
= inst
->next
) {
542 if (inst
->flags
& FLAG_DONE
)
544 kill(inst
->pid
, signum
);
551 * Wait for one child process to exit; when it does, unlink it from
552 * the list of executing child processes, and return it.
554 static struct fsck_instance
*wait_one(int flags
)
558 struct fsck_instance
*inst
, *inst2
, *prev
;
565 inst
= instance_list
;
568 while (inst
->next
&& (random() & 1)) {
573 inst
->exit_status
= 0;
578 * gcc -Wall fails saving throw against stupidity
579 * (inst and prev are thought to be uninitialized variables)
584 pid
= waitpid(-1, &status
, flags
);
585 if (cancel_requested
&& !kill_sent
) {
589 if ((pid
== 0) && (flags
& WNOHANG
))
592 if ((errno
== EINTR
) || (errno
== EAGAIN
))
594 if (errno
== ECHILD
) {
596 _("%s: wait: No more child process?!?\n"),
603 for (prev
= 0, inst
= instance_list
;
605 prev
= inst
, inst
= inst
->next
) {
606 if (inst
->pid
== pid
)
611 if (WIFEXITED(status
))
612 status
= WEXITSTATUS(status
);
613 else if (WIFSIGNALED(status
)) {
614 sig
= WTERMSIG(status
);
616 status
= EXIT_UNCORRECTED
;
618 printf(_("Warning... %s for device %s exited "
619 "with signal %d.\n"),
620 inst
->prog
, inst
->device
, sig
);
624 printf(_("%s %s: status is %x, should never happen.\n"),
625 inst
->prog
, inst
->device
, status
);
628 inst
->exit_status
= status
;
629 inst
->flags
|= FLAG_DONE
;
630 if (progress
&& (inst
->flags
& FLAG_PROGRESS
) &&
631 !progress_active()) {
632 for (inst2
= instance_list
; inst2
; inst2
= inst2
->next
) {
633 if (inst2
->flags
& FLAG_DONE
)
635 if (strcmp(inst2
->type
, "ext2") &&
636 strcmp(inst2
->type
, "ext3") &&
637 strcmp(inst2
->type
, "ext4") &&
638 strcmp(inst2
->type
, "ext4dev"))
641 * If we've just started the fsck, wait a tiny
642 * bit before sending the kill, to give it
643 * time to set up the signal handler
645 if (inst2
->start_time
< time(0)+2) {
648 kill(inst2
->pid
, SIGUSR1
);
652 kill(inst2
->pid
, SIGUSR1
);
653 inst2
->flags
|= FLAG_PROGRESS
;
659 prev
->next
= inst
->next
;
661 instance_list
= inst
->next
;
663 printf(_("Finished with %s (exit status %d)\n"),
664 inst
->device
, inst
->exit_status
);
669 #define FLAG_WAIT_ALL 0
670 #define FLAG_WAIT_ATLEAST_ONE 1
672 * Wait until all executing child processes have exited; return the
673 * logical OR of all of their exit code values.
675 static int wait_many(int flags
)
677 struct fsck_instance
*inst
;
678 int global_status
= 0;
681 while ((inst
= wait_one(wait_flags
))) {
682 global_status
|= inst
->exit_status
;
685 if (noexecute
&& (flags
& WNOHANG
) && !(random() % 3))
688 if (flags
& FLAG_WAIT_ATLEAST_ONE
)
689 wait_flags
= WNOHANG
;
691 return global_status
;
695 * Run the fsck program on a particular device
697 * If the type is specified using -t, and it isn't prefixed with "no"
698 * (as in "noext2") and only one filesystem type is specified, then
699 * use that type regardless of what is specified in /etc/fstab.
701 * If the type isn't specified by the user, then use either the type
702 * specified in /etc/fstab, or DEFAULT_FSTYPE.
704 static void fsck_device(struct fs_info
*fs
, int interactive
)
711 if (strcmp(fs
->type
, "auto") != 0)
713 else if (fstype
&& strncmp(fstype
, "no", 2) &&
714 strncmp(fstype
, "opts=", 5) && strncmp(fstype
, "loop", 4) &&
715 !strchr(fstype
, ','))
718 type
= DEFAULT_FSTYPE
;
721 retval
= execute(type
, fs
->device
, fs
->mountpt
, interactive
);
723 fprintf(stderr
, _("%s: Error %d while executing fsck.%s "
724 "for %s\n"), progname
, retval
, type
, fs
->device
);
731 * Deal with the fsck -t argument.
733 static struct fs_type_compile
{
739 #define FS_TYPE_NORMAL 0
740 #define FS_TYPE_OPT 1
741 #define FS_TYPE_NEGOPT 2
743 static const char *fs_type_syntax_error
=
744 N_("Either all or none of the filesystem types passed to -t must be prefixed\n"
745 "with 'no' or '!'.\n");
747 static void compile_fs_type(char *fs_type
, struct fs_type_compile
*cmp
)
751 int negate
, first_negate
= 1;
754 for (cp
=fs_type
; *cp
; cp
++) {
760 cmp
->list
= malloc(num
* sizeof(char *));
761 cmp
->type
= malloc(num
* sizeof(int));
762 if (!cmp
->list
|| !cmp
->type
) {
763 fputs(_("Couldn't allocate memory for filesystem types\n"),
767 memset(cmp
->list
, 0, num
* sizeof(char *));
768 memset(cmp
->type
, 0, num
* sizeof(int));
774 list
= string_copy(fs_type
);
776 s
= strtok(list
, ",");
779 if (strncmp(s
, "no", 2) == 0) {
782 } else if (*s
== '!') {
786 if (strcmp(s
, "loop") == 0)
787 /* loop is really short-hand for opts=loop */
788 goto loop_special_case
;
789 else if (strncmp(s
, "opts=", 5) == 0) {
792 cmp
->type
[num
] = negate
? FS_TYPE_NEGOPT
: FS_TYPE_OPT
;
795 cmp
->negate
= negate
;
798 if ((negate
&& !cmp
->negate
) ||
799 (!negate
&& cmp
->negate
)) {
800 fputs(_(fs_type_syntax_error
), stderr
);
805 printf("Adding %s to list (type %d).\n", s
, cmp
->type
[num
]);
807 cmp
->list
[num
++] = string_copy(s
);
808 s
= strtok(NULL
, ",");
814 * This function returns true if a particular option appears in a
815 * comma-delimited options list
817 static int opt_in_list(const char *opt
, char *optlist
)
823 list
= string_copy(optlist
);
825 s
= strtok(list
, ",");
827 if (strcmp(s
, opt
) == 0) {
831 s
= strtok(NULL
, ",");
837 /* See if the filesystem matches the criteria given by the -t option */
838 static int fs_match(struct fs_info
*fs
, struct fs_type_compile
*cmp
)
840 int n
, ret
= 0, checked_type
= 0;
843 if (cmp
->list
== 0 || cmp
->list
[0] == 0)
846 for (n
=0; (cp
= cmp
->list
[n
]); n
++) {
847 switch (cmp
->type
[n
]) {
850 if (strcmp(cp
, fs
->type
) == 0) {
855 if (opt_in_list(cp
, fs
->opts
))
859 if (!opt_in_list(cp
, fs
->opts
))
864 if (checked_type
== 0)
866 return (cmp
->negate
? !ret
: ret
);
869 /* Check if we should ignore this filesystem. */
870 static int ignore(struct fs_info
*fs
)
876 * If the pass number is 0, ignore it.
882 * If this is a bind mount, ignore it.
884 if (opt_in_list("bind", fs
->opts
)) {
886 _("%s: skipping bad line in /etc/fstab: bind mount with nonzero fsck pass number\n"),
894 * If a specific fstype is specified, and it doesn't match,
897 if (!fs_match(fs
, &fs_type_compiled
)) return 1;
899 /* Are we ignoring this type? */
900 for(ip
= ignored_types
; *ip
; ip
++)
901 if (strcmp(fs
->type
, *ip
) == 0) return 1;
903 /* Do we really really want to check this fs? */
904 for(ip
= really_wanted
; *ip
; ip
++)
905 if (strcmp(fs
->type
, *ip
) == 0) {
910 /* See if the <fsck.fs> program is available. */
911 if (find_fsck(fs
->type
) == NULL
) {
913 fprintf(stderr
, _("fsck: cannot check %s: fsck.%s not found\n"),
914 fs
->device
, fs
->type
);
918 /* We can and want to check this file system type. */
923 * Returns TRUE if a partition on the same disk is already being
926 static int device_already_active(char *device
)
928 struct fsck_instance
*inst
;
931 if (force_all_parallel
)
935 /* Don't check a soft raid disk with any other disk */
937 (!strncmp(instance_list
->device
, BASE_MD
, sizeof(BASE_MD
)-1) ||
938 !strncmp(device
, BASE_MD
, sizeof(BASE_MD
)-1)))
942 base
= base_device(device
);
944 * If we don't know the base device, assume that the device is
945 * already active if there are any fsck instances running.
948 return (instance_list
!= 0);
949 for (inst
= instance_list
; inst
; inst
= inst
->next
) {
950 if (!inst
->base_device
|| !strcmp(base
, inst
->base_device
)) {
959 /* Check all file systems, using the /etc/fstab table. */
960 static int check_all(NOARGS
)
962 struct fs_info
*fs
= NULL
;
963 int status
= EXIT_OK
;
964 int not_done_yet
= 1;
969 fputs(_("Checking all file systems.\n"), stdout
);
972 * Do an initial scan over the filesystem; mark filesystems
973 * which should be ignored as done, and resolve any "auto"
974 * filesystem types (done as a side-effect of calling ignore()).
976 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
978 fs
->flags
|= FLAG_DONE
;
982 * Find and check the root filesystem.
984 if (!parallel_root
) {
985 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
986 if (!strcmp(fs
->mountpt
, "/"))
990 if (!skip_root
&& !ignore(fs
) &&
991 !(ignore_mounted
&& is_mounted(fs
->device
))) {
993 status
|= wait_many(FLAG_WAIT_ALL
);
994 if (status
> EXIT_NONDESTRUCT
)
997 fs
->flags
|= FLAG_DONE
;
1001 * This is for the bone-headed user who enters the root
1002 * filesystem twice. Skip root will skip all root entries.
1005 for (fs
= filesys_info
; fs
; fs
= fs
->next
)
1006 if (!strcmp(fs
->mountpt
, "/"))
1007 fs
->flags
|= FLAG_DONE
;
1009 while (not_done_yet
) {
1013 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
1014 if (cancel_requested
)
1016 if (fs
->flags
& FLAG_DONE
)
1019 * If the filesystem's pass number is higher
1020 * than the current pass number, then we don't
1023 if (fs
->passno
> passno
) {
1027 if (ignore_mounted
&& is_mounted(fs
->device
)) {
1028 fs
->flags
|= FLAG_DONE
;
1032 * If a filesystem on a particular device has
1033 * already been spawned, then we need to defer
1034 * this to another pass.
1036 if (device_already_active(fs
->device
)) {
1041 * Spawn off the fsck process
1043 fsck_device(fs
, serialize
);
1044 fs
->flags
|= FLAG_DONE
;
1047 * Only do one filesystem at a time, or if we
1048 * have a limit on the number of fsck's extant
1049 * at one time, apply that limit.
1052 (max_running
&& (num_running
>= max_running
))) {
1057 if (cancel_requested
)
1060 printf(_("--waiting-- (pass %d)\n"), passno
);
1061 status
|= wait_many(pass_done
? FLAG_WAIT_ALL
:
1062 FLAG_WAIT_ATLEAST_ONE
);
1065 printf("----------------------------------\n");
1070 if (cancel_requested
&& !kill_sent
) {
1074 status
|= wait_many(FLAG_WAIT_ATLEAST_ONE
);
1078 static void usage(NOARGS
)
1080 fputs(_("Usage: fsck [-AMNPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr
);
1084 #ifdef HAVE_SIGNAL_H
1085 static void signal_cancel(int sig
FSCK_ATTR((unused
)))
1091 static void PRS(int argc
, char *argv
[])
1094 char *arg
, *dev
, *tmp
= 0;
1097 int opts_for_fsck
= 0;
1098 #ifdef HAVE_SIGNAL_H
1099 struct sigaction sa
;
1102 * Set up signal action
1104 memset(&sa
, 0, sizeof(struct sigaction
));
1105 sa
.sa_handler
= signal_cancel
;
1106 sigaction(SIGINT
, &sa
, 0);
1107 sigaction(SIGTERM
, &sa
, 0);
1116 for (i
=1; i
< argc
; i
++) {
1120 if ((arg
[0] == '/' && !opts_for_fsck
) || strchr(arg
, '=')) {
1121 if (num_devices
>= MAX_DEVICES
) {
1122 fprintf(stderr
, _("%s: too many devices\n"),
1126 dev
= blkid_get_devname(cache
, arg
, NULL
);
1127 if (!dev
&& strchr(arg
, '=')) {
1129 * Check to see if we failed because
1130 * /proc/partitions isn't found.
1132 if (access("/proc/partitions", R_OK
) < 0) {
1133 fprintf(stderr
, "Couldn't open /proc/partitions: %s\n",
1135 fprintf(stderr
, "Is /proc mounted?\n");
1139 * Check to see if this is because
1140 * we're not running as root
1144 "Must be root to scan for matching filesystems: %s\n", arg
);
1147 "Couldn't find matching filesystem: %s\n", arg
);
1150 devices
[num_devices
++] = dev
? dev
: string_copy(arg
);
1153 if (arg
[0] != '-' || opts_for_fsck
) {
1154 if (num_args
>= MAX_ARGS
) {
1155 fprintf(stderr
, _("%s: too many arguments\n"),
1159 args
[num_args
++] = string_copy(arg
);
1162 for (j
=1; arg
[j
]; j
++) {
1163 if (opts_for_fsck
) {
1164 options
[++opt
] = arg
[j
];
1174 progress_fd
= string_to_int(arg
+j
+1);
1175 if (progress_fd
< 0)
1179 } else if (argc
> i
+ 1 &&
1180 argv
[i
+ 1][0] != '-') {
1181 progress_fd
= string_to_int(argv
[i
]);
1182 if (progress_fd
< 0)
1217 else if ((i
+1) < argc
)
1221 fstype
= string_copy(tmp
);
1222 compile_fs_type(fstype
, &fs_type_compiled
);
1231 options
[++opt
] = arg
[j
];
1238 options
[++opt
] = '\0';
1239 if (num_args
>= MAX_ARGS
) {
1241 _("%s: too many arguments\n"),
1245 args
[num_args
++] = string_copy(options
);
1249 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1250 force_all_parallel
++;
1251 if ((tmp
= getenv("FSCK_MAX_INST")))
1252 max_running
= atoi(tmp
);
1255 int main(int argc
, char *argv
[])
1258 int interactive
= 0;
1259 char *oldpath
= getenv("PATH");
1263 setvbuf(stdout
, NULL
, _IONBF
, BUFSIZ
);
1264 setvbuf(stderr
, NULL
, _IONBF
, BUFSIZ
);
1267 setlocale(LC_MESSAGES
, "");
1268 setlocale(LC_CTYPE
, "");
1269 bindtextdomain(NLS_CAT_NAME
, LOCALEDIR
);
1270 textdomain(NLS_CAT_NAME
);
1272 blkid_get_cache(&cache
, NULL
);
1276 printf("fsck %s (%s)\n", E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
1278 fstab
= getenv("FSTAB_FILE");
1280 fstab
= _PATH_MNTTAB
;
1281 load_fs_info(fstab
);
1283 /* Update our search path to include uncommon directories. */
1285 fsck_path
= malloc (strlen (fsck_prefix_path
) + 1 +
1286 strlen (oldpath
) + 1);
1288 fprintf(stderr
, "%s: Unable to allocate memory for fsck_path\n", progname
);
1291 strcpy (fsck_path
, fsck_prefix_path
);
1292 strcat (fsck_path
, ":");
1293 strcat (fsck_path
, oldpath
);
1295 fsck_path
= string_copy(fsck_prefix_path
);
1298 if ((num_devices
== 1) || (serialize
))
1301 /* If -A was specified ("check all"), do that! */
1305 if (num_devices
== 0) {
1310 for (i
= 0 ; i
< num_devices
; i
++) {
1311 if (cancel_requested
) {
1318 fs
= lookup(devices
[i
]);
1320 fs
= create_fs_device(devices
[i
], 0, "auto",
1325 if (ignore_mounted
&& is_mounted(fs
->device
))
1327 fsck_device(fs
, interactive
);
1329 (max_running
&& (num_running
>= max_running
))) {
1330 struct fsck_instance
*inst
;
1334 status
|= inst
->exit_status
;
1335 free_instance(inst
);
1338 printf("----------------------------------\n");
1341 status
|= wait_many(FLAG_WAIT_ALL
);
1343 blkid_put_cache(cache
);