Re: [PATCH] Use update_mtab() when using -f to prevent duplicate entries from being created.

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

 



On Mon, Apr 30, 2007 at 03:24:43PM -0400, Mike Frysinger wrote:
> On Tuesday 24 April 2007, Karel Zak wrote:
> > On Fri, Apr 13, 2007 at 07:28:25AM -0400, Mike Frysinger wrote:
> > > ---
> > >  mount/mount.c |    2 +-
> > >  1 files changed, 1 insertions(+), 1 deletions(-)
> > >
> > > diff --git a/mount/mount.c b/mount/mount.c
> > > index 8e850b0..ea5ddc9 100644
> > > --- a/mount/mount.c
> > > +++ b/mount/mount.c
> > > @@ -759,7 +759,7 @@ update_mtab_entry(const char *spec, const char *node,
> > > const char *type, print_one (&mnt);
> > >
> > >  	if (!nomtab && mtab_is_writable()) {
> > > -		if (flags & MS_REMOUNT)
> > > +		if (fake || (flags & MS_REMOUNT))
> > >  			update_mtab (mnt.mnt_dir, &mnt);
> > >  		else {
> > >  			mntFILE *mfp;
> >
> >  Sorry, NAK.
> >
> >  man mount (about -f):
> >     Causes everything to be done except for the actual system call;
> >
> >
> >  there is nothing about any other exception. It's root's mistake when
> >  add to mtab duplicate entry. The mount command prevents duplicate
> >  mounts for "mount -a" or MS_USER/MS_USERS only. I don't think that we
> >  need an exception for fake mounts. The fake mount has to work exactly
> >  like normal mount otherwise it's nonsense.
> 
> well, the reason for the change was because of the usage in the man page you 
> also referred to:
> 
> Causes everything to be done except for the actual system call; if it's not 
> obvious, this fakes'' mounting the file system. This option is useful in 
> conjunction with the -v flag to determine what the 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 description (last sentence) indicates that the process should be a lot 
> more safe than it actually is ... if the change i proposed above is NACKed, 

 Well, I'm not so stubborn ... but I'd like to add there a check for
 duplicate entries rather than hide the problem and update the mtab
 for fake mounts in a other way than for normal mounts (as was proposed
 by your patch). See the patch below.

    Karel


diff --git a/mount/mount.8 b/mount/mount.8
index 2d7c218..6cd1abc 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. It also checks for duplicate 
+entries, because for normal non-fake mounts it's kernel that avoid duplicate 
+mounts.
 .TP
 .B \-i
 Don't call the /sbin/mount.<filesystem> helper even if it exists.
diff --git a/mount/mount.c b/mount/mount.c
index 1526f26..9eb7f3b 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);
 
+  /* To avoid duplicate entries in mtab -- for normal non-fake mounts
+   * it's kernel that checks duplicates.
+   */
+  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)

-
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