kfan / rpms / util-linux

Forked from rpms/util-linux 3 years ago
Clone
169b953
--- util-linux-2.12p/mount/mount.c.ocfs2	2005-07-12 16:31:16.000000000 +0200
169b953
+++ util-linux-2.12p/mount/mount.c	2005-07-12 16:31:46.000000000 +0200
169b953
@@ -466,6 +466,61 @@
169b953
 }
169b953
 
169b953
 /*
169b953
+ * check_special_mountprog()
169b953
+ *	If there is a special mount program for this type, exec it.
169b953
+ * returns: 0: no exec was done, 1: exec was done, status has result
169b953
+ */
169b953
+
169b953
+static int
169b953
+check_special_mountprog(const char *spec, const char *node, const char *type, int flags,
169b953
+			char *extra_opts, int *status) {
169b953
+  char mountprog[120];
169b953
+  struct stat statbuf;
169b953
+  int res;
169b953
+
169b953
+  if (!external_allowed)
169b953
+      return 0;
169b953
+
169b953
+  if (type && strlen(type) < 100) {
169b953
+       sprintf(mountprog, "/sbin/mount.%s", type);
169b953
+       if (stat(mountprog, &statbuf) == 0) {
169b953
+	    res = fork();
169b953
+	    if (res == 0) {
169b953
+		 char *oo, *mountargs[10];
169b953
+		 int i = 0;
169b953
+
169b953
+		 setuid(getuid());
169b953
+		 setgid(getgid());
169b953
+		 oo = fix_opts_string (flags, extra_opts, NULL);
169b953
+		 mountargs[i++] = mountprog;
169b953
+		 mountargs[i++] = spec;
169b953
+		 mountargs[i++] = node;
169b953
+		 if (nomtab)
169b953
+		      mountargs[i++] = "-n";
169b953
+		 if (verbose)
169b953
+		      mountargs[i++] = "-v";
169b953
+		 if (oo && *oo) {
169b953
+		      mountargs[i++] = "-o";
169b953
+		      mountargs[i++] = oo;
169b953
+		 }
169b953
+		 mountargs[i] = NULL;
169b953
+		 execv(mountprog, mountargs);
169b953
+		 exit(1);	/* exec failed */
169b953
+	    } else if (res != -1) {
169b953
+		 int st;
169b953
+		 wait(&st);
169b953
+		 *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
169b953
+		 return 1;
169b953
+	    } else {
169b953
+	    	 int errsv = errno;
169b953
+		 error(_("mount: cannot fork: %s"), strerror(errsv));
169b953
+	    }
169b953
+       }
169b953
+  }
169b953
+  return 0;
169b953
+}
169b953
+
169b953
+/*
169b953
  * guess_fstype_and_mount()
169b953
  *	Mount a single file system. Guess the type when unknown.
169b953
  * returns: 0: OK, -1: error in errno, 1: other error
169b953
@@ -474,9 +529,11 @@
169b953
  */
169b953
 static int
