]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mount/stropts.c
text-based mount.nfs: Remove unused top level functions
[nfs-utils.git] / utils / mount / stropts.c
index e3a3ac941d322c55950f7347a0b3f26154d71941..6f57e86ed4633e59f94c4f38903f1b520ce406ad 100644 (file)
@@ -191,82 +191,65 @@ static int append_clientaddr_option(struct sockaddr_in *saddr,
 }
 
 /*
- * nfsmount_s - Mount an NFSv2 or v3 file system using C string options
- *
- * @spec:      C string hostname:path specifying remoteshare to mount
- * @node:      C string pathname of local mounted on directory
- * @flags:     MS_ style flags
- * @extra_opts:        pointer to C string containing fs-specific mount options
- *             (possibly also a return argument)
- * @fake:      flag indicating whether to carry out the whole operation
- * @child:     one if this is a backgrounded mount
- *
- * XXX: need to handle bg, fg, and retry options.
+ * Resolve the 'mounthost=' hostname and append a new option using
+ * the resulting IPv4 address.
  */
-int nfsmount_s(const char *spec, const char *node, int flags,
-               char **extra_opts, int fake, int child)
+static int fix_mounthost_option(struct mount_options *options)
 {
-       struct mount_options *options = NULL;
-       struct sockaddr_in saddr;
-       char *hostname;
-       int err, retval = EX_FAIL;
+       struct sockaddr_in maddr;
+       char *mounthost, new_option[32];
 
-       if (!parse_devname(spec, &hostname))
-               goto out;
-       err = fill_ipv4_sockaddr(hostname, &saddr);
-       free(hostname);
-       if (!err)
-               goto out;
+       mounthost = po_get(options, "mounthost");
+       if (!mounthost)
+               return 1;
 
-       options = po_split(*extra_opts);
-       if (!options) {
-               nfs_error(_("%s: internal option parsing error"), progname);
-               goto out;
-       }
+       if (!fill_ipv4_sockaddr(mounthost, &maddr))
+               return 0;
 
-       if (!append_addr_option(&saddr, options))
-               goto out;
+       snprintf(new_option, sizeof(new_option) - 1,
+                       "mountaddr=%s", inet_ntoa(maddr.sin_addr));
 
-       if (po_join(options, extra_opts) == PO_FAILED) {
-               nfs_error(_("%s: internal option parsing error"), progname);
-               goto out;
-       }
+       if (po_append(options, new_option) == PO_SUCCEEDED)
+               return 1;
+       return 0;
+}
 
-       if (verbose)
-               printf(_("%s: text-based options: '%s'\n"),
-                       progname, *extra_opts);
+/*
+ * 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 (!fake) {
-               if (mount(spec, node, "nfs",
-                               flags & ~(MS_USER|MS_USERS), *extra_opts)) {
-                       mount_error(spec, node, errno);
-                       goto out;
-               }
+       if (strncmp(type, "nfs4", 4) == 0) {
+               if (!append_clientaddr_option(saddr, options))
+                       return 0;
+       } else {
+               if (!fix_mounthost_option(options))
+                       return 0;
        }
 
-       retval = EX_SUCCESS;
-
-out:
-       po_destroy(options);
-       return retval;
+       return 1;
 }
 
-/*
- * nfs4mount_s - Mount an NFSv4 file system using C string options
- *
- * @spec:      C string hostname:path specifying remoteshare to mount
- * @node:      C string pathname of local mounted on directory
- * @flags:     MS_ style flags
+/**
+ * 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
- *             (possibly also a return argument)
- * @fake:      flag indicating whether to carry out the whole operation
- * @child:     one if this is a backgrounded mount
- *
- * XXX: need to handle bg, fg, and retry 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 nfs4mount_s(const char *spec, const char *node, int flags,
-               char **extra_opts, int fake, int child)
+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;
@@ -286,10 +269,7 @@ int nfs4mount_s(const char *spec, const char *node, int flags,
                goto out;
        }
 
-       if (!append_addr_option(&saddr, options))
-               goto out;
-
-       if (!append_clientaddr_option(&saddr, options))
+       if (!set_mandatory_options(type, &saddr, options))
                goto out;
 
        if (po_join(options, extra_opts) == PO_FAILED) {
@@ -302,7 +282,7 @@ int nfs4mount_s(const char *spec, const char *node, int flags,
                        progname, *extra_opts);
 
        if (!fake) {
-               if (mount(spec, node, "nfs4",
+               if (mount(spec, node, type,
                                flags & ~(MS_USER|MS_USERS), *extra_opts)) {
                        mount_error(spec, node, errno);
                        goto out;