From: Matthias Koenig Date: Mon, 17 Dec 2007 10:33:20 +0000 (+0100) Subject: mount: "nofail" mount option X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb00bb33bbf772de79fcbc8a9261a66f3f47adf0;p=util-linux mount: "nofail" mount option It would be nice to have a mount option "nofail" indicating that mount should not return an error if the device does not exit. This is useful for hotpluggable devices which are configured in fstab and __might__ not exist at boot time. Co-Author: Karel Zak Signed-off-by: Matthias Koenig Signed-off-by: Karel Zak --- diff --git a/mount/mount.8 b/mount/mount.8 index 54b11d46..ce52dd84 100644 --- a/mount/mount.8 +++ b/mount/mount.8 @@ -615,6 +615,9 @@ This option implies the options (unless overridden by subsequent options, as in the option line .BR group,dev,suid ). .TP +.B nofail +Do not report errors for this device if it does not exist. +.TP .B mand Allow mandatory locks on this filesystem. See .BR fcntl (2). diff --git a/mount/mount.c b/mount/mount.c index 917f62ac..0688c57f 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -176,9 +176,12 @@ static const struct opt_map opt_map[] = { { "norelatime", 0, 1, MS_RELATIME }, /* Update access time without regard to mtime/ctime */ #endif + { "nofail", 0, 0, MS_COMMENT}, /* Do not fail if ENOENT on dev */ { NULL, 0, 0, 0 } }; +static int opt_nofail = 0; + static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption, *opt_speed, *opt_comment, *opt_uhelper; @@ -383,6 +386,8 @@ parse_opt(char *opt, int *mask, char **extra_opts) { verbose = 0; } #endif + if (streq(opt, "nofail")) + opt_nofail = 1; return; } @@ -1198,9 +1203,11 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, else if (stat (node, &statbuf)) error (_("mount: mount point %s is a symbolic link to nowhere"), node); - else if (stat (spec, &statbuf)) + else if (stat (spec, &statbuf)) { + if (opt_nofail) + goto out; error (_("mount: special device %s does not exist"), spec); - else { + } else { errno = mnt_err; perror("mount"); } @@ -1208,10 +1215,12 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, case ENOTDIR: if (stat (node, &statbuf) || ! S_ISDIR(statbuf.st_mode)) error (_("mount: mount point %s is not a directory"), node); - else if (stat (spec, &statbuf) && errno == ENOTDIR) + else if (stat (spec, &statbuf) && errno == ENOTDIR) { + if (opt_nofail) + goto out; error (_("mount: special device %s does not exist\n" " (a path prefix is not a directory)\n"), spec); - else { + } else { errno = mnt_err; perror("mount"); } @@ -1296,6 +1305,8 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, break; } case ENOTBLK: + if (opt_nofail) + goto out; if (stat (spec, &statbuf)) /* strange ... */ error (_("mount: %s is not a block device, and stat fails?"), spec); else if (S_ISBLK(statbuf.st_mode)) @@ -1308,6 +1319,8 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, error (_("mount: %s is not a block device"), spec); break; case ENXIO: + if (opt_nofail) + goto out; error (_("mount: %s is not a valid block device"), spec); break; case EACCES: /* pre-linux 1.1.38, 1.1.41 and later */ case EROFS: /* linux 1.1.38 and later */