Fixes so "make allnoconfig" works again.
[oweals/busybox.git] / util-linux / nfsmount.c
index ba14aa6bc7362834e70f7bc77b1eecc316df84bd..11ca3268ed74df521e6560bf59b0afcc65697c9b 100644 (file)
@@ -24,7 +24,7 @@
  *
  * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
  * - added Native Language Support
- * 
+ *
  * Modified by Olaf Kirch and Trond Myklebust for new NFS code,
  * plus NFSv3 stuff.
  */
@@ -95,7 +95,7 @@ enum nfs_stat {
        NFSERR_BADTYPE = 10007,         /*    v3 */
        NFSERR_JUKEBOX = 10008          /*    v3 */
 };
+
 #define NFS_PROGRAM    100003
 
 
@@ -303,7 +303,7 @@ return &p;
 }
 
 int nfsmount(const char *spec, const char *node, int *flags,
-            char **extra_opts, char **mount_opts, int running_bg)
+            char **mount_opts, int running_bg)
 {
        static char *prev_bg_host;
        char hostdir[1024];
@@ -315,7 +315,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
        char new_opts[1024];
        struct timeval total_timeout;
        enum clnt_stat clnt_stat;
-       static struct nfs_mount_data data;
+       struct nfs_mount_data data;
        char *opt, *opteq;
        int val;
        struct hostent *hp;
@@ -357,7 +357,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
        msock = fsock = -1;
        mclient = NULL;
        if (strlen(spec) >= sizeof(hostdir)) {
-               error_msg("excessively long host:dir argument");
+               bb_error_msg("excessively long host:dir argument");
                goto fail;
        }
        strcpy(hostdir, spec);
@@ -369,10 +369,10 @@ int nfsmount(const char *spec, const char *node, int *flags,
                   until they can be fully supported. (mack@sgi.com) */
                if ((s = strchr(hostdir, ','))) {
                        *s = '\0';
-                       error_msg("warning: multiple hostnames not supported");
+                       bb_error_msg("warning: multiple hostnames not supported");
                }
        } else {
-               error_msg("directory to mount not in host:dir format");
+               bb_error_msg("directory to mount not in host:dir format");
                goto fail;
        }
 
@@ -382,11 +382,11 @@ int nfsmount(const char *spec, const char *node, int *flags,
 #endif
        {
                if ((hp = gethostbyname(hostname)) == NULL) {
-                       herror_msg("%s", hostname);
+                       bb_herror_msg("%s", hostname);
                        goto fail;
                } else {
                        if (hp->h_length > sizeof(struct in_addr)) {
-                               error_msg("got bad hp->h_length");
+                               bb_error_msg("got bad hp->h_length");
                                hp->h_length = sizeof(struct in_addr);
                        }
                        memcpy(&server_addr.sin_addr,
@@ -399,16 +399,16 @@ int nfsmount(const char *spec, const char *node, int *flags,
        /* add IP address to mtab options for use when unmounting */
 
        s = inet_ntoa(server_addr.sin_addr);
-       old_opts = *extra_opts;
+       old_opts = *mount_opts;
        if (!old_opts)
                old_opts = "";
        if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) {
-               error_msg("excessively long option argument");
+               bb_error_msg("excessively long option argument");
                goto fail;
        }
        sprintf(new_opts, "%s%saddr=%s",
                old_opts, *old_opts ? "," : "", s);
-       *extra_opts = xstrdup(new_opts);
+       *mount_opts = bb_xstrdup(new_opts);
 
        /* Set default options.
         * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to
@@ -445,7 +445,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
 
        for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
                if ((opteq = strchr(opt, '='))) {
-                       val = atoi(opteq + 1);  
+                       val = atoi(opteq + 1);
                        *opteq = '\0';
                        if (!strcmp(opt, "rsize"))
                                data.rsize = val;
@@ -476,7 +476,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
                        else if (!strcmp(opt, "mountport"))
                                mountport = val;
                        else if (!strcmp(opt, "mounthost"))
-                               mounthost=xstrndup(opteq+1,
+                               mounthost=bb_xstrndup(opteq+1,
                                                  strcspn(opteq+1," \t\n\r,"));
                        else if (!strcmp(opt, "mountprog"))
                                mountprog = val;
@@ -515,9 +515,9 @@ int nfsmount(const char *spec, const char *node, int *flags,
                                val = 0;
                                opt += 2;
                        }
-                       if (!strcmp(opt, "bg")) 
+                       if (!strcmp(opt, "bg"))
                                bg = val;
-                       else if (!strcmp(opt, "fg")) 
+                       else if (!strcmp(opt, "fg"))
                                bg = !val;
                        else if (!strcmp(opt, "soft"))
                                soft = val;
@@ -563,11 +563,11 @@ int nfsmount(const char *spec, const char *node, int *flags,
                data.flags |= (nolock ? NFS_MOUNT_NONLM : 0);
 #endif
        if (nfsvers > MAX_NFSPROT) {
-               error_msg("NFSv%d not supported!", nfsvers);
+               bb_error_msg("NFSv%d not supported!", nfsvers);
                return 0;
        }
        if (mountvers > MAX_NFSPROT) {
-               error_msg("NFSv%d not supported!", nfsvers);
+               bb_error_msg("NFSv%d not supported!", nfsvers);
                return 0;
        }
        if (nfsvers && !mountvers)
@@ -602,10 +602,9 @@ int nfsmount(const char *spec, const char *node, int *flags,
 #endif
 
        data.version = nfs_mount_version;
-       *mount_opts = (char *) &data;
 
        if (*flags & MS_REMOUNT)
-               return 0;
+               goto copy_data_and_return;
 
        /*
         * If the previous mount operation on the same host was
@@ -627,11 +626,11 @@ int nfsmount(const char *spec, const char *node, int *flags,
            mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
          } else {
                  if ((hp = gethostbyname(mounthost)) == NULL) {
-                         herror_msg("%s", mounthost);
+                         bb_herror_msg("%s", mounthost);
                          goto fail;
                  } else {
                          if (hp->h_length > sizeof(struct in_addr)) {
-                                 error_msg("got bad hp->h_length?");
+                                 bb_error_msg("got bad hp->h_length?");
                                  hp->h_length = sizeof(struct in_addr);
                          }
                          mount_server_addr.sin_family = AF_INET;
@@ -753,7 +752,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
                if (!bg)
                        goto fail;
                if (!running_bg) {
-                       prev_bg_host = xstrdup(hostname);
+                       prev_bg_host = bb_xstrdup(hostname);
                        if (retry > 0)
                                retval = EX_BG;
                        goto fail;
@@ -766,7 +765,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
 
        if (nfsvers == 2) {
                if (status.nfsv2.fhs_status != 0) {
-                       error_msg("%s:%s failed, reason given by server: %s",
+                       bb_error_msg("%s:%s failed, reason given by server: %s",
                                hostname, pathname,
                                nfs_strerror(status.nfsv2.fhs_status));
                        goto fail;
@@ -784,7 +783,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
 #if NFS_MOUNT_VERSION >= 4
                fhandle3 *my_fhandle;
                if (status.nfsv3.fhs_status != 0) {
-                       error_msg("%s:%s failed, reason given by server: %s",
+                       bb_error_msg("%s:%s failed, reason given by server: %s",
                                hostname, pathname,
                                nfs_strerror(status.nfsv3.fhs_status));
                        goto fail;
@@ -857,6 +856,9 @@ int nfsmount(const char *spec, const char *node, int *flags,
        auth_destroy(mclient->cl_auth);
        clnt_destroy(mclient);
        close(msock);
+copy_data_and_return:
+       *mount_opts = xrealloc(*mount_opts, sizeof(data));
+       memcpy(*mount_opts, &data, sizeof(data));
        return 0;
 
        /* abort */
@@ -872,7 +874,7 @@ fail:
        if (fsock != -1)
                close(fsock);
        return retval;
-}      
+}
 
 /*
  * We need to translate between nfs status return values and
@@ -976,7 +978,7 @@ xdr_fhandle3 (XDR *xdrs, fhandle3 *objp)
 {
        //register int32_t *buf;
 
-        if (!xdr_bytes (xdrs, (char **)&objp->fhandle3_val, (u_int *) &objp->fhandle3_len, FHSIZE3))
+        if (!xdr_bytes (xdrs, (char **)&objp->fhandle3_val, (unsigned int *) &objp->fhandle3_len, FHSIZE3))
                 return FALSE;
        return TRUE;
 }
@@ -988,7 +990,7 @@ xdr_mountres3_ok (XDR *xdrs, mountres3_ok *objp)
 
         if (!xdr_fhandle3 (xdrs, &objp->fhandle))
                 return FALSE;
-        if (!xdr_array (xdrs, (char **)&objp->auth_flavours.auth_flavours_val, (u_int *) &objp->auth_flavours.auth_flavours_len, ~0,
+        if (!xdr_array (xdrs, (char **)&objp->auth_flavours.auth_flavours_val, (unsigned int *) &objp->auth_flavours.auth_flavours_len, ~0,
                sizeof (int), (xdrproc_t) xdr_int))
                 return FALSE;
        return TRUE;