169b953
 guess_fstype_and_mount(const char *spec, const char *node, const char **types,
169b953
-		       int flags, char *mount_opts) {
169b953
+		       int flags, char *mount_opts, int *special, int *status) {
169b953
    struct mountargs args = { spec, node, NULL, flags & ~MS_NOSYS, mount_opts };
169b953
    
169b953
+   *special = 0;
169b953
+   
169b953
    if (*types && strcasecmp (*types, "auto") == 0)
169b953
       *types = NULL;
169b953
 
169b953
@@ -485,10 +542,16 @@
169b953
 
169b953
    if (!*types && !(flags & MS_REMOUNT)) {
169b953
       *types = guess_fstype(spec);
169b953
-      if (*types && !strcmp(*types, "swap")) {
169b953
-	  error(_("%s looks like swapspace - not mounted"), spec);
169b953
-	  *types = NULL;
169b953
-	  return 1;
169b953
+      if (*types) {
169b953
+	  if (!strcmp(*types, "swap")) {
169b953
+	      error(_("%s looks like swapspace - not mounted"), spec);
169b953
+	      *types = NULL;
169b953
+	      return 1;
169b953
+	  } else if (check_special_mountprog(spec, node, *types, flags,
169b953
+					     mount_opts, status)) {
169b953
+	      *special = 1;
169b953
+	      return 0;
169b953
+          }
169b953
       }
169b953
    }
169b953
 
169b953
@@ -741,61 +804,6 @@
169b953
 }
169b953
 
169b953
 /*
169b953
- * check_special_mountprog()
169b953
- *	If there is a special mount program for this type, exec it.
169b953
- * returns: 0: no exec was done, 1: exec was done, status has result
169b953
- */
169b953
-
169b953
-static int
169b953
-check_special_mountprog(const char *spec, const char *node, const char *type,
169b953
-			int flags, char *extra_opts, int *status) {
169b953
-  char mountprog[120];
169b953
-  struct stat statbuf;
169b953
-  int res;
169b953
-
169b953
-  if (!external_allowed)
169b953
-      return 0;
169b953
-
169b953
-  if (type && strlen(type) < 100) {
169b953
-       sprintf(mountprog, "/sbin/mount.%s", type);
169b953
-       if (stat(mountprog, &statbuf) == 0) {
169b953
-	    res = fork();
169b953
-	    if (res == 0) {
169b953
-		 const char *oo, *mountargs[10];
169b953
-		 int i = 0;
169b953
-
169b953
-		 setuid(getuid());
169b953
-		 setgid(getgid());
169b953
-		 oo = fix_opts_string (flags, extra_opts, NULL);
169b953
-		 mountargs[i++] = mountprog;
169b953
-		 mountargs[i++] = spec;
169b953
-		 mountargs[i++] = node;
169b953
-		 if (nomtab)
169b953
-		      mountargs[i++] = "-n";
169b953
-		 if (verbose)
169b953
-		      mountargs[i++] = "-v";
169b953
-		 if (oo && *oo) {
169b953
-		      mountargs[i++] = "-o";
169b953
-		      mountargs[i++] = oo;
169b953
-		 }
169b953
-		 mountargs[i] = NULL;
169b953
-		 execv(mountprog, (char **) mountargs);
169b953
-		 exit(1);	/* exec failed */
169b953
-	    } else if (res != -1) {
169b953
-		 int st;
169b953
-		 wait(&st);
169b953
-		 *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
169b953
-		 return 1;
169b953
-	    } else {
169b953
-	    	 int errsv = errno;
169b953
-		 error(_("mount: cannot fork: %s"), strerror(errsv));
169b953
-	    }
169b953
-       }
169b953
-  }
169b953
-  return 0;
169b953
-}
169b953
-
169b953
-/*
169b953
  * try_mount_one()
169b953
  *	Try to mount one file system. When "bg" is 1, this is a retry
169b953
  *	in the background. One additional exit code EX_BG is used here.
169b953
@@ -807,7 +815,7 @@
169b953
 static int
169b953
 try_mount_one (const char *spec0, const char *node0, const char *types0,
169b953
 	       const char *opts0, int freq, int pass, int bg, int ro) {
169b953
-  int res = 0, status;
169b953
+  int res = 0, status, special;
169b953
   int mnt5_res = 0;		/* only for gcc */
169b953
   int mnt_err;
169b953
   int flags;
169b953
@@ -898,9 +906,15 @@
169b953
   block_signals (SIG_BLOCK);
169b953
 nosigblock:
169b953
 
169b953
-  if (!fake)
169b953
+  if (!fake) {
169b953
     mnt5_res = guess_fstype_and_mount (spec, node, &types, flags & ~MS_NOSYS,
169b953
-				       mount_opts);
169b953
+				       mount_opts, &special, &status);
169b953
+
169b953
+    if (special) {
169b953
+      block_signals (SIG_UNBLOCK);
169b953
+      return status;
169b953
+    }
169b953
+  }
169b953
 
169b953
   if (fake || mnt5_res == 0) {
169b953
       /* Mount succeeded, report this (if verbose) and write mtab entry.  */