]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mount/network.c
mount.nfs: squelch compiler warning for TI-RPC builds
[nfs-utils.git] / utils / mount / network.c
index 91a005cc9fc5cac052a5876d79dc8d041048ecf5..bcd0c0fc315bbc0546b3093db75d6b1e5e5b1039 100644 (file)
@@ -291,7 +291,7 @@ int nfs_name_to_address(const char *hostname,
        }
 
        memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
-       *salen = hp->h_length;
+       *salen = sizeof(struct sockaddr_in);
        return 1;
 }
 #endif /* HAVE_DECL_AI_ADDRCONFIG */
@@ -546,8 +546,9 @@ static void nfs_pp_debug(const struct sockaddr *sap, const socklen_t salen,
                strcat(buf, "unknown host");
        }
 
-       fprintf(stderr, _("%s: trying %s prog %ld vers %ld prot %s port %d\n"),
-                       progname, buf, program, version,
+       fprintf(stderr, _("%s: trying %s prog %lu vers %lu prot %s port %d\n"),
+                       progname, buf, (unsigned long)program,
+                       (unsigned long)version,
                        (protocol == IPPROTO_UDP ? _("UDP") : _("TCP")),
                        port);
 }
@@ -837,6 +838,59 @@ int start_statd(void)
        return 0;
 }
 
+/**
+ * nfs_advise_umount - ask the server to remove a share from it's rmtab
+ * @sap: pointer to IP address of server to call
+ * @salen: length of server address
+ * @pmap: partially filled-in mountd RPC service tuple
+ * @argp: directory path of share to "unmount"
+ *
+ * Returns one if the unmount call succeeded; zero if the unmount
+ * failed for any reason;  rpccreateerr.cf_stat is set to reflect
+ * the nature of the error.
+ *
+ * We use a fast timeout since this call is advisory only.
+ */
+int nfs_advise_umount(const struct sockaddr *sap, const socklen_t salen,
+                     const struct pmap *pmap, const dirpath *argp)
+{
+       struct sockaddr_storage address;
+       struct sockaddr *saddr = (struct sockaddr *)&address;
+       struct pmap mnt_pmap = *pmap;
+       struct timeval timeout = {
+               .tv_sec         = MOUNT_TIMEOUT >> 3,
+       };
+       CLIENT *client;
+       enum clnt_stat res = 0;
+
+       if (nfs_probe_mntport(sap, salen, &mnt_pmap) == 0)
+               return 0;
+
+       memcpy(saddr, sap, salen);
+       nfs_set_port(saddr, mnt_pmap.pm_port);
+
+       client = nfs_get_rpcclient(saddr, salen, mnt_pmap.pm_prot,
+                                       mnt_pmap.pm_prog, mnt_pmap.pm_vers,
+                                       &timeout);
+       if (client == NULL)
+               return 0;
+
+       client->cl_auth = authunix_create_default();
+
+       res = CLNT_CALL(client, MOUNTPROC_UMNT,
+                       (xdrproc_t)xdr_dirpath, (caddr_t)argp,
+                       (xdrproc_t)xdr_void, NULL,
+                       timeout);
+
+       auth_destroy(client->cl_auth);
+       CLNT_DESTROY(client);
+
+       if (res != RPC_SUCCESS)
+               return 0;
+
+       return 1;
+}
+
 /**
  * nfs_call_umount - ask the server to remove a share from it's rmtab
  * @mnt_server: address of RPC MNT program server
@@ -1168,16 +1222,16 @@ static rpcvers_t nfs_nfs_version(struct mount_options *options)
        long tmp;
 
        switch (po_rightmost(options, nfs_version_opttbl)) {
-       case 1: /* v2 */
+       case 0: /* v2 */
                return 2;
-       case 2: /* v3 */
+       case 1: /* v3 */
                return 3;
-       case 3: /* vers */
+       case 2: /* vers */
                if (po_get_numeric(options, "vers", &tmp) == PO_FOUND)
                        if (tmp >= 2 && tmp <= 3)
                                return tmp;
                break;
-       case 4: /* nfsvers */
+       case 3: /* nfsvers */
                if (po_get_numeric(options, "nfsvers", &tmp) == PO_FOUND)
                        if (tmp >= 2 && tmp <= 3)
                                return tmp;
@@ -1198,11 +1252,9 @@ static unsigned short nfs_nfs_protocol(struct mount_options *options)
        char *option;
 
        switch (po_rightmost(options, nfs_transport_opttbl)) {
-       case 1: /* udp */
-               return IPPROTO_UDP;
-       case 2: /* tcp */
+       case 1: /* tcp */
                return IPPROTO_TCP;
-       case 3: /* proto */
+       case 2: /* proto */
                option = po_get(options, "proto");
                if (option) {
                        if (strcmp(option, "tcp") == 0)
@@ -1211,6 +1263,7 @@ static unsigned short nfs_nfs_protocol(struct mount_options *options)
                                return IPPROTO_UDP;
                }
        }
+
        return IPPROTO_UDP;
 }