util-linux/util-linux-2.12r-external-prog-on-guess.diff

134 lines
3.9 KiB
Diff

From: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH] mount: needs to handle special mountprog even on guessed file systems.
If the user doesn't specify -t <fstype> mount.fstype will never be called.
This patch fixes that.
Update: Fixes a bug where the mount would get added to mtab twice.
--
mount.c | 47 +++++++++++++++++++++++++++++++++++++++++------
mount_guess_fstype.c | 3 +--
2 files changed, 42 insertions(+), 8 deletions(-)
diff -rup util-linux-2.12r/mount/mount.c util-linux-2.12r.updated/mount/mount.c
--- util-linux-2.12r/mount/mount.c 2006-05-17 17:35:37.000000000 -0400
+++ util-linux-2.12r.updated/mount/mount.c 2006-05-17 17:35:17.000000000 -0400
@@ -451,6 +451,10 @@ create_mtab (void) {
unlock_mtab();
}
+static int check_special_mountprog(const char *spec, const char *node,
+ const char *type, int flags,
+ char *extra_opts, int *status);
+
/* count successful mount system calls */
static int mountcount = 0;
@@ -462,12 +466,30 @@ static int mountcount = 0;
static int
do_mount_syscall (struct mountargs *args) {
int flags = args->flags;
- int ret;
if ((flags & MS_MGC_MSK) == 0)
flags |= MS_MGC_VAL;
- ret = mount (args->spec, args->node, args->type, flags, args->data);
+ return mount (args->spec, args->node, args->type, flags, args->data);
+}
+
+/*
+ * do_mount()
+ * Mount a single file system, possibly invoking an external handler to
+ * do so. Keep track of successes.
+ * returns: 0: OK, -1: error in errno
+ */
+static int
+do_mount (struct mountargs *args) {
+ int ret;
+ if (check_special_mountprog(args->spec, args->node, args->type,
+ args->flags, args->data, &ret) == 0)
+ ret = do_mount_syscall(args);
+ else if (ret == 0) { /* set by the call */
+ mountcount++;
+ ret = 1;
+ }
+
if (ret == 0)
mountcount++;
return ret;
@@ -507,10 +529,11 @@ guess_fstype_and_mount(const char *spec,
char *p;
while((p = index(t,',')) != NULL) {
+ int ret;
*p = 0;
args.type = *types = t;
- if(do_mount_syscall (&args) == 0)
- return 0;
+ if((ret = do_mount (&args)) >= 0)
+ return ret;
t = p+1;
}
/* do last type below */
@@ -519,10 +542,10 @@ guess_fstype_and_mount(const char *spec,
if (*types || (flags & MS_REMOUNT)) {
args.type = *types;
- return do_mount_syscall (&args);
+ return do_mount (&args);
}
- return procfsloop(do_mount_syscall, &args, types);
+ return procfsloop(do_mount, &args, types);
}
/*
@@ -895,8 +918,16 @@ retry_nfs:
nosigblock:
if (!fake) {
+ int skip_mtab = 0;
mnt5_res = guess_fstype_and_mount (spec, node, &types, flags & ~MS_NOSYS,
mount_opts);
+ /* External program was executed to mount the file system, skip updating
+ * mtab. */
+ if (mnt5_res == 1) {
+ skip_mtab = 1;
+ mnt5_res = 0;
+ res = 0;
+ }
if(!mnt5_res && LoopMountAutomaticChmod && (getuid() == 0)) {
/*
* If loop was set up using random keys and new file system
@@ -907,8 +938,12 @@ nosigblock:
error (_("Error: encrypted file system chmod() failed"));
}
}
+
+ if (skip_mtab)
+ goto out;
}
+
if (fake || mnt5_res == 0) {
/* Mount succeeded, report this (if verbose) and write mtab entry. */
if (loop)
diff -rup util-linux-2.12r/mount/mount_guess_fstype.c util-linux-2.12r.updated/mount/mount_guess_fstype.c
--- util-linux-2.12r/mount/mount_guess_fstype.c 2006-05-17 17:35:37.000000000 -0400
+++ util-linux-2.12r.updated/mount/mount_guess_fstype.c 2006-05-17 17:19:44.000000000 -0400
@@ -695,9 +695,8 @@ procfsloop(int (*mount_fn)(struct mounta
printf(_("Trying %s\n"), fsname);
fflush(stdout);
}
- if ((*mount_fn) (args) == 0) {
+ if ((ret = (*mount_fn) (args)) >= 0) {
*types = fsname;
- ret = 0;
break;
} else if (errno != EINVAL &&
is_in_procfs(fsname) == 1) {