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