From: Karel Zak Date: Mon, 30 Apr 2007 22:28:08 +0000 (+0200) Subject: mount: avoid duplicate entries in mtab when mount -f X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb369b14044f822e36097928efe9c121a225f9cb;p=util-linux mount: avoid duplicate entries in mtab when mount -f Signed-off-by: Karel Zak --- diff --git a/mount/mount.8 b/mount/mount.8 index 2d7c2189..4692a42b 100644 --- a/mount/mount.8 +++ b/mount/mount.8 @@ -341,7 +341,9 @@ conjunction with the flag to determine what the .B mount command is trying to do. It can also be used to add entries for devices -that were mounted earlier with the -n option. +that were mounted earlier with the -n option. The -f option checks for +existing record in /etc/mtab and fails when the record already +exists (with regular non-fake mount, this check is done by kernel). .TP .B \-i Don't call the /sbin/mount. helper even if it exists. diff --git a/mount/mount.c b/mount/mount.c index 1526f263..f54a90e8 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -190,6 +190,8 @@ static const struct opt_map opt_map[] = { static const char *opt_loopdev, *opt_vfstype, *opt_offset, *opt_encryption, *opt_speed, *opt_comment, *opt_uhelper; +static int mounted (const char *spec0, const char *node0); + static struct string_opt_map { char *tag; int skip; @@ -861,6 +863,14 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, suid_check(spec, node, &flags, &user); + /* The "mount -f" checks for for existing record in /etc/mtab (with + * regular non-fake mount this is usually done by kernel) + */ + if (fake && mounted (spec, node)) + die(EX_USAGE, _("mount: according to mtab, " + "%s is already mounted on %s\n"), + spec, node); + mount_opts = extra_opts; if (opt_speed)