]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - fsck/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.
22 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
24 * This file may be redistributed under the terms of the GNU Public
28 #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */
30 #include <sys/types.h>
32 #include <sys/signal.h>
51 #include "pathnames.h"
52 #include "ismounted.h"
56 static const char *ignored_types
[] = {
68 static const char *really_wanted
[] = {
81 #define BASE_MD "/dev/md"
84 * Global variables for options
86 char *devices
[MAX_DEVICES
];
88 int num_devices
, num_args
;
95 int ignore_mounted
= 0;
97 int parallel_root
= 0;
100 int force_all_parallel
= 0;
103 volatile int cancel_requested
= 0;
107 struct fs_info
*filesys_info
= NULL
, *filesys_last
= NULL
;
108 struct fsck_instance
*instance_list
;
109 const char fsck_prefix_path
[] = FS_SEARCH_PATH
;
112 static char *string_copy(const char *s
)
118 ret
= malloc(strlen(s
)+1);
124 static int string_to_int(const char *s
)
129 l
= strtol(s
, &p
, 0);
130 if (*p
|| l
== LONG_MIN
|| l
== LONG_MAX
|| l
< 0 || l
> INT_MAX
)
136 static int ignore(struct fs_info
*);
138 static char *skip_over_blank(char *cp
)
140 while (*cp
&& isspace(*cp
))
145 static char *skip_over_word(char *cp
)
147 while (*cp
&& !isspace(*cp
))
152 static void strip_line(char *line
)
157 p
= line
+ strlen(line
) - 1;
158 if ((*p
== '\n') || (*p
== '\r'))
165 static char *parse_word(char **buf
)
173 word
= skip_over_blank(word
);
174 next
= skip_over_word(word
);
181 static void parse_escape(char *word
)
189 for (p
= word
, q
= word
; *p
; p
++, q
++) {
208 for (i
= 0; i
< 3; i
++, p
++) {
211 ac
= (ac
* 8) + (*p
- '0');
219 static void free_instance(struct fsck_instance
*i
)
226 static struct fs_info
*create_fs_device(const char *device
, const char *mntpnt
,
227 const char *type
, const char *opts
,
228 int freq
, int passno
)
232 if (!(fs
= malloc(sizeof(struct fs_info
))))
235 fs
->device
= string_copy(device
);
236 fs
->mountpt
= string_copy(mntpnt
);
237 fs
->type
= string_copy(type
);
238 fs
->opts
= string_copy(opts
? opts
: "");
249 filesys_last
->next
= fs
;
257 static int parse_fstab_line(char *line
, struct fs_info
**ret_fs
)
259 char *dev
, *device
, *mntpnt
, *type
, *opts
, *freq
, *passno
, *cp
;
266 device
= parse_word(&cp
);
267 if (!device
|| *device
== '#')
268 return 0; /* Ignore blank lines and comments */
269 mntpnt
= parse_word(&cp
);
270 type
= parse_word(&cp
);
271 opts
= parse_word(&cp
);
272 freq
= parse_word(&cp
);
273 passno
= parse_word(&cp
);
275 if (!mntpnt
|| !type
)
278 parse_escape(device
);
279 parse_escape(mntpnt
);
283 parse_escape(passno
);
285 dev
= fsprobe_get_devname_by_spec(device
);
289 if (strchr(type
, ','))
292 fs
= create_fs_device(device
, mntpnt
, type
? type
: "auto", opts
,
293 freq
? atoi(freq
) : -1,
294 passno
? atoi(passno
) : -1);
303 static void interpret_type(struct fs_info
*fs
)
307 if (strcmp(fs
->type
, "auto") != 0)
309 t
= fsprobe_get_fstype_by_devname(fs
->device
);
317 * Load the filesystem database from /etc/fstab
319 static void load_fs_info(const char *filename
)
327 if ((f
= fopen(filename
, "r")) == NULL
) {
328 fprintf(stderr
, _("WARNING: couldn't open %s: %s\n"),
329 filename
, strerror(errno
));
334 if (!fgets(buf
, sizeof(buf
), f
))
336 buf
[sizeof(buf
)-1] = 0;
337 if (parse_fstab_line(buf
, &fs
) < 0) {
338 fprintf(stderr
, _("WARNING: bad format "
339 "on line %d of %s\n"), lineno
, filename
);
352 if (old_fstab
&& filesys_info
) {
354 "WARNING: Your /etc/fstab does not contain the fsck passno\n"
355 " field. I will kludge around things for you, but you\n"
356 " should fix your /etc/fstab file as soon as you can.\n\n"), stderr
);
358 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
364 /* Lookup filesys in /etc/fstab and return the corresponding entry. */
365 static struct fs_info
*lookup(char *filesys
)
369 /* No filesys name given. */
373 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
374 if (!strcmp(filesys
, fs
->device
) ||
375 (fs
->mountpt
&& !strcmp(filesys
, fs
->mountpt
)))
382 /* Find fsck program for a given fs type. */
383 static char *find_fsck(char *type
)
387 static char prog
[256];
388 char *p
= string_copy(fsck_path
);
391 /* Are we looking for a program or just a type? */
392 tpl
= (strncmp(type
, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
394 for(s
= strtok(p
, ":"); s
; s
= strtok(NULL
, ":")) {
395 sprintf(prog
, tpl
, s
, type
);
396 if (stat(prog
, &st
) == 0) break;
399 return(s
? prog
: NULL
);
402 static int progress_active(NOARGS
)
404 struct fsck_instance
*inst
;
406 for (inst
= instance_list
; inst
; inst
= inst
->next
) {
407 if (inst
->flags
& FLAG_DONE
)
409 if (inst
->flags
& FLAG_PROGRESS
)
416 * Execute a particular fsck program, and link it into the list of
417 * child processes we are waiting for.
419 static int execute(const char *type
, struct fs_info
*fs
, int interactive
)
421 char *s
, *argv
[80], prog
[80];
423 struct fsck_instance
*inst
, *p
;
426 inst
= malloc(sizeof(struct fsck_instance
));
429 memset(inst
, 0, sizeof(struct fsck_instance
));
431 sprintf(prog
, "fsck.%s", type
);
432 argv
[0] = string_copy(prog
);
435 for (i
=0; i
<num_args
; i
++)
436 argv
[argc
++] = string_copy(args
[i
]);
439 if ((strcmp(type
, "ext2") == 0) ||
440 (strcmp(type
, "ext3") == 0) ||
441 (strcmp(type
, "ext4") == 0) ||
442 (strcmp(type
, "ext4dev") == 0)) {
446 if (!progress_active()) {
447 snprintf(tmp
, 80, "-C%d", progress_fd
);
448 inst
->flags
|= FLAG_PROGRESS
;
449 } else if (progress_fd
)
450 snprintf(tmp
, 80, "-C%d", progress_fd
* -1);
452 argv
[argc
++] = string_copy(tmp
);
456 argv
[argc
++] = string_copy(fs
->device
);
461 fprintf(stderr
, _("fsck: %s: not found\n"), prog
);
466 if (verbose
|| noexecute
) {
467 printf("[%s (%d) -- %s] ", s
, num_running
,
468 fs
->mountpt
? fs
->mountpt
: fs
->device
);
469 for (i
=0; i
< argc
; i
++)
470 printf("%s ", argv
[i
]);
474 /* Fork and execute the correct program. */
477 else if ((pid
= fork()) < 0) {
481 } else if (pid
== 0) {
484 (void) execv(s
, argv
);
490 for (i
=0; i
< argc
; i
++)
494 inst
->prog
= string_copy(prog
);
495 inst
->type
= string_copy(type
);
496 inst
->start_time
= time(0);
501 * Find the end of the list, so we add the instance on at the end.
503 for (p
= instance_list
; p
&& p
->next
; p
= p
->next
);
508 instance_list
= inst
;
514 * Send a signal to all outstanding fsck child processes
516 static int kill_all(int signum
)
518 struct fsck_instance
*inst
;
521 for (inst
= instance_list
; inst
; inst
= inst
->next
) {
522 if (inst
->flags
& FLAG_DONE
)
524 kill(inst
->pid
, signum
);
531 * Wait for one child process to exit; when it does, unlink it from
532 * the list of executing child processes, and return it.
534 static struct fsck_instance
*wait_one(int flags
)
538 struct fsck_instance
*inst
, *inst2
, *prev
;
545 inst
= instance_list
;
548 while (inst
->next
&& (random() & 1)) {
553 inst
->exit_status
= 0;
558 * gcc -Wall fails saving throw against stupidity
559 * (inst and prev are thought to be uninitialized variables)
564 pid
= waitpid(-1, &status
, flags
);
565 if (cancel_requested
&& !kill_sent
) {
569 if ((pid
== 0) && (flags
& WNOHANG
))
572 if ((errno
== EINTR
) || (errno
== EAGAIN
))
574 if (errno
== ECHILD
) {
576 _("%s: wait: No more child process?!?\n"),
583 for (prev
= 0, inst
= instance_list
;
585 prev
= inst
, inst
= inst
->next
) {
586 if (inst
->pid
== pid
)
591 if (WIFEXITED(status
))
592 status
= WEXITSTATUS(status
);
593 else if (WIFSIGNALED(status
)) {
594 sig
= WTERMSIG(status
);
596 status
= EXIT_UNCORRECTED
;
598 printf(_("Warning... %s for device %s exited "
599 "with signal %d.\n"),
600 inst
->prog
, inst
->fs
->device
, sig
);
604 printf(_("%s %s: status is %x, should never happen.\n"),
605 inst
->prog
, inst
->fs
->device
, status
);
608 inst
->exit_status
= status
;
609 inst
->flags
|= FLAG_DONE
;
610 if (progress
&& (inst
->flags
& FLAG_PROGRESS
) &&
611 !progress_active()) {
612 for (inst2
= instance_list
; inst2
; inst2
= inst2
->next
) {
613 if (inst2
->flags
& FLAG_DONE
)
615 if (strcmp(inst2
->type
, "ext2") &&
616 strcmp(inst2
->type
, "ext3") &&
617 strcmp(inst2
->type
, "ext4") &&
618 strcmp(inst2
->type
, "ext4dev"))
621 * If we've just started the fsck, wait a tiny
622 * bit before sending the kill, to give it
623 * time to set up the signal handler
625 if (inst2
->start_time
< time(0)+2) {
628 kill(inst2
->pid
, SIGUSR1
);
632 kill(inst2
->pid
, SIGUSR1
);
633 inst2
->flags
|= FLAG_PROGRESS
;
639 prev
->next
= inst
->next
;
641 instance_list
= inst
->next
;
643 printf(_("Finished with %s (exit status %d)\n"),
644 inst
->fs
->device
, inst
->exit_status
);
649 #define FLAG_WAIT_ALL 0
650 #define FLAG_WAIT_ATLEAST_ONE 1
652 * Wait until all executing child processes have exited; return the
653 * logical OR of all of their exit code values.
655 static int wait_many(int flags
)
657 struct fsck_instance
*inst
;
658 int global_status
= 0;
661 while ((inst
= wait_one(wait_flags
))) {
662 global_status
|= inst
->exit_status
;
665 if (noexecute
&& (flags
& WNOHANG
) && !(random() % 3))
668 if (flags
& FLAG_WAIT_ATLEAST_ONE
)
669 wait_flags
= WNOHANG
;
671 return global_status
;
675 * Run the fsck program on a particular device
677 * If the type is specified using -t, and it isn't prefixed with "no"
678 * (as in "noext2") and only one filesystem type is specified, then
679 * use that type regardless of what is specified in /etc/fstab.
681 * If the type isn't specified by the user, then use either the type
682 * specified in /etc/fstab, or DEFAULT_FSTYPE.
684 static void fsck_device(struct fs_info
*fs
, int interactive
)
691 if (strcmp(fs
->type
, "auto") != 0)
693 else if (fstype
&& strncmp(fstype
, "no", 2) &&
694 strncmp(fstype
, "opts=", 5) && strncmp(fstype
, "loop", 4) &&
695 !strchr(fstype
, ','))
698 type
= DEFAULT_FSTYPE
;
701 retval
= execute(type
, fs
, interactive
);
703 fprintf(stderr
, _("%s: Error %d while executing fsck.%s "
704 "for %s\n"), progname
, retval
, type
, fs
->device
);
711 * Deal with the fsck -t argument.
713 struct fs_type_compile
{
719 #define FS_TYPE_NORMAL 0
720 #define FS_TYPE_OPT 1
721 #define FS_TYPE_NEGOPT 2
723 static const char *fs_type_syntax_error
=
724 N_("Either all or none of the filesystem types passed to -t must be prefixed\n"
725 "with 'no' or '!'.\n");
727 static void compile_fs_type(char *fs_type
, struct fs_type_compile
*cmp
)
731 int negate
, first_negate
= 1;
734 for (cp
=fs_type
; *cp
; cp
++) {
740 cmp
->list
= malloc(num
* sizeof(char *));
741 cmp
->type
= malloc(num
* sizeof(int));
742 if (!cmp
->list
|| !cmp
->type
) {
743 fputs(_("Couldn't allocate memory for filesystem types\n"),
747 memset(cmp
->list
, 0, num
* sizeof(char *));
748 memset(cmp
->type
, 0, num
* sizeof(int));
754 list
= string_copy(fs_type
);
756 s
= strtok(list
, ",");
759 if (strncmp(s
, "no", 2) == 0) {
762 } else if (*s
== '!') {
766 if (strcmp(s
, "loop") == 0)
767 /* loop is really short-hand for opts=loop */
768 goto loop_special_case
;
769 else if (strncmp(s
, "opts=", 5) == 0) {
772 cmp
->type
[num
] = negate
? FS_TYPE_NEGOPT
: FS_TYPE_OPT
;
775 cmp
->negate
= negate
;
778 if ((negate
&& !cmp
->negate
) ||
779 (!negate
&& cmp
->negate
)) {
780 fputs(_(fs_type_syntax_error
), stderr
);
785 printf("Adding %s to list (type %d).\n", s
, cmp
->type
[num
]);
787 cmp
->list
[num
++] = string_copy(s
);
788 s
= strtok(NULL
, ",");
794 * This function returns true if a particular option appears in a
795 * comma-delimited options list
797 static int opt_in_list(const char *opt
, char *optlist
)
803 list
= string_copy(optlist
);
805 s
= strtok(list
, ",");
807 if (strcmp(s
, opt
) == 0) {
811 s
= strtok(NULL
, ",");
817 /* See if the filesystem matches the criteria given by the -t option */
818 static int fs_match(struct fs_info
*fs
, struct fs_type_compile
*cmp
)
820 int n
, ret
= 0, checked_type
= 0;
823 if (cmp
->list
== 0 || cmp
->list
[0] == 0)
826 for (n
=0; (cp
= cmp
->list
[n
]); n
++) {
827 switch (cmp
->type
[n
]) {
830 if (strcmp(cp
, fs
->type
) == 0) {
835 if (opt_in_list(cp
, fs
->opts
))
839 if (!opt_in_list(cp
, fs
->opts
))
844 if (checked_type
== 0)
846 return (cmp
->negate
? !ret
: ret
);
850 * Check if a device exists
852 static int device_exists(const char *device
)
856 if (stat(device
, &st
) == -1)
859 if (!S_ISBLK(st
.st_mode
))
865 /* Check if we should ignore this filesystem. */
866 static int ignore(struct fs_info
*fs
)
872 * If the pass number is 0, ignore it.
878 * If this is a bind mount, ignore it.
880 if (opt_in_list("bind", fs
->opts
)) {
882 _("%s: skipping bad line in /etc/fstab: bind mount with nonzero fsck pass number\n"),
888 * ignore devices that don't exist and have the "nofail" mount option
890 if (!device_exists(fs
->device
) && opt_in_list("nofail", fs
->opts
)) {
892 printf(_("%s: skipping nonexistent device\n"), fs
->device
);
899 * If a specific fstype is specified, and it doesn't match,
902 if (!fs_match(fs
, &fs_type_compiled
)) return 1;
904 /* Are we ignoring this type? */
905 for(ip
= ignored_types
; *ip
; ip
++)
906 if (strcmp(fs
->type
, *ip
) == 0) return 1;
908 /* Do we really really want to check this fs? */
909 for(ip
= really_wanted
; *ip
; ip
++)
910 if (strcmp(fs
->type
, *ip
) == 0) {
915 /* See if the <fsck.fs> program is available. */
916 if (find_fsck(fs
->type
) == NULL
) {
918 fprintf(stderr
, _("fsck: cannot check %s: fsck.%s not found\n"),
919 fs
->device
, fs
->type
);
923 /* We can and want to check this file system type. */
927 static int count_slaves(dev_t disk
)
931 char dirname
[PATH_MAX
];
934 snprintf(dirname
, sizeof(dirname
),
935 "/sys/dev/block/%u:%u/slaves/",
936 major(disk
), minor(disk
));
938 if (!(dir
= opendir(dirname
)))
941 while ((dp
= readdir(dir
)) != 0) {
942 #ifdef _DIRENT_HAVE_D_TYPE
943 if (dp
->d_type
!= DT_UNKNOWN
&& dp
->d_type
!= DT_LNK
)
946 if (dp
->d_name
[0] == '.' &&
947 ((dp
->d_name
[1] == 0) ||
948 ((dp
->d_name
[1] == '.') && (dp
->d_name
[2] == 0))))
958 * Returns TRUE if a partition on the same disk is already being
961 static int disk_already_active(struct fs_info
*fs
)
963 struct fsck_instance
*inst
;
965 if (force_all_parallel
)
968 if (instance_list
&& instance_list
->fs
->stacked
)
969 /* any instance for a stacked device is already running */
976 if (!stat(fs
->device
, &st
) &&
977 !blkid_devno_to_wholedisk(st
.st_rdev
, NULL
, 0, &disk
)) {
979 fs
->stacked
= count_slaves(disk
);
984 * If we don't know the base device, assume that the device is
985 * already active if there are any fsck instances running.
987 * Don't check a stacked device with any other disk too.
989 if (!fs
->disk
|| fs
->stacked
)
990 return (instance_list
!= 0);
992 for (inst
= instance_list
; inst
; inst
= inst
->next
) {
993 if (!inst
->fs
->disk
|| fs
->disk
== inst
->fs
->disk
)
999 /* Check all file systems, using the /etc/fstab table. */
1000 static int check_all(NOARGS
)
1002 struct fs_info
*fs
= NULL
;
1003 int status
= EXIT_OK
;
1004 int not_done_yet
= 1;
1009 fputs(_("Checking all file systems.\n"), stdout
);
1012 * Do an initial scan over the filesystem; mark filesystems
1013 * which should be ignored as done, and resolve any "auto"
1014 * filesystem types (done as a side-effect of calling ignore()).
1016 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
1018 fs
->flags
|= FLAG_DONE
;
1022 * Find and check the root filesystem.
1024 if (!parallel_root
) {
1025 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
1026 if (!strcmp(fs
->mountpt
, "/"))
1030 if (!skip_root
&& !ignore(fs
) &&
1031 !(ignore_mounted
&& is_mounted(fs
->device
))) {
1033 status
|= wait_many(FLAG_WAIT_ALL
);
1034 if (status
> EXIT_NONDESTRUCT
)
1037 fs
->flags
|= FLAG_DONE
;
1041 * This is for the bone-headed user who enters the root
1042 * filesystem twice. Skip root will skep all root entries.
1045 for (fs
= filesys_info
; fs
; fs
= fs
->next
)
1046 if (!strcmp(fs
->mountpt
, "/"))
1047 fs
->flags
|= FLAG_DONE
;
1049 while (not_done_yet
) {
1053 for (fs
= filesys_info
; fs
; fs
= fs
->next
) {
1054 if (cancel_requested
)
1056 if (fs
->flags
& FLAG_DONE
)
1059 * If the filesystem's pass number is higher
1060 * than the current pass number, then we don't
1063 if (fs
->passno
> passno
) {
1067 if (ignore_mounted
&& is_mounted(fs
->device
)) {
1068 fs
->flags
|= FLAG_DONE
;
1072 * If a filesystem on a particular device has
1073 * already been spawned, then we need to defer
1074 * this to another pass.
1076 if (disk_already_active(fs
)) {
1081 * Spawn off the fsck process
1083 fsck_device(fs
, serialize
);
1084 fs
->flags
|= FLAG_DONE
;
1087 * Only do one filesystem at a time, or if we
1088 * have a limit on the number of fsck's extant
1089 * at one time, apply that limit.
1092 (max_running
&& (num_running
>= max_running
))) {
1097 if (cancel_requested
)
1100 printf(_("--waiting-- (pass %d)\n"), passno
);
1101 status
|= wait_many(pass_done
? FLAG_WAIT_ALL
:
1102 FLAG_WAIT_ATLEAST_ONE
);
1105 printf("----------------------------------\n");
1110 if (cancel_requested
&& !kill_sent
) {
1114 status
|= wait_many(FLAG_WAIT_ATLEAST_ONE
);
1118 static void usage(NOARGS
)
1120 fputs(_("Usage: fsck [-AMNPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr
);
1124 static void signal_cancel(int sig
FSCK_ATTR((unused
)))
1129 static void PRS(int argc
, char *argv
[])
1132 char *arg
, *dev
, *tmp
= 0;
1135 int opts_for_fsck
= 0;
1136 struct sigaction sa
;
1139 * Set up signal action
1141 memset(&sa
, 0, sizeof(struct sigaction
));
1142 sa
.sa_handler
= signal_cancel
;
1143 sigaction(SIGINT
, &sa
, 0);
1144 sigaction(SIGTERM
, &sa
, 0);
1152 for (i
=1; i
< argc
; i
++) {
1156 if ((arg
[0] == '/' && !opts_for_fsck
) || strchr(arg
, '=')) {
1157 if (num_devices
>= MAX_DEVICES
) {
1158 fprintf(stderr
, _("%s: too many devices\n"),
1162 dev
= fsprobe_get_devname_by_spec(arg
);
1163 if (!dev
&& strchr(arg
, '=')) {
1165 * Check to see if we failed because
1166 * /proc/partitions isn't found.
1168 if (access(_PATH_PROC_PARTITIONS
, R_OK
) < 0) {
1169 fprintf(stderr
, _("Couldn't open %s: %s\n"),
1170 _PATH_PROC_PARTITIONS
, strerror(errno
));
1171 fprintf(stderr
, _("Is /proc mounted?\n"));
1175 * Check to see if this is because
1176 * we're not running as root
1180 _("Must be root to scan for matching filesystems: %s\n"), arg
);
1183 _("Couldn't find matching filesystem: %s\n"), arg
);
1186 devices
[num_devices
++] = dev
? dev
: string_copy(arg
);
1189 if (arg
[0] != '-' || opts_for_fsck
) {
1190 if (num_args
>= MAX_ARGS
) {
1191 fprintf(stderr
, _("%s: too many arguments\n"),
1195 args
[num_args
++] = string_copy(arg
);
1198 for (j
=1; arg
[j
]; j
++) {
1199 if (opts_for_fsck
) {
1200 options
[++opt
] = arg
[j
];
1210 progress_fd
= string_to_int(arg
+j
+1);
1211 if (progress_fd
< 0)
1215 } else if ((i
+1) < argc
&&
1216 !strncmp(argv
[i
+1], "-", 1) == 0) {
1217 progress_fd
= string_to_int(argv
[i
]);
1218 if (progress_fd
< 0)
1253 else if ((i
+1) < argc
)
1257 fstype
= string_copy(tmp
);
1258 compile_fs_type(fstype
, &fs_type_compiled
);
1267 options
[++opt
] = arg
[j
];
1274 options
[++opt
] = '\0';
1275 if (num_args
>= MAX_ARGS
) {
1277 _("%s: too many arguments\n"),
1281 args
[num_args
++] = string_copy(options
);
1285 if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1286 force_all_parallel
++;
1287 if ((tmp
= getenv("FSCK_MAX_INST")))
1288 max_running
= atoi(tmp
);
1291 int main(int argc
, char *argv
[])
1294 int interactive
= 0;
1295 char *oldpath
= getenv("PATH");
1299 setvbuf(stdout
, NULL
, _IONBF
, BUFSIZ
);
1300 setvbuf(stderr
, NULL
, _IONBF
, BUFSIZ
);
1302 setlocale(LC_MESSAGES
, "");
1303 setlocale(LC_CTYPE
, "");
1304 bindtextdomain(PACKAGE
, LOCALEDIR
);
1305 textdomain(PACKAGE
);
1311 printf(_("fsck from %s\n"), PACKAGE_STRING
);
1313 fstab
= getenv("FSTAB_FILE");
1315 fstab
= _PATH_MNTTAB
;
1316 load_fs_info(fstab
);
1318 /* Update our search path to include uncommon directories. */
1320 fsck_path
= malloc (strlen (fsck_prefix_path
) + 1 +
1321 strlen (oldpath
) + 1);
1323 fprintf(stderr
, _("%s: Unable to allocate memory for fsck_path\n"), progname
);
1326 strcpy (fsck_path
, fsck_prefix_path
);
1327 strcat (fsck_path
, ":");
1328 strcat (fsck_path
, oldpath
);
1330 fsck_path
= string_copy(fsck_prefix_path
);
1333 if ((num_devices
== 1) || (serialize
))
1336 /* If -A was specified ("check all"), do that! */
1340 if (num_devices
== 0) {
1345 for (i
= 0 ; i
< num_devices
; i
++) {
1346 if (cancel_requested
) {
1353 fs
= lookup(devices
[i
]);
1355 fs
= create_fs_device(devices
[i
], 0, "auto",
1360 if (ignore_mounted
&& is_mounted(fs
->device
))
1362 fsck_device(fs
, interactive
);
1364 (max_running
&& (num_running
>= max_running
))) {
1365 struct fsck_instance
*inst
;
1369 status
|= inst
->exit_status
;
1370 free_instance(inst
);
1373 printf("----------------------------------\n");
1376 status
|= wait_many(FLAG_WAIT_ALL
);