X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fstropts.c;h=8859bf584bb44eb0a504f0bfd68d3ab460a93bc7;hp=3d83f9e5743bb9dd2c974ecf1242d7477677bd9f;hb=b9f4b66a81420b0832ce4ef6965b1cdc9615772c;hpb=e8232ab2cfd9d5b6669c5ba47d423925bdc25e12 diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index 3d83f9e..8859bf5 100644 --- a/utils/mount/stropts.c +++ b/utils/mount/stropts.c @@ -214,6 +214,29 @@ static int fix_mounthost_option(struct mount_options *options) return 0; } +/* + * Set up mandatory mount options. + * + * Returns 1 if successful; otherwise zero. + */ +static int set_mandatory_options(const char *type, + struct sockaddr_in *saddr, + struct mount_options *options) +{ + if (!append_addr_option(saddr, options)) + return 0; + + if (strncmp(type, "nfs4", 4) == 0) { + if (!append_clientaddr_option(saddr, options)) + return 0; + } else { + if (!fix_mounthost_option(options)) + return 0; + } + + return 1; +} + /* * nfsmount_s - Mount an NFSv2 or v3 file system using C string options * @@ -342,3 +365,62 @@ out: po_destroy(options); return retval; } + +/** + * nfsmount_string - Mount an NFS file system using C string options + * @spec: C string specifying remote share to mount ("hostname:path") + * @node: C string pathname of local mounted-on directory + * @type: C string that represents file system type ("nfs" or "nfs4") + * @flags: MS_ style mount flags + * @extra_opts: pointer to C string containing fs-specific mount options + * (input and output argument) + * @fake: flag indicating whether to carry out the whole operation + * @child: one if this is a mount daemon (bg) + */ +int nfsmount_string(const char *spec, const char *node, const char *type, + int flags, char **extra_opts, int fake, int child) +{ + struct mount_options *options = NULL; + struct sockaddr_in saddr; + char *hostname; + int err, retval = EX_FAIL; + + if (!parse_devname(spec, &hostname)) + goto out; + err = fill_ipv4_sockaddr(hostname, &saddr); + free(hostname); + if (!err) + goto out; + + options = po_split(*extra_opts); + if (!options) { + nfs_error(_("%s: internal option parsing error"), progname); + goto out; + } + + if (!set_mandatory_options(type, &saddr, options)) + goto out; + + if (po_join(options, extra_opts) == PO_FAILED) { + nfs_error(_("%s: internal option parsing error"), progname); + goto out; + } + + if (verbose) + printf(_("%s: text-based options: '%s'\n"), + progname, *extra_opts); + + if (!fake) { + if (mount(spec, node, type, + flags & ~(MS_USER|MS_USERS), *extra_opts)) { + mount_error(spec, node, errno); + goto out; + } + } + + retval = EX_SUCCESS; + +out: + po_destroy(options); + return retval; +}