Whamcloud - gitweb
Makefile.in:
[tools/e2fsprogs.git] / misc / fsck.c
1 /*
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
7  * parallel execution.
8  *
9  * Written by Theodore Ts'o, <tytso@mit.edu>
10  * 
11  * Usage:       fsck [-AVRNTM] [-s] [-t fstype] [fs-options] device
12  * 
13  * Miquel van Smoorenburg (miquels@drinkel.ow.org) 20-Oct-1994:
14  *   o Changed -t fstype to behave like with mount when -A (all file
15  *     systems) or -M (like mount) is specified.
16  *   o fsck looks if it can find the fsck.type program to decide
17  *     if it should ignore the fs type. This way more fsck programs
18  *     can be added without changing this front-end.
19  *   o -R flag skip root file system.
20  *
21  * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
22  *
23  * %Begin-Header%
24  * This file may be redistributed under the terms of the GNU Public
25  * License.
26  * %End-Header%
27  */
28
29 #include <sys/types.h>
30 #include <sys/wait.h>
31 #include <sys/signal.h>
32 #include <sys/stat.h>
33 #include <limits.h>
34 #include <stdio.h>
35 #include <string.h>
36 #if HAVE_STDLIB_H
37 #include <stdlib.h>
38 #endif
39 #if HAVE_ERRNO_H
40 #include <errno.h>
41 #endif
42 #if HAVE_PATHS_H
43 #include <paths.h>
44 #endif
45 #if HAVE_UNISTD_H
46 #include <unistd.h>
47 #endif
48 #if HAVE_ERRNO_H
49 #include <errno.h>
50 #endif
51 #include <malloc.h>
52
53 #include "../version.h"
54 #include "fsck.h"
55 #include "get_device_by_label.h"
56
57 #ifndef _PATH_MNTTAB
58 #define _PATH_MNTTAB    "/etc/fstab"
59 #endif
60
61 static const char *ignored_types[] = {
62         "ignore",
63         "iso9660",
64         "nfs",
65         "proc",
66         "sw",
67         "swap",
68         NULL
69 };
70
71 static const char *really_wanted[] = {
72         "minix",
73         "ext2",
74         "xiafs",
75         NULL
76 };
77
78 #ifdef DEV_DSK_DEVICES
79 static const char *base_devices[] = {
80         "/dev/dsk/hda",
81         "/dev/dsk/hdb",
82         "/dev/dsk/hdc",
83         "/dev/dsk/hdd",
84         "/dev/dsk/hd1a",
85         "/dev/dsk/hd1b",
86         "/dev/dsk/hd1c",
87         "/dev/dsk/hd1d",
88         "/dev/dsk/sda",
89         "/dev/dsk/sdb",
90         "/dev/dsk/sdc",
91         "/dev/dsk/sdd",
92         "/dev/dsk/sde",
93         "/dev/dsk/sdf",
94         "/dev/dsk/sdg",
95         NULL
96 };
97 #else
98 static const char *base_devices[] = {
99         "/dev/hda",
100         "/dev/hdb",
101         "/dev/hdc",
102         "/dev/hdd",
103         "/dev/hd1a",
104         "/dev/hd1b",
105         "/dev/hd1c",
106         "/dev/hd1d",
107         "/dev/sda",
108         "/dev/sdb",
109         "/dev/sdc",
110         "/dev/sdd",
111         "/dev/sde",
112         "/dev/sdf",
113         "/dev/sdg",
114         NULL
115 };
116 #endif
117
118 /*
119  * Global variables for options
120  */
121 char *devices[MAX_DEVICES];
122 char *args[MAX_ARGS];
123 int num_devices, num_args;
124
125 int verbose = 0;
126 int doall = 0;
127 int noexecute = 0;
128 int serialize = 0;
129 int skip_root = 0;
130 int like_mount = 0;
131 int notitle = 0;
132 int parallel_root = 0;
133 char *progname;
134 char *fstype = NULL;
135 struct fs_info *filesys_info;
136 struct fsck_instance *instance_list;
137 const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
138 char *fsck_path = 0;
139 static int ignore(struct fs_info *);
140
141 static char *string_copy(const char *s)
142 {
143         char    *ret;
144
145         ret = malloc(strlen(s)+1);
146         if (ret)
147                 strcpy(ret, s);
148         return ret;
149 }
150
151 static char *skip_over_blank(char *cp)
152 {
153         while (*cp && isspace(*cp))
154                 cp++;
155         return cp;
156 }
157
158 static char *skip_over_word(char *cp)
159 {
160         while (*cp && !isspace(*cp))
161                 cp++;
162         return cp;
163 }
164
165 static void strip_line(char *line)
166 {
167         char    *p;
168
169         while (*line) {
170                 p = line + strlen(line) - 1;
171                 if ((*p == '\n') || (*p == '\r'))
172                         *p = 0;
173                 else
174                         break;
175         }
176 }
177
178 static char *parse_word(char **buf)
179 {
180         char *word, *next;
181
182         word = *buf;
183         if (*word == 0)
184                 return 0;
185
186         word = skip_over_blank(word);
187         next = skip_over_word(word);
188         if (*next)
189                 *next++ = 0;
190         *buf = next;
191         return word;
192 }
193
194 static void free_instance(struct fsck_instance *i)
195 {
196         if (i->prog)
197                 free(i->prog);
198         if (i->device)
199                 free(i->device);
200         free(i);
201         return;
202 }
203
204 int parse_fstab_line(char *line, struct fs_info **ret_fs)
205 {
206         char    *device, *mntpnt, *type, *opts, *freq, *passno, *cp;
207         struct fs_info *fs;
208
209         *ret_fs = 0;
210         strip_line(line);
211         if (cp = strchr(line, '#'))
212                 *cp = 0;        /* Ignore everything after the comment char */
213         cp = line;
214
215         device = parse_word(&cp);
216         mntpnt = parse_word(&cp);
217         type = parse_word(&cp);
218         opts = parse_word(&cp);
219         freq = parse_word(&cp);
220         passno = parse_word(&cp);
221
222         if (!device)
223                 return 0;       /* Allow blank lines */
224         
225         if (!mntpnt || !type)
226                 return -1;
227         
228         if (!(fs = malloc(sizeof(struct fs_info))))
229                 return -1;
230
231         fs->device = string_copy(device);
232         fs->mountpt = string_copy(mntpnt);
233         fs->type = string_copy(type);
234         fs->opts = string_copy(opts ? opts : "");
235         fs->freq = freq ? atoi(freq) : -1;
236         fs->passno = passno ? atoi(passno) : -1;
237         fs->flags = 0;
238         fs->next = NULL;
239
240         *ret_fs = fs;
241
242         return 0;
243 }
244
245 /*
246  * Interpret the device name if necessary 
247  */
248 static char *interpret_device(char *spec)
249 {
250         char *dev = NULL;
251         
252         if (!strncmp(spec, "UUID=", 5))
253                 dev = get_spec_by_uuid(spec+5);
254         else if (!strncmp(spec, "LABEL=", 6))
255                 dev = get_spec_by_volume_label(spec+6);
256         if (dev) {
257                 free(spec);
258                 spec = dev;
259         }
260         return spec;
261 }
262
263 /*
264  * Load the filesystem database from /etc/fstab
265  */
266 static void load_fs_info(char *filename)
267 {
268         FILE    *f;
269         char    buf[1024];
270         int     lineno = 0;
271         int     old_fstab = 1;
272         struct fs_info *fs, *fs_last = NULL;
273
274         filesys_info = NULL;
275         if ((f = fopen(filename, "r")) == NULL) {
276                 fprintf(stderr, "WARNING: couldn't open %s: %s\n",
277                         filename, strerror(errno));
278                 return;
279         }
280         while (!feof(f)) {
281                 lineno++;
282                 if (!fgets(buf, sizeof(buf), f))
283                         break;
284                 buf[sizeof(buf)-1] = 0;
285                 if (parse_fstab_line(buf, &fs) < 0) {
286                         fprintf(stderr, "WARNING: bad format "
287                                 "on line %d of %s\n", lineno, filename);
288                         continue;
289                 }
290                 if (!fs)
291                         continue;
292                 fs->device = interpret_device(fs->device);
293                 if (!filesys_info)
294                         filesys_info = fs;
295                 else
296                         fs_last->next = fs;
297                 fs_last = fs;
298                 if (fs->passno < 0)
299                         fs->passno = 0;
300                 else
301                         old_fstab = 0;
302         }
303         
304         fclose(f);
305         
306         if (old_fstab) {
307                 fprintf(stderr, "\007\007\007"
308         "WARNING: Your /etc/fstab does not contain the fsck passno\n");
309                 fprintf(stderr,
310         "       field.  I will kludge around things for you, but you\n");
311                 fprintf(stderr,
312         "       should fix your /etc/fstab file as soon as you can.\n\n");
313                 
314                 for (fs = filesys_info; fs; fs = fs->next) {
315                         fs->passno = 1;
316                 }
317         }
318 }
319         
320 /* Lookup filesys in /etc/fstab and return the corresponding entry. */
321 static struct fs_info *lookup(char *filesys)
322 {
323         struct fs_info *fs;
324
325         /* No filesys name given. */
326         if (filesys == NULL)
327                 return NULL;
328
329         for (fs = filesys_info; fs; fs = fs->next) {
330                 if (!strcmp(filesys, fs->device) ||
331                     !strcmp(filesys, fs->mountpt))
332                         break;
333         }
334
335         return fs;
336 }
337
338 /* Find fsck program for a given fs type. */
339 static char *find_fsck(char *type)
340 {
341   char *s;
342   const char *tpl;
343   static char prog[256];
344   char *p = string_copy(fsck_path);
345   struct stat st;
346
347   /* Are we looking for a program or just a type? */
348   tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
349
350   for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
351         sprintf(prog, tpl, s, type);
352         if (stat(prog, &st) == 0) break;
353   }
354   free(p);
355   return(s ? prog : NULL);
356 }
357
358 /*
359  * Execute a particular fsck program, and link it into the list of
360  * child processes we are waiting for.
361  */
362 static int execute(char *prog, char *device, char *mntpt, int interactive)
363 {
364         char *s, *argv[80];
365         int  argc, i;
366         struct fsck_instance *inst;
367         pid_t   pid;
368
369         argv[0] = string_copy(prog);
370         argc = 1;
371         
372         for (i=0; i <num_args; i++)
373                 argv[argc++] = string_copy(args[i]);
374
375         argv[argc++] = string_copy(device);
376         argv[argc] = 0;
377
378         s = find_fsck(prog);
379         if (s == NULL) {
380                 fprintf(stderr, "fsck: %s: not found\n", prog);
381                 return ENOENT;
382         }
383
384         if (verbose || noexecute) {
385                 printf("[%s -- %s] ", s, mntpt ? mntpt : device);
386                 for (i=0; i < argc; i++)
387                         printf("%s ", argv[i]);
388                 printf("\n");
389         }
390         
391         /* Fork and execute the correct program. */
392         if (noexecute)
393                 pid = -1;
394         else if ((pid = fork()) < 0) {
395                 perror("fork");
396                 return errno;
397         } else if (pid == 0) {
398                 if (!interactive)
399                         close(0);
400                 (void) execv(s, argv);
401                 perror(argv[0]);
402                 exit(EXIT_ERROR);
403         }
404         inst = malloc(sizeof(struct fsck_instance));
405         if (!inst)
406                 return ENOMEM;
407         memset(inst, 0, sizeof(struct fsck_instance));
408         inst->pid = pid;
409         inst->prog = string_copy(prog);
410         inst->device = string_copy(device);
411         inst->next = instance_list;
412         instance_list = inst;
413         
414         return 0;
415 }
416
417 /*
418  * Wait for one child process to exit; when it does, unlink it from
419  * the list of executing child processes, and return it.
420  */
421 static struct fsck_instance *wait_one(NOARGS)
422 {
423         int     status;
424         int     sig;
425         struct fsck_instance *inst, *prev;
426         pid_t   pid;
427
428         if (!instance_list)
429                 return NULL;
430
431         if (noexecute) {
432                 inst = instance_list;
433                 instance_list = inst->next;
434                 inst->exit_status = 0;
435                 return(inst);
436         }
437
438 retry:
439         pid = wait(&status);
440         if (pid < 0) {
441                 if ((errno == EINTR) || (errno == EAGAIN))
442                         goto retry;
443                 if (errno == ECHILD) {
444                         fprintf(stderr,
445                                 "%s: wait: No more child process?!?\n",
446                                 progname);
447                         return NULL;
448                 }
449                 perror("wait");
450                 goto retry;
451         }
452         for (prev = 0, inst = instance_list;
453              inst;
454              prev = inst, inst = inst->next) {
455                 if (inst->pid == pid)
456                         break;
457         }
458         if (!inst) {
459                 printf("Unexpected child process %d, status = 0x%x\n",
460                        pid, status);
461                 goto retry;
462         }
463         if (WIFEXITED(status)) 
464                 status = WEXITSTATUS(status);
465         else if (WIFSIGNALED(status)) {
466                 sig = WTERMSIG(status);
467                 if (sig == SIGINT) {
468                         status = EXIT_UNCORRECTED;
469                 } else {
470                         printf("Warning... %s for device %s exited "
471                                "with signal %d.\n",
472                                inst->prog, inst->device, sig);
473                         status = EXIT_ERROR;
474                 }
475         } else {
476                 printf("%s %s: status is %x, should never happen.\n",
477                        inst->prog, inst->device, status);
478                 status = EXIT_ERROR;
479         }
480         inst->exit_status = status;
481         if (prev)
482                 prev->next = inst->next;
483         else
484                 instance_list = inst->next;
485         return inst;
486 }
487
488 /*
489  * Wait until all executing child processes have exited; return the
490  * logical OR of all of their exit code values.
491  */
492 static int wait_all(NOARGS)
493 {
494         struct fsck_instance *inst;
495         int     global_status = 0;
496
497         while (instance_list) {
498                 inst = wait_one();
499                 if (!inst)
500                         break;
501                 global_status |= inst->exit_status;
502                 free_instance(inst);
503         }
504         return global_status;
505 }
506
507 /*
508  * Run the fsck program on a particular device
509  * 
510  * If the type is specified using -t, and it isn't prefixed with "no"
511  * (as in "noext2") and only one filesystem type is specified, then
512  * use that type regardless of what is specified in /etc/fstab.
513  * 
514  * If the type isn't specified by the user, then use either the type
515  * specified in /etc/fstab, or DEFAULT_FSTYPE.
516  */
517 static void fsck_device(char *device, int interactive)
518 {
519         const char      *type = 0;
520         struct fs_info *fsent;
521         int retval;
522         char prog[80];
523
524         if (fstype && strncmp(fstype, "no", 2) && !strchr(fstype, ','))
525                 type = fstype;
526
527         if ((fsent = lookup(device))) {
528                 device = fsent->device;
529                 if (!type)
530                         type = fsent->type;
531         }
532         if (!type)
533                 type = DEFAULT_FSTYPE;
534
535         sprintf(prog, "fsck.%s", type);
536         retval = execute(prog, device, fsent ? fsent->mountpt : 0,
537                          interactive);
538         if (retval) {
539                 fprintf(stderr, "%s: Error %d while executing %s for %s\n",
540                         progname, retval, prog, device);
541         }
542 }
543
544 /* See if filesystem type matches the list. */
545 static int fs_match(char *type, char *fs_type)
546 {
547   int ret = 0, negate = 0;
548   char list[128];
549   char *s;
550
551   if (!fs_type) return(1);
552
553   if (strncmp(fs_type, "no", 2) == 0) {
554         fs_type += 2;
555         negate = 1;
556   }
557   strcpy(list, fs_type);
558   s = strtok(list, ",");
559   while(s) {
560         if (strcmp(s, type) == 0) {
561                 ret = 1;
562                 break;
563         }
564         s = strtok(NULL, ",");
565   }
566   return(negate ? !ret : ret);
567 }
568
569
570 /* Check if we should ignore this filesystem. */
571 static int ignore(struct fs_info *fs)
572 {
573         const char **ip;
574         int wanted = 0;
575
576         /*
577          * If the pass number is 0, ignore it.
578          */
579         if (fs->passno == 0)
580                 return 1;
581
582         /*
583          * If a specific fstype is specified, and it doesn't match,
584          * ignore it.
585          */
586         if (!fs_match(fs->type, fstype)) return 1;
587         
588         /* Are we ignoring this type? */
589         for(ip = ignored_types; *ip; ip++)
590                 if (strcmp(fs->type, *ip) == 0) return(1);
591
592         /* Do we really really want to check this fs? */
593         for(ip = really_wanted; *ip; ip++)
594                 if (strcmp(fs->type, *ip) == 0) {
595                         wanted = 1;
596                         break;
597                 }
598
599         /* See if the <fsck.fs> program is available. */
600         if (find_fsck(fs->type) == NULL) {
601                 if (wanted)
602                         fprintf(stderr, "fsck: cannot check %s: fsck.%s not found\n",
603                                 fs->device, fs->type);
604                 return(1);
605         }
606
607         /* We can and want to check this file system type. */
608         return 0;
609 }
610
611 /*
612  * Return the "base device" given a particular device; this is used to
613  * assure that we only fsck one partition on a particular drive at any
614  * one time.  Otherwise, the disk heads will be seeking all over the
615  * place.
616  */
617 static const char *base_device(char *device)
618 {
619         const char **base;
620
621         for (base = base_devices; *base; base++) {
622                 if (!strncmp(*base, device, strlen(*base)))
623                         return *base;
624         }
625         return device;
626 }
627
628 /*
629  * Returns TRUE if a partition on the same disk is already being
630  * checked.
631  */
632 static int device_already_active(char *device)
633 {
634         struct fsck_instance *inst;
635         const char *base;
636
637         base = base_device(device);
638
639         for (inst = instance_list; inst; inst = inst->next) {
640                 if (!strcmp(base, base_device(inst->device)))
641                         return 1;
642         }
643
644         return 0;
645 }
646
647 /* Check all file systems, using the /etc/fstab table. */
648 static int check_all(NOARGS)
649 {
650         struct fs_info *fs = NULL;
651         struct fsck_instance *inst;
652         int status = EXIT_OK;
653         int not_done_yet = 1;
654         int passno = 1;
655         int pass_done;
656
657         if (verbose)
658                 printf("Checking all file systems.\n");
659
660         /*
661          * Find and check the root filesystem first.
662          */
663         if (!parallel_root) {
664                 for (fs = filesys_info; fs; fs = fs->next) {
665                         if (!strcmp(fs->mountpt, "/"))
666                                 break;
667                 }
668                 if (fs && !skip_root && !ignore(fs)) {
669                         fsck_device(fs->device, 0);
670                         fs->flags |= FLAG_DONE;
671                         status |= wait_all();
672                         if (status > EXIT_NONDESTRUCT)
673                                 return status;
674                 }
675         }
676         if (fs) fs->flags |= FLAG_DONE;
677
678         /*
679          * Mark filesystems that should be ignored as done.
680          */
681         for (fs = filesys_info; fs; fs = fs->next) {
682                 if (ignore(fs))
683                         fs->flags |= FLAG_DONE;
684         }
685                 
686         while (not_done_yet) {
687                 not_done_yet = 0;
688                 pass_done = 1;
689
690                 for (fs = filesys_info; fs; fs = fs->next) {
691                         if (fs->flags & FLAG_DONE)
692                                 continue;
693                         /*
694                          * If the filesystem's pass number is higher
695                          * than the current pass number, then we don't
696                          * do it yet.
697                          */
698                         if (fs->passno > passno) {
699                                 not_done_yet++;
700                                 continue;
701                         }
702                         /*
703                          * If a filesystem on a particular device has
704                          * already been spawned, then we need to defer
705                          * this to another pass.
706                          */
707                         if (device_already_active(fs->device)) {
708                                 pass_done = 0;
709                                 continue;
710                         }
711                         /*
712                          * Spawn off the fsck process
713                          */
714                         fsck_device(fs->device, 0);
715                         fs->flags |= FLAG_DONE;
716
717                         if (serialize) {
718                                 pass_done = 0;
719                                 break; /* Only do one filesystem at a time */
720
721                         }
722                 }
723                 if (verbose > 1)
724                         printf("--waiting-- (pass %d)\n", passno);
725                 inst = wait_one();
726                 if (inst) {
727                         status |= inst->exit_status;
728                         free_instance(inst);
729                 }
730                 if (pass_done) {
731                         status |= wait_all();
732                         if (verbose > 1) 
733                                 printf("----------------------------------\n");
734                         passno++;
735                 } else
736                         not_done_yet++;
737         }
738         status |= wait_all();
739         return status;
740 }
741
742 static void usage(NOARGS)
743 {
744         fprintf(stderr,
745                 "Usage: fsck [-AV] [-t fstype] [fs-options] filesys\n");
746         exit(EXIT_USAGE);
747 }
748
749 static void PRS(int argc, char *argv[])
750 {
751         int     i, j;
752         char    *arg;
753         char    options[128];
754         int     opt = 0;
755         int     opts_for_fsck = 0;
756         
757         num_devices = 0;
758         num_args = 0;
759         instance_list = 0;
760
761         progname = argv[0];
762
763         for (i=1; i < argc; i++) {
764                 arg = argv[i];
765                 if (!arg)
766                         continue;
767                 if ((arg[0] == '/' && !opts_for_fsck) ||
768                     (strncmp(arg, "LABEL=", 6) == 0) ||
769                     (strncmp(arg, "UUID=", 5) == 0)) {
770                         if (num_devices >= MAX_DEVICES) {
771                                 fprintf(stderr, "%s: too many devices\n",
772                                         progname);
773                                 exit(1);
774                         }
775                         devices[num_devices++] =
776                                 interpret_device(string_copy(arg));
777                         continue;
778                 }
779                 if (arg[0] != '-' || opts_for_fsck) {
780                         if (num_args >= MAX_ARGS) {
781                                 fprintf(stderr, "%s: too many arguments\n",
782                                         progname);
783                                 exit(1);
784                         }
785                         args[num_args++] = string_copy(arg);
786                         continue;
787                 }
788                 for (j=1; arg[j]; j++) {
789                         if (opts_for_fsck) {
790                                 options[++opt] = arg[j];
791                                 continue;
792                         }
793                         switch (arg[j]) {
794                         case 'A':
795                                 doall++;
796                                 break;
797                         case 'V':
798                                 verbose++;
799                                 break;
800                         case 'N':
801                                 noexecute++;
802                                 break;
803                         case 'R':
804                                 skip_root++;
805                                 break;
806                         case 'T':
807                                 notitle++;
808                                 break;
809                         case 'M':
810                                 like_mount++;
811                                 break;
812                         case 'P':
813                                 parallel_root++;
814                                 break;
815                         case 's':
816                                 serialize++;
817                                 break;
818                         case 't':
819                                 if (arg[j+1]) {
820                                         fstype = string_copy(arg+j+1);
821                                         goto next_arg;
822                                 }
823                                 if ((i+1) < argc) {
824                                         i++;
825                                         fstype = string_copy(argv[i]);
826                                         goto next_arg;
827                                 }
828                                 usage();
829                                 break;
830                         case '-':
831                                 opts_for_fsck++;
832                                 break;
833                         default:
834                                 options[++opt] = arg[j];
835                                 break;
836                         }
837                 }
838         next_arg:
839                 if (opt) {
840                         options[0] = '-';
841                         options[++opt] = '\0';
842                         if (num_args >= MAX_ARGS) {
843                                 fprintf(stderr,
844                                         "%s: too many arguments\n",
845                                         progname);
846                                 exit(1);
847                         }
848                         args[num_args++] = string_copy(options);
849                         opt = 0;
850                 }
851         }
852 }
853
854 int main(int argc, char *argv[])
855 {
856         int i;
857         int status = 0;
858         int interactive = 0;
859         char *oldpath = getenv("PATH");
860         char *fstab;
861
862         PRS(argc, argv);
863
864         if (!notitle)
865                 printf("Parallelizing fsck version %s (%s)\n",
866                         E2FSPROGS_VERSION, E2FSPROGS_DATE);
867
868         fstab = getenv("FSTAB_FILE");
869         if (!fstab)
870                 fstab = _PATH_MNTTAB;
871         load_fs_info(fstab);
872
873         /* Update our search path to include uncommon directories. */
874         if (oldpath) {
875                 fsck_path = malloc (strlen (fsck_prefix_path) + 1 +
876                                     strlen (oldpath) + 1);
877                 strcpy (fsck_path, fsck_prefix_path);
878                 strcat (fsck_path, ":");
879                 strcat (fsck_path, oldpath);
880         } else {
881                 fsck_path = string_copy(fsck_prefix_path);
882         }
883         
884         /* If -A was specified ("check all"), do that! */
885         if (doall)
886                 return check_all();
887
888         if ((num_devices == 1) || (serialize))
889                 interactive = 1;
890
891         for (i = 0 ; i < num_devices; i++) {
892                 fsck_device(devices[i], interactive);
893                 if (serialize) {
894                         struct fsck_instance *inst;
895
896                         inst = wait_one();
897                         if (inst) {
898                                 status |= inst->exit_status;
899                                 free_instance(inst);
900                         }
901                 }
902         }
903         status |= wait_all();
904         free(fsck_path);
905         return status;
906 }