1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker * pfsck --- A generic, parallelizing front-end for the fsck program.
3*6a54128fSAndroid Build Coastguard Worker * It will automatically try to run fsck programs in parallel if the
4*6a54128fSAndroid Build Coastguard Worker * devices are on separate spindles. It is based on the same ideas as
5*6a54128fSAndroid Build Coastguard Worker * the generic front end for fsck by David Engel and Fred van Kempen,
6*6a54128fSAndroid Build Coastguard Worker * but it has been completely rewritten from scratch to support
7*6a54128fSAndroid Build Coastguard Worker * parallel execution.
8*6a54128fSAndroid Build Coastguard Worker *
9*6a54128fSAndroid Build Coastguard Worker * Written by Theodore Ts'o, <[email protected]>
10*6a54128fSAndroid Build Coastguard Worker *
11*6a54128fSAndroid Build Coastguard Worker * Miquel van Smoorenburg ([email protected]) 20-Oct-1994:
12*6a54128fSAndroid Build Coastguard Worker * o Changed -t fstype to behave like with mount when -A (all file
13*6a54128fSAndroid Build Coastguard Worker * systems) or -M (like mount) is specified.
14*6a54128fSAndroid Build Coastguard Worker * o fsck looks if it can find the fsck.type program to decide
15*6a54128fSAndroid Build Coastguard Worker * if it should ignore the fs type. This way more fsck programs
16*6a54128fSAndroid Build Coastguard Worker * can be added without changing this front-end.
17*6a54128fSAndroid Build Coastguard Worker * o -R flag skip root file system.
18*6a54128fSAndroid Build Coastguard Worker *
19*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
20*6a54128fSAndroid Build Coastguard Worker * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o.
21*6a54128fSAndroid Build Coastguard Worker *
22*6a54128fSAndroid Build Coastguard Worker * %Begin-Header%
23*6a54128fSAndroid Build Coastguard Worker * This file may be redistributed under the terms of the GNU Public
24*6a54128fSAndroid Build Coastguard Worker * License.
25*6a54128fSAndroid Build Coastguard Worker * %End-Header%
26*6a54128fSAndroid Build Coastguard Worker */
27*6a54128fSAndroid Build Coastguard Worker
28*6a54128fSAndroid Build Coastguard Worker #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */
29*6a54128fSAndroid Build Coastguard Worker
30*6a54128fSAndroid Build Coastguard Worker #include "config.h"
31*6a54128fSAndroid Build Coastguard Worker #include <sys/types.h>
32*6a54128fSAndroid Build Coastguard Worker #include <sys/wait.h>
33*6a54128fSAndroid Build Coastguard Worker #include <sys/stat.h>
34*6a54128fSAndroid Build Coastguard Worker #include <limits.h>
35*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
36*6a54128fSAndroid Build Coastguard Worker #include <ctype.h>
37*6a54128fSAndroid Build Coastguard Worker #include <string.h>
38*6a54128fSAndroid Build Coastguard Worker #include <time.h>
39*6a54128fSAndroid Build Coastguard Worker #if HAVE_STDLIB_H
40*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
41*6a54128fSAndroid Build Coastguard Worker #endif
42*6a54128fSAndroid Build Coastguard Worker #if HAVE_ERRNO_H
43*6a54128fSAndroid Build Coastguard Worker #include <errno.h>
44*6a54128fSAndroid Build Coastguard Worker #endif
45*6a54128fSAndroid Build Coastguard Worker #if HAVE_PATHS_H
46*6a54128fSAndroid Build Coastguard Worker #include <paths.h>
47*6a54128fSAndroid Build Coastguard Worker #endif
48*6a54128fSAndroid Build Coastguard Worker #if HAVE_UNISTD_H
49*6a54128fSAndroid Build Coastguard Worker #include <unistd.h>
50*6a54128fSAndroid Build Coastguard Worker #endif
51*6a54128fSAndroid Build Coastguard Worker #if HAVE_ERRNO_H
52*6a54128fSAndroid Build Coastguard Worker #include <errno.h>
53*6a54128fSAndroid Build Coastguard Worker #endif
54*6a54128fSAndroid Build Coastguard Worker #if HAVE_MALLOC_H
55*6a54128fSAndroid Build Coastguard Worker #include <malloc.h>
56*6a54128fSAndroid Build Coastguard Worker #endif
57*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SIGNAL_H
58*6a54128fSAndroid Build Coastguard Worker #include <signal.h>
59*6a54128fSAndroid Build Coastguard Worker #endif
60*6a54128fSAndroid Build Coastguard Worker
61*6a54128fSAndroid Build Coastguard Worker #include "../version.h"
62*6a54128fSAndroid Build Coastguard Worker #include "support/devname.h"
63*6a54128fSAndroid Build Coastguard Worker #include "support/nls-enable.h"
64*6a54128fSAndroid Build Coastguard Worker #include "fsck.h"
65*6a54128fSAndroid Build Coastguard Worker #include "blkid/blkid.h"
66*6a54128fSAndroid Build Coastguard Worker
67*6a54128fSAndroid Build Coastguard Worker #ifndef _PATH_MNTTAB
68*6a54128fSAndroid Build Coastguard Worker #define _PATH_MNTTAB "/etc/fstab"
69*6a54128fSAndroid Build Coastguard Worker #endif
70*6a54128fSAndroid Build Coastguard Worker
71*6a54128fSAndroid Build Coastguard Worker static const char *ignored_types[] = {
72*6a54128fSAndroid Build Coastguard Worker "ignore",
73*6a54128fSAndroid Build Coastguard Worker "iso9660",
74*6a54128fSAndroid Build Coastguard Worker "nfs",
75*6a54128fSAndroid Build Coastguard Worker "proc",
76*6a54128fSAndroid Build Coastguard Worker "sw",
77*6a54128fSAndroid Build Coastguard Worker "swap",
78*6a54128fSAndroid Build Coastguard Worker "tmpfs",
79*6a54128fSAndroid Build Coastguard Worker "devpts",
80*6a54128fSAndroid Build Coastguard Worker NULL
81*6a54128fSAndroid Build Coastguard Worker };
82*6a54128fSAndroid Build Coastguard Worker
83*6a54128fSAndroid Build Coastguard Worker static const char *really_wanted[] = {
84*6a54128fSAndroid Build Coastguard Worker "minix",
85*6a54128fSAndroid Build Coastguard Worker "ext2",
86*6a54128fSAndroid Build Coastguard Worker "ext3",
87*6a54128fSAndroid Build Coastguard Worker "ext4",
88*6a54128fSAndroid Build Coastguard Worker "ext4dev",
89*6a54128fSAndroid Build Coastguard Worker "jfs",
90*6a54128fSAndroid Build Coastguard Worker "reiserfs",
91*6a54128fSAndroid Build Coastguard Worker "xiafs",
92*6a54128fSAndroid Build Coastguard Worker "xfs",
93*6a54128fSAndroid Build Coastguard Worker NULL
94*6a54128fSAndroid Build Coastguard Worker };
95*6a54128fSAndroid Build Coastguard Worker
96*6a54128fSAndroid Build Coastguard Worker #define BASE_MD "/dev/md"
97*6a54128fSAndroid Build Coastguard Worker
98*6a54128fSAndroid Build Coastguard Worker /*
99*6a54128fSAndroid Build Coastguard Worker * Global variables for options
100*6a54128fSAndroid Build Coastguard Worker */
101*6a54128fSAndroid Build Coastguard Worker static char *devices[MAX_DEVICES];
102*6a54128fSAndroid Build Coastguard Worker static char *args[MAX_ARGS];
103*6a54128fSAndroid Build Coastguard Worker static int num_devices, num_args;
104*6a54128fSAndroid Build Coastguard Worker
105*6a54128fSAndroid Build Coastguard Worker static int verbose = 0;
106*6a54128fSAndroid Build Coastguard Worker static int doall = 0;
107*6a54128fSAndroid Build Coastguard Worker static int noexecute = 0;
108*6a54128fSAndroid Build Coastguard Worker static int serialize = 0;
109*6a54128fSAndroid Build Coastguard Worker static int skip_root = 0;
110*6a54128fSAndroid Build Coastguard Worker static int ignore_mounted = 0;
111*6a54128fSAndroid Build Coastguard Worker static int notitle = 0;
112*6a54128fSAndroid Build Coastguard Worker static int parallel_root = 0;
113*6a54128fSAndroid Build Coastguard Worker static int progress = 0;
114*6a54128fSAndroid Build Coastguard Worker static int progress_fd = 0;
115*6a54128fSAndroid Build Coastguard Worker static int force_all_parallel = 0;
116*6a54128fSAndroid Build Coastguard Worker static int num_running = 0;
117*6a54128fSAndroid Build Coastguard Worker static int max_running = 0;
118*6a54128fSAndroid Build Coastguard Worker static volatile int cancel_requested = 0;
119*6a54128fSAndroid Build Coastguard Worker static int kill_sent = 0;
120*6a54128fSAndroid Build Coastguard Worker static char *progname;
121*6a54128fSAndroid Build Coastguard Worker static char *fstype = NULL;
122*6a54128fSAndroid Build Coastguard Worker static struct fs_info *filesys_info = NULL, *filesys_last = NULL;
123*6a54128fSAndroid Build Coastguard Worker static struct fsck_instance *instance_list;
124*6a54128fSAndroid Build Coastguard Worker static const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
125*6a54128fSAndroid Build Coastguard Worker static char *fsck_path = 0;
126*6a54128fSAndroid Build Coastguard Worker static blkid_cache cache = NULL;
127*6a54128fSAndroid Build Coastguard Worker
string_copy(const char * s)128*6a54128fSAndroid Build Coastguard Worker static char *string_copy(const char *s)
129*6a54128fSAndroid Build Coastguard Worker {
130*6a54128fSAndroid Build Coastguard Worker char *ret;
131*6a54128fSAndroid Build Coastguard Worker
132*6a54128fSAndroid Build Coastguard Worker if (!s)
133*6a54128fSAndroid Build Coastguard Worker return 0;
134*6a54128fSAndroid Build Coastguard Worker ret = malloc(strlen(s)+1);
135*6a54128fSAndroid Build Coastguard Worker if (ret)
136*6a54128fSAndroid Build Coastguard Worker strcpy(ret, s);
137*6a54128fSAndroid Build Coastguard Worker return ret;
138*6a54128fSAndroid Build Coastguard Worker }
139*6a54128fSAndroid Build Coastguard Worker
string_to_int(const char * s)140*6a54128fSAndroid Build Coastguard Worker static int string_to_int(const char *s)
141*6a54128fSAndroid Build Coastguard Worker {
142*6a54128fSAndroid Build Coastguard Worker long l;
143*6a54128fSAndroid Build Coastguard Worker char *p;
144*6a54128fSAndroid Build Coastguard Worker
145*6a54128fSAndroid Build Coastguard Worker l = strtol(s, &p, 0);
146*6a54128fSAndroid Build Coastguard Worker if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX)
147*6a54128fSAndroid Build Coastguard Worker return -1;
148*6a54128fSAndroid Build Coastguard Worker else
149*6a54128fSAndroid Build Coastguard Worker return (int) l;
150*6a54128fSAndroid Build Coastguard Worker }
151*6a54128fSAndroid Build Coastguard Worker
152*6a54128fSAndroid Build Coastguard Worker static int ignore(struct fs_info *);
153*6a54128fSAndroid Build Coastguard Worker
skip_over_blank(char * cp)154*6a54128fSAndroid Build Coastguard Worker static char *skip_over_blank(char *cp)
155*6a54128fSAndroid Build Coastguard Worker {
156*6a54128fSAndroid Build Coastguard Worker while (*cp && isspace(*cp))
157*6a54128fSAndroid Build Coastguard Worker cp++;
158*6a54128fSAndroid Build Coastguard Worker return cp;
159*6a54128fSAndroid Build Coastguard Worker }
160*6a54128fSAndroid Build Coastguard Worker
skip_over_word(char * cp)161*6a54128fSAndroid Build Coastguard Worker static char *skip_over_word(char *cp)
162*6a54128fSAndroid Build Coastguard Worker {
163*6a54128fSAndroid Build Coastguard Worker while (*cp && !isspace(*cp))
164*6a54128fSAndroid Build Coastguard Worker cp++;
165*6a54128fSAndroid Build Coastguard Worker return cp;
166*6a54128fSAndroid Build Coastguard Worker }
167*6a54128fSAndroid Build Coastguard Worker
strip_line(char * line)168*6a54128fSAndroid Build Coastguard Worker static void strip_line(char *line)
169*6a54128fSAndroid Build Coastguard Worker {
170*6a54128fSAndroid Build Coastguard Worker char *p;
171*6a54128fSAndroid Build Coastguard Worker
172*6a54128fSAndroid Build Coastguard Worker while (*line) {
173*6a54128fSAndroid Build Coastguard Worker p = line + strlen(line) - 1;
174*6a54128fSAndroid Build Coastguard Worker if ((*p == '\n') || (*p == '\r'))
175*6a54128fSAndroid Build Coastguard Worker *p = 0;
176*6a54128fSAndroid Build Coastguard Worker else
177*6a54128fSAndroid Build Coastguard Worker break;
178*6a54128fSAndroid Build Coastguard Worker }
179*6a54128fSAndroid Build Coastguard Worker }
180*6a54128fSAndroid Build Coastguard Worker
parse_word(char ** buf)181*6a54128fSAndroid Build Coastguard Worker static char *parse_word(char **buf)
182*6a54128fSAndroid Build Coastguard Worker {
183*6a54128fSAndroid Build Coastguard Worker char *word, *next;
184*6a54128fSAndroid Build Coastguard Worker
185*6a54128fSAndroid Build Coastguard Worker word = *buf;
186*6a54128fSAndroid Build Coastguard Worker if (*word == 0)
187*6a54128fSAndroid Build Coastguard Worker return 0;
188*6a54128fSAndroid Build Coastguard Worker
189*6a54128fSAndroid Build Coastguard Worker word = skip_over_blank(word);
190*6a54128fSAndroid Build Coastguard Worker next = skip_over_word(word);
191*6a54128fSAndroid Build Coastguard Worker if (*next)
192*6a54128fSAndroid Build Coastguard Worker *next++ = 0;
193*6a54128fSAndroid Build Coastguard Worker *buf = next;
194*6a54128fSAndroid Build Coastguard Worker return word;
195*6a54128fSAndroid Build Coastguard Worker }
196*6a54128fSAndroid Build Coastguard Worker
parse_escape(char * word)197*6a54128fSAndroid Build Coastguard Worker static void parse_escape(char *word)
198*6a54128fSAndroid Build Coastguard Worker {
199*6a54128fSAndroid Build Coastguard Worker char *p, *q;
200*6a54128fSAndroid Build Coastguard Worker int ac, i;
201*6a54128fSAndroid Build Coastguard Worker
202*6a54128fSAndroid Build Coastguard Worker if (!word)
203*6a54128fSAndroid Build Coastguard Worker return;
204*6a54128fSAndroid Build Coastguard Worker
205*6a54128fSAndroid Build Coastguard Worker for (p = word, q = word; *p; p++, q++) {
206*6a54128fSAndroid Build Coastguard Worker *q = *p;
207*6a54128fSAndroid Build Coastguard Worker if (*p != '\\')
208*6a54128fSAndroid Build Coastguard Worker continue;
209*6a54128fSAndroid Build Coastguard Worker if (*++p == 0)
210*6a54128fSAndroid Build Coastguard Worker break;
211*6a54128fSAndroid Build Coastguard Worker if (*p == 't') {
212*6a54128fSAndroid Build Coastguard Worker *q = '\t';
213*6a54128fSAndroid Build Coastguard Worker continue;
214*6a54128fSAndroid Build Coastguard Worker }
215*6a54128fSAndroid Build Coastguard Worker if (*p == 'n') {
216*6a54128fSAndroid Build Coastguard Worker *q = '\n';
217*6a54128fSAndroid Build Coastguard Worker continue;
218*6a54128fSAndroid Build Coastguard Worker }
219*6a54128fSAndroid Build Coastguard Worker if (!isdigit(*p)) {
220*6a54128fSAndroid Build Coastguard Worker *q = *p;
221*6a54128fSAndroid Build Coastguard Worker continue;
222*6a54128fSAndroid Build Coastguard Worker }
223*6a54128fSAndroid Build Coastguard Worker ac = 0;
224*6a54128fSAndroid Build Coastguard Worker for (i = 0; i < 3; i++, p++) {
225*6a54128fSAndroid Build Coastguard Worker if (!isdigit(*p))
226*6a54128fSAndroid Build Coastguard Worker break;
227*6a54128fSAndroid Build Coastguard Worker ac = (ac * 8) + (*p - '0');
228*6a54128fSAndroid Build Coastguard Worker }
229*6a54128fSAndroid Build Coastguard Worker *q = ac;
230*6a54128fSAndroid Build Coastguard Worker p--;
231*6a54128fSAndroid Build Coastguard Worker }
232*6a54128fSAndroid Build Coastguard Worker *q = 0;
233*6a54128fSAndroid Build Coastguard Worker }
234*6a54128fSAndroid Build Coastguard Worker
free_instance(struct fsck_instance * i)235*6a54128fSAndroid Build Coastguard Worker static void free_instance(struct fsck_instance *i)
236*6a54128fSAndroid Build Coastguard Worker {
237*6a54128fSAndroid Build Coastguard Worker free(i->prog);
238*6a54128fSAndroid Build Coastguard Worker free(i->device);
239*6a54128fSAndroid Build Coastguard Worker free(i->base_device);
240*6a54128fSAndroid Build Coastguard Worker free(i);
241*6a54128fSAndroid Build Coastguard Worker return;
242*6a54128fSAndroid Build Coastguard Worker }
243*6a54128fSAndroid Build Coastguard Worker
create_fs_device(const char * device,const char * mntpnt,const char * type,const char * opts,int freq,int passno)244*6a54128fSAndroid Build Coastguard Worker static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
245*6a54128fSAndroid Build Coastguard Worker const char *type, const char *opts,
246*6a54128fSAndroid Build Coastguard Worker int freq, int passno)
247*6a54128fSAndroid Build Coastguard Worker {
248*6a54128fSAndroid Build Coastguard Worker struct fs_info *fs;
249*6a54128fSAndroid Build Coastguard Worker
250*6a54128fSAndroid Build Coastguard Worker if (!(fs = malloc(sizeof(struct fs_info))))
251*6a54128fSAndroid Build Coastguard Worker return NULL;
252*6a54128fSAndroid Build Coastguard Worker
253*6a54128fSAndroid Build Coastguard Worker fs->device = string_copy(device);
254*6a54128fSAndroid Build Coastguard Worker fs->mountpt = string_copy(mntpnt);
255*6a54128fSAndroid Build Coastguard Worker fs->type = string_copy(type);
256*6a54128fSAndroid Build Coastguard Worker fs->opts = string_copy(opts ? opts : "");
257*6a54128fSAndroid Build Coastguard Worker fs->freq = freq;
258*6a54128fSAndroid Build Coastguard Worker fs->passno = passno;
259*6a54128fSAndroid Build Coastguard Worker fs->flags = 0;
260*6a54128fSAndroid Build Coastguard Worker fs->next = NULL;
261*6a54128fSAndroid Build Coastguard Worker
262*6a54128fSAndroid Build Coastguard Worker if (!filesys_info)
263*6a54128fSAndroid Build Coastguard Worker filesys_info = fs;
264*6a54128fSAndroid Build Coastguard Worker else
265*6a54128fSAndroid Build Coastguard Worker filesys_last->next = fs;
266*6a54128fSAndroid Build Coastguard Worker filesys_last = fs;
267*6a54128fSAndroid Build Coastguard Worker
268*6a54128fSAndroid Build Coastguard Worker return fs;
269*6a54128fSAndroid Build Coastguard Worker }
270*6a54128fSAndroid Build Coastguard Worker
271*6a54128fSAndroid Build Coastguard Worker
272*6a54128fSAndroid Build Coastguard Worker
parse_fstab_line(char * line,struct fs_info ** ret_fs)273*6a54128fSAndroid Build Coastguard Worker static int parse_fstab_line(char *line, struct fs_info **ret_fs)
274*6a54128fSAndroid Build Coastguard Worker {
275*6a54128fSAndroid Build Coastguard Worker char *dev, *device, *mntpnt, *type, *opts, *freq, *passno, *cp;
276*6a54128fSAndroid Build Coastguard Worker struct fs_info *fs;
277*6a54128fSAndroid Build Coastguard Worker
278*6a54128fSAndroid Build Coastguard Worker *ret_fs = 0;
279*6a54128fSAndroid Build Coastguard Worker strip_line(line);
280*6a54128fSAndroid Build Coastguard Worker cp = line;
281*6a54128fSAndroid Build Coastguard Worker
282*6a54128fSAndroid Build Coastguard Worker device = parse_word(&cp);
283*6a54128fSAndroid Build Coastguard Worker if (!device || *device == '#')
284*6a54128fSAndroid Build Coastguard Worker return 0; /* Ignore blank lines and comments */
285*6a54128fSAndroid Build Coastguard Worker mntpnt = parse_word(&cp);
286*6a54128fSAndroid Build Coastguard Worker type = parse_word(&cp);
287*6a54128fSAndroid Build Coastguard Worker opts = parse_word(&cp);
288*6a54128fSAndroid Build Coastguard Worker freq = parse_word(&cp);
289*6a54128fSAndroid Build Coastguard Worker passno = parse_word(&cp);
290*6a54128fSAndroid Build Coastguard Worker
291*6a54128fSAndroid Build Coastguard Worker if (!mntpnt || !type)
292*6a54128fSAndroid Build Coastguard Worker return -1;
293*6a54128fSAndroid Build Coastguard Worker
294*6a54128fSAndroid Build Coastguard Worker parse_escape(device);
295*6a54128fSAndroid Build Coastguard Worker parse_escape(mntpnt);
296*6a54128fSAndroid Build Coastguard Worker parse_escape(type);
297*6a54128fSAndroid Build Coastguard Worker parse_escape(opts);
298*6a54128fSAndroid Build Coastguard Worker parse_escape(freq);
299*6a54128fSAndroid Build Coastguard Worker parse_escape(passno);
300*6a54128fSAndroid Build Coastguard Worker
301*6a54128fSAndroid Build Coastguard Worker dev = get_devname(cache, device, NULL);
302*6a54128fSAndroid Build Coastguard Worker if (dev)
303*6a54128fSAndroid Build Coastguard Worker device = dev;
304*6a54128fSAndroid Build Coastguard Worker
305*6a54128fSAndroid Build Coastguard Worker if (strchr(type, ','))
306*6a54128fSAndroid Build Coastguard Worker type = 0;
307*6a54128fSAndroid Build Coastguard Worker
308*6a54128fSAndroid Build Coastguard Worker fs = create_fs_device(device, mntpnt, type ? type : "auto", opts,
309*6a54128fSAndroid Build Coastguard Worker freq ? atoi(freq) : -1,
310*6a54128fSAndroid Build Coastguard Worker passno ? atoi(passno) : -1);
311*6a54128fSAndroid Build Coastguard Worker free(dev);
312*6a54128fSAndroid Build Coastguard Worker
313*6a54128fSAndroid Build Coastguard Worker if (!fs)
314*6a54128fSAndroid Build Coastguard Worker return -1;
315*6a54128fSAndroid Build Coastguard Worker *ret_fs = fs;
316*6a54128fSAndroid Build Coastguard Worker return 0;
317*6a54128fSAndroid Build Coastguard Worker }
318*6a54128fSAndroid Build Coastguard Worker
interpret_type(struct fs_info * fs)319*6a54128fSAndroid Build Coastguard Worker static void interpret_type(struct fs_info *fs)
320*6a54128fSAndroid Build Coastguard Worker {
321*6a54128fSAndroid Build Coastguard Worker char *t;
322*6a54128fSAndroid Build Coastguard Worker
323*6a54128fSAndroid Build Coastguard Worker if (strcmp(fs->type, "auto") != 0)
324*6a54128fSAndroid Build Coastguard Worker return;
325*6a54128fSAndroid Build Coastguard Worker t = blkid_get_tag_value(cache, "TYPE", fs->device);
326*6a54128fSAndroid Build Coastguard Worker if (t) {
327*6a54128fSAndroid Build Coastguard Worker free(fs->type);
328*6a54128fSAndroid Build Coastguard Worker fs->type = t;
329*6a54128fSAndroid Build Coastguard Worker }
330*6a54128fSAndroid Build Coastguard Worker }
331*6a54128fSAndroid Build Coastguard Worker
332*6a54128fSAndroid Build Coastguard Worker /*
333*6a54128fSAndroid Build Coastguard Worker * Load the filesystem database from /etc/fstab
334*6a54128fSAndroid Build Coastguard Worker */
load_fs_info(const char * filename)335*6a54128fSAndroid Build Coastguard Worker static void load_fs_info(const char *filename)
336*6a54128fSAndroid Build Coastguard Worker {
337*6a54128fSAndroid Build Coastguard Worker FILE *f;
338*6a54128fSAndroid Build Coastguard Worker char buf[1024];
339*6a54128fSAndroid Build Coastguard Worker int lineno = 0;
340*6a54128fSAndroid Build Coastguard Worker int old_fstab = 1;
341*6a54128fSAndroid Build Coastguard Worker struct fs_info *fs;
342*6a54128fSAndroid Build Coastguard Worker
343*6a54128fSAndroid Build Coastguard Worker if ((f = fopen(filename, "r")) == NULL) {
344*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("WARNING: couldn't open %s: %s\n"),
345*6a54128fSAndroid Build Coastguard Worker filename, strerror(errno));
346*6a54128fSAndroid Build Coastguard Worker return;
347*6a54128fSAndroid Build Coastguard Worker }
348*6a54128fSAndroid Build Coastguard Worker while (!feof(f)) {
349*6a54128fSAndroid Build Coastguard Worker lineno++;
350*6a54128fSAndroid Build Coastguard Worker if (!fgets(buf, sizeof(buf), f))
351*6a54128fSAndroid Build Coastguard Worker break;
352*6a54128fSAndroid Build Coastguard Worker buf[sizeof(buf)-1] = 0;
353*6a54128fSAndroid Build Coastguard Worker if (parse_fstab_line(buf, &fs) < 0) {
354*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("WARNING: bad format "
355*6a54128fSAndroid Build Coastguard Worker "on line %d of %s\n"), lineno, filename);
356*6a54128fSAndroid Build Coastguard Worker continue;
357*6a54128fSAndroid Build Coastguard Worker }
358*6a54128fSAndroid Build Coastguard Worker if (!fs)
359*6a54128fSAndroid Build Coastguard Worker continue;
360*6a54128fSAndroid Build Coastguard Worker if (fs->passno < 0)
361*6a54128fSAndroid Build Coastguard Worker fs->passno = 0;
362*6a54128fSAndroid Build Coastguard Worker else
363*6a54128fSAndroid Build Coastguard Worker old_fstab = 0;
364*6a54128fSAndroid Build Coastguard Worker }
365*6a54128fSAndroid Build Coastguard Worker
366*6a54128fSAndroid Build Coastguard Worker fclose(f);
367*6a54128fSAndroid Build Coastguard Worker
368*6a54128fSAndroid Build Coastguard Worker if (old_fstab && filesys_info) {
369*6a54128fSAndroid Build Coastguard Worker fputs("\007\007\007", stderr);
370*6a54128fSAndroid Build Coastguard Worker fputs(_(
371*6a54128fSAndroid Build Coastguard Worker "WARNING: Your /etc/fstab does not contain the fsck passno\n"
372*6a54128fSAndroid Build Coastguard Worker " field. I will kludge around things for you, but you\n"
373*6a54128fSAndroid Build Coastguard Worker " should fix your /etc/fstab file as soon as you can.\n\n"), stderr);
374*6a54128fSAndroid Build Coastguard Worker
375*6a54128fSAndroid Build Coastguard Worker for (fs = filesys_info; fs; fs = fs->next) {
376*6a54128fSAndroid Build Coastguard Worker fs->passno = 1;
377*6a54128fSAndroid Build Coastguard Worker }
378*6a54128fSAndroid Build Coastguard Worker }
379*6a54128fSAndroid Build Coastguard Worker }
380*6a54128fSAndroid Build Coastguard Worker
381*6a54128fSAndroid Build Coastguard Worker /* Lookup filesys in /etc/fstab and return the corresponding entry. */
lookup(char * filesys)382*6a54128fSAndroid Build Coastguard Worker static struct fs_info *lookup(char *filesys)
383*6a54128fSAndroid Build Coastguard Worker {
384*6a54128fSAndroid Build Coastguard Worker struct fs_info *fs;
385*6a54128fSAndroid Build Coastguard Worker
386*6a54128fSAndroid Build Coastguard Worker /* No filesys name given. */
387*6a54128fSAndroid Build Coastguard Worker if (filesys == NULL)
388*6a54128fSAndroid Build Coastguard Worker return NULL;
389*6a54128fSAndroid Build Coastguard Worker
390*6a54128fSAndroid Build Coastguard Worker for (fs = filesys_info; fs; fs = fs->next) {
391*6a54128fSAndroid Build Coastguard Worker if (!strcmp(filesys, fs->device) ||
392*6a54128fSAndroid Build Coastguard Worker (fs->mountpt && !strcmp(filesys, fs->mountpt)))
393*6a54128fSAndroid Build Coastguard Worker break;
394*6a54128fSAndroid Build Coastguard Worker }
395*6a54128fSAndroid Build Coastguard Worker
396*6a54128fSAndroid Build Coastguard Worker return fs;
397*6a54128fSAndroid Build Coastguard Worker }
398*6a54128fSAndroid Build Coastguard Worker
399*6a54128fSAndroid Build Coastguard Worker /* Find fsck program for a given fs type. */
find_fsck(char * type)400*6a54128fSAndroid Build Coastguard Worker static char *find_fsck(char *type)
401*6a54128fSAndroid Build Coastguard Worker {
402*6a54128fSAndroid Build Coastguard Worker char *s;
403*6a54128fSAndroid Build Coastguard Worker const char *tpl;
404*6a54128fSAndroid Build Coastguard Worker static char prog[256];
405*6a54128fSAndroid Build Coastguard Worker char *p = string_copy(fsck_path);
406*6a54128fSAndroid Build Coastguard Worker struct stat st;
407*6a54128fSAndroid Build Coastguard Worker
408*6a54128fSAndroid Build Coastguard Worker /* Are we looking for a program or just a type? */
409*6a54128fSAndroid Build Coastguard Worker tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
410*6a54128fSAndroid Build Coastguard Worker
411*6a54128fSAndroid Build Coastguard Worker for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
412*6a54128fSAndroid Build Coastguard Worker int len = snprintf(prog, sizeof(prog), tpl, s, type);
413*6a54128fSAndroid Build Coastguard Worker
414*6a54128fSAndroid Build Coastguard Worker if ((len < 0) || (len >= (int) sizeof(prog)))
415*6a54128fSAndroid Build Coastguard Worker continue;
416*6a54128fSAndroid Build Coastguard Worker if (stat(prog, &st) == 0)
417*6a54128fSAndroid Build Coastguard Worker break;
418*6a54128fSAndroid Build Coastguard Worker }
419*6a54128fSAndroid Build Coastguard Worker free(p);
420*6a54128fSAndroid Build Coastguard Worker return(s ? prog : NULL);
421*6a54128fSAndroid Build Coastguard Worker }
422*6a54128fSAndroid Build Coastguard Worker
progress_active(NOARGS)423*6a54128fSAndroid Build Coastguard Worker static int progress_active(NOARGS)
424*6a54128fSAndroid Build Coastguard Worker {
425*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst;
426*6a54128fSAndroid Build Coastguard Worker
427*6a54128fSAndroid Build Coastguard Worker for (inst = instance_list; inst; inst = inst->next) {
428*6a54128fSAndroid Build Coastguard Worker if (inst->flags & FLAG_DONE)
429*6a54128fSAndroid Build Coastguard Worker continue;
430*6a54128fSAndroid Build Coastguard Worker if (inst->flags & FLAG_PROGRESS)
431*6a54128fSAndroid Build Coastguard Worker return 1;
432*6a54128fSAndroid Build Coastguard Worker }
433*6a54128fSAndroid Build Coastguard Worker return 0;
434*6a54128fSAndroid Build Coastguard Worker }
435*6a54128fSAndroid Build Coastguard Worker
436*6a54128fSAndroid Build Coastguard Worker /*
437*6a54128fSAndroid Build Coastguard Worker * Execute a particular fsck program, and link it into the list of
438*6a54128fSAndroid Build Coastguard Worker * child processes we are waiting for.
439*6a54128fSAndroid Build Coastguard Worker */
execute(const char * type,const char * device,const char * mntpt,int interactive)440*6a54128fSAndroid Build Coastguard Worker static int execute(const char *type, const char *device, const char *mntpt,
441*6a54128fSAndroid Build Coastguard Worker int interactive)
442*6a54128fSAndroid Build Coastguard Worker {
443*6a54128fSAndroid Build Coastguard Worker char *s, *argv[80], prog[256];
444*6a54128fSAndroid Build Coastguard Worker int argc, i, len;
445*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst, *p;
446*6a54128fSAndroid Build Coastguard Worker pid_t pid;
447*6a54128fSAndroid Build Coastguard Worker
448*6a54128fSAndroid Build Coastguard Worker len = snprintf(prog, sizeof(prog), "fsck.%s", type);
449*6a54128fSAndroid Build Coastguard Worker if ((len < 0) || (len >= (int) sizeof(prog)))
450*6a54128fSAndroid Build Coastguard Worker return EINVAL;
451*6a54128fSAndroid Build Coastguard Worker
452*6a54128fSAndroid Build Coastguard Worker inst = malloc(sizeof(struct fsck_instance));
453*6a54128fSAndroid Build Coastguard Worker if (!inst)
454*6a54128fSAndroid Build Coastguard Worker return ENOMEM;
455*6a54128fSAndroid Build Coastguard Worker memset(inst, 0, sizeof(struct fsck_instance));
456*6a54128fSAndroid Build Coastguard Worker
457*6a54128fSAndroid Build Coastguard Worker argv[0] = string_copy(prog);
458*6a54128fSAndroid Build Coastguard Worker argc = 1;
459*6a54128fSAndroid Build Coastguard Worker
460*6a54128fSAndroid Build Coastguard Worker for (i=0; i <num_args; i++)
461*6a54128fSAndroid Build Coastguard Worker argv[argc++] = string_copy(args[i]);
462*6a54128fSAndroid Build Coastguard Worker
463*6a54128fSAndroid Build Coastguard Worker if (progress) {
464*6a54128fSAndroid Build Coastguard Worker if ((strcmp(type, "ext2") == 0) ||
465*6a54128fSAndroid Build Coastguard Worker (strcmp(type, "ext3") == 0) ||
466*6a54128fSAndroid Build Coastguard Worker (strcmp(type, "ext4") == 0) ||
467*6a54128fSAndroid Build Coastguard Worker (strcmp(type, "ext4dev") == 0)) {
468*6a54128fSAndroid Build Coastguard Worker char tmp[80];
469*6a54128fSAndroid Build Coastguard Worker
470*6a54128fSAndroid Build Coastguard Worker tmp[0] = 0;
471*6a54128fSAndroid Build Coastguard Worker if (!progress_active()) {
472*6a54128fSAndroid Build Coastguard Worker snprintf(tmp, 80, "-C%d", progress_fd);
473*6a54128fSAndroid Build Coastguard Worker inst->flags |= FLAG_PROGRESS;
474*6a54128fSAndroid Build Coastguard Worker } else if (progress_fd)
475*6a54128fSAndroid Build Coastguard Worker snprintf(tmp, 80, "-C%d", progress_fd * -1);
476*6a54128fSAndroid Build Coastguard Worker if (tmp[0])
477*6a54128fSAndroid Build Coastguard Worker argv[argc++] = string_copy(tmp);
478*6a54128fSAndroid Build Coastguard Worker }
479*6a54128fSAndroid Build Coastguard Worker }
480*6a54128fSAndroid Build Coastguard Worker
481*6a54128fSAndroid Build Coastguard Worker argv[argc++] = string_copy(device);
482*6a54128fSAndroid Build Coastguard Worker argv[argc] = 0;
483*6a54128fSAndroid Build Coastguard Worker
484*6a54128fSAndroid Build Coastguard Worker s = find_fsck(prog);
485*6a54128fSAndroid Build Coastguard Worker if (s == NULL) {
486*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("fsck: %s: not found\n"), prog);
487*6a54128fSAndroid Build Coastguard Worker free(inst);
488*6a54128fSAndroid Build Coastguard Worker return ENOENT;
489*6a54128fSAndroid Build Coastguard Worker }
490*6a54128fSAndroid Build Coastguard Worker
491*6a54128fSAndroid Build Coastguard Worker if (verbose || noexecute) {
492*6a54128fSAndroid Build Coastguard Worker printf("[%s (%d) -- %s] ", s, num_running,
493*6a54128fSAndroid Build Coastguard Worker mntpt ? mntpt : device);
494*6a54128fSAndroid Build Coastguard Worker for (i=0; i < argc; i++)
495*6a54128fSAndroid Build Coastguard Worker printf("%s ", argv[i]);
496*6a54128fSAndroid Build Coastguard Worker printf("\n");
497*6a54128fSAndroid Build Coastguard Worker }
498*6a54128fSAndroid Build Coastguard Worker
499*6a54128fSAndroid Build Coastguard Worker /* Fork and execute the correct program. */
500*6a54128fSAndroid Build Coastguard Worker if (noexecute)
501*6a54128fSAndroid Build Coastguard Worker pid = -1;
502*6a54128fSAndroid Build Coastguard Worker else if ((pid = fork()) < 0) {
503*6a54128fSAndroid Build Coastguard Worker perror("fork");
504*6a54128fSAndroid Build Coastguard Worker free(inst);
505*6a54128fSAndroid Build Coastguard Worker return errno;
506*6a54128fSAndroid Build Coastguard Worker } else if (pid == 0) {
507*6a54128fSAndroid Build Coastguard Worker if (!interactive)
508*6a54128fSAndroid Build Coastguard Worker close(0);
509*6a54128fSAndroid Build Coastguard Worker (void) execv(s, argv);
510*6a54128fSAndroid Build Coastguard Worker perror(argv[0]);
511*6a54128fSAndroid Build Coastguard Worker free(inst);
512*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
513*6a54128fSAndroid Build Coastguard Worker }
514*6a54128fSAndroid Build Coastguard Worker
515*6a54128fSAndroid Build Coastguard Worker for (i=0; i < argc; i++)
516*6a54128fSAndroid Build Coastguard Worker free(argv[i]);
517*6a54128fSAndroid Build Coastguard Worker
518*6a54128fSAndroid Build Coastguard Worker inst->pid = pid;
519*6a54128fSAndroid Build Coastguard Worker inst->prog = string_copy(prog);
520*6a54128fSAndroid Build Coastguard Worker inst->type = string_copy(type);
521*6a54128fSAndroid Build Coastguard Worker inst->device = string_copy(device);
522*6a54128fSAndroid Build Coastguard Worker inst->base_device = base_device(device);
523*6a54128fSAndroid Build Coastguard Worker inst->start_time = time(0);
524*6a54128fSAndroid Build Coastguard Worker inst->next = NULL;
525*6a54128fSAndroid Build Coastguard Worker
526*6a54128fSAndroid Build Coastguard Worker /*
527*6a54128fSAndroid Build Coastguard Worker * Find the end of the list, so we add the instance on at the end.
528*6a54128fSAndroid Build Coastguard Worker */
529*6a54128fSAndroid Build Coastguard Worker for (p = instance_list; p && p->next; p = p->next);
530*6a54128fSAndroid Build Coastguard Worker
531*6a54128fSAndroid Build Coastguard Worker if (p)
532*6a54128fSAndroid Build Coastguard Worker p->next = inst;
533*6a54128fSAndroid Build Coastguard Worker else
534*6a54128fSAndroid Build Coastguard Worker instance_list = inst;
535*6a54128fSAndroid Build Coastguard Worker
536*6a54128fSAndroid Build Coastguard Worker return 0;
537*6a54128fSAndroid Build Coastguard Worker }
538*6a54128fSAndroid Build Coastguard Worker
539*6a54128fSAndroid Build Coastguard Worker /*
540*6a54128fSAndroid Build Coastguard Worker * Send a signal to all outstanding fsck child processes
541*6a54128fSAndroid Build Coastguard Worker */
kill_all(int signum)542*6a54128fSAndroid Build Coastguard Worker static int kill_all(int signum)
543*6a54128fSAndroid Build Coastguard Worker {
544*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst;
545*6a54128fSAndroid Build Coastguard Worker int n = 0;
546*6a54128fSAndroid Build Coastguard Worker
547*6a54128fSAndroid Build Coastguard Worker for (inst = instance_list; inst; inst = inst->next) {
548*6a54128fSAndroid Build Coastguard Worker if (inst->flags & FLAG_DONE)
549*6a54128fSAndroid Build Coastguard Worker continue;
550*6a54128fSAndroid Build Coastguard Worker if (inst->pid <= 0)
551*6a54128fSAndroid Build Coastguard Worker continue;
552*6a54128fSAndroid Build Coastguard Worker kill(inst->pid, signum);
553*6a54128fSAndroid Build Coastguard Worker n++;
554*6a54128fSAndroid Build Coastguard Worker }
555*6a54128fSAndroid Build Coastguard Worker return n;
556*6a54128fSAndroid Build Coastguard Worker }
557*6a54128fSAndroid Build Coastguard Worker
558*6a54128fSAndroid Build Coastguard Worker /*
559*6a54128fSAndroid Build Coastguard Worker * Wait for one child process to exit; when it does, unlink it from
560*6a54128fSAndroid Build Coastguard Worker * the list of executing child processes, and return it.
561*6a54128fSAndroid Build Coastguard Worker */
wait_one(int flags)562*6a54128fSAndroid Build Coastguard Worker static struct fsck_instance *wait_one(int flags)
563*6a54128fSAndroid Build Coastguard Worker {
564*6a54128fSAndroid Build Coastguard Worker int status;
565*6a54128fSAndroid Build Coastguard Worker int sig;
566*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst, *inst2, *prev;
567*6a54128fSAndroid Build Coastguard Worker pid_t pid;
568*6a54128fSAndroid Build Coastguard Worker
569*6a54128fSAndroid Build Coastguard Worker if (!instance_list)
570*6a54128fSAndroid Build Coastguard Worker return NULL;
571*6a54128fSAndroid Build Coastguard Worker
572*6a54128fSAndroid Build Coastguard Worker if (noexecute) {
573*6a54128fSAndroid Build Coastguard Worker inst = instance_list;
574*6a54128fSAndroid Build Coastguard Worker prev = 0;
575*6a54128fSAndroid Build Coastguard Worker #ifdef RANDOM_DEBUG
576*6a54128fSAndroid Build Coastguard Worker while (inst->next && (random() & 1)) {
577*6a54128fSAndroid Build Coastguard Worker prev = inst;
578*6a54128fSAndroid Build Coastguard Worker inst = inst->next;
579*6a54128fSAndroid Build Coastguard Worker }
580*6a54128fSAndroid Build Coastguard Worker #endif
581*6a54128fSAndroid Build Coastguard Worker inst->exit_status = 0;
582*6a54128fSAndroid Build Coastguard Worker goto ret_inst;
583*6a54128fSAndroid Build Coastguard Worker }
584*6a54128fSAndroid Build Coastguard Worker
585*6a54128fSAndroid Build Coastguard Worker /*
586*6a54128fSAndroid Build Coastguard Worker * gcc -Wall fails saving throw against stupidity
587*6a54128fSAndroid Build Coastguard Worker * (inst and prev are thought to be uninitialized variables)
588*6a54128fSAndroid Build Coastguard Worker */
589*6a54128fSAndroid Build Coastguard Worker inst = prev = NULL;
590*6a54128fSAndroid Build Coastguard Worker
591*6a54128fSAndroid Build Coastguard Worker do {
592*6a54128fSAndroid Build Coastguard Worker pid = waitpid(-1, &status, flags);
593*6a54128fSAndroid Build Coastguard Worker if (cancel_requested && !kill_sent) {
594*6a54128fSAndroid Build Coastguard Worker kill_all(SIGTERM);
595*6a54128fSAndroid Build Coastguard Worker kill_sent++;
596*6a54128fSAndroid Build Coastguard Worker }
597*6a54128fSAndroid Build Coastguard Worker if ((pid == 0) && (flags & WNOHANG))
598*6a54128fSAndroid Build Coastguard Worker return NULL;
599*6a54128fSAndroid Build Coastguard Worker if (pid < 0) {
600*6a54128fSAndroid Build Coastguard Worker if ((errno == EINTR) || (errno == EAGAIN))
601*6a54128fSAndroid Build Coastguard Worker continue;
602*6a54128fSAndroid Build Coastguard Worker if (errno == ECHILD) {
603*6a54128fSAndroid Build Coastguard Worker fprintf(stderr,
604*6a54128fSAndroid Build Coastguard Worker _("%s: wait: No more child process?!?\n"),
605*6a54128fSAndroid Build Coastguard Worker progname);
606*6a54128fSAndroid Build Coastguard Worker return NULL;
607*6a54128fSAndroid Build Coastguard Worker }
608*6a54128fSAndroid Build Coastguard Worker perror("wait");
609*6a54128fSAndroid Build Coastguard Worker continue;
610*6a54128fSAndroid Build Coastguard Worker }
611*6a54128fSAndroid Build Coastguard Worker for (prev = 0, inst = instance_list;
612*6a54128fSAndroid Build Coastguard Worker inst;
613*6a54128fSAndroid Build Coastguard Worker prev = inst, inst = inst->next) {
614*6a54128fSAndroid Build Coastguard Worker if (inst->pid == pid)
615*6a54128fSAndroid Build Coastguard Worker break;
616*6a54128fSAndroid Build Coastguard Worker }
617*6a54128fSAndroid Build Coastguard Worker } while (!inst);
618*6a54128fSAndroid Build Coastguard Worker
619*6a54128fSAndroid Build Coastguard Worker if (WIFEXITED(status))
620*6a54128fSAndroid Build Coastguard Worker status = WEXITSTATUS(status);
621*6a54128fSAndroid Build Coastguard Worker else if (WIFSIGNALED(status)) {
622*6a54128fSAndroid Build Coastguard Worker sig = WTERMSIG(status);
623*6a54128fSAndroid Build Coastguard Worker if (sig == SIGINT) {
624*6a54128fSAndroid Build Coastguard Worker status = EXIT_UNCORRECTED;
625*6a54128fSAndroid Build Coastguard Worker } else {
626*6a54128fSAndroid Build Coastguard Worker printf(_("Warning... %s for device %s exited "
627*6a54128fSAndroid Build Coastguard Worker "with signal %d.\n"),
628*6a54128fSAndroid Build Coastguard Worker inst->prog, inst->device, sig);
629*6a54128fSAndroid Build Coastguard Worker status = EXIT_ERROR;
630*6a54128fSAndroid Build Coastguard Worker }
631*6a54128fSAndroid Build Coastguard Worker } else {
632*6a54128fSAndroid Build Coastguard Worker printf(_("%s %s: status is %x, should never happen.\n"),
633*6a54128fSAndroid Build Coastguard Worker inst->prog, inst->device, status);
634*6a54128fSAndroid Build Coastguard Worker status = EXIT_ERROR;
635*6a54128fSAndroid Build Coastguard Worker }
636*6a54128fSAndroid Build Coastguard Worker inst->exit_status = status;
637*6a54128fSAndroid Build Coastguard Worker inst->flags |= FLAG_DONE;
638*6a54128fSAndroid Build Coastguard Worker if (progress && (inst->flags & FLAG_PROGRESS) &&
639*6a54128fSAndroid Build Coastguard Worker !progress_active()) {
640*6a54128fSAndroid Build Coastguard Worker for (inst2 = instance_list; inst2; inst2 = inst2->next) {
641*6a54128fSAndroid Build Coastguard Worker if (inst2->flags & FLAG_DONE)
642*6a54128fSAndroid Build Coastguard Worker continue;
643*6a54128fSAndroid Build Coastguard Worker if (strcmp(inst2->type, "ext2") &&
644*6a54128fSAndroid Build Coastguard Worker strcmp(inst2->type, "ext3") &&
645*6a54128fSAndroid Build Coastguard Worker strcmp(inst2->type, "ext4") &&
646*6a54128fSAndroid Build Coastguard Worker strcmp(inst2->type, "ext4dev"))
647*6a54128fSAndroid Build Coastguard Worker continue;
648*6a54128fSAndroid Build Coastguard Worker /*
649*6a54128fSAndroid Build Coastguard Worker * If we've just started the fsck, wait a tiny
650*6a54128fSAndroid Build Coastguard Worker * bit before sending the kill, to give it
651*6a54128fSAndroid Build Coastguard Worker * time to set up the signal handler
652*6a54128fSAndroid Build Coastguard Worker */
653*6a54128fSAndroid Build Coastguard Worker if (inst2->start_time < time(0)+2) {
654*6a54128fSAndroid Build Coastguard Worker if (fork() == 0) {
655*6a54128fSAndroid Build Coastguard Worker sleep(1);
656*6a54128fSAndroid Build Coastguard Worker kill(inst2->pid, SIGUSR1);
657*6a54128fSAndroid Build Coastguard Worker exit(0);
658*6a54128fSAndroid Build Coastguard Worker }
659*6a54128fSAndroid Build Coastguard Worker } else
660*6a54128fSAndroid Build Coastguard Worker kill(inst2->pid, SIGUSR1);
661*6a54128fSAndroid Build Coastguard Worker inst2->flags |= FLAG_PROGRESS;
662*6a54128fSAndroid Build Coastguard Worker break;
663*6a54128fSAndroid Build Coastguard Worker }
664*6a54128fSAndroid Build Coastguard Worker }
665*6a54128fSAndroid Build Coastguard Worker ret_inst:
666*6a54128fSAndroid Build Coastguard Worker if (prev)
667*6a54128fSAndroid Build Coastguard Worker prev->next = inst->next;
668*6a54128fSAndroid Build Coastguard Worker else
669*6a54128fSAndroid Build Coastguard Worker instance_list = inst->next;
670*6a54128fSAndroid Build Coastguard Worker if (verbose > 1)
671*6a54128fSAndroid Build Coastguard Worker printf(_("Finished with %s (exit status %d)\n"),
672*6a54128fSAndroid Build Coastguard Worker inst->device, inst->exit_status);
673*6a54128fSAndroid Build Coastguard Worker num_running--;
674*6a54128fSAndroid Build Coastguard Worker return inst;
675*6a54128fSAndroid Build Coastguard Worker }
676*6a54128fSAndroid Build Coastguard Worker
677*6a54128fSAndroid Build Coastguard Worker #define FLAG_WAIT_ALL 0
678*6a54128fSAndroid Build Coastguard Worker #define FLAG_WAIT_ATLEAST_ONE 1
679*6a54128fSAndroid Build Coastguard Worker /*
680*6a54128fSAndroid Build Coastguard Worker * Wait until all executing child processes have exited; return the
681*6a54128fSAndroid Build Coastguard Worker * logical OR of all of their exit code values.
682*6a54128fSAndroid Build Coastguard Worker */
wait_many(int flags)683*6a54128fSAndroid Build Coastguard Worker static int wait_many(int flags)
684*6a54128fSAndroid Build Coastguard Worker {
685*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst;
686*6a54128fSAndroid Build Coastguard Worker int global_status = 0;
687*6a54128fSAndroid Build Coastguard Worker int wait_flags = 0;
688*6a54128fSAndroid Build Coastguard Worker
689*6a54128fSAndroid Build Coastguard Worker while ((inst = wait_one(wait_flags))) {
690*6a54128fSAndroid Build Coastguard Worker global_status |= inst->exit_status;
691*6a54128fSAndroid Build Coastguard Worker free_instance(inst);
692*6a54128fSAndroid Build Coastguard Worker #ifdef RANDOM_DEBUG
693*6a54128fSAndroid Build Coastguard Worker if (noexecute && (flags & WNOHANG) && !(random() % 3))
694*6a54128fSAndroid Build Coastguard Worker break;
695*6a54128fSAndroid Build Coastguard Worker #endif
696*6a54128fSAndroid Build Coastguard Worker if (flags & FLAG_WAIT_ATLEAST_ONE)
697*6a54128fSAndroid Build Coastguard Worker wait_flags = WNOHANG;
698*6a54128fSAndroid Build Coastguard Worker }
699*6a54128fSAndroid Build Coastguard Worker return global_status;
700*6a54128fSAndroid Build Coastguard Worker }
701*6a54128fSAndroid Build Coastguard Worker
702*6a54128fSAndroid Build Coastguard Worker /*
703*6a54128fSAndroid Build Coastguard Worker * Run the fsck program on a particular device
704*6a54128fSAndroid Build Coastguard Worker *
705*6a54128fSAndroid Build Coastguard Worker * If the type is specified using -t, and it isn't prefixed with "no"
706*6a54128fSAndroid Build Coastguard Worker * (as in "noext2") and only one filesystem type is specified, then
707*6a54128fSAndroid Build Coastguard Worker * use that type regardless of what is specified in /etc/fstab.
708*6a54128fSAndroid Build Coastguard Worker *
709*6a54128fSAndroid Build Coastguard Worker * If the type isn't specified by the user, then use either the type
710*6a54128fSAndroid Build Coastguard Worker * specified in /etc/fstab, or DEFAULT_FSTYPE.
711*6a54128fSAndroid Build Coastguard Worker */
fsck_device(struct fs_info * fs,int interactive)712*6a54128fSAndroid Build Coastguard Worker static void fsck_device(struct fs_info *fs, int interactive)
713*6a54128fSAndroid Build Coastguard Worker {
714*6a54128fSAndroid Build Coastguard Worker const char *type;
715*6a54128fSAndroid Build Coastguard Worker int retval;
716*6a54128fSAndroid Build Coastguard Worker
717*6a54128fSAndroid Build Coastguard Worker interpret_type(fs);
718*6a54128fSAndroid Build Coastguard Worker
719*6a54128fSAndroid Build Coastguard Worker if (strcmp(fs->type, "auto") != 0)
720*6a54128fSAndroid Build Coastguard Worker type = fs->type;
721*6a54128fSAndroid Build Coastguard Worker else if (fstype && strncmp(fstype, "no", 2) &&
722*6a54128fSAndroid Build Coastguard Worker strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) &&
723*6a54128fSAndroid Build Coastguard Worker !strchr(fstype, ','))
724*6a54128fSAndroid Build Coastguard Worker type = fstype;
725*6a54128fSAndroid Build Coastguard Worker else
726*6a54128fSAndroid Build Coastguard Worker type = DEFAULT_FSTYPE;
727*6a54128fSAndroid Build Coastguard Worker
728*6a54128fSAndroid Build Coastguard Worker num_running++;
729*6a54128fSAndroid Build Coastguard Worker retval = execute(type, fs->device, fs->mountpt, interactive);
730*6a54128fSAndroid Build Coastguard Worker if (retval) {
731*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("%s: Error %d while executing fsck.%s "
732*6a54128fSAndroid Build Coastguard Worker "for %s\n"), progname, retval, type, fs->device);
733*6a54128fSAndroid Build Coastguard Worker num_running--;
734*6a54128fSAndroid Build Coastguard Worker }
735*6a54128fSAndroid Build Coastguard Worker }
736*6a54128fSAndroid Build Coastguard Worker
737*6a54128fSAndroid Build Coastguard Worker
738*6a54128fSAndroid Build Coastguard Worker /*
739*6a54128fSAndroid Build Coastguard Worker * Deal with the fsck -t argument.
740*6a54128fSAndroid Build Coastguard Worker */
741*6a54128fSAndroid Build Coastguard Worker static struct fs_type_compile {
742*6a54128fSAndroid Build Coastguard Worker char **list;
743*6a54128fSAndroid Build Coastguard Worker int *type;
744*6a54128fSAndroid Build Coastguard Worker int negate;
745*6a54128fSAndroid Build Coastguard Worker } fs_type_compiled;
746*6a54128fSAndroid Build Coastguard Worker
747*6a54128fSAndroid Build Coastguard Worker #define FS_TYPE_NORMAL 0
748*6a54128fSAndroid Build Coastguard Worker #define FS_TYPE_OPT 1
749*6a54128fSAndroid Build Coastguard Worker #define FS_TYPE_NEGOPT 2
750*6a54128fSAndroid Build Coastguard Worker
751*6a54128fSAndroid Build Coastguard Worker static const char *fs_type_syntax_error =
752*6a54128fSAndroid Build Coastguard Worker N_("Either all or none of the filesystem types passed to -t must be prefixed\n"
753*6a54128fSAndroid Build Coastguard Worker "with 'no' or '!'.\n");
754*6a54128fSAndroid Build Coastguard Worker
compile_fs_type(char * fs_type,struct fs_type_compile * cmp)755*6a54128fSAndroid Build Coastguard Worker static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
756*6a54128fSAndroid Build Coastguard Worker {
757*6a54128fSAndroid Build Coastguard Worker char *cp, *list, *s;
758*6a54128fSAndroid Build Coastguard Worker int num = 2;
759*6a54128fSAndroid Build Coastguard Worker int negate, first_negate = 1;
760*6a54128fSAndroid Build Coastguard Worker
761*6a54128fSAndroid Build Coastguard Worker if (fs_type) {
762*6a54128fSAndroid Build Coastguard Worker for (cp=fs_type; *cp; cp++) {
763*6a54128fSAndroid Build Coastguard Worker if (*cp == ',')
764*6a54128fSAndroid Build Coastguard Worker num++;
765*6a54128fSAndroid Build Coastguard Worker }
766*6a54128fSAndroid Build Coastguard Worker }
767*6a54128fSAndroid Build Coastguard Worker
768*6a54128fSAndroid Build Coastguard Worker cmp->list = malloc(num * sizeof(char *));
769*6a54128fSAndroid Build Coastguard Worker cmp->type = malloc(num * sizeof(int));
770*6a54128fSAndroid Build Coastguard Worker if (!cmp->list || !cmp->type) {
771*6a54128fSAndroid Build Coastguard Worker fputs(_("Couldn't allocate memory for filesystem types\n"),
772*6a54128fSAndroid Build Coastguard Worker stderr);
773*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
774*6a54128fSAndroid Build Coastguard Worker }
775*6a54128fSAndroid Build Coastguard Worker memset(cmp->list, 0, num * sizeof(char *));
776*6a54128fSAndroid Build Coastguard Worker memset(cmp->type, 0, num * sizeof(int));
777*6a54128fSAndroid Build Coastguard Worker cmp->negate = 0;
778*6a54128fSAndroid Build Coastguard Worker
779*6a54128fSAndroid Build Coastguard Worker if (!fs_type)
780*6a54128fSAndroid Build Coastguard Worker return;
781*6a54128fSAndroid Build Coastguard Worker
782*6a54128fSAndroid Build Coastguard Worker list = string_copy(fs_type);
783*6a54128fSAndroid Build Coastguard Worker num = 0;
784*6a54128fSAndroid Build Coastguard Worker s = strtok(list, ",");
785*6a54128fSAndroid Build Coastguard Worker while(s) {
786*6a54128fSAndroid Build Coastguard Worker negate = 0;
787*6a54128fSAndroid Build Coastguard Worker if (strncmp(s, "no", 2) == 0) {
788*6a54128fSAndroid Build Coastguard Worker s += 2;
789*6a54128fSAndroid Build Coastguard Worker negate = 1;
790*6a54128fSAndroid Build Coastguard Worker } else if (*s == '!') {
791*6a54128fSAndroid Build Coastguard Worker s++;
792*6a54128fSAndroid Build Coastguard Worker negate = 1;
793*6a54128fSAndroid Build Coastguard Worker }
794*6a54128fSAndroid Build Coastguard Worker if (strcmp(s, "loop") == 0)
795*6a54128fSAndroid Build Coastguard Worker /* loop is really short-hand for opts=loop */
796*6a54128fSAndroid Build Coastguard Worker goto loop_special_case;
797*6a54128fSAndroid Build Coastguard Worker else if (strncmp(s, "opts=", 5) == 0) {
798*6a54128fSAndroid Build Coastguard Worker s += 5;
799*6a54128fSAndroid Build Coastguard Worker loop_special_case:
800*6a54128fSAndroid Build Coastguard Worker cmp->type[num] = negate ? FS_TYPE_NEGOPT : FS_TYPE_OPT;
801*6a54128fSAndroid Build Coastguard Worker } else {
802*6a54128fSAndroid Build Coastguard Worker if (first_negate) {
803*6a54128fSAndroid Build Coastguard Worker cmp->negate = negate;
804*6a54128fSAndroid Build Coastguard Worker first_negate = 0;
805*6a54128fSAndroid Build Coastguard Worker }
806*6a54128fSAndroid Build Coastguard Worker if ((negate && !cmp->negate) ||
807*6a54128fSAndroid Build Coastguard Worker (!negate && cmp->negate)) {
808*6a54128fSAndroid Build Coastguard Worker fputs(_(fs_type_syntax_error), stderr);
809*6a54128fSAndroid Build Coastguard Worker exit(EXIT_USAGE);
810*6a54128fSAndroid Build Coastguard Worker }
811*6a54128fSAndroid Build Coastguard Worker }
812*6a54128fSAndroid Build Coastguard Worker #if 0
813*6a54128fSAndroid Build Coastguard Worker printf("Adding %s to list (type %d).\n", s, cmp->type[num]);
814*6a54128fSAndroid Build Coastguard Worker #endif
815*6a54128fSAndroid Build Coastguard Worker cmp->list[num++] = string_copy(s);
816*6a54128fSAndroid Build Coastguard Worker s = strtok(NULL, ",");
817*6a54128fSAndroid Build Coastguard Worker }
818*6a54128fSAndroid Build Coastguard Worker free(list);
819*6a54128fSAndroid Build Coastguard Worker }
820*6a54128fSAndroid Build Coastguard Worker
821*6a54128fSAndroid Build Coastguard Worker /*
822*6a54128fSAndroid Build Coastguard Worker * This function returns true if a particular option appears in a
823*6a54128fSAndroid Build Coastguard Worker * comma-delimited options list
824*6a54128fSAndroid Build Coastguard Worker */
opt_in_list(const char * opt,char * optlist)825*6a54128fSAndroid Build Coastguard Worker static int opt_in_list(const char *opt, char *optlist)
826*6a54128fSAndroid Build Coastguard Worker {
827*6a54128fSAndroid Build Coastguard Worker char *list, *s;
828*6a54128fSAndroid Build Coastguard Worker
829*6a54128fSAndroid Build Coastguard Worker if (!optlist)
830*6a54128fSAndroid Build Coastguard Worker return 0;
831*6a54128fSAndroid Build Coastguard Worker list = string_copy(optlist);
832*6a54128fSAndroid Build Coastguard Worker
833*6a54128fSAndroid Build Coastguard Worker s = strtok(list, ",");
834*6a54128fSAndroid Build Coastguard Worker while(s) {
835*6a54128fSAndroid Build Coastguard Worker if (strcmp(s, opt) == 0) {
836*6a54128fSAndroid Build Coastguard Worker free(list);
837*6a54128fSAndroid Build Coastguard Worker return 1;
838*6a54128fSAndroid Build Coastguard Worker }
839*6a54128fSAndroid Build Coastguard Worker s = strtok(NULL, ",");
840*6a54128fSAndroid Build Coastguard Worker }
841*6a54128fSAndroid Build Coastguard Worker free(list);
842*6a54128fSAndroid Build Coastguard Worker return 0;
843*6a54128fSAndroid Build Coastguard Worker }
844*6a54128fSAndroid Build Coastguard Worker
845*6a54128fSAndroid Build Coastguard Worker /* See if the filesystem matches the criteria given by the -t option */
fs_match(struct fs_info * fs,struct fs_type_compile * cmp)846*6a54128fSAndroid Build Coastguard Worker static int fs_match(struct fs_info *fs, struct fs_type_compile *cmp)
847*6a54128fSAndroid Build Coastguard Worker {
848*6a54128fSAndroid Build Coastguard Worker int n, ret = 0, checked_type = 0;
849*6a54128fSAndroid Build Coastguard Worker char *cp;
850*6a54128fSAndroid Build Coastguard Worker
851*6a54128fSAndroid Build Coastguard Worker if (cmp->list == 0 || cmp->list[0] == 0)
852*6a54128fSAndroid Build Coastguard Worker return 1;
853*6a54128fSAndroid Build Coastguard Worker
854*6a54128fSAndroid Build Coastguard Worker for (n=0; (cp = cmp->list[n]); n++) {
855*6a54128fSAndroid Build Coastguard Worker switch (cmp->type[n]) {
856*6a54128fSAndroid Build Coastguard Worker case FS_TYPE_NORMAL:
857*6a54128fSAndroid Build Coastguard Worker checked_type++;
858*6a54128fSAndroid Build Coastguard Worker if (strcmp(cp, fs->type) == 0) {
859*6a54128fSAndroid Build Coastguard Worker ret = 1;
860*6a54128fSAndroid Build Coastguard Worker }
861*6a54128fSAndroid Build Coastguard Worker break;
862*6a54128fSAndroid Build Coastguard Worker case FS_TYPE_NEGOPT:
863*6a54128fSAndroid Build Coastguard Worker if (opt_in_list(cp, fs->opts))
864*6a54128fSAndroid Build Coastguard Worker return 0;
865*6a54128fSAndroid Build Coastguard Worker break;
866*6a54128fSAndroid Build Coastguard Worker case FS_TYPE_OPT:
867*6a54128fSAndroid Build Coastguard Worker if (!opt_in_list(cp, fs->opts))
868*6a54128fSAndroid Build Coastguard Worker return 0;
869*6a54128fSAndroid Build Coastguard Worker break;
870*6a54128fSAndroid Build Coastguard Worker }
871*6a54128fSAndroid Build Coastguard Worker }
872*6a54128fSAndroid Build Coastguard Worker if (checked_type == 0)
873*6a54128fSAndroid Build Coastguard Worker return 1;
874*6a54128fSAndroid Build Coastguard Worker return (cmp->negate ? !ret : ret);
875*6a54128fSAndroid Build Coastguard Worker }
876*6a54128fSAndroid Build Coastguard Worker
877*6a54128fSAndroid Build Coastguard Worker /* Check if we should ignore this filesystem. */
ignore(struct fs_info * fs)878*6a54128fSAndroid Build Coastguard Worker static int ignore(struct fs_info *fs)
879*6a54128fSAndroid Build Coastguard Worker {
880*6a54128fSAndroid Build Coastguard Worker const char **ip;
881*6a54128fSAndroid Build Coastguard Worker int wanted = 0;
882*6a54128fSAndroid Build Coastguard Worker
883*6a54128fSAndroid Build Coastguard Worker /*
884*6a54128fSAndroid Build Coastguard Worker * If the pass number is 0, ignore it.
885*6a54128fSAndroid Build Coastguard Worker */
886*6a54128fSAndroid Build Coastguard Worker if (fs->passno == 0)
887*6a54128fSAndroid Build Coastguard Worker return 1;
888*6a54128fSAndroid Build Coastguard Worker
889*6a54128fSAndroid Build Coastguard Worker /*
890*6a54128fSAndroid Build Coastguard Worker * If this is a bind mount, ignore it.
891*6a54128fSAndroid Build Coastguard Worker */
892*6a54128fSAndroid Build Coastguard Worker if (opt_in_list("bind", fs->opts)) {
893*6a54128fSAndroid Build Coastguard Worker fprintf(stderr,
894*6a54128fSAndroid Build Coastguard Worker _("%s: skipping bad line in /etc/fstab: bind mount with nonzero fsck pass number\n"),
895*6a54128fSAndroid Build Coastguard Worker fs->mountpt);
896*6a54128fSAndroid Build Coastguard Worker return 1;
897*6a54128fSAndroid Build Coastguard Worker }
898*6a54128fSAndroid Build Coastguard Worker
899*6a54128fSAndroid Build Coastguard Worker interpret_type(fs);
900*6a54128fSAndroid Build Coastguard Worker
901*6a54128fSAndroid Build Coastguard Worker /*
902*6a54128fSAndroid Build Coastguard Worker * If a specific fstype is specified, and it doesn't match,
903*6a54128fSAndroid Build Coastguard Worker * ignore it.
904*6a54128fSAndroid Build Coastguard Worker */
905*6a54128fSAndroid Build Coastguard Worker if (!fs_match(fs, &fs_type_compiled)) return 1;
906*6a54128fSAndroid Build Coastguard Worker
907*6a54128fSAndroid Build Coastguard Worker /* Are we ignoring this type? */
908*6a54128fSAndroid Build Coastguard Worker for(ip = ignored_types; *ip; ip++)
909*6a54128fSAndroid Build Coastguard Worker if (strcmp(fs->type, *ip) == 0) return 1;
910*6a54128fSAndroid Build Coastguard Worker
911*6a54128fSAndroid Build Coastguard Worker /* Do we really really want to check this fs? */
912*6a54128fSAndroid Build Coastguard Worker for(ip = really_wanted; *ip; ip++)
913*6a54128fSAndroid Build Coastguard Worker if (strcmp(fs->type, *ip) == 0) {
914*6a54128fSAndroid Build Coastguard Worker wanted = 1;
915*6a54128fSAndroid Build Coastguard Worker break;
916*6a54128fSAndroid Build Coastguard Worker }
917*6a54128fSAndroid Build Coastguard Worker
918*6a54128fSAndroid Build Coastguard Worker /* See if the <fsck.fs> program is available. */
919*6a54128fSAndroid Build Coastguard Worker if (find_fsck(fs->type) == NULL) {
920*6a54128fSAndroid Build Coastguard Worker if (wanted)
921*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("fsck: cannot check %s: fsck.%s not found\n"),
922*6a54128fSAndroid Build Coastguard Worker fs->device, fs->type);
923*6a54128fSAndroid Build Coastguard Worker return 1;
924*6a54128fSAndroid Build Coastguard Worker }
925*6a54128fSAndroid Build Coastguard Worker
926*6a54128fSAndroid Build Coastguard Worker /* We can and want to check this file system type. */
927*6a54128fSAndroid Build Coastguard Worker return 0;
928*6a54128fSAndroid Build Coastguard Worker }
929*6a54128fSAndroid Build Coastguard Worker
930*6a54128fSAndroid Build Coastguard Worker /*
931*6a54128fSAndroid Build Coastguard Worker * Returns TRUE if a partition on the same disk is already being
932*6a54128fSAndroid Build Coastguard Worker * checked.
933*6a54128fSAndroid Build Coastguard Worker */
device_already_active(char * device)934*6a54128fSAndroid Build Coastguard Worker static int device_already_active(char *device)
935*6a54128fSAndroid Build Coastguard Worker {
936*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst;
937*6a54128fSAndroid Build Coastguard Worker char *base;
938*6a54128fSAndroid Build Coastguard Worker
939*6a54128fSAndroid Build Coastguard Worker if (force_all_parallel)
940*6a54128fSAndroid Build Coastguard Worker return 0;
941*6a54128fSAndroid Build Coastguard Worker
942*6a54128fSAndroid Build Coastguard Worker #ifdef BASE_MD
943*6a54128fSAndroid Build Coastguard Worker /* Don't check a soft raid disk with any other disk */
944*6a54128fSAndroid Build Coastguard Worker if (instance_list &&
945*6a54128fSAndroid Build Coastguard Worker (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1) ||
946*6a54128fSAndroid Build Coastguard Worker !strncmp(device, BASE_MD, sizeof(BASE_MD)-1)))
947*6a54128fSAndroid Build Coastguard Worker return 1;
948*6a54128fSAndroid Build Coastguard Worker #endif
949*6a54128fSAndroid Build Coastguard Worker
950*6a54128fSAndroid Build Coastguard Worker base = base_device(device);
951*6a54128fSAndroid Build Coastguard Worker /*
952*6a54128fSAndroid Build Coastguard Worker * If we don't know the base device, assume that the device is
953*6a54128fSAndroid Build Coastguard Worker * already active if there are any fsck instances running.
954*6a54128fSAndroid Build Coastguard Worker */
955*6a54128fSAndroid Build Coastguard Worker if (!base)
956*6a54128fSAndroid Build Coastguard Worker return (instance_list != 0);
957*6a54128fSAndroid Build Coastguard Worker for (inst = instance_list; inst; inst = inst->next) {
958*6a54128fSAndroid Build Coastguard Worker if (!inst->base_device || !strcmp(base, inst->base_device)) {
959*6a54128fSAndroid Build Coastguard Worker free(base);
960*6a54128fSAndroid Build Coastguard Worker return 1;
961*6a54128fSAndroid Build Coastguard Worker }
962*6a54128fSAndroid Build Coastguard Worker }
963*6a54128fSAndroid Build Coastguard Worker free(base);
964*6a54128fSAndroid Build Coastguard Worker return 0;
965*6a54128fSAndroid Build Coastguard Worker }
966*6a54128fSAndroid Build Coastguard Worker
967*6a54128fSAndroid Build Coastguard Worker /* Check all file systems, using the /etc/fstab table. */
check_all(NOARGS)968*6a54128fSAndroid Build Coastguard Worker static int check_all(NOARGS)
969*6a54128fSAndroid Build Coastguard Worker {
970*6a54128fSAndroid Build Coastguard Worker struct fs_info *fs = NULL;
971*6a54128fSAndroid Build Coastguard Worker int status = EXIT_OK;
972*6a54128fSAndroid Build Coastguard Worker int not_done_yet = 1;
973*6a54128fSAndroid Build Coastguard Worker int passno = 1;
974*6a54128fSAndroid Build Coastguard Worker int pass_done;
975*6a54128fSAndroid Build Coastguard Worker
976*6a54128fSAndroid Build Coastguard Worker if (verbose)
977*6a54128fSAndroid Build Coastguard Worker fputs(_("Checking all file systems.\n"), stdout);
978*6a54128fSAndroid Build Coastguard Worker
979*6a54128fSAndroid Build Coastguard Worker /*
980*6a54128fSAndroid Build Coastguard Worker * Do an initial scan over the filesystem; mark filesystems
981*6a54128fSAndroid Build Coastguard Worker * which should be ignored as done, and resolve any "auto"
982*6a54128fSAndroid Build Coastguard Worker * filesystem types (done as a side-effect of calling ignore()).
983*6a54128fSAndroid Build Coastguard Worker */
984*6a54128fSAndroid Build Coastguard Worker for (fs = filesys_info; fs; fs = fs->next) {
985*6a54128fSAndroid Build Coastguard Worker if (ignore(fs))
986*6a54128fSAndroid Build Coastguard Worker fs->flags |= FLAG_DONE;
987*6a54128fSAndroid Build Coastguard Worker }
988*6a54128fSAndroid Build Coastguard Worker
989*6a54128fSAndroid Build Coastguard Worker /*
990*6a54128fSAndroid Build Coastguard Worker * Find and check the root filesystem.
991*6a54128fSAndroid Build Coastguard Worker */
992*6a54128fSAndroid Build Coastguard Worker if (!parallel_root) {
993*6a54128fSAndroid Build Coastguard Worker for (fs = filesys_info; fs; fs = fs->next) {
994*6a54128fSAndroid Build Coastguard Worker if (!strcmp(fs->mountpt, "/"))
995*6a54128fSAndroid Build Coastguard Worker break;
996*6a54128fSAndroid Build Coastguard Worker }
997*6a54128fSAndroid Build Coastguard Worker if (fs) {
998*6a54128fSAndroid Build Coastguard Worker if (!skip_root && !ignore(fs) &&
999*6a54128fSAndroid Build Coastguard Worker !(ignore_mounted && is_mounted(fs->device))) {
1000*6a54128fSAndroid Build Coastguard Worker fsck_device(fs, 1);
1001*6a54128fSAndroid Build Coastguard Worker status |= wait_many(FLAG_WAIT_ALL);
1002*6a54128fSAndroid Build Coastguard Worker if (status > EXIT_NONDESTRUCT)
1003*6a54128fSAndroid Build Coastguard Worker return status;
1004*6a54128fSAndroid Build Coastguard Worker }
1005*6a54128fSAndroid Build Coastguard Worker fs->flags |= FLAG_DONE;
1006*6a54128fSAndroid Build Coastguard Worker }
1007*6a54128fSAndroid Build Coastguard Worker }
1008*6a54128fSAndroid Build Coastguard Worker /*
1009*6a54128fSAndroid Build Coastguard Worker * This is for the bone-headed user who enters the root
1010*6a54128fSAndroid Build Coastguard Worker * filesystem twice. Skip root will skip all root entries.
1011*6a54128fSAndroid Build Coastguard Worker */
1012*6a54128fSAndroid Build Coastguard Worker if (skip_root)
1013*6a54128fSAndroid Build Coastguard Worker for (fs = filesys_info; fs; fs = fs->next)
1014*6a54128fSAndroid Build Coastguard Worker if (!strcmp(fs->mountpt, "/"))
1015*6a54128fSAndroid Build Coastguard Worker fs->flags |= FLAG_DONE;
1016*6a54128fSAndroid Build Coastguard Worker
1017*6a54128fSAndroid Build Coastguard Worker while (not_done_yet) {
1018*6a54128fSAndroid Build Coastguard Worker not_done_yet = 0;
1019*6a54128fSAndroid Build Coastguard Worker pass_done = 1;
1020*6a54128fSAndroid Build Coastguard Worker
1021*6a54128fSAndroid Build Coastguard Worker for (fs = filesys_info; fs; fs = fs->next) {
1022*6a54128fSAndroid Build Coastguard Worker if (cancel_requested)
1023*6a54128fSAndroid Build Coastguard Worker break;
1024*6a54128fSAndroid Build Coastguard Worker if (fs->flags & FLAG_DONE)
1025*6a54128fSAndroid Build Coastguard Worker continue;
1026*6a54128fSAndroid Build Coastguard Worker /*
1027*6a54128fSAndroid Build Coastguard Worker * If the filesystem's pass number is higher
1028*6a54128fSAndroid Build Coastguard Worker * than the current pass number, then we don't
1029*6a54128fSAndroid Build Coastguard Worker * do it yet.
1030*6a54128fSAndroid Build Coastguard Worker */
1031*6a54128fSAndroid Build Coastguard Worker if (fs->passno > passno) {
1032*6a54128fSAndroid Build Coastguard Worker not_done_yet++;
1033*6a54128fSAndroid Build Coastguard Worker continue;
1034*6a54128fSAndroid Build Coastguard Worker }
1035*6a54128fSAndroid Build Coastguard Worker if (ignore_mounted && is_mounted(fs->device)) {
1036*6a54128fSAndroid Build Coastguard Worker fs->flags |= FLAG_DONE;
1037*6a54128fSAndroid Build Coastguard Worker continue;
1038*6a54128fSAndroid Build Coastguard Worker }
1039*6a54128fSAndroid Build Coastguard Worker /*
1040*6a54128fSAndroid Build Coastguard Worker * If a filesystem on a particular device has
1041*6a54128fSAndroid Build Coastguard Worker * already been spawned, then we need to defer
1042*6a54128fSAndroid Build Coastguard Worker * this to another pass.
1043*6a54128fSAndroid Build Coastguard Worker */
1044*6a54128fSAndroid Build Coastguard Worker if (device_already_active(fs->device)) {
1045*6a54128fSAndroid Build Coastguard Worker pass_done = 0;
1046*6a54128fSAndroid Build Coastguard Worker continue;
1047*6a54128fSAndroid Build Coastguard Worker }
1048*6a54128fSAndroid Build Coastguard Worker /*
1049*6a54128fSAndroid Build Coastguard Worker * Spawn off the fsck process
1050*6a54128fSAndroid Build Coastguard Worker */
1051*6a54128fSAndroid Build Coastguard Worker fsck_device(fs, serialize);
1052*6a54128fSAndroid Build Coastguard Worker fs->flags |= FLAG_DONE;
1053*6a54128fSAndroid Build Coastguard Worker
1054*6a54128fSAndroid Build Coastguard Worker /*
1055*6a54128fSAndroid Build Coastguard Worker * Only do one filesystem at a time, or if we
1056*6a54128fSAndroid Build Coastguard Worker * have a limit on the number of fsck's extant
1057*6a54128fSAndroid Build Coastguard Worker * at one time, apply that limit.
1058*6a54128fSAndroid Build Coastguard Worker */
1059*6a54128fSAndroid Build Coastguard Worker if (serialize ||
1060*6a54128fSAndroid Build Coastguard Worker (max_running && (num_running >= max_running))) {
1061*6a54128fSAndroid Build Coastguard Worker pass_done = 0;
1062*6a54128fSAndroid Build Coastguard Worker break;
1063*6a54128fSAndroid Build Coastguard Worker }
1064*6a54128fSAndroid Build Coastguard Worker }
1065*6a54128fSAndroid Build Coastguard Worker if (cancel_requested)
1066*6a54128fSAndroid Build Coastguard Worker break;
1067*6a54128fSAndroid Build Coastguard Worker if (verbose > 1)
1068*6a54128fSAndroid Build Coastguard Worker printf(_("--waiting-- (pass %d)\n"), passno);
1069*6a54128fSAndroid Build Coastguard Worker status |= wait_many(pass_done ? FLAG_WAIT_ALL :
1070*6a54128fSAndroid Build Coastguard Worker FLAG_WAIT_ATLEAST_ONE);
1071*6a54128fSAndroid Build Coastguard Worker if (pass_done) {
1072*6a54128fSAndroid Build Coastguard Worker if (verbose > 1)
1073*6a54128fSAndroid Build Coastguard Worker printf("----------------------------------\n");
1074*6a54128fSAndroid Build Coastguard Worker passno++;
1075*6a54128fSAndroid Build Coastguard Worker } else
1076*6a54128fSAndroid Build Coastguard Worker not_done_yet++;
1077*6a54128fSAndroid Build Coastguard Worker }
1078*6a54128fSAndroid Build Coastguard Worker if (cancel_requested && !kill_sent) {
1079*6a54128fSAndroid Build Coastguard Worker kill_all(SIGTERM);
1080*6a54128fSAndroid Build Coastguard Worker kill_sent++;
1081*6a54128fSAndroid Build Coastguard Worker }
1082*6a54128fSAndroid Build Coastguard Worker status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
1083*6a54128fSAndroid Build Coastguard Worker return status;
1084*6a54128fSAndroid Build Coastguard Worker }
1085*6a54128fSAndroid Build Coastguard Worker
usage(NOARGS)1086*6a54128fSAndroid Build Coastguard Worker static void usage(NOARGS)
1087*6a54128fSAndroid Build Coastguard Worker {
1088*6a54128fSAndroid Build Coastguard Worker fputs(_("Usage: fsck [-AMNPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr);
1089*6a54128fSAndroid Build Coastguard Worker exit(EXIT_USAGE);
1090*6a54128fSAndroid Build Coastguard Worker }
1091*6a54128fSAndroid Build Coastguard Worker
1092*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SIGNAL_H
signal_cancel(int sig FSCK_ATTR ((unused)))1093*6a54128fSAndroid Build Coastguard Worker static void signal_cancel(int sig FSCK_ATTR((unused)))
1094*6a54128fSAndroid Build Coastguard Worker {
1095*6a54128fSAndroid Build Coastguard Worker cancel_requested++;
1096*6a54128fSAndroid Build Coastguard Worker }
1097*6a54128fSAndroid Build Coastguard Worker #endif
1098*6a54128fSAndroid Build Coastguard Worker
PRS(int argc,char * argv[])1099*6a54128fSAndroid Build Coastguard Worker static void PRS(int argc, char *argv[])
1100*6a54128fSAndroid Build Coastguard Worker {
1101*6a54128fSAndroid Build Coastguard Worker int i, j;
1102*6a54128fSAndroid Build Coastguard Worker char *arg, *dev, *tmp = 0;
1103*6a54128fSAndroid Build Coastguard Worker char options[128];
1104*6a54128fSAndroid Build Coastguard Worker int opt = 0;
1105*6a54128fSAndroid Build Coastguard Worker int opts_for_fsck = 0;
1106*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SIGNAL_H
1107*6a54128fSAndroid Build Coastguard Worker struct sigaction sa;
1108*6a54128fSAndroid Build Coastguard Worker
1109*6a54128fSAndroid Build Coastguard Worker /*
1110*6a54128fSAndroid Build Coastguard Worker * Set up signal action
1111*6a54128fSAndroid Build Coastguard Worker */
1112*6a54128fSAndroid Build Coastguard Worker memset(&sa, 0, sizeof(struct sigaction));
1113*6a54128fSAndroid Build Coastguard Worker sa.sa_handler = signal_cancel;
1114*6a54128fSAndroid Build Coastguard Worker sigaction(SIGINT, &sa, 0);
1115*6a54128fSAndroid Build Coastguard Worker sigaction(SIGTERM, &sa, 0);
1116*6a54128fSAndroid Build Coastguard Worker #endif
1117*6a54128fSAndroid Build Coastguard Worker
1118*6a54128fSAndroid Build Coastguard Worker num_devices = 0;
1119*6a54128fSAndroid Build Coastguard Worker num_args = 0;
1120*6a54128fSAndroid Build Coastguard Worker instance_list = 0;
1121*6a54128fSAndroid Build Coastguard Worker
1122*6a54128fSAndroid Build Coastguard Worker progname = argv[0];
1123*6a54128fSAndroid Build Coastguard Worker
1124*6a54128fSAndroid Build Coastguard Worker for (i=1; i < argc; i++) {
1125*6a54128fSAndroid Build Coastguard Worker arg = argv[i];
1126*6a54128fSAndroid Build Coastguard Worker if (!arg)
1127*6a54128fSAndroid Build Coastguard Worker continue;
1128*6a54128fSAndroid Build Coastguard Worker if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
1129*6a54128fSAndroid Build Coastguard Worker if (num_devices >= MAX_DEVICES) {
1130*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("%s: too many devices\n"),
1131*6a54128fSAndroid Build Coastguard Worker progname);
1132*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
1133*6a54128fSAndroid Build Coastguard Worker }
1134*6a54128fSAndroid Build Coastguard Worker dev = get_devname(cache, arg, NULL);
1135*6a54128fSAndroid Build Coastguard Worker if (!dev && strchr(arg, '=')) {
1136*6a54128fSAndroid Build Coastguard Worker /*
1137*6a54128fSAndroid Build Coastguard Worker * Check to see if we failed because
1138*6a54128fSAndroid Build Coastguard Worker * /proc/partitions isn't found.
1139*6a54128fSAndroid Build Coastguard Worker */
1140*6a54128fSAndroid Build Coastguard Worker if (access("/proc/partitions", R_OK) < 0) {
1141*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "Couldn't open /proc/partitions: %s\n",
1142*6a54128fSAndroid Build Coastguard Worker strerror(errno));
1143*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "Is /proc mounted?\n");
1144*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
1145*6a54128fSAndroid Build Coastguard Worker }
1146*6a54128fSAndroid Build Coastguard Worker /*
1147*6a54128fSAndroid Build Coastguard Worker * Check to see if this is because
1148*6a54128fSAndroid Build Coastguard Worker * we're not running as root
1149*6a54128fSAndroid Build Coastguard Worker */
1150*6a54128fSAndroid Build Coastguard Worker if (geteuid())
1151*6a54128fSAndroid Build Coastguard Worker fprintf(stderr,
1152*6a54128fSAndroid Build Coastguard Worker "Must be root to scan for matching filesystems: %s\n", arg);
1153*6a54128fSAndroid Build Coastguard Worker else
1154*6a54128fSAndroid Build Coastguard Worker fprintf(stderr,
1155*6a54128fSAndroid Build Coastguard Worker "Couldn't find matching filesystem: %s\n", arg);
1156*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
1157*6a54128fSAndroid Build Coastguard Worker }
1158*6a54128fSAndroid Build Coastguard Worker devices[num_devices++] = dev ? dev : string_copy(arg);
1159*6a54128fSAndroid Build Coastguard Worker continue;
1160*6a54128fSAndroid Build Coastguard Worker }
1161*6a54128fSAndroid Build Coastguard Worker if (arg[0] != '-' || opts_for_fsck) {
1162*6a54128fSAndroid Build Coastguard Worker if (num_args >= MAX_ARGS) {
1163*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, _("%s: too many arguments\n"),
1164*6a54128fSAndroid Build Coastguard Worker progname);
1165*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
1166*6a54128fSAndroid Build Coastguard Worker }
1167*6a54128fSAndroid Build Coastguard Worker args[num_args++] = string_copy(arg);
1168*6a54128fSAndroid Build Coastguard Worker continue;
1169*6a54128fSAndroid Build Coastguard Worker }
1170*6a54128fSAndroid Build Coastguard Worker for (j=1; arg[j]; j++) {
1171*6a54128fSAndroid Build Coastguard Worker if (opts_for_fsck) {
1172*6a54128fSAndroid Build Coastguard Worker options[++opt] = arg[j];
1173*6a54128fSAndroid Build Coastguard Worker continue;
1174*6a54128fSAndroid Build Coastguard Worker }
1175*6a54128fSAndroid Build Coastguard Worker switch (arg[j]) {
1176*6a54128fSAndroid Build Coastguard Worker case 'A':
1177*6a54128fSAndroid Build Coastguard Worker doall++;
1178*6a54128fSAndroid Build Coastguard Worker break;
1179*6a54128fSAndroid Build Coastguard Worker case 'C':
1180*6a54128fSAndroid Build Coastguard Worker progress++;
1181*6a54128fSAndroid Build Coastguard Worker if (arg[j+1]) {
1182*6a54128fSAndroid Build Coastguard Worker progress_fd = string_to_int(arg+j+1);
1183*6a54128fSAndroid Build Coastguard Worker if (progress_fd < 0)
1184*6a54128fSAndroid Build Coastguard Worker progress_fd = 0;
1185*6a54128fSAndroid Build Coastguard Worker else
1186*6a54128fSAndroid Build Coastguard Worker goto next_arg;
1187*6a54128fSAndroid Build Coastguard Worker } else if (argc > i + 1 &&
1188*6a54128fSAndroid Build Coastguard Worker argv[i + 1][0] != '-') {
1189*6a54128fSAndroid Build Coastguard Worker progress_fd = string_to_int(argv[i]);
1190*6a54128fSAndroid Build Coastguard Worker if (progress_fd < 0)
1191*6a54128fSAndroid Build Coastguard Worker progress_fd = 0;
1192*6a54128fSAndroid Build Coastguard Worker else {
1193*6a54128fSAndroid Build Coastguard Worker ++i;
1194*6a54128fSAndroid Build Coastguard Worker goto next_arg;
1195*6a54128fSAndroid Build Coastguard Worker }
1196*6a54128fSAndroid Build Coastguard Worker }
1197*6a54128fSAndroid Build Coastguard Worker break;
1198*6a54128fSAndroid Build Coastguard Worker case 'V':
1199*6a54128fSAndroid Build Coastguard Worker verbose++;
1200*6a54128fSAndroid Build Coastguard Worker break;
1201*6a54128fSAndroid Build Coastguard Worker case 'N':
1202*6a54128fSAndroid Build Coastguard Worker noexecute++;
1203*6a54128fSAndroid Build Coastguard Worker break;
1204*6a54128fSAndroid Build Coastguard Worker case 'R':
1205*6a54128fSAndroid Build Coastguard Worker skip_root++;
1206*6a54128fSAndroid Build Coastguard Worker break;
1207*6a54128fSAndroid Build Coastguard Worker case 'T':
1208*6a54128fSAndroid Build Coastguard Worker notitle++;
1209*6a54128fSAndroid Build Coastguard Worker break;
1210*6a54128fSAndroid Build Coastguard Worker case 'M':
1211*6a54128fSAndroid Build Coastguard Worker ignore_mounted++;
1212*6a54128fSAndroid Build Coastguard Worker break;
1213*6a54128fSAndroid Build Coastguard Worker case 'P':
1214*6a54128fSAndroid Build Coastguard Worker parallel_root++;
1215*6a54128fSAndroid Build Coastguard Worker break;
1216*6a54128fSAndroid Build Coastguard Worker case 's':
1217*6a54128fSAndroid Build Coastguard Worker serialize++;
1218*6a54128fSAndroid Build Coastguard Worker break;
1219*6a54128fSAndroid Build Coastguard Worker case 't':
1220*6a54128fSAndroid Build Coastguard Worker tmp = 0;
1221*6a54128fSAndroid Build Coastguard Worker if (fstype)
1222*6a54128fSAndroid Build Coastguard Worker usage();
1223*6a54128fSAndroid Build Coastguard Worker if (arg[j+1])
1224*6a54128fSAndroid Build Coastguard Worker tmp = arg+j+1;
1225*6a54128fSAndroid Build Coastguard Worker else if ((i+1) < argc)
1226*6a54128fSAndroid Build Coastguard Worker tmp = argv[++i];
1227*6a54128fSAndroid Build Coastguard Worker else
1228*6a54128fSAndroid Build Coastguard Worker usage();
1229*6a54128fSAndroid Build Coastguard Worker fstype = string_copy(tmp);
1230*6a54128fSAndroid Build Coastguard Worker compile_fs_type(fstype, &fs_type_compiled);
1231*6a54128fSAndroid Build Coastguard Worker goto next_arg;
1232*6a54128fSAndroid Build Coastguard Worker case '-':
1233*6a54128fSAndroid Build Coastguard Worker opts_for_fsck++;
1234*6a54128fSAndroid Build Coastguard Worker break;
1235*6a54128fSAndroid Build Coastguard Worker case '?':
1236*6a54128fSAndroid Build Coastguard Worker usage();
1237*6a54128fSAndroid Build Coastguard Worker break;
1238*6a54128fSAndroid Build Coastguard Worker default:
1239*6a54128fSAndroid Build Coastguard Worker options[++opt] = arg[j];
1240*6a54128fSAndroid Build Coastguard Worker break;
1241*6a54128fSAndroid Build Coastguard Worker }
1242*6a54128fSAndroid Build Coastguard Worker }
1243*6a54128fSAndroid Build Coastguard Worker next_arg:
1244*6a54128fSAndroid Build Coastguard Worker if (opt) {
1245*6a54128fSAndroid Build Coastguard Worker options[0] = '-';
1246*6a54128fSAndroid Build Coastguard Worker options[++opt] = '\0';
1247*6a54128fSAndroid Build Coastguard Worker if (num_args >= MAX_ARGS) {
1248*6a54128fSAndroid Build Coastguard Worker fprintf(stderr,
1249*6a54128fSAndroid Build Coastguard Worker _("%s: too many arguments\n"),
1250*6a54128fSAndroid Build Coastguard Worker progname);
1251*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
1252*6a54128fSAndroid Build Coastguard Worker }
1253*6a54128fSAndroid Build Coastguard Worker args[num_args++] = string_copy(options);
1254*6a54128fSAndroid Build Coastguard Worker opt = 0;
1255*6a54128fSAndroid Build Coastguard Worker }
1256*6a54128fSAndroid Build Coastguard Worker }
1257*6a54128fSAndroid Build Coastguard Worker if (getenv("FSCK_FORCE_ALL_PARALLEL"))
1258*6a54128fSAndroid Build Coastguard Worker force_all_parallel++;
1259*6a54128fSAndroid Build Coastguard Worker if ((tmp = getenv("FSCK_MAX_INST")))
1260*6a54128fSAndroid Build Coastguard Worker max_running = atoi(tmp);
1261*6a54128fSAndroid Build Coastguard Worker }
1262*6a54128fSAndroid Build Coastguard Worker
main(int argc,char * argv[])1263*6a54128fSAndroid Build Coastguard Worker int main(int argc, char *argv[])
1264*6a54128fSAndroid Build Coastguard Worker {
1265*6a54128fSAndroid Build Coastguard Worker int i, status = 0;
1266*6a54128fSAndroid Build Coastguard Worker int interactive = 0;
1267*6a54128fSAndroid Build Coastguard Worker char *oldpath = getenv("PATH");
1268*6a54128fSAndroid Build Coastguard Worker const char *fstab;
1269*6a54128fSAndroid Build Coastguard Worker struct fs_info *fs;
1270*6a54128fSAndroid Build Coastguard Worker
1271*6a54128fSAndroid Build Coastguard Worker setvbuf(stdout, NULL, _IONBF, BUFSIZ);
1272*6a54128fSAndroid Build Coastguard Worker setvbuf(stderr, NULL, _IONBF, BUFSIZ);
1273*6a54128fSAndroid Build Coastguard Worker
1274*6a54128fSAndroid Build Coastguard Worker #ifdef ENABLE_NLS
1275*6a54128fSAndroid Build Coastguard Worker setlocale(LC_MESSAGES, "");
1276*6a54128fSAndroid Build Coastguard Worker setlocale(LC_CTYPE, "");
1277*6a54128fSAndroid Build Coastguard Worker bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1278*6a54128fSAndroid Build Coastguard Worker textdomain(NLS_CAT_NAME);
1279*6a54128fSAndroid Build Coastguard Worker #endif
1280*6a54128fSAndroid Build Coastguard Worker blkid_get_cache(&cache, NULL);
1281*6a54128fSAndroid Build Coastguard Worker PRS(argc, argv);
1282*6a54128fSAndroid Build Coastguard Worker
1283*6a54128fSAndroid Build Coastguard Worker if (!notitle)
1284*6a54128fSAndroid Build Coastguard Worker printf("fsck %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
1285*6a54128fSAndroid Build Coastguard Worker
1286*6a54128fSAndroid Build Coastguard Worker fstab = getenv("FSTAB_FILE");
1287*6a54128fSAndroid Build Coastguard Worker if (!fstab)
1288*6a54128fSAndroid Build Coastguard Worker fstab = _PATH_MNTTAB;
1289*6a54128fSAndroid Build Coastguard Worker load_fs_info(fstab);
1290*6a54128fSAndroid Build Coastguard Worker
1291*6a54128fSAndroid Build Coastguard Worker /* Update our search path to include uncommon directories. */
1292*6a54128fSAndroid Build Coastguard Worker if (oldpath) {
1293*6a54128fSAndroid Build Coastguard Worker fsck_path = malloc (strlen (fsck_prefix_path) + 1 +
1294*6a54128fSAndroid Build Coastguard Worker strlen (oldpath) + 1);
1295*6a54128fSAndroid Build Coastguard Worker if (!fsck_path) {
1296*6a54128fSAndroid Build Coastguard Worker fprintf(stderr, "%s: Unable to allocate memory for fsck_path\n", progname);
1297*6a54128fSAndroid Build Coastguard Worker exit(EXIT_ERROR);
1298*6a54128fSAndroid Build Coastguard Worker }
1299*6a54128fSAndroid Build Coastguard Worker strcpy (fsck_path, fsck_prefix_path);
1300*6a54128fSAndroid Build Coastguard Worker strcat (fsck_path, ":");
1301*6a54128fSAndroid Build Coastguard Worker strcat (fsck_path, oldpath);
1302*6a54128fSAndroid Build Coastguard Worker } else {
1303*6a54128fSAndroid Build Coastguard Worker fsck_path = string_copy(fsck_prefix_path);
1304*6a54128fSAndroid Build Coastguard Worker }
1305*6a54128fSAndroid Build Coastguard Worker
1306*6a54128fSAndroid Build Coastguard Worker if ((num_devices == 1) || (serialize))
1307*6a54128fSAndroid Build Coastguard Worker interactive = 1;
1308*6a54128fSAndroid Build Coastguard Worker
1309*6a54128fSAndroid Build Coastguard Worker /* If -A was specified ("check all"), do that! */
1310*6a54128fSAndroid Build Coastguard Worker if (doall)
1311*6a54128fSAndroid Build Coastguard Worker return check_all();
1312*6a54128fSAndroid Build Coastguard Worker
1313*6a54128fSAndroid Build Coastguard Worker if (num_devices == 0) {
1314*6a54128fSAndroid Build Coastguard Worker serialize++;
1315*6a54128fSAndroid Build Coastguard Worker interactive++;
1316*6a54128fSAndroid Build Coastguard Worker return check_all();
1317*6a54128fSAndroid Build Coastguard Worker }
1318*6a54128fSAndroid Build Coastguard Worker for (i = 0 ; i < num_devices; i++) {
1319*6a54128fSAndroid Build Coastguard Worker if (cancel_requested) {
1320*6a54128fSAndroid Build Coastguard Worker if (!kill_sent) {
1321*6a54128fSAndroid Build Coastguard Worker kill_all(SIGTERM);
1322*6a54128fSAndroid Build Coastguard Worker kill_sent++;
1323*6a54128fSAndroid Build Coastguard Worker }
1324*6a54128fSAndroid Build Coastguard Worker break;
1325*6a54128fSAndroid Build Coastguard Worker }
1326*6a54128fSAndroid Build Coastguard Worker fs = lookup(devices[i]);
1327*6a54128fSAndroid Build Coastguard Worker if (!fs) {
1328*6a54128fSAndroid Build Coastguard Worker fs = create_fs_device(devices[i], 0, "auto",
1329*6a54128fSAndroid Build Coastguard Worker 0, -1, -1);
1330*6a54128fSAndroid Build Coastguard Worker if (!fs)
1331*6a54128fSAndroid Build Coastguard Worker continue;
1332*6a54128fSAndroid Build Coastguard Worker }
1333*6a54128fSAndroid Build Coastguard Worker if (ignore_mounted && is_mounted(fs->device))
1334*6a54128fSAndroid Build Coastguard Worker continue;
1335*6a54128fSAndroid Build Coastguard Worker fsck_device(fs, interactive);
1336*6a54128fSAndroid Build Coastguard Worker if (serialize ||
1337*6a54128fSAndroid Build Coastguard Worker (max_running && (num_running >= max_running))) {
1338*6a54128fSAndroid Build Coastguard Worker struct fsck_instance *inst;
1339*6a54128fSAndroid Build Coastguard Worker
1340*6a54128fSAndroid Build Coastguard Worker inst = wait_one(0);
1341*6a54128fSAndroid Build Coastguard Worker if (inst) {
1342*6a54128fSAndroid Build Coastguard Worker status |= inst->exit_status;
1343*6a54128fSAndroid Build Coastguard Worker free_instance(inst);
1344*6a54128fSAndroid Build Coastguard Worker }
1345*6a54128fSAndroid Build Coastguard Worker if (verbose > 1)
1346*6a54128fSAndroid Build Coastguard Worker printf("----------------------------------\n");
1347*6a54128fSAndroid Build Coastguard Worker }
1348*6a54128fSAndroid Build Coastguard Worker }
1349*6a54128fSAndroid Build Coastguard Worker status |= wait_many(FLAG_WAIT_ALL);
1350*6a54128fSAndroid Build Coastguard Worker free(fsck_path);
1351*6a54128fSAndroid Build Coastguard Worker blkid_put_cache(cache);
1352*6a54128fSAndroid Build Coastguard Worker return status;
1353*6a54128fSAndroid Build Coastguard Worker }
1354