2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#) Copyright (c) 1992, 1993, 1994 The Regents of the University of California. All rights reserved.
33 * @(#)mount_nfs.c 8.11 (Berkeley) 5/4/95
34 * $FreeBSD: src/sbin/mount_nfs/mount_nfs.c,v 1.36.2.6 2003/05/13 14:45:40 trhodes Exp $
37 #include <sys/param.h>
38 #include <sys/mount.h>
39 #include <sys/socket.h>
41 #include <sys/syslog.h>
44 #include <rpc/pmap_clnt.h>
45 #include <rpc/pmap_prot.h>
47 #include <vfs/nfs/rpcv2.h>
48 #include <vfs/nfs/nfsproto.h>
49 #include <vfs/nfs/nfs.h>
51 #include <arpa/inet.h>
68 #define ALTF_NOCONN 0x2
69 #define ALTF_DUMBTIMR 0x4
71 /* 0x10 was for ALTF_KERB */
72 #define ALTF_NFSV3 0x20
73 #define ALTF_RDIRPLUS 0x40
74 #define ALTF_CACHE 0x80
75 #define ALTF_RESVPORT 0x100
76 #define ALTF_SEQPACKET 0x200
77 #define ALTF_UNUSED400 0x400
78 #define ALTF_SOFT 0x800
79 #define ALTF_TCP 0x1000
80 #define ALTF_PORT 0x2000
81 #define ALTF_NFSV2 0x4000
82 #define ALTF_ACREGMIN 0x8000
83 #define ALTF_ACREGMAX 0x10000
84 #define ALTF_ACDIRMIN 0x20000
85 #define ALTF_ACDIRMAX 0x40000
86 #define ALTF_RETRYCNT 0x80000
88 struct mntopt mopts
[] = {
93 { "bg", 0, ALTF_BG
, 1 },
94 { "conn", 1, ALTF_NOCONN
, 1 },
95 { "dumbtimer", 0, ALTF_DUMBTIMR
, 1 },
96 { "intr", 0, ALTF_INTR
, 1 },
97 { "nfsv3", 0, ALTF_NFSV3
, 1 },
98 { "rdirplus", 0, ALTF_RDIRPLUS
, 1 },
99 { "mntudp", 1, ALTF_TCP
, 1 },
100 { "resvport", 0, ALTF_RESVPORT
, 1 },
101 { "soft", 0, ALTF_SOFT
, 1 },
102 { "tcp", 0, ALTF_TCP
, 1 },
103 { "udp", 1, ALTF_TCP
, 1 },
104 { "port=", 0, ALTF_PORT
, 1 },
105 { "nfsv2", 0, ALTF_NFSV2
, 1 },
106 { "acregmin=", 0, ALTF_ACREGMIN
, 1 },
107 { "acregmax=", 0, ALTF_ACREGMAX
, 1 },
108 { "acdirmin=", 0, ALTF_ACDIRMIN
, 1 },
109 { "acdirmax=", 0, ALTF_ACDIRMAX
, 1 },
110 { "cache", 0, ALTF_CACHE
, 1 },
111 { "retrycnt=", 0, ALTF_RETRYCNT
, 1 },
115 struct nfs_args nfsdefargs
= {
118 sizeof (struct sockaddr_in
),
141 /* Table for af,sotype -> netid conversions. */
147 {"udp", AF_INET
, SOCK_DGRAM
},
148 {"tcp", AF_INET
, SOCK_STREAM
},
149 {"udp6", AF_INET6
, SOCK_DGRAM
},
150 {"tcp6", AF_INET6
, SOCK_STREAM
},
159 u_char nfh
[NFSX_V3FHMAX
];
166 char *portspec
= NULL
; /* Server nfs port; NULL means look up via rpcbind. */
173 /* Return codes for nfs_tryproto. */
176 TRYRET_TIMEOUT
, /* No response received. */
177 TRYRET_REMOTEERR
, /* Error received from remote server. */
178 TRYRET_LOCALERR
/* Local failure. */
182 void set_rpc_maxgrouplist(int);
184 static struct netconfig
*getnetconf_cached(const char *);
185 static const char *netidbytype(int, int);
186 static int getnfsargs(char *, struct nfs_args
*);
187 static void usage(void) __dead2
;
188 static int xdr_dir(XDR
*, char *);
189 static int xdr_fh(XDR
*, struct nfhret
*);
191 nfs_tryproto(struct nfs_args
*, struct addrinfo
*,
192 char *, char *, char **);
194 returncode(enum clnt_stat
, struct rpc_err
*);
197 * Used to set mount flags with getmntopts. Call with dir=TRUE to
198 * initialize altflags from the current mount flags. Call with
199 * dir=FALSE to update mount flags with the new value of altflags after
200 * the call to getmntopts.
203 set_flags(int* altflags
, int* nfsflags
, int dir
)
207 if (*nfsflags & NFSMNT_##nf) \
208 *altflags |= ALTF_##af; \
210 *altflags &= ~ALTF_##af; \
212 if (*altflags & ALTF_##af) \
213 *nfsflags |= NFSMNT_##nf; \
215 *nfsflags &= ~NFSMNT_##nf; \
239 main(int argc
, char **argv
)
242 struct nfs_args
*nfsargsp
;
243 struct nfs_args nfsargs
;
244 int mntflags
, altflags
, num
;
245 char *name
, *p
, *spec
;
246 char mntpath
[MAXPATHLEN
];
251 altflags
= ALTF_TCP
| ALTF_RDIRPLUS
;
252 nfsargs
= nfsdefargs
;
254 if (altflags
& ALTF_TCP
) {
255 nfsproto
= IPPROTO_TCP
;
256 nfsargsp
->sotype
= SOCK_STREAM
;
258 nfsproto
= IPPROTO_UDP
;
259 nfsargsp
->sotype
= SOCK_DGRAM
;
261 while ((c
= getopt(argc
, argv
,
262 "23a:bcdD:g:I:ilNo:PR:r:sTt:w:x:U")) != -1)
271 num
= strtol(optarg
, &p
, 10);
273 errx(1, "illegal -a value -- %s", optarg
);
274 nfsargsp
->readahead
= num
;
275 nfsargsp
->flags
|= NFSMNT_READAHEAD
;
281 nfsargsp
->flags
|= NFSMNT_NOCONN
;
284 num
= strtol(optarg
, &p
, 10);
286 errx(1, "illegal -D value -- %s", optarg
);
287 nfsargsp
->deadthresh
= num
;
288 nfsargsp
->flags
|= NFSMNT_DEADTHRESH
;
291 nfsargsp
->flags
|= NFSMNT_DUMBTIMR
;
295 num
= strtol(optarg
, &p
, 10);
297 errx(1, "illegal -g value -- %s", optarg
);
298 set_rpc_maxgrouplist(num
);
299 nfsargsp
->maxgrouplist
= num
;
300 nfsargsp
->flags
|= NFSMNT_MAXGRPS
;
304 num
= strtol(optarg
, &p
, 10);
306 errx(1, "illegal -I value -- %s", optarg
);
307 nfsargsp
->readdirsize
= num
;
308 nfsargsp
->flags
|= NFSMNT_READDIRSIZE
;
311 nfsargsp
->flags
|= NFSMNT_INT
;
314 nfsargsp
->flags
|= NFSMNT_RDIRPLUS
;
317 nfsargsp
->flags
&= ~NFSMNT_RESVPORT
;
320 set_flags(&altflags
, &nfsargsp
->flags
, TRUE
);
321 altflags
|= ALTF_RDIRPLUS
;
322 if (nfsproto
== IPPROTO_TCP
)
323 altflags
|= ALTF_TCP
;
325 altflags
|= ALTF_NFSV2
;
326 else if (mountmode
== V3
)
327 altflags
|= ALTF_NFSV3
;
328 getmntopts(optarg
, mopts
, &mntflags
, &altflags
);
329 set_flags(&altflags
, &nfsargsp
->flags
, FALSE
);
331 * Handle altflags which don't map directly to
334 if(altflags
& ALTF_BG
)
336 if (altflags
& ALTF_TCP
) {
337 nfsproto
= IPPROTO_TCP
;
338 nfsargsp
->sotype
= SOCK_STREAM
;
340 nfsproto
= IPPROTO_UDP
;
341 nfsargsp
->sotype
= SOCK_DGRAM
;
343 if(altflags
& ALTF_PORT
) {
345 * XXX Converting from a string to an int
346 * and back again is silly, and we should
347 * allow /etc/services names.
349 asprintf(&portspec
, "%d",
350 atoi(strstr(optarg
, "port=") + 5));
351 if (portspec
== NULL
)
355 if(altflags
& ALTF_NFSV2
)
357 if(altflags
& ALTF_NFSV3
)
359 if(altflags
& ALTF_ACREGMIN
)
360 nfsargsp
->acregmin
= atoi(strstr(optarg
,
362 if(altflags
& ALTF_ACREGMAX
)
363 nfsargsp
->acregmax
= atoi(strstr(optarg
,
365 if(altflags
& ALTF_ACDIRMIN
)
366 nfsargsp
->acdirmin
= atoi(strstr(optarg
,
368 if(altflags
& ALTF_ACDIRMAX
)
369 nfsargsp
->acdirmax
= atoi(strstr(optarg
,
371 if(altflags
& ALTF_RETRYCNT
) {
372 num
= atoi(strstr(optarg
, "retrycnt=") + 9);
374 errx(1, "illegal -o retrycnt value -- %s", optarg
);
379 /* obsolete for NFSMNT_RESVPORT, now default */
382 num
= strtol(optarg
, &p
, 10);
384 errx(1, "illegal -R value -- %s", optarg
);
388 num
= strtol(optarg
, &p
, 10);
390 errx(1, "illegal -r value -- %s", optarg
);
391 nfsargsp
->rsize
= num
;
392 nfsargsp
->flags
|= NFSMNT_RSIZE
;
395 nfsargsp
->flags
|= NFSMNT_SOFT
;
398 nfsargsp
->sotype
= SOCK_STREAM
;
399 nfsproto
= IPPROTO_TCP
;
400 altflags
|= ALTF_TCP
;
403 num
= strtol(optarg
, &p
, 10);
405 errx(1, "illegal -t value -- %s", optarg
);
406 nfsargsp
->timeo
= num
;
407 nfsargsp
->flags
|= NFSMNT_TIMEO
;
410 num
= strtol(optarg
, &p
, 10);
412 errx(1, "illegal -w value -- %s", optarg
);
413 nfsargsp
->wsize
= num
;
414 nfsargsp
->flags
|= NFSMNT_WSIZE
;
417 num
= strtol(optarg
, &p
, 10);
419 errx(1, "illegal -x value -- %s", optarg
);
420 nfsargsp
->retrans
= num
;
421 nfsargsp
->flags
|= NFSMNT_RETRANS
;
424 nfsargsp
->sotype
= SOCK_DGRAM
;
425 nfsproto
= IPPROTO_UDP
;
426 altflags
&= ~ALTF_TCP
;
444 /* The default is to keep retrying forever. */
446 if (!getnfsargs(spec
, nfsargsp
))
449 /* resolve the mountpoint with realpath(3) */
450 checkpath(name
, mntpath
);
452 error
= getvfsbyname("nfs", &vfc
);
453 if (error
&& vfsisloadable("nfs")) {
455 err(EX_OSERR
, "vfsload(nfs)");
456 endvfsent(); /* clear cache */
457 error
= getvfsbyname("nfs", &vfc
);
460 errx(EX_OSERR
, "nfs filesystem is not available");
462 if (mount(vfc
.vfc_name
, mntpath
, mntflags
, nfsargsp
))
463 err(1, "%s", mntpath
);
468 getnfsargs(char *spec
, struct nfs_args
*nfsargsp
)
470 struct addrinfo hints
, *ai_nfs
, *ai
;
472 int ecode
, speclen
, remoteerr
;
473 char *hostp
, *delimp
, *errstr
;
475 static char nam
[MNAMELEN
+ 1];
477 if ((delimp
= strrchr(spec
, ':')) != NULL
) {
480 } else if ((delimp
= strrchr(spec
, '@')) != NULL
) {
481 warnx("path@server syntax is deprecated, use server:path");
484 warnx("no <host>:<dirpath> nfs-name");
490 * If there has been a trailing slash at mounttime it seems
491 * that some mountd implementations fail to remove the mount
492 * entries from their mountlist while unmounting.
494 for (speclen
= strlen(spec
);
495 speclen
> 1 && spec
[speclen
- 1] == '/';
497 spec
[speclen
- 1] = '\0';
498 if (strlen(hostp
) + strlen(spec
) + 1 > MNAMELEN
) {
499 warnx("%s:%s: %s", hostp
, spec
, strerror(ENAMETOOLONG
));
502 /* Make both '@' and ':' notations equal */
503 if (*hostp
!= '\0') {
505 memmove(nam
, hostp
, len
);
507 memmove(nam
+ len
+ 1, spec
, speclen
);
508 nam
[len
+ speclen
+ 1] = '\0';
512 * Handle an internet host address.
514 memset(&hints
, 0, sizeof hints
);
515 hints
.ai_flags
= AI_NUMERICHOST
;
516 hints
.ai_socktype
= nfsargsp
->sotype
;
517 if (getaddrinfo(hostp
, portspec
, &hints
, &ai_nfs
) != 0) {
519 if ((ecode
= getaddrinfo(hostp
, portspec
, &hints
, &ai_nfs
))
521 if (portspec
== NULL
)
522 errx(1, "%s: %s", hostp
, gai_strerror(ecode
));
524 errx(1, "%s:%s: %s", hostp
, portspec
,
525 gai_strerror(ecode
));
530 ret
= TRYRET_LOCALERR
;
533 * Try each entry returned by getaddrinfo(). Note the
534 * occurence of remote errors by setting `remoteerr'.
537 for (ai
= ai_nfs
; ai
!= NULL
; ai
= ai
->ai_next
) {
538 ret
= nfs_tryproto(nfsargsp
, ai
, hostp
, spec
, &errstr
);
539 if (ret
== TRYRET_SUCCESS
)
541 if (ret
!= TRYRET_LOCALERR
)
543 if ((opflags
& ISBGRND
) == 0)
544 fprintf(stderr
, "%s\n", errstr
);
546 if (ret
== TRYRET_SUCCESS
)
549 /* Exit if all errors were local. */
554 * If retrycnt == 0, we are to keep retrying forever.
555 * Otherwise decrement it, and exit if it hits zero.
557 if (retrycnt
!= 0 && --retrycnt
== 0)
560 if ((opflags
& (BGRND
| ISBGRND
)) == BGRND
) {
561 warnx("Cannot immediately mount %s:%s, backgrounding",
564 if (daemon(0, 0) != 0)
569 freeaddrinfo(ai_nfs
);
570 nfsargsp
->hostname
= nam
;
571 /* Add mounted filesystem to PATH_MOUNTTAB */
572 if (!add_mtab(hostp
, spec
))
573 warnx("can't update %s for %s:%s", PATH_MOUNTTAB
, hostp
, spec
);
578 * Try to set up the NFS arguments according to the address
579 * family, protocol (and possibly port) specified in `ai'.
581 * Returns TRYRET_SUCCESS if successful, or:
582 * TRYRET_TIMEOUT The server did not respond.
583 * TRYRET_REMOTEERR The server reported an error.
584 * TRYRET_LOCALERR Local failure.
586 * In all error cases, *errstr will be set to a statically-allocated string
587 * describing the error.
590 nfs_tryproto(struct nfs_args
*nfsargsp
, struct addrinfo
*ai
, char *hostp
,
591 char *spec
, char **errstr
)
593 static char errbuf
[256];
594 struct sockaddr_storage nfs_ss
;
595 struct netbuf nfs_nb
;
596 struct nfhret nfhret
;
598 struct rpc_err rpcerr
;
600 struct netconfig
*nconf
, *nconf_mnt
;
601 const char *netid
, *netid_mnt
;
602 int doconnect
, nfsvers
, mntvers
;
603 enum clnt_stat status
;
604 enum mountmode trymntmode
;
606 trymntmode
= mountmode
;
610 if ((netid
= netidbytype(ai
->ai_family
, nfsargsp
->sotype
)) == NULL
) {
611 snprintf(errbuf
, sizeof errbuf
,
612 "af %d sotype %d not supported", ai
->ai_family
,
614 return (TRYRET_LOCALERR
);
616 if ((nconf
= getnetconf_cached(netid
)) == NULL
) {
617 snprintf(errbuf
, sizeof errbuf
, "%s: %s", netid
, nc_sperror());
618 return (TRYRET_LOCALERR
);
625 if (trymntmode
== V2
) {
633 if (portspec
!= NULL
) {
634 /* `ai' contains the complete nfsd sockaddr. */
635 nfs_nb
.buf
= ai
->ai_addr
;
636 nfs_nb
.len
= nfs_nb
.maxlen
= ai
->ai_addrlen
;
638 /* Ask the remote rpcbind. */
639 nfs_nb
.buf
= &nfs_ss
;
640 nfs_nb
.len
= nfs_nb
.maxlen
= sizeof nfs_ss
;
642 if (!rpcb_getaddr(RPCPROG_NFS
, nfsvers
, nconf
, &nfs_nb
,
644 if (rpc_createerr
.cf_stat
== RPC_PROGVERSMISMATCH
&&
649 snprintf(errbuf
, sizeof errbuf
, "[%s] %s:%s: %s",
651 clnt_spcreateerror("RPCPROG_NFS"));
652 return (returncode(rpc_createerr
.cf_stat
,
653 &rpc_createerr
.cf_error
));
657 /* Check that the server (nfsd) responds on the port we have chosen. */
658 clp
= clnt_tli_create(RPC_ANYFD
, nconf
, &nfs_nb
, RPCPROG_NFS
, nfsvers
,
661 snprintf(errbuf
, sizeof errbuf
, "[%s] %s:%s: %s", netid
,
662 hostp
, spec
, clnt_spcreateerror("nfsd: RPCPROG_NFS"));
663 return (returncode(rpc_createerr
.cf_stat
,
664 &rpc_createerr
.cf_error
));
666 if (nfsargsp
->sotype
== SOCK_DGRAM
&&
667 !(nfsargsp
->flags
& NFSMNT_NOCONN
)) {
669 * Use connect(), to match what the kernel does. This
670 * catches cases where the server responds from the
671 * wrong source address.
674 if (!clnt_control(clp
, CLSET_CONNECT
, (char *)&doconnect
)) {
676 snprintf(errbuf
, sizeof errbuf
,
677 "[%s] %s:%s: CLSET_CONNECT failed", netid
, hostp
,
679 return (TRYRET_LOCALERR
);
685 status
= clnt_call(clp
, NFSPROC_NULL
, (xdrproc_t
)xdr_void
, NULL
,
686 (xdrproc_t
)xdr_void
, NULL
, try);
687 if (status
!= RPC_SUCCESS
) {
688 if (status
== RPC_PROGVERSMISMATCH
&& trymntmode
== ANY
) {
693 clnt_geterr(clp
, &rpcerr
);
694 snprintf(errbuf
, sizeof errbuf
, "[%s] %s:%s: %s", netid
,
695 hostp
, spec
, clnt_sperror(clp
, "NFSPROC_NULL"));
697 return (returncode(status
, &rpcerr
));
701 /* Send the RPCMNT_MOUNT RPC to get the root filehandle. */
704 clp
= clnt_tp_create(hostp
, RPCPROG_MNT
, mntvers
, nconf_mnt
);
706 snprintf(errbuf
, sizeof errbuf
, "[%s] %s:%s: %s", netid_mnt
,
707 hostp
, spec
, clnt_spcreateerror("RPCMNT: clnt_create"));
708 return (returncode(rpc_createerr
.cf_stat
,
709 &rpc_createerr
.cf_error
));
711 clp
->cl_auth
= authsys_create_default();
712 nfhret
.auth
= RPCAUTH_UNIX
;
713 nfhret
.vers
= mntvers
;
714 status
= clnt_call(clp
, RPCMNT_MOUNT
, (xdrproc_t
)xdr_dir
, spec
,
715 (xdrproc_t
)xdr_fh
, &nfhret
, try);
716 auth_destroy(clp
->cl_auth
);
717 if (status
!= RPC_SUCCESS
) {
718 if (status
== RPC_PROGVERSMISMATCH
&& trymntmode
== ANY
) {
723 clnt_geterr(clp
, &rpcerr
);
724 snprintf(errbuf
, sizeof errbuf
, "[%s] %s:%s: %s", netid_mnt
,
725 hostp
, spec
, clnt_sperror(clp
, "RPCPROG_MNT"));
727 return (returncode(status
, &rpcerr
));
731 if (nfhret
.stat
!= 0) {
732 snprintf(errbuf
, sizeof errbuf
, "[%s] %s:%s: %s", netid_mnt
,
733 hostp
, spec
, strerror(nfhret
.stat
));
734 return (TRYRET_REMOTEERR
);
738 * Store the filehandle and server address in nfsargsp, making
739 * sure to copy any locally allocated structures.
741 nfsargsp
->addrlen
= nfs_nb
.len
;
742 nfsargsp
->addr
= malloc(nfsargsp
->addrlen
);
743 nfsargsp
->fhsize
= nfhret
.fhsize
;
744 nfsargsp
->fh
= malloc(nfsargsp
->fhsize
);
745 if (nfsargsp
->addr
== NULL
|| nfsargsp
->fh
== NULL
)
747 bcopy(nfs_nb
.buf
, nfsargsp
->addr
, nfsargsp
->addrlen
);
748 bcopy(nfhret
.nfh
, nfsargsp
->fh
, nfsargsp
->fhsize
);
751 nfsargsp
->flags
|= NFSMNT_NFSV3
;
753 nfsargsp
->flags
&= ~NFSMNT_NFSV3
;
755 return (TRYRET_SUCCESS
);
760 * Catagorise a RPC return status and error into an `enum tryret'
764 returncode(enum clnt_stat status
, struct rpc_err
*rpcerr
)
768 return (TRYRET_TIMEOUT
);
769 case RPC_PMAPFAILURE
:
770 case RPC_PROGNOTREGISTERED
:
771 case RPC_PROGVERSMISMATCH
:
772 /* XXX, these can be local or remote. */
775 return (TRYRET_REMOTEERR
);
776 case RPC_SYSTEMERROR
:
777 switch (rpcerr
->re_errno
) {
779 return (TRYRET_TIMEOUT
);
783 return (TRYRET_REMOTEERR
);
789 return (TRYRET_LOCALERR
);
793 * Look up a netid based on an address family and socket type.
794 * `af' is the address family, and `sotype' is SOCK_DGRAM or SOCK_STREAM.
796 * XXX there should be a library function for this.
799 netidbytype(int af
, int sotype
)
803 for (p
= nc_protos
; p
->netid
!= NULL
; p
++) {
804 if (af
!= p
->af
|| sotype
!= p
->sotype
)
812 * Look up a netconfig entry based on a netid, and cache the result so
813 * that we don't need to remember to call freenetconfigent().
815 * Otherwise it behaves just like getnetconfigent(), so nc_*error()
818 static struct netconfig
*
819 getnetconf_cached(const char *netid
)
821 static struct nc_entry
{
822 struct netconfig
*nconf
;
823 struct nc_entry
*next
;
826 struct netconfig
*nconf
;
828 for (p
= head
; p
!= NULL
; p
= p
->next
)
829 if (strcmp(netid
, p
->nconf
->nc_netid
) == 0)
832 if ((nconf
= getnetconfigent(netid
)) == NULL
)
834 if ((p
= malloc(sizeof(*p
))) == NULL
)
844 * xdr routines for mount rpc's
847 xdr_dir(XDR
*xdrsp
, char *dirp
)
849 return (xdr_string(xdrsp
, &dirp
, RPCMNT_PATHLEN
));
853 xdr_fh(XDR
*xdrsp
, struct nfhret
*np
)
856 long auth
, authcnt
, authfnd
= 0;
858 if (!xdr_u_long(xdrsp
, &np
->stat
))
864 np
->fhsize
= NFSX_V2FH
;
865 return (xdr_opaque(xdrsp
, (caddr_t
)np
->nfh
, NFSX_V2FH
));
867 if (!xdr_long(xdrsp
, &np
->fhsize
))
869 if (np
->fhsize
<= 0 || np
->fhsize
> NFSX_V3FHMAX
)
871 if (!xdr_opaque(xdrsp
, (caddr_t
)np
->nfh
, np
->fhsize
))
873 if (!xdr_long(xdrsp
, &authcnt
))
875 for (i
= 0; i
< authcnt
; i
++) {
876 if (!xdr_long(xdrsp
, &auth
))
878 if (auth
== np
->auth
)
882 * Some servers, such as DEC's OSF/1 return a nil authenticator
883 * list to indicate RPCAUTH_UNIX.
885 if (!authfnd
&& (authcnt
> 0 || np
->auth
!= RPCAUTH_UNIX
))
895 fprintf(stderr
, "%s\n%s\n%s\n%s\n",
896 "usage: mount_nfs [-23NPTUbcdils] [-D deadthresh] [-I readdirsize]",
897 " [-R retrycnt] [-a maxreadahead]",
898 " [-g maxgroups] [-o options] [-r readsize]",
899 " [-t timeout] [-w writesize] [-x retrans] rhost:path node");