[PATCH] honor nofail option in fsck

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <ludwig.nussel@xxxxxxx>

---
 fsck/fsck.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index e11bbe9..fd4b9ae 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);
 
 	/*
-- 
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux