From 1bb516c34bf42d2ae9dc4aa40ae34b0df4e464a7 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Fri, 27 Nov 2009 10:15:53 +0100 Subject: [PATCH] fsck: honor nofail option in fsck analog to mount gracefully ignoring non existing devices if the "nofail" option is specified in fstab, also have fsck -A skip them. This way it's possible to have devices optionally not available during boot but still have them fsck'd if they are there. Signed-off-by: Ludwig Nussel --- fsck/fsck.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fsck/fsck.c b/fsck/fsck.c index e11bbe9b..66c027c7 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -847,6 +847,22 @@ static int fs_match(struct fs_info *fs, struct fs_type_compile *cmp) return (cmp->negate ? !ret : ret); } +/* + * Check if a device exists + */ +static int device_exists(const char *device) +{ + struct stat st; + + if (stat(device, &st) == -1) + return 0; + + if (!S_ISBLK(st.st_mode)) + return 0; + + return 1; +} + /* Check if we should ignore this filesystem. */ static int ignore(struct fs_info *fs) { @@ -869,6 +885,15 @@ static int ignore(struct fs_info *fs) return 1; } + /* + * ignore devices that don't exist and have the "nofail" mount option + */ + if (!device_exists(fs->device) && opt_in_list("nofail", fs->opts)) { + if (verbose) + printf(_("%s: skipping nonexistent device\n"), fs->device); + return 1; + } + interpret_type(fs); /* -- 2.39.5