diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2007-10-08 11:54:02 -0400 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2007-10-09 11:18:04 +1000 |
commit | 7d31c6a73cf371cb05f7aab34a11a8acb627a85b (patch) | |
tree | ad66c2fc34e9adb375b86aa9d6433179951afc52 | |
parent | 0e65b81caabbc0029d17a0a5042badb1417b2b4d (diff) | |
download | nfs-utils-7d31c6a73cf371cb05f7aab34a11a8acb627a85b.tar.gz nfs-utils-7d31c6a73cf371cb05f7aab34a11a8acb627a85b.tar.xz nfs-utils-7d31c6a73cf371cb05f7aab34a11a8acb627a85b.zip |
text-based mount.nfs: Create helpers for invoking mount(2) system call
Add simple helper functions that invoke the mount(2) system call for
text-based mounts. These look the same right now, but the NFSv2/v3 helper
will become more complex over the following patches as we implement version
and transport protocol fallback.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
-rw-r--r-- | utils/mount/stropts.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index 6f57e86..c048be0 100644 --- a/utils/mount/stropts.c +++ b/utils/mount/stropts.c @@ -237,6 +237,80 @@ static int set_mandatory_options(const char *type, return 1; } +/* + * Attempt an NFSv2/3 mount via a mount(2) system call. + * + * Returns 1 if successful. Otherwise, returns zero. + * "errno" is set to reflect the individual error. + */ +static int try_nfs23mount(const char *spec, const char *node, + int flags, struct mount_options *options, + int fake, char **extra_opts) +{ + if (po_join(options, extra_opts) == PO_FAILED) { + errno = EIO; + 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)) + return 1; + return 0; +} + +/* + * Attempt an NFS v4 mount via a mount(2) system call. + * + * Returns 1 if successful. Otherwise, returns zero. + * "errno" is set to reflect the individual error. + */ +static int try_nfs4mount(const char *spec, const char *node, + int flags, struct mount_options *options, + int fake, char **extra_opts) +{ + if (po_join(options, extra_opts) == PO_FAILED) { + errno = EIO; + 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)) + return 1; + return 0; +} + +/* + * Try the mount(2) system call. + * + * Returns 1 if successful. Otherwise, returns zero. + * "errno" is set to reflect the individual error. + */ +static int try_mount(const char *spec, const char *node, const char *type, + int flags, struct mount_options *options, int fake, + char **extra_opts) +{ + if (strncmp(type, "nfs4", 4) == 0) + return try_nfs4mount(spec, node, flags, + options, fake, extra_opts); + else + return try_nfs23mount(spec, node, flags, + options, fake, extra_opts); +} + /** * nfsmount_string - Mount an NFS file system using C string options * @spec: C string specifying remote share to mount ("hostname:path") |