Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * fsck --- A generic, parallelizing front-end for the fsck program. |
| 4 | * It will automatically try to run fsck programs in parallel if the |
| 5 | * devices are on separate spindles. It is based on the same ideas as |
| 6 | * the generic front end for fsck by David Engel and Fred van Kempen, |
| 7 | * but it has been completely rewritten from scratch to support |
| 8 | * parallel execution. |
| 9 | * |
| 10 | * Written by Theodore Ts'o, <tytso@mit.edu> |
| 11 | * |
| 12 | * Miquel van Smoorenburg (miquels@drinkel.ow.org) 20-Oct-1994: |
| 13 | * o Changed -t fstype to behave like with mount when -A (all file |
| 14 | * systems) or -M (like mount) is specified. |
| 15 | * o fsck looks if it can find the fsck.type program to decide |
| 16 | * if it should ignore the fs type. This way more fsck programs |
| 17 | * can be added without changing this front-end. |
| 18 | * o -R flag skip root file system. |
| 19 | * |
| 20 | * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
| 21 | * 2001, 2002, 2003, 2004, 2005 by 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 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 29 | /* All filesystem specific hooks have been removed. |
| 30 | * If filesystem cannot be determined, we will execute |
| 31 | * "fsck.auto". Currently this also happens if you specify |
| 32 | * UUID=xxx or LABEL=xxx as an object to check. |
| 33 | * Detection code for that is also probably has to be in fsck.auto. |
| 34 | * |
| 35 | * In other words, this is _really_ is just a driver program which |
| 36 | * spawns actual fsck.something for each filesystem to check. |
| 37 | * It doesn't guess filesystem types from on-disk format. |
| 38 | */ |
| 39 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 40 | #include "libbb.h" |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 41 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 42 | /* "progress indicator" code is somewhat buggy and ext[23] specific. |
| 43 | * We should be filesystem agnostic. IOW: there should be a well-defined |
| 44 | * API for fsck.something, NOT ad-hoc hacks in generic fsck. */ |
| 45 | #define DO_PROGRESS_INDICATOR 0 |
| 46 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 47 | #define EXIT_OK 0 |
| 48 | #define EXIT_NONDESTRUCT 1 |
| 49 | #define EXIT_DESTRUCT 2 |
| 50 | #define EXIT_UNCORRECTED 4 |
| 51 | #define EXIT_ERROR 8 |
| 52 | #define EXIT_USAGE 16 |
| 53 | #define FSCK_CANCELED 32 /* Aborted with a signal or ^C */ |
| 54 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 55 | /* |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 56 | * Internal structure for mount table entries. |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 57 | */ |
| 58 | |
| 59 | struct fs_info { |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 60 | struct fs_info *next; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 61 | char *device; |
| 62 | char *mountpt; |
| 63 | char *type; |
| 64 | char *opts; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 65 | int passno; |
| 66 | int flags; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | #define FLAG_DONE 1 |
| 70 | #define FLAG_PROGRESS 2 |
| 71 | /* |
| 72 | * Structure to allow exit codes to be stored |
| 73 | */ |
| 74 | struct fsck_instance { |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 75 | struct fsck_instance *next; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 76 | int pid; |
| 77 | int flags; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 78 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 79 | time_t start_time; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 80 | #endif |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 81 | char *prog; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 82 | char *device; |
| 83 | char *base_device; /* /dev/hda for /dev/hdaN etc */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 86 | static const char ignored_types[] ALIGN1 = |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 87 | "ignore\0" |
| 88 | "iso9660\0" |
| 89 | "nfs\0" |
| 90 | "proc\0" |
| 91 | "sw\0" |
| 92 | "swap\0" |
| 93 | "tmpfs\0" |
| 94 | "devpts\0"; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 95 | |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 96 | #if 0 |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 97 | static const char really_wanted[] ALIGN1 = |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 98 | "minix\0" |
| 99 | "ext2\0" |
| 100 | "ext3\0" |
| 101 | "jfs\0" |
| 102 | "reiserfs\0" |
| 103 | "xiafs\0" |
| 104 | "xfs\0"; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 105 | #endif |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 106 | |
| 107 | #define BASE_MD "/dev/md" |
| 108 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 109 | static char **devices; |
| 110 | static char **args; |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 111 | static int num_devices; |
| 112 | static int num_args; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 113 | static int verbose; |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 114 | |
| 115 | #define FS_TYPE_FLAG_NORMAL 0 |
| 116 | #define FS_TYPE_FLAG_OPT 1 |
| 117 | #define FS_TYPE_FLAG_NEGOPT 2 |
| 118 | static char **fs_type_list; |
| 119 | static uint8_t *fs_type_flag; |
| 120 | static smallint fs_type_negated; |
| 121 | |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 122 | static volatile smallint cancel_requested; |
| 123 | static smallint doall; |
| 124 | static smallint noexecute; |
| 125 | static smallint serialize; |
| 126 | static smallint skip_root; |
| 127 | /* static smallint like_mount; */ |
| 128 | static smallint notitle; |
| 129 | static smallint parallel_root; |
| 130 | static smallint force_all_parallel; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 131 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 132 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 133 | static smallint progress; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 134 | static int progress_fd; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 135 | #endif |
| 136 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 137 | static int num_running; |
| 138 | static int max_running; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 139 | static char *fstype; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 140 | static struct fs_info *filesys_info; |
| 141 | static struct fs_info *filesys_last; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 142 | static struct fsck_instance *instance_list; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 143 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 144 | /* |
| 145 | * Return the "base device" given a particular device; this is used to |
| 146 | * assure that we only fsck one partition on a particular drive at any |
| 147 | * one time. Otherwise, the disk heads will be seeking all over the |
| 148 | * place. If the base device cannot be determined, return NULL. |
| 149 | * |
| 150 | * The base_device() function returns an allocated string which must |
| 151 | * be freed. |
| 152 | */ |
| 153 | #if ENABLE_FEATURE_DEVFS |
| 154 | /* |
| 155 | * Required for the uber-silly devfs /dev/ide/host1/bus2/target3/lun3 |
| 156 | * pathames. |
| 157 | */ |
| 158 | static const char *const devfs_hier[] = { |
| 159 | "host", "bus", "target", "lun", NULL |
| 160 | }; |
| 161 | #endif |
| 162 | |
| 163 | static char *base_device(const char *device) |
| 164 | { |
| 165 | char *str, *cp; |
| 166 | #if ENABLE_FEATURE_DEVFS |
| 167 | const char *const *hier; |
| 168 | const char *disk; |
| 169 | int len; |
| 170 | #endif |
| 171 | cp = str = xstrdup(device); |
| 172 | |
| 173 | /* Skip over /dev/; if it's not present, give up. */ |
| 174 | if (strncmp(cp, "/dev/", 5) != 0) |
| 175 | goto errout; |
| 176 | cp += 5; |
| 177 | |
| 178 | /* |
| 179 | * For md devices, we treat them all as if they were all |
| 180 | * on one disk, since we don't know how to parallelize them. |
| 181 | */ |
| 182 | if (cp[0] == 'm' && cp[1] == 'd') { |
| 183 | cp[2] = 0; |
| 184 | return str; |
| 185 | } |
| 186 | |
| 187 | /* Handle DAC 960 devices */ |
| 188 | if (strncmp(cp, "rd/", 3) == 0) { |
| 189 | cp += 3; |
| 190 | if (cp[0] != 'c' || !isdigit(cp[1]) |
| 191 | || cp[2] != 'd' || !isdigit(cp[3])) |
| 192 | goto errout; |
| 193 | cp[4] = 0; |
| 194 | return str; |
| 195 | } |
| 196 | |
| 197 | /* Now let's handle /dev/hd* and /dev/sd* devices.... */ |
| 198 | if ((cp[0] == 'h' || cp[0] == 's') && cp[1] == 'd') { |
| 199 | cp += 2; |
| 200 | /* If there's a single number after /dev/hd, skip it */ |
| 201 | if (isdigit(*cp)) |
| 202 | cp++; |
| 203 | /* What follows must be an alpha char, or give up */ |
| 204 | if (!isalpha(*cp)) |
| 205 | goto errout; |
| 206 | cp[1] = 0; |
| 207 | return str; |
| 208 | } |
| 209 | |
| 210 | #if ENABLE_FEATURE_DEVFS |
| 211 | /* Now let's handle devfs (ugh) names */ |
| 212 | len = 0; |
| 213 | if (strncmp(cp, "ide/", 4) == 0) |
| 214 | len = 4; |
| 215 | if (strncmp(cp, "scsi/", 5) == 0) |
| 216 | len = 5; |
| 217 | if (len) { |
| 218 | cp += len; |
| 219 | /* |
| 220 | * Now we proceed down the expected devfs hierarchy. |
| 221 | * i.e., .../host1/bus2/target3/lun4/... |
| 222 | * If we don't find the expected token, followed by |
| 223 | * some number of digits at each level, abort. |
| 224 | */ |
| 225 | for (hier = devfs_hier; *hier; hier++) { |
| 226 | len = strlen(*hier); |
| 227 | if (strncmp(cp, *hier, len) != 0) |
| 228 | goto errout; |
| 229 | cp += len; |
| 230 | while (*cp != '/' && *cp != 0) { |
| 231 | if (!isdigit(*cp)) |
| 232 | goto errout; |
| 233 | cp++; |
| 234 | } |
| 235 | cp++; |
| 236 | } |
| 237 | cp[-1] = 0; |
| 238 | return str; |
| 239 | } |
| 240 | |
| 241 | /* Now handle devfs /dev/disc or /dev/disk names */ |
| 242 | disk = 0; |
| 243 | if (strncmp(cp, "discs/", 6) == 0) |
| 244 | disk = "disc"; |
| 245 | else if (strncmp(cp, "disks/", 6) == 0) |
| 246 | disk = "disk"; |
| 247 | if (disk) { |
| 248 | cp += 6; |
| 249 | if (strncmp(cp, disk, 4) != 0) |
| 250 | goto errout; |
| 251 | cp += 4; |
| 252 | while (*cp != '/' && *cp != 0) { |
| 253 | if (!isdigit(*cp)) |
| 254 | goto errout; |
| 255 | cp++; |
| 256 | } |
| 257 | *cp = 0; |
| 258 | return str; |
| 259 | } |
| 260 | #endif |
| 261 | errout: |
| 262 | free(str); |
| 263 | return NULL; |
| 264 | } |
| 265 | |
| 266 | static void free_instance(struct fsck_instance *p) |
| 267 | { |
| 268 | free(p->prog); |
| 269 | free(p->device); |
| 270 | free(p->base_device); |
| 271 | free(p); |
| 272 | } |
| 273 | |
| 274 | static struct fs_info *create_fs_device(const char *device, const char *mntpnt, |
| 275 | const char *type, const char *opts, |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 276 | int passno) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 277 | { |
| 278 | struct fs_info *fs; |
| 279 | |
| 280 | fs = xzalloc(sizeof(*fs)); |
| 281 | fs->device = xstrdup(device); |
| 282 | fs->mountpt = xstrdup(mntpnt); |
Denis Vlasenko | b9f5d59 | 2008-08-20 02:38:48 +0000 | [diff] [blame] | 283 | if (strchr(type, ',')) |
| 284 | type = (char *)"auto"; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 285 | fs->type = xstrdup(type); |
| 286 | fs->opts = xstrdup(opts ? opts : ""); |
Denis Vlasenko | b9f5d59 | 2008-08-20 02:38:48 +0000 | [diff] [blame] | 287 | fs->passno = passno < 0 ? 1 : passno; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 288 | /*fs->flags = 0; */ |
| 289 | /*fs->next = NULL; */ |
| 290 | |
| 291 | if (!filesys_info) |
| 292 | filesys_info = fs; |
| 293 | else |
| 294 | filesys_last->next = fs; |
| 295 | filesys_last = fs; |
| 296 | |
| 297 | return fs; |
| 298 | } |
| 299 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 300 | /* Load the filesystem database from /etc/fstab */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 301 | static void load_fs_info(const char *filename) |
| 302 | { |
Denis Vlasenko | b9f5d59 | 2008-08-20 02:38:48 +0000 | [diff] [blame] | 303 | FILE *fstab; |
| 304 | struct mntent mte; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 305 | struct fs_info *fs; |
| 306 | |
Denis Vlasenko | b9f5d59 | 2008-08-20 02:38:48 +0000 | [diff] [blame] | 307 | fstab = setmntent(filename, "r"); |
| 308 | if (!fstab) { |
| 309 | bb_perror_msg("cannot read %s", filename); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 310 | return; |
| 311 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 312 | |
Denis Vlasenko | b9f5d59 | 2008-08-20 02:38:48 +0000 | [diff] [blame] | 313 | // Loop through entries |
| 314 | while (getmntent_r(fstab, &mte, bb_common_bufsiz1, COMMON_BUFSIZE)) { |
| 315 | //bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir, |
| 316 | // mte.mnt_type, mte.mnt_opts, |
| 317 | // mte.mnt_passno); |
| 318 | fs = create_fs_device(mte.mnt_fsname, mte.mnt_dir, |
| 319 | mte.mnt_type, mte.mnt_opts, |
| 320 | mte.mnt_passno); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 321 | } |
Denis Vlasenko | b9f5d59 | 2008-08-20 02:38:48 +0000 | [diff] [blame] | 322 | endmntent(fstab); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /* Lookup filesys in /etc/fstab and return the corresponding entry. */ |
| 326 | static struct fs_info *lookup(char *filesys) |
| 327 | { |
| 328 | struct fs_info *fs; |
| 329 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 330 | for (fs = filesys_info; fs; fs = fs->next) { |
| 331 | if (strcmp(filesys, fs->device) == 0 |
| 332 | || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0) |
| 333 | ) |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | return fs; |
| 338 | } |
| 339 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 340 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 341 | static int progress_active(void) |
| 342 | { |
| 343 | struct fsck_instance *inst; |
| 344 | |
| 345 | for (inst = instance_list; inst; inst = inst->next) { |
| 346 | if (inst->flags & FLAG_DONE) |
| 347 | continue; |
| 348 | if (inst->flags & FLAG_PROGRESS) |
| 349 | return 1; |
| 350 | } |
| 351 | return 0; |
| 352 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 353 | #endif |
| 354 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 355 | |
| 356 | /* |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 357 | * Send a signal to all outstanding fsck child processes |
| 358 | */ |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 359 | static void kill_all_if_cancel_requested(void) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 360 | { |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 361 | static smallint kill_sent; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 362 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 363 | struct fsck_instance *inst; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 364 | |
| 365 | if (!cancel_requested || kill_sent) |
| 366 | return; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 367 | |
| 368 | for (inst = instance_list; inst; inst = inst->next) { |
| 369 | if (inst->flags & FLAG_DONE) |
| 370 | continue; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 371 | kill(inst->pid, SIGTERM); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 372 | } |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 373 | kill_sent = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* |
| 377 | * Wait for one child process to exit; when it does, unlink it from |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 378 | * the list of executing child processes, free, and return its exit status. |
| 379 | * If there is no exited child, return -1. |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 380 | */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 381 | static int wait_one(int flags) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 382 | { |
| 383 | int status; |
| 384 | int sig; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 385 | struct fsck_instance *inst, *prev; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 386 | pid_t pid; |
| 387 | |
| 388 | if (!instance_list) |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 389 | return -1; |
| 390 | /* if (noexecute) { already returned -1; } */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 391 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 392 | while (1) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 393 | pid = waitpid(-1, &status, flags); |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 394 | kill_all_if_cancel_requested(); |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 395 | if (pid == 0) /* flags == WNOHANG and no children exited */ |
| 396 | return -1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 397 | if (pid < 0) { |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 398 | if (errno == EINTR) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 399 | continue; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 400 | if (errno == ECHILD) { /* paranoia */ |
| 401 | bb_error_msg("wait: no more children"); |
| 402 | return -1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 403 | } |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 404 | bb_perror_msg("wait"); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 405 | continue; |
| 406 | } |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 407 | prev = NULL; |
| 408 | inst = instance_list; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 409 | do { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 410 | if (inst->pid == pid) |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 411 | goto child_died; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 412 | prev = inst; |
| 413 | inst = inst->next; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 414 | } while (inst); |
| 415 | } |
| 416 | child_died: |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 417 | |
| 418 | if (WIFEXITED(status)) |
| 419 | status = WEXITSTATUS(status); |
| 420 | else if (WIFSIGNALED(status)) { |
| 421 | sig = WTERMSIG(status); |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 422 | status = EXIT_UNCORRECTED; |
| 423 | if (sig != SIGINT) { |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 424 | printf("Warning: %s %s terminated " |
| 425 | "by signal %d\n", |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 426 | inst->prog, inst->device, sig); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 427 | status = EXIT_ERROR; |
| 428 | } |
| 429 | } else { |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 430 | printf("%s %s: status is %x, should never happen\n", |
| 431 | inst->prog, inst->device, status); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 432 | status = EXIT_ERROR; |
| 433 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 434 | |
| 435 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 436 | if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) { |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 437 | struct fsck_instance *inst2; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 438 | for (inst2 = instance_list; inst2; inst2 = inst2->next) { |
| 439 | if (inst2->flags & FLAG_DONE) |
| 440 | continue; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 441 | if (strcmp(inst2->type, "ext2") != 0 |
| 442 | && strcmp(inst2->type, "ext3") != 0 |
| 443 | ) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 444 | continue; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 445 | } |
| 446 | /* ext[23], we will send USR1 |
| 447 | * (request to start displaying progress bar) |
| 448 | * |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 449 | * If we've just started the fsck, wait a tiny |
| 450 | * bit before sending the kill, to give it |
| 451 | * time to set up the signal handler |
| 452 | */ |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 453 | if (inst2->start_time >= time(NULL) - 1) |
| 454 | sleep(1); |
| 455 | kill(inst2->pid, SIGUSR1); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 456 | inst2->flags |= FLAG_PROGRESS; |
| 457 | break; |
| 458 | } |
| 459 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 460 | #endif |
| 461 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 462 | if (prev) |
| 463 | prev->next = inst->next; |
| 464 | else |
| 465 | instance_list = inst->next; |
| 466 | if (verbose > 1) |
| 467 | printf("Finished with %s (exit status %d)\n", |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 468 | inst->device, status); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 469 | num_running--; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 470 | free_instance(inst); |
| 471 | |
| 472 | return status; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 475 | /* |
| 476 | * Wait until all executing child processes have exited; return the |
| 477 | * logical OR of all of their exit code values. |
| 478 | */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 479 | #define FLAG_WAIT_ALL 0 |
| 480 | #define FLAG_WAIT_ATLEAST_ONE WNOHANG |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 481 | static int wait_many(int flags) |
| 482 | { |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 483 | int exit_status; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 484 | int global_status = 0; |
| 485 | int wait_flags = 0; |
| 486 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 487 | while ((exit_status = wait_one(wait_flags)) != -1) { |
| 488 | global_status |= exit_status; |
| 489 | wait_flags |= flags; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 490 | } |
| 491 | return global_status; |
| 492 | } |
| 493 | |
| 494 | /* |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 495 | * Execute a particular fsck program, and link it into the list of |
| 496 | * child processes we are waiting for. |
| 497 | */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 498 | static void execute(const char *type, const char *device, |
| 499 | const char *mntpt /*, int interactive */) |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 500 | { |
| 501 | char *argv[num_args + 4]; /* see count below: */ |
| 502 | int argc; |
| 503 | int i; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 504 | struct fsck_instance *inst; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 505 | pid_t pid; |
| 506 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 507 | argv[0] = xasprintf("fsck.%s", type); /* 1 */ |
| 508 | for (i = 0; i < num_args; i++) |
| 509 | argv[i+1] = args[i]; /* num_args */ |
| 510 | argc = num_args + 1; |
| 511 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 512 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 513 | if (progress && !progress_active()) { |
| 514 | if (strcmp(type, "ext2") == 0 |
| 515 | || strcmp(type, "ext3") == 0 |
| 516 | ) { |
| 517 | argv[argc++] = xasprintf("-C%d", progress_fd); /* 1 */ |
| 518 | inst->flags |= FLAG_PROGRESS; |
| 519 | } |
| 520 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 521 | #endif |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 522 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 523 | argv[argc++] = (char*)device; /* 1 */ |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 524 | argv[argc] = NULL; /* 1 */ |
| 525 | |
| 526 | if (verbose || noexecute) { |
| 527 | printf("[%s (%d) -- %s]", argv[0], num_running, |
| 528 | mntpt ? mntpt : device); |
| 529 | for (i = 0; i < argc; i++) |
| 530 | printf(" %s", argv[i]); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 531 | bb_putchar('\n'); |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* Fork and execute the correct program. */ |
| 535 | pid = -1; |
| 536 | if (!noexecute) { |
Denis Vlasenko | 53091ec | 2007-03-26 13:35:09 +0000 | [diff] [blame] | 537 | pid = spawn(argv); |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 538 | if (pid < 0) |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 539 | bb_simple_perror_msg(argv[0]); |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 542 | #if DO_PROGRESS_INDICATOR |
| 543 | free(argv[num_args + 1]); |
| 544 | #endif |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 545 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 546 | /* No child, so don't record an instance */ |
| 547 | if (pid <= 0) { |
| 548 | free(argv[0]); |
Denis Vlasenko | 30eb319 | 2008-02-02 18:54:58 +0000 | [diff] [blame] | 549 | return; |
| 550 | } |
| 551 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 552 | inst = xzalloc(sizeof(*inst)); |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 553 | inst->pid = pid; |
| 554 | inst->prog = argv[0]; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 555 | inst->device = xstrdup(device); |
| 556 | inst->base_device = base_device(device); |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 557 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 558 | inst->start_time = time(NULL); |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 559 | #endif |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 560 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 561 | /* Add to the list of running fsck's. |
| 562 | * (was adding to the end, but adding to the front is simpler...) */ |
| 563 | inst->next = instance_list; |
| 564 | instance_list = inst; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 568 | * Run the fsck program on a particular device |
| 569 | * |
| 570 | * If the type is specified using -t, and it isn't prefixed with "no" |
| 571 | * (as in "noext2") and only one filesystem type is specified, then |
| 572 | * use that type regardless of what is specified in /etc/fstab. |
| 573 | * |
| 574 | * If the type isn't specified by the user, then use either the type |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 575 | * specified in /etc/fstab, or "auto". |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 576 | */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 577 | static void fsck_device(struct fs_info *fs /*, int interactive */) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 578 | { |
| 579 | const char *type; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 580 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 581 | if (strcmp(fs->type, "auto") != 0) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 582 | type = fs->type; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 583 | if (verbose > 2) |
| 584 | bb_info_msg("using filesystem type '%s' %s", |
| 585 | type, "from fstab"); |
| 586 | } else if (fstype |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 587 | && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */ |
| 588 | && strncmp(fstype, "opts=", 5) != 0 |
| 589 | && strncmp(fstype, "loop", 4) != 0 |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 590 | && !strchr(fstype, ',') |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 591 | ) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 592 | type = fstype; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 593 | if (verbose > 2) |
| 594 | bb_info_msg("using filesystem type '%s' %s", |
| 595 | type, "from -t"); |
| 596 | } else { |
| 597 | type = "auto"; |
| 598 | if (verbose > 2) |
| 599 | bb_info_msg("using filesystem type '%s' %s", |
| 600 | type, "(default)"); |
| 601 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 602 | |
| 603 | num_running++; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 604 | execute(type, fs->device, fs->mountpt /*, interactive */); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /* |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 608 | * Returns TRUE if a partition on the same disk is already being |
| 609 | * checked. |
| 610 | */ |
| 611 | static int device_already_active(char *device) |
| 612 | { |
| 613 | struct fsck_instance *inst; |
| 614 | char *base; |
| 615 | |
| 616 | if (force_all_parallel) |
| 617 | return 0; |
| 618 | |
| 619 | #ifdef BASE_MD |
| 620 | /* Don't check a soft raid disk with any other disk */ |
| 621 | if (instance_list |
| 622 | && (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1) |
| 623 | || !strncmp(device, BASE_MD, sizeof(BASE_MD)-1)) |
| 624 | ) { |
| 625 | return 1; |
| 626 | } |
| 627 | #endif |
| 628 | |
| 629 | base = base_device(device); |
| 630 | /* |
| 631 | * If we don't know the base device, assume that the device is |
| 632 | * already active if there are any fsck instances running. |
| 633 | */ |
| 634 | if (!base) |
| 635 | return (instance_list != NULL); |
| 636 | |
| 637 | for (inst = instance_list; inst; inst = inst->next) { |
| 638 | if (!inst->base_device || !strcmp(base, inst->base_device)) { |
| 639 | free(base); |
| 640 | return 1; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | free(base); |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | /* |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 649 | * This function returns true if a particular option appears in a |
| 650 | * comma-delimited options list |
| 651 | */ |
| 652 | static int opt_in_list(char *opt, char *optlist) |
| 653 | { |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 654 | char *s; |
| 655 | int len; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 656 | |
| 657 | if (!optlist) |
| 658 | return 0; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 659 | |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 660 | len = strlen(opt); |
| 661 | s = optlist - 1; |
| 662 | while (1) { |
| 663 | s = strstr(s + 1, opt); |
| 664 | if (!s) |
| 665 | return 0; |
| 666 | /* neither "opt.." nor "xxx,opt.."? */ |
| 667 | if (s != optlist && s[-1] != ',') |
| 668 | continue; |
| 669 | /* neither "..opt" nor "..opt,xxx"? */ |
| 670 | if (s[len] != '\0' && s[len] != ',') |
| 671 | continue; |
| 672 | return 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 673 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | /* See if the filesystem matches the criteria given by the -t option */ |
| 677 | static int fs_match(struct fs_info *fs) |
| 678 | { |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 679 | int n, ret, checked_type; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 680 | char *cp; |
| 681 | |
| 682 | if (!fs_type_list) |
| 683 | return 1; |
| 684 | |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 685 | ret = 0; |
| 686 | checked_type = 0; |
| 687 | n = 0; |
| 688 | while (1) { |
| 689 | cp = fs_type_list[n]; |
| 690 | if (!cp) |
| 691 | break; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 692 | switch (fs_type_flag[n]) { |
| 693 | case FS_TYPE_FLAG_NORMAL: |
| 694 | checked_type++; |
| 695 | if (strcmp(cp, fs->type) == 0) |
| 696 | ret = 1; |
| 697 | break; |
| 698 | case FS_TYPE_FLAG_NEGOPT: |
| 699 | if (opt_in_list(cp, fs->opts)) |
| 700 | return 0; |
| 701 | break; |
| 702 | case FS_TYPE_FLAG_OPT: |
| 703 | if (!opt_in_list(cp, fs->opts)) |
| 704 | return 0; |
| 705 | break; |
| 706 | } |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 707 | n++; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 708 | } |
| 709 | if (checked_type == 0) |
| 710 | return 1; |
| 711 | |
| 712 | return (fs_type_negated ? !ret : ret); |
| 713 | } |
| 714 | |
| 715 | /* Check if we should ignore this filesystem. */ |
| 716 | static int ignore(struct fs_info *fs) |
| 717 | { |
| 718 | /* |
| 719 | * If the pass number is 0, ignore it. |
| 720 | */ |
| 721 | if (fs->passno == 0) |
| 722 | return 1; |
| 723 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 724 | /* |
| 725 | * If a specific fstype is specified, and it doesn't match, |
| 726 | * ignore it. |
| 727 | */ |
| 728 | if (!fs_match(fs)) |
| 729 | return 1; |
| 730 | |
| 731 | /* Are we ignoring this type? */ |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 732 | if (index_in_strings(ignored_types, fs->type) >= 0) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 733 | return 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 734 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 735 | /* We can and want to check this file system type. */ |
| 736 | return 0; |
| 737 | } |
| 738 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 739 | /* Check all file systems, using the /etc/fstab table. */ |
| 740 | static int check_all(void) |
| 741 | { |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 742 | struct fs_info *fs; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 743 | int status = EXIT_OK; |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 744 | smallint not_done_yet; |
| 745 | smallint pass_done; |
| 746 | int passno; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 747 | |
| 748 | if (verbose) |
| 749 | puts("Checking all filesystems"); |
| 750 | |
| 751 | /* |
| 752 | * Do an initial scan over the filesystem; mark filesystems |
| 753 | * which should be ignored as done, and resolve any "auto" |
| 754 | * filesystem types (done as a side-effect of calling ignore()). |
| 755 | */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 756 | for (fs = filesys_info; fs; fs = fs->next) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 757 | if (ignore(fs)) |
| 758 | fs->flags |= FLAG_DONE; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 759 | |
| 760 | /* |
| 761 | * Find and check the root filesystem. |
| 762 | */ |
| 763 | if (!parallel_root) { |
| 764 | for (fs = filesys_info; fs; fs = fs->next) { |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 765 | if (LONE_CHAR(fs->mountpt, '/')) { |
| 766 | if (!skip_root && !ignore(fs)) { |
| 767 | fsck_device(fs /*, 1*/); |
| 768 | status |= wait_many(FLAG_WAIT_ALL); |
| 769 | if (status > EXIT_NONDESTRUCT) |
| 770 | return status; |
| 771 | } |
| 772 | fs->flags |= FLAG_DONE; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 773 | break; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 774 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | /* |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 778 | * This is for the bone-headed user who has root |
| 779 | * filesystem listed twice. |
| 780 | * "Skip root" will skip _all_ root entries. |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 781 | */ |
| 782 | if (skip_root) |
| 783 | for (fs = filesys_info; fs; fs = fs->next) |
| 784 | if (LONE_CHAR(fs->mountpt, '/')) |
| 785 | fs->flags |= FLAG_DONE; |
| 786 | |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 787 | not_done_yet = 1; |
| 788 | passno = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 789 | while (not_done_yet) { |
| 790 | not_done_yet = 0; |
| 791 | pass_done = 1; |
| 792 | |
| 793 | for (fs = filesys_info; fs; fs = fs->next) { |
| 794 | if (cancel_requested) |
| 795 | break; |
| 796 | if (fs->flags & FLAG_DONE) |
| 797 | continue; |
| 798 | /* |
| 799 | * If the filesystem's pass number is higher |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 800 | * than the current pass number, then we didn't |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 801 | * do it yet. |
| 802 | */ |
| 803 | if (fs->passno > passno) { |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 804 | not_done_yet = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 805 | continue; |
| 806 | } |
| 807 | /* |
| 808 | * If a filesystem on a particular device has |
| 809 | * already been spawned, then we need to defer |
| 810 | * this to another pass. |
| 811 | */ |
| 812 | if (device_already_active(fs->device)) { |
| 813 | pass_done = 0; |
| 814 | continue; |
| 815 | } |
| 816 | /* |
| 817 | * Spawn off the fsck process |
| 818 | */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 819 | fsck_device(fs /*, serialize*/); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 820 | fs->flags |= FLAG_DONE; |
| 821 | |
| 822 | /* |
| 823 | * Only do one filesystem at a time, or if we |
| 824 | * have a limit on the number of fsck's extant |
| 825 | * at one time, apply that limit. |
| 826 | */ |
| 827 | if (serialize |
| 828 | || (max_running && (num_running >= max_running)) |
| 829 | ) { |
| 830 | pass_done = 0; |
| 831 | break; |
| 832 | } |
| 833 | } |
| 834 | if (cancel_requested) |
| 835 | break; |
| 836 | if (verbose > 1) |
| 837 | printf("--waiting-- (pass %d)\n", passno); |
| 838 | status |= wait_many(pass_done ? FLAG_WAIT_ALL : |
| 839 | FLAG_WAIT_ATLEAST_ONE); |
| 840 | if (pass_done) { |
| 841 | if (verbose > 1) |
| 842 | puts("----------------------------------"); |
| 843 | passno++; |
| 844 | } else |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 845 | not_done_yet = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 846 | } |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 847 | kill_all_if_cancel_requested(); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 848 | status |= wait_many(FLAG_WAIT_ATLEAST_ONE); |
| 849 | return status; |
| 850 | } |
| 851 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 852 | /* |
| 853 | * Deal with the fsck -t argument. |
| 854 | * Huh, for mount "-t novfat,nfs" means "neither vfat nor nfs"! |
| 855 | * Why here we require "-t novfat,nonfs" ?? |
| 856 | */ |
| 857 | static void compile_fs_type(char *fs_type) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 858 | { |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 859 | char *s; |
| 860 | int num = 2; |
| 861 | smallint negate; |
| 862 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 863 | s = fs_type; |
| 864 | while ((s = strchr(s, ','))) { |
| 865 | num++; |
| 866 | s++; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | fs_type_list = xzalloc(num * sizeof(fs_type_list[0])); |
| 870 | fs_type_flag = xzalloc(num * sizeof(fs_type_flag[0])); |
| 871 | fs_type_negated = -1; /* not yet known is it negated or not */ |
| 872 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 873 | num = 0; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 874 | s = fs_type; |
| 875 | while (1) { |
| 876 | char *comma; |
| 877 | |
| 878 | negate = 0; |
| 879 | if (s[0] == 'n' && s[1] == 'o') { /* "no.." */ |
| 880 | s += 2; |
| 881 | negate = 1; |
| 882 | } else if (s[0] == '!') { |
| 883 | s++; |
| 884 | negate = 1; |
| 885 | } |
Denis Vlasenko | e18a293 | 2007-01-19 02:03:14 +0000 | [diff] [blame] | 886 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 887 | if (strcmp(s, "loop") == 0) |
| 888 | /* loop is really short-hand for opts=loop */ |
| 889 | goto loop_special_case; |
| 890 | if (strncmp(s, "opts=", 5) == 0) { |
| 891 | s += 5; |
| 892 | loop_special_case: |
| 893 | fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT; |
| 894 | } else { |
| 895 | if (fs_type_negated == -1) |
| 896 | fs_type_negated = negate; |
| 897 | if (fs_type_negated != negate) |
| 898 | bb_error_msg_and_die( |
| 899 | "either all or none of the filesystem types passed to -t must be prefixed " |
| 900 | "with 'no' or '!'"); |
| 901 | } |
| 902 | comma = strchr(s, ','); |
| 903 | fs_type_list[num++] = comma ? xstrndup(s, comma-s) : xstrdup(s); |
| 904 | if (!comma) |
| 905 | break; |
| 906 | s = comma + 1; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 907 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 910 | static void parse_args(char **argv) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 911 | { |
| 912 | int i, j; |
| 913 | char *arg, *tmp; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 914 | char *options; |
| 915 | int optpos; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 916 | int opts_for_fsck = 0; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 917 | |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 918 | /* in bss, so already zeroed |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 919 | num_devices = 0; |
| 920 | num_args = 0; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 921 | instance_list = NULL; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 922 | */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 923 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 924 | for (i = 1; argv[i]; i++) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 925 | arg = argv[i]; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 926 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 927 | /* "/dev/blk" or "/path" or "UUID=xxx" or "LABEL=xxx" */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 928 | if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) { |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 929 | // FIXME: must check that arg is a blkdev, or resolve |
| 930 | // "/path", "UUID=xxx" or "LABEL=xxx" into block device name |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 931 | // ("UUID=xxx"/"LABEL=xxx" can probably shifted to fsck.auto duties) |
Denis Vlasenko | deeed59 | 2008-07-08 05:14:36 +0000 | [diff] [blame] | 932 | devices = xrealloc_vector(devices, 2, num_devices); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 933 | devices[num_devices++] = xstrdup(arg); |
| 934 | continue; |
| 935 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 936 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 937 | if (arg[0] != '-' || opts_for_fsck) { |
Denis Vlasenko | deeed59 | 2008-07-08 05:14:36 +0000 | [diff] [blame] | 938 | args = xrealloc_vector(args, 2, num_args); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 939 | args[num_args++] = xstrdup(arg); |
| 940 | continue; |
| 941 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 942 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 943 | if (LONE_CHAR(arg + 1, '-')) { /* "--" ? */ |
| 944 | opts_for_fsck = 1; |
| 945 | continue; |
| 946 | } |
| 947 | |
| 948 | optpos = 0; |
| 949 | options = NULL; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 950 | for (j = 1; arg[j]; j++) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 951 | switch (arg[j]) { |
| 952 | case 'A': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 953 | doall = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 954 | break; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 955 | #if DO_PROGRESS_INDICATOR |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 956 | case 'C': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 957 | progress = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 958 | if (arg[++j]) { /* -Cn */ |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 959 | progress_fd = xatoi_u(&arg[j]); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 960 | goto next_arg; |
| 961 | } |
| 962 | /* -C n */ |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 963 | if (!argv[++i]) bb_show_usage(); |
| 964 | progress_fd = xatoi_u(argv[i]); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 965 | goto next_arg; |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 966 | #endif |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 967 | case 'V': |
| 968 | verbose++; |
| 969 | break; |
| 970 | case 'N': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 971 | noexecute = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 972 | break; |
| 973 | case 'R': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 974 | skip_root = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 975 | break; |
| 976 | case 'T': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 977 | notitle = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 978 | break; |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 979 | /* case 'M': |
| 980 | like_mount = 1; |
| 981 | break; */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 982 | case 'P': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 983 | parallel_root = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 984 | break; |
| 985 | case 's': |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 986 | serialize = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 987 | break; |
| 988 | case 't': |
| 989 | if (fstype) |
| 990 | bb_show_usage(); |
| 991 | if (arg[++j]) |
| 992 | tmp = &arg[j]; |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 993 | else if (argv[++i]) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 994 | tmp = argv[i]; |
| 995 | else |
| 996 | bb_show_usage(); |
| 997 | fstype = xstrdup(tmp); |
| 998 | compile_fs_type(fstype); |
| 999 | goto next_arg; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1000 | case '?': |
| 1001 | bb_show_usage(); |
| 1002 | break; |
| 1003 | default: |
| 1004 | optpos++; |
| 1005 | /* one extra for '\0' */ |
| 1006 | options = xrealloc(options, optpos + 2); |
| 1007 | options[optpos] = arg[j]; |
| 1008 | break; |
| 1009 | } |
| 1010 | } |
| 1011 | next_arg: |
| 1012 | if (optpos) { |
| 1013 | options[0] = '-'; |
| 1014 | options[optpos + 1] = '\0'; |
Denis Vlasenko | deeed59 | 2008-07-08 05:14:36 +0000 | [diff] [blame] | 1015 | args = xrealloc_vector(args, 2, num_args); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1016 | args[num_args++] = options; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | if (getenv("FSCK_FORCE_ALL_PARALLEL")) |
Denis Vlasenko | a0e701d | 2007-01-19 02:01:19 +0000 | [diff] [blame] | 1020 | force_all_parallel = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1021 | tmp = getenv("FSCK_MAX_INST"); |
| 1022 | if (tmp) |
| 1023 | max_running = xatoi(tmp); |
| 1024 | } |
| 1025 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 1026 | static void signal_cancel(int sig UNUSED_PARAM) |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 1027 | { |
| 1028 | cancel_requested = 1; |
| 1029 | } |
| 1030 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 1031 | int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 1032 | int fsck_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1033 | { |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1034 | int i, status; |
| 1035 | /*int interactive;*/ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1036 | const char *fstab; |
| 1037 | struct fs_info *fs; |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 1038 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1039 | /* we want wait() to be interruptible */ |
Denis Vlasenko | 8e2cfec | 2008-03-12 23:19:35 +0000 | [diff] [blame] | 1040 | signal_no_SA_RESTART_empty_mask(SIGINT, signal_cancel); |
| 1041 | signal_no_SA_RESTART_empty_mask(SIGTERM, signal_cancel); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1042 | |
| 1043 | setbuf(stdout, NULL); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1044 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1045 | parse_args(argv); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1046 | |
| 1047 | if (!notitle) |
| 1048 | puts("fsck (busybox "BB_VER", "BB_BT")"); |
| 1049 | |
Denis Vlasenko | 1abf91a | 2007-01-19 02:02:33 +0000 | [diff] [blame] | 1050 | /* Even plain "fsck /dev/hda1" needs fstab to get fs type, |
| 1051 | * so we are scanning it anyway */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1052 | fstab = getenv("FSTAB_FILE"); |
| 1053 | if (!fstab) |
| 1054 | fstab = "/etc/fstab"; |
| 1055 | load_fs_info(fstab); |
| 1056 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1057 | /*interactive = (num_devices == 1) | serialize;*/ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1058 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1059 | if (num_devices == 0) |
| 1060 | /*interactive =*/ serialize = doall = 1; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1061 | if (doall) |
| 1062 | return check_all(); |
| 1063 | |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1064 | status = 0; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 1065 | for (i = 0; i < num_devices; i++) { |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1066 | if (cancel_requested) { |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 1067 | kill_all_if_cancel_requested(); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1068 | break; |
| 1069 | } |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 1070 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1071 | fs = lookup(devices[i]); |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 1072 | if (!fs) |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1073 | fs = create_fs_device(devices[i], "", "auto", NULL, -1); |
| 1074 | fsck_device(fs /*, interactive */); |
Denis Vlasenko | f8c11aa | 2007-01-19 02:04:09 +0000 | [diff] [blame] | 1075 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1076 | if (serialize |
| 1077 | || (max_running && (num_running >= max_running)) |
| 1078 | ) { |
Denis Vlasenko | a55bd05 | 2008-03-17 08:59:19 +0000 | [diff] [blame] | 1079 | int exit_status = wait_one(0); |
| 1080 | if (exit_status >= 0) |
| 1081 | status |= exit_status; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1082 | if (verbose > 1) |
| 1083 | puts("----------------------------------"); |
| 1084 | } |
| 1085 | } |
| 1086 | status |= wait_many(FLAG_WAIT_ALL); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1087 | return status; |
| 1088 | } |