Skip to contentSkip to conversation

text-based mount.nfs: Create helpers for invoking mount(2) system call

PATCH New Chuck Lever 1 participant 1 message Sep 11, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 10/19 text-based mount.nfs: Create helpers for invoking mount(2) system call

Add a simple helper functions that invoke the mount(2) system call for text-based mounts. These functions will become more complex over the following patches as we implement fallback and background mounting.

---

 utils/mount/stropts.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
utils/mount/stropts.c +61 -0
index 796a741..2fd01ca 100644
@@ -210,6 +210,37 @@ static int fix_up_mounthost_opt(struct mount_options *options)
 }
 
 /*
+ * Attempt an NFS mount via a mount(2) system call.
+ *
+ * Returns 1 if successful.  Otherwise, returns zero.
+ */
+static int try_nfsmount(const char *spec, const char *node,
+			int flags, struct mount_options *options,
+			int fake, char **extra_opts)
+{
+	*extra_opts = po_join(options);
+	if (!*extra_opts) {
+		nfs_error(_("%s: internal option parsing error"), progname);
+		return 0;
+	}
+
+	if (verbose)
+		printf(_("%s: text-based options: '%s'\n"),
+			progname, *extra_opts);
+
+	if (fake)
+		return 1;
+
+	if (mount(spec, node, "nfs",
+				flags & ~(MS_USER|MS_USERS), *extra_opts)) {
+		mount_error(spec, node, errno);
+		return 0;
+	}
+
+	return 1;
+}
+
+/*
  * nfsmount_s - Mount an NFSv2 or v3 file system using C string options
  *
  * @spec:	C string hostname:path specifying remoteshare to mount
@@ -275,6 +306,36 @@ out:
 }
 
 /*
+ * Attempt an NFS v4 mount via a mount(2) system call.
+ *
+ * Returns 1 if successful.  Otherwise, returns zero.
+ */
+static int try_nfs4mount(const char *spec, const char *node,
+			 int flags, struct mount_options *options,
+			 int fake, char **extra_opts)
+{
+	*extra_opts = po_join(options);
+	if (!*extra_opts) {
+		nfs_error(_("%s: internal option parsing error"), progname);
+		return 0;
+	}
+
+	if (verbose)
+		printf(_("%s: text-based options: '%s'\n"),
+			progname, *extra_opts);
+
+	if (fake)
+		return 1;
+
+	if (mount(spec, node, "nfs4",
+				flags & ~(MS_USER|MS_USERS), *extra_opts)) {
+		mount_error(spec, node, errno);
+		return 0;
+	}
+	return 1;
+}
+
+/*
  * nfs4mount_s - Mount an NFSv4 file system using C string options
  *
  * @spec:	C string hostname:path specifying remoteshare to mount

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs