]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mount/stropts.c
text-based mount.nfs: refactor mandatory mount option processing
[nfs-utils.git] / utils / mount / stropts.c
index b31b3a28e20cc7a0ed9a7c2422f7d33ce19364aa..627031215a9c286ab76c0ff245722ea5f8105bd8 100644 (file)
@@ -191,10 +191,10 @@ static int append_clientaddr_option(struct sockaddr_in *saddr,
 }
 
 /*
- * Called to resolve the 'mounthost=' hostname and append a new
- * option using an IPv4 address.
+ * Resolve the 'mounthost=' hostname and append a new option using
+ * the resulting IPv4 address.
  */
-static int fix_up_mounthost_opt(struct mount_options *options)
+static int fix_mounthost_option(struct mount_options *options)
 {
        struct sockaddr_in maddr;
        char *mounthost, new_option[32];
@@ -214,6 +214,29 @@ static int fix_up_mounthost_opt(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
  *
@@ -251,7 +274,7 @@ int nfsmount_s(const char *spec, const char *node, int flags,
        if (!append_addr_option(&saddr, options))
                goto out;
 
-       if (!fix_up_mounthost_opt(options))
+       if (!fix_mounthost_option(options))
                goto out;
 
        if (po_join(options, extra_opts) == PO_FAILED) {