int parallel_root = 0;
int progress = 0;
int force_all_parallel = 0;
+int num_running = 0;
+int max_running = 0;
char *progname;
char *fstype = NULL;
struct fs_info *filesys_info;
char *fsck_path = 0;
static int ignore(struct fs_info *);
-char *string_copy(const char *s)
-{
- char *ret;
-
- ret = malloc(strlen(s)+1);
- if (ret)
- strcpy(ret, s);
- return ret;
-}
-
static char *skip_over_blank(char *cp)
{
while (*cp && isspace(*cp))
*/
static char *interpret_device(char *spec)
{
- char *dev = NULL;
-
- if (!strncmp(spec, "UUID=", 5))
- dev = get_spec_by_uuid(spec+5);
- else if (!strncmp(spec, "LABEL=", 6))
- dev = get_spec_by_volume_label(spec+6);
- else
- return spec;
- if (dev) {
- free(spec);
- return (dev);
- }
+ char *dev = interpret_spec(spec);
+
+ if (dev)
+ return dev;
+
/*
* Check to see if this was because /proc/partitions isn't
* found.
* Check to see if this is because we're not running as root
*/
if (geteuid())
- fprintf(stderr, "Must be root to scan for matching "
- "filesystems: %s\n", spec);
+ fprintf(stderr,
+ "Must be root to scan for matching filesystems: %s\n",
+ spec);
else
- fprintf(stderr, "Couldn't find matching filesystem: %s\n",
+ fprintf(stderr, "Couldn't find matching filesystem: %s\n",
spec);
exit(EXIT_ERROR);
}
/*
+ * Interpret filesystem auto type if necessary
+ */
+static void interpret_type(struct fs_info *fs)
+{
+ const char *type;
+
+ if (strcmp(fs->type, "auto") == 0 ||
+ (strchr(fs->type, ',') != 0)) {
+ if (fs && strchr(fs->device, '='))
+ fs->device = interpret_device(fs->device);
+ type = identify_fs(fs->device, fs->type);
+ if (type) {
+ free(fs->type);
+ fs->type = string_copy(type);
+ } else
+ fprintf(stderr, _("Could not determine "
+ "filesystem type for %s\n"),
+ fs->device);
+ }
+}
+
+
+/*
* Load the filesystem database from /etc/fstab
*/
static void load_fs_info(const char *filename)
}
if (verbose || noexecute) {
- printf("[%s -- %s] ", s, mntpt ? mntpt : device);
+ printf("[%s (%d) -- %s] ", s, num_running,
+ mntpt ? mntpt : device);
for (i=0; i < argc; i++)
printf("%s ", argv[i]);
printf("\n");
* Wait for one child process to exit; when it does, unlink it from
* the list of executing child processes, and return it.
*/
-static struct fsck_instance *wait_one(NOARGS)
+static struct fsck_instance *wait_one(int flags)
{
int status;
int sig;
if (noexecute) {
inst = instance_list;
- instance_list = inst->next;
+ prev = 0;
+#ifdef RANDOM_DEBUG
+ while (inst->next && (random() & 1)) {
+ prev = inst;
+ inst = inst->next;
+ }
+#endif
inst->exit_status = 0;
- return(inst);
+ goto ret_inst;
}
/*
inst = prev = NULL;
do {
- pid = wait(&status);
+ pid = waitpid(-1, &status, flags);
+ if ((pid == 0) && (flags & WNOHANG))
+ return NULL;
if (pid < 0) {
if ((errno == EINTR) || (errno == EAGAIN))
continue;
status = EXIT_ERROR;
}
inst->exit_status = status;
- if (prev)
- prev->next = inst->next;
- else
- instance_list = inst->next;
if (progress && (inst->flags & FLAG_PROGRESS) &&
!progress_active()) {
for (inst2 = instance_list; inst2; inst2 = inst2->next) {
break;
}
}
+ret_inst:
+ if (prev)
+ prev->next = inst->next;
+ else
+ instance_list = inst->next;
+ if (verbose > 1)
+ printf(_("Finished with %s (exit status %d)\n"),
+ inst->device, inst->exit_status);
+ num_running--;
return inst;
}
* Wait until all executing child processes have exited; return the
* logical OR of all of their exit code values.
*/
-static int wait_all(NOARGS)
+static int wait_all(int flags)
{
struct fsck_instance *inst;
int global_status = 0;
- while (instance_list) {
- inst = wait_one();
- if (!inst)
- break;
+ while ((inst = wait_one(flags))) {
global_status |= inst->exit_status;
free_instance(inst);
+#ifdef RANDOM_DEBUG
+ if (noexecute && (flags & WNOHANG) && !(random() % 3))
+ break;
+#endif
}
return global_status;
}
if ((fsent = lookup(device))) {
device = fsent->device;
+ interpret_type(fsent);
if (!type)
type = fsent->type;
}
if (!type)
type = DEFAULT_FSTYPE;
+ num_running++;
retval = execute(type, device, fsent ? fsent->mountpt : 0,
interactive);
if (retval) {
fprintf(stderr, _("%s: Error %d while executing fsck.%s "
"for %s\n"), progname, retval, type, device);
+ num_running--;
}
}
if (cmp->list == 0 || cmp->list[0] == 0)
return 1;
- for (n=0; cp = cmp->list[n]; n++) {
+ for (n=0; (cp = cmp->list[n]); n++) {
switch (cmp->type[n]) {
case FS_TYPE_NORMAL:
checked_type++;
if (fs->passno == 0)
return 1;
+ interpret_type(fs);
+
/*
* If a specific fstype is specified, and it doesn't match,
* ignore it.
for (fs = filesys_info; fs; fs = fs->next) {
if (ignore(fs))
fs->flags |= FLAG_DONE;
- fs->device = interpret_device(fs->device);
+ else
+ fs->device = interpret_device(fs->device);
}
/*
if (fs) {
if (!skip_root && !ignore(fs)) {
fsck_device(fs->device, 1);
- status |= wait_all();
+ status |= wait_all(0);
if (status > EXIT_NONDESTRUCT)
return status;
}
fsck_device(fs->device, serialize);
fs->flags |= FLAG_DONE;
- if (serialize) {
+ /*
+ * Only do one filesystem at a time, or if we
+ * have a limit on the number of fsck's extant
+ * at one time, apply that limit.
+ */
+ if (serialize ||
+ (max_running && (num_running >= max_running))) {
pass_done = 0;
- break; /* Only do one filesystem at a time */
+ break;
}
}
if (verbose > 1)
printf(_("--waiting-- (pass %d)\n"), passno);
- inst = wait_one();
- if (inst) {
- status |= inst->exit_status;
- free_instance(inst);
- }
+ status |= wait_all(pass_done ? 0 : WNOHANG);
if (pass_done) {
- status |= wait_all();
if (verbose > 1)
printf("----------------------------------\n");
passno++;
} else
not_done_yet++;
}
- status |= wait_all();
+ status |= wait_all(0);
return status;
}
static void PRS(int argc, char *argv[])
{
int i, j;
- char *arg;
+ char *arg, *tmp;
char options[128];
int opt = 0;
int opts_for_fsck = 0;
serialize++;
break;
case 't':
- if (arg[j+1]) {
- fstype = string_copy(arg+j+1);
- compile_fs_type(fstype, &fs_type_compiled);
- goto next_arg;
- }
- if ((i+1) < argc) {
- i++;
- fstype = string_copy(argv[i]);
- compile_fs_type(fstype, &fs_type_compiled);
- goto next_arg;
- }
- usage();
- break;
+ if (fstype)
+ usage();
+ if (arg[j+1])
+ tmp = arg+j+1;
+ else if ((i+1) < argc)
+ tmp = argv[++i];
+ else
+ usage();
+ fstype = string_copy(tmp);
+ compile_fs_type(fstype, &fs_type_compiled);
+ goto next_arg;
case '-':
opts_for_fsck++;
break;
}
if (getenv("FSCK_FORCE_ALL_PARALLEL"))
force_all_parallel++;
+ if ((tmp = getenv("FSCK_MAX_INST")))
+ max_running = atoi(tmp);
}
int main(int argc, char *argv[])
#ifdef ENABLE_NLS
setlocale(LC_MESSAGES, "");
+ setlocale(LC_CTYPE, "");
bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
textdomain(NLS_CAT_NAME);
#endif
PRS(argc, argv);
if (!notitle)
- printf(_("Parallelizing fsck version %s (%s)\n"),
- E2FSPROGS_VERSION, E2FSPROGS_DATE);
+ printf("fsck %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
fstab = getenv("FSTAB_FILE");
if (!fstab)
if (doall)
return check_all();
+ if (num_devices == 0) {
+ fprintf(stderr, _("\nNo devices specified to be checked!\n"));
+ exit(EXIT_ERROR);
+ }
for (i = 0 ; i < num_devices; i++) {
fsck_device(devices[i], interactive);
- if (serialize) {
+ if (serialize || (num_running >= max_running)) {
struct fsck_instance *inst;
- inst = wait_one();
+ inst = wait_one(0);
if (inst) {
status |= inst->exit_status;
free_instance(inst);
}
}
}
- status |= wait_all();
+ status |= wait_all(0);
free(fsck_path);
return status;
}