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