kalev / rpms / util-linux

Forked from rpms/util-linux 4 years ago
Clone
632f494
--- util-linux-2.13-pre6/mount/fstab.c.twiceloop	2006-01-03 18:35:05.000000000 +0100
632f494
+++ util-linux-2.13-pre6/mount/fstab.c	2006-01-03 18:37:44.000000000 +0100
632f494
@@ -254,6 +254,27 @@
632f494
 	return (ct == 1);
632f494
 }
632f494
 
632f494
+/*
632f494
+ * Given the loop file LOOPFILE, and the mount point DIR, check that
632f494
+ * same file is already mounted on same directory 
632f494
+ *
632f494
+ * Don't forget there's 
632f494
+ *   /path/loopfile /path/dir loop=/dev/loop0
632f494
+ * in mtab for loop devices.
632f494
+ */
632f494
+int
632f494
+is_mounted_same_loopfile(const char *loopfile, const char *dir) {
632f494
+	struct mntentchn *mc, *mc0;
632f494
+	int ct = 0;
632f494
+
632f494
+	mc0 = mtab_head();
632f494
+	for (mc = mc0->prev; mc && mc != mc0; mc = mc->prev)
632f494
+		if (streq(mc->m.mnt_fsname, loopfile) && 
632f494
+		    streq(mc->m.mnt_dir, dir))
632f494
+			ct++;
632f494
+	return (ct == 1);
632f494
+}
632f494
+
632f494
 /* Given the name FILE, try to find the option "loop=FILE" in mtab.  */ 
632f494
 struct mntentchn *
632f494
 getmntoptfile (const char *file) {
632f494
--- util-linux-2.13-pre6/mount/mount.c.twiceloop	2006-01-03 18:35:06.000000000 +0100
632f494
+++ util-linux-2.13-pre6/mount/mount.c	2006-01-03 18:37:44.000000000 +0100
632f494
@@ -671,7 +671,7 @@
632f494
 
632f494
 static int
632f494
 loop_check(const char **spec, const char **type, int *flags,
632f494
-	   int *loop, const char **loopdev, const char **loopfile) {
632f494
+	   int *loop, const char **loopdev, const char **loopfile, const char *dir) {
632f494
   int looptype;
632f494
   unsigned long long offset;
632f494
 
632f494
@@ -709,6 +709,11 @@
632f494
     } else {
632f494
       int loopro = (*flags & MS_RDONLY);
632f494
 
632f494
+      if (is_mounted_same_loopfile(*loopfile, dir)) {
632f494
+	error(_("mount: %s already mounted on %s"), *loopfile, dir);
632f494
+	return EX_FAIL;
632f494
+      }
632f494
+      
632f494
       if (!*loopdev || !**loopdev)
632f494
 	*loopdev = find_unused_loop_device();
632f494
       if (!*loopdev)
632f494
@@ -856,7 +861,7 @@
632f494
        * stale assignments of files to loop devices. Nasty when used for
632f494
        * encryption.
632f494
        */
632f494
-      res = loop_check(&spec, &types, &flags, &loop, &loopdev, &loopfile);
632f494
+      res = loop_check(&spec, &types, &flags, &loop, &loopdev, &loopfile, node);
632f494
       if (res)
632f494
 	  goto out;
632f494
   }