xref: /original-bsd/sbin/mount/mount.c (revision c2d8c538)
1 /*
2  * Copyright (c) 1980, 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
11  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)mount.c	5.42 (Berkeley) 11/12/90";
16 #endif /* not lint */
17 
18 #include <sys/param.h>
19 #include <sys/file.h>
20 #include <sys/time.h>
21 #include <sys/wait.h>
22 #include <sys/errno.h>
23 #include <sys/signal.h>
24 #include <sys/mount.h>
25 #ifdef NFS
26 #include <sys/socket.h>
27 #include <sys/socketvar.h>
28 #include <netdb.h>
29 #include <rpc/rpc.h>
30 #include <rpc/pmap_clnt.h>
31 #include <rpc/pmap_prot.h>
32 #include <nfs/rpcv2.h>
33 #include <nfs/nfsv2.h>
34 #include <nfs/nfs.h>
35 #endif
36 #include <fstab.h>
37 #include <string.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include "pathnames.h"
41 
42 #define DEFAULT_ROOTUID	-2
43 
44 #define	BADTYPE(type) \
45 	(strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \
46 	    strcmp(type, FSTAB_RQ))
47 #define	SETTYPE(type) \
48 	(!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ))
49 
50 int fake, verbose, updateflg, mnttype;
51 char *mntname, **envp;
52 char **vfslist, **makevfslist();
53 
54 #ifdef NFS
55 int xdr_dir(), xdr_fh();
56 char *getnfsargs();
57 struct nfs_args nfsdefargs = {
58 	(struct sockaddr *)0,
59 	SOCK_DGRAM,
60 	0,
61 	(nfsv2fh_t *)0,
62 	0,
63 	NFS_WSIZE,
64 	NFS_RSIZE,
65 	NFS_TIMEO,
66 	NFS_RETRANS,
67 	(char *)0,
68 };
69 
70 struct nfhret {
71 	u_long	stat;
72 	nfsv2fh_t nfh;
73 };
74 #define	DEF_RETRY	10000
75 int retrycnt;
76 #define	BGRND	1
77 #define	ISBGRND	2
78 int opflags = 0;
79 #endif
80 
81 main(argc, argv, arge)
82 	int argc;
83 	char **argv;
84 	char **arge;
85 {
86 	extern char *optarg;
87 	extern int optind;
88 	register struct fstab *fs;
89 	int all, ch, rval, flags, ret, pid, i;
90 	long mntsize;
91 	struct statfs *mntbuf, *getmntpt();
92 	char *type, *options = NULL;
93 	FILE *pidfile;
94 
95 	envp = arge;
96 	all = 0;
97 	type = NULL;
98 	mnttype = MOUNT_UFS;
99 	mntname = "ufs";
100 	while ((ch = getopt(argc, argv, "afrwuvt:o:")) != EOF)
101 		switch((char)ch) {
102 		case 'a':
103 			all = 1;
104 			break;
105 		case 'f':
106 			fake = 1;
107 			break;
108 		case 'r':
109 			type = FSTAB_RO;
110 			break;
111 		case 'u':
112 			updateflg = MNT_UPDATE;
113 			break;
114 		case 'v':
115 			verbose = 1;
116 			break;
117 		case 'w':
118 			type = FSTAB_RW;
119 			break;
120 		case 'o':
121 			options = optarg;
122 			break;
123 		case 't':
124 			vfslist = makevfslist(optarg);
125 			mnttype = getmnttype(optarg);
126 			break;
127 		case '?':
128 		default:
129 			usage();
130 			/* NOTREACHED */
131 		}
132 	argc -= optind;
133 	argv += optind;
134 
135 	/* NOSTRICT */
136 
137 	if (all) {
138 		rval = 0;
139 		while (fs = getfsent()) {
140 			if (BADTYPE(fs->fs_type))
141 				continue;
142 			if (badvfsname(fs->fs_vfstype, vfslist))
143 				continue;
144 			/* `/' is special, it's always mounted */
145 			if (!strcmp(fs->fs_file, "/"))
146 				flags = MNT_UPDATE;
147 			else
148 				flags = updateflg;
149 			mnttype = getmnttype(fs->fs_vfstype);
150 			rval |= mountfs(fs->fs_spec, fs->fs_file, flags,
151 			    type, options, fs->fs_mntops);
152 		}
153 		exit(rval);
154 	}
155 
156 	if (argc == 0) {
157 		if (verbose || fake || type)
158 			usage();
159 		if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
160 			fprintf(stderr,
161 				"mount: cannot get mount information\n");
162 			exit(1);
163 		}
164 		for (i = 0; i < mntsize; i++) {
165 			if (badvfstype(mntbuf[i].f_type, vfslist))
166 				continue;
167 			prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname,
168 				mntbuf[i].f_flags);
169 		}
170 		exit(0);
171 	}
172 
173 	if (argc == 1 && updateflg) {
174 		if ((mntbuf = getmntpt(*argv)) == NULL) {
175 			fprintf(stderr,
176 			    "mount: unknown special file or file system %s.\n",
177 			    *argv);
178 			exit(1);
179 		}
180 		mnttype = mntbuf->f_type;
181 		if (!strcmp(mntbuf->f_mntfromname, "root_device")) {
182 			fs = getfsfile("/");
183 			strcpy(mntbuf->f_mntfromname, fs->fs_spec);
184 		}
185 		ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
186 		    updateflg, type, options, (char *)NULL);
187 	} else if (argc == 1) {
188 		if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
189 			fprintf(stderr,
190 			    "mount: unknown special file or file system %s.\n",
191 			    *argv);
192 			exit(1);
193 		}
194 		if (BADTYPE(fs->fs_type)) {
195 			fprintf(stderr,
196 			    "mount: %s has unknown file system type.\n", *argv);
197 			exit(1);
198 		}
199 		mnttype = getmnttype(fs->fs_vfstype);
200 		ret = mountfs(fs->fs_spec, fs->fs_file, updateflg,
201 		    type, options, fs->fs_mntops);
202 	} else if (argc != 2) {
203 		usage();
204 		ret = 1;
205 	} else {
206 		/*
207 		 * If -t flag has not been specified, and spec
208 		 * contains either a ':' or a '@' then assume that
209 		 * an NFS filesystem is being specified ala Sun.
210 		 */
211 		if (vfslist == (char **)0 &&
212 		    (index(argv[0], ':') || index(argv[0], '@')))
213 			mnttype = MOUNT_NFS;
214 		ret = mountfs(argv[0], argv[1], updateflg, type, options,
215 		    (char *)NULL);
216 	}
217 	if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
218 		pid = 0;
219 		fscanf(pidfile, "%d", &pid);
220 		fclose(pidfile);
221 		if (pid > 0)
222 			kill(pid, SIGHUP);
223 	}
224 	exit (ret);
225 }
226 
227 mountfs(spec, name, flags, type, options, mntopts)
228 	char *spec, *name, *type, *options, *mntopts;
229 	int flags;
230 {
231 	union wait status;
232 	pid_t pid;
233 	int argc, i;
234 	struct ufs_args args;
235 	struct nfs_args nfsargs;
236 	char *argp, *argv[50];
237 	char execname[MAXPATHLEN + 1], flagval[12];
238 
239 	nfsargs = nfsdefargs;
240 	if (mntopts)
241 		getstdopts(mntopts, &flags);
242 	if (options)
243 		getstdopts(options, &flags);
244 	if (type)
245 		getstdopts(type, &flags);
246 	switch (mnttype) {
247 	case MOUNT_UFS:
248 		if (mntopts)
249 			getufsopts(mntopts, &flags);
250 		if (options)
251 			getufsopts(options, &flags);
252 		args.fspec = spec;
253 		args.exroot = DEFAULT_ROOTUID;
254 		if (flags & MNT_RDONLY)
255 			args.exflags = MNT_EXRDONLY;
256 		else
257 			args.exflags = 0;
258 		argp = (caddr_t)&args;
259 		break;
260 
261 #ifdef NFS
262 	case MOUNT_NFS:
263 		retrycnt = DEF_RETRY;
264 		if (mntopts)
265 			getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
266 		if (options)
267 			getnfsopts(options, &nfsargs, &opflags, &retrycnt);
268 		if (argp = getnfsargs(spec, &nfsargs))
269 			break;
270 		return (1);
271 #endif /* NFS */
272 
273 	case MOUNT_MFS:
274 	default:
275 		argv[0] = mntname;
276 		argc = 1;
277 		if (flags) {
278 			argv[argc++] = "-F";
279 			sprintf(flagval, "%d", flags);
280 			argv[argc++] = flagval;
281 		}
282 		if (mntopts)
283 			argc += getexecopts(mntopts, &argv[argc]);
284 		if (options)
285 			argc += getexecopts(options, &argv[argc]);
286 		argv[argc++] = spec;
287 		argv[argc++] = name;
288 		argv[argc++] = NULL;
289 		sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
290 		if (verbose) {
291 			(void)printf("exec: %s", execname);
292 			for (i = 1; i < argc - 1; i++)
293 				(void)printf(" %s", argv[i]);
294 			(void)printf("\n");
295 		}
296 		if (fake)
297 			break;
298 		if (pid = vfork()) {
299 			if (pid == -1) {
300 				perror("mount: vfork starting file system");
301 				return (1);
302 			}
303 			if (waitpid(pid, &status, 0) != -1 &&
304 			    WIFEXITED(status) &&
305 			    WEXITSTATUS(status) != 0)
306 				return (WEXITSTATUS(status));
307 			spec = mntname;
308 			goto out;
309 		}
310 		execve(execname, argv, envp);
311 		fprintf(stderr, "mount: cannot exec %s for %s: ",
312 			execname, name);
313 		perror((char *)NULL);
314 		exit (1);
315 		/* NOTREACHED */
316 
317 	}
318 	if (!fake && mount(mnttype, name, flags, argp)) {
319 		if (opflags & ISBGRND)
320 			exit(1);
321 		fprintf(stderr, "%s on %s: ", spec, name);
322 		switch (errno) {
323 		case EMFILE:
324 			fprintf(stderr, "Mount table full\n");
325 			break;
326 		case EINVAL:
327 			if (flags & MNT_UPDATE)
328 				fprintf(stderr, "Specified device does %s\n",
329 					"not match mounted device");
330 			else if (mnttype == MOUNT_UFS)
331 				fprintf(stderr, "Bogus super block\n");
332 			else
333 				perror((char *)NULL);
334 			break;
335 		case EOPNOTSUPP:
336 			fprintf(stderr, "Operation not supported\n");
337 			break;
338 		default:
339 			perror((char *)NULL);
340 			break;
341 		}
342 		return(1);
343 	}
344 
345 out:
346 	if (verbose)
347 		prmount(spec, name, flags);
348 
349 	if (opflags & ISBGRND)
350 		exit(1);
351 	return(0);
352 }
353 
354 static
355 prmount(spec, name, flags)
356 	char *spec, *name;
357 	register short flags;
358 {
359 	register int first;
360 
361 	if (opflags & ISBGRND)
362 		return;
363 	(void)printf("%s on %s", spec, name);
364 	if (!(flags & MNT_VISFLAGMASK)) {
365 		(void)printf("\n");
366 		return;
367 	}
368 	first = 0;
369 #define	PR(msg)	(void)printf("%s%s", !first++ ? " (" : ", ", msg)
370 	if (flags & MNT_RDONLY)
371 		PR("read-only");
372 	if (flags & MNT_NOEXEC)
373 		PR("noexec");
374 	if (flags & MNT_NOSUID)
375 		PR("nosuid");
376 	if (flags & MNT_NODEV)
377 		PR("nodev");
378 	if (flags & MNT_SYNCHRONOUS)
379 		PR("synchronous");
380 	if (flags & MNT_QUOTA)
381 		PR("with quotas");
382 	if (flags & MNT_LOCAL)
383 		PR("local");
384 	if (flags & MNT_EXPORTED)
385 		if (flags & MNT_EXRDONLY)
386 			PR("NFS exported read-only");
387 		else
388 			PR("NFS exported");
389 	(void)printf(")\n");
390 }
391 
392 getmnttype(fstype)
393 	char *fstype;
394 {
395 
396 	mntname = fstype;
397 	if (!strcmp(fstype, "ufs"))
398 		return (MOUNT_UFS);
399 	if (!strcmp(fstype, "nfs"))
400 		return (MOUNT_NFS);
401 	if (!strcmp(fstype, "mfs"))
402 		return (MOUNT_MFS);
403 	return (0);
404 }
405 
406 usage()
407 {
408 
409 	fprintf(stderr, "usage:\n  mount %s %s\n  mount %s\n  mount %s\n",
410 		"[ -frwu ] [ -t nfs | ufs | external_type ]",
411 		"[ -o options ] special node",
412 		"[ -afrwu ] [ -t nfs | ufs | external_type ]",
413 		"[ -frwu ] special | node");
414 	exit(1);
415 }
416 
417 getstdopts(options, flagp)
418 	char *options;
419 	int *flagp;
420 {
421 	register char *opt;
422 	int negative;
423 	char optbuf[BUFSIZ];
424 
425 	(void)strcpy(optbuf, options);
426 	for (opt = strtok(optbuf, ","); opt; opt = strtok((char *)NULL, ",")) {
427 		if (opt[0] == 'n' && opt[1] == 'o') {
428 			negative++;
429 			opt += 2;
430 		} else {
431 			negative = 0;
432 		}
433 		if (!negative && !strcasecmp(opt, FSTAB_RO)) {
434 			*flagp |= MNT_RDONLY;
435 			continue;
436 		}
437 		if (!negative && !strcasecmp(opt, FSTAB_RW)) {
438 			*flagp &= ~MNT_RDONLY;
439 			continue;
440 		}
441 		if (!strcasecmp(opt, "exec")) {
442 			if (negative)
443 				*flagp |= MNT_NOEXEC;
444 			else
445 				*flagp &= ~MNT_NOEXEC;
446 			continue;
447 		}
448 		if (!strcasecmp(opt, "suid")) {
449 			if (negative)
450 				*flagp |= MNT_NOSUID;
451 			else
452 				*flagp &= ~MNT_NOSUID;
453 			continue;
454 		}
455 		if (!strcasecmp(opt, "dev")) {
456 			if (negative)
457 				*flagp |= MNT_NODEV;
458 			else
459 				*flagp &= ~MNT_NODEV;
460 			continue;
461 		}
462 		if (!strcasecmp(opt, "synchronous")) {
463 			if (!negative)
464 				*flagp |= MNT_SYNCHRONOUS;
465 			else
466 				*flagp &= ~MNT_SYNCHRONOUS;
467 			continue;
468 		}
469 	}
470 }
471 
472 /* ARGSUSED */
473 getufsopts(options, flagp)
474 	char *options;
475 	int *flagp;
476 {
477 	return;
478 }
479 
480 getexecopts(options, argv)
481 	char *options;
482 	char **argv;
483 {
484 	register int argc = 0;
485 	register char *opt;
486 
487 	for (opt = strtok(options, ","); opt; opt = strtok((char *)NULL, ",")) {
488 		if (opt[0] != '-')
489 			continue;
490 		argv[argc++] = opt;
491 		if (opt[2] == '\0' || opt[2] != '=')
492 			continue;
493 		opt[2] = '\0';
494 		argv[argc++] = &opt[3];
495 	}
496 	return (argc);
497 }
498 
499 struct statfs *
500 getmntpt(name)
501 	char *name;
502 {
503 	long mntsize;
504 	register long i;
505 	struct statfs *mntbuf;
506 
507 	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
508 	for (i = 0; i < mntsize; i++) {
509 		if (!strcmp(mntbuf[i].f_mntfromname, name) ||
510 		    !strcmp(mntbuf[i].f_mntonname, name))
511 			return (&mntbuf[i]);
512 	}
513 	return ((struct statfs *)0);
514 }
515 
516 static int skipvfs;
517 
518 badvfstype(vfstype, vfslist)
519 	short vfstype;
520 	char **vfslist;
521 {
522 
523 	if (vfslist == 0)
524 		return(0);
525 	while (*vfslist) {
526 		if (vfstype == getmnttype(*vfslist))
527 			return(skipvfs);
528 		vfslist++;
529 	}
530 	return (!skipvfs);
531 }
532 
533 badvfsname(vfsname, vfslist)
534 	char *vfsname;
535 	char **vfslist;
536 {
537 
538 	if (vfslist == 0)
539 		return(0);
540 	while (*vfslist) {
541 		if (strcmp(vfsname, *vfslist) == 0)
542 			return(skipvfs);
543 		vfslist++;
544 	}
545 	return (!skipvfs);
546 }
547 
548 char **
549 makevfslist(fslist)
550 	char *fslist;
551 {
552 	register char **av, *nextcp;
553 	register int i;
554 
555 	if (fslist == NULL)
556 		return (NULL);
557 	if (fslist[0] == 'n' && fslist[1] == 'o') {
558 		fslist += 2;
559 		skipvfs = 1;
560 	}
561 	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
562 		if (*nextcp == ',')
563 			i++;
564 	av = (char **)malloc((size_t)(i+2) * sizeof(char *));
565 	if (av == NULL)
566 		return (NULL);
567 	nextcp = fslist;
568 	i = 0;
569 	av[i++] = nextcp;
570 	while (nextcp = index(nextcp, ',')) {
571 		*nextcp++ = '\0';
572 		av[i++] = nextcp;
573 	}
574 	av[i++] = 0;
575 	return (av);
576 }
577 
578 #ifdef NFS
579 /*
580  * Handle the getoption arg.
581  * Essentially update "opflags", "retrycnt" and "nfsargs"
582  */
583 getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
584 	char *optarg;
585 	struct nfs_args *nfsargsp;
586 	int *opflagsp;
587 	int *retrycntp;
588 {
589 	register char *cp, *nextcp;
590 	int num;
591 	char *nump;
592 
593 	cp = optarg;
594 	while (cp != NULL && *cp != '\0') {
595 		if ((nextcp = index(cp, ',')) != NULL)
596 			*nextcp++ = '\0';
597 		if ((nump = index(cp, '=')) != NULL) {
598 			*nump++ = '\0';
599 			num = atoi(nump);
600 		} else
601 			num = -1;
602 		/*
603 		 * Just test for a string match and do it
604 		 */
605 		if (!strcmp(cp, "bg")) {
606 			*opflagsp |= BGRND;
607 		} else if (!strcmp(cp, "soft")) {
608 			if (nfsargsp->flags & NFSMNT_SPONGY) {
609 				fprintf(stderr,
610 					"Options soft, spongy mutually exclusive\n");
611 				exit(1);
612 			}
613 			nfsargsp->flags |= NFSMNT_SOFT;
614 		} else if (!strcmp(cp, "spongy")) {
615 			if (nfsargsp->flags & NFSMNT_SOFT) {
616 				fprintf(stderr,
617 					"Options soft, spongy mutually exclusive\n");
618 				exit(1);
619 			}
620 			nfsargsp->flags |= NFSMNT_SPONGY;
621 		} else if (!strcmp(cp, "compress")) {
622 			nfsargsp->flags |= NFSMNT_COMPRESS;
623 		} else if (!strcmp(cp, "intr")) {
624 			nfsargsp->flags |= NFSMNT_INT;
625 		} else if (!strcmp(cp, "tcp")) {
626 			nfsargsp->sotype = SOCK_STREAM;
627 		} else if (!strcmp(cp, "noconn")) {
628 			nfsargsp->flags |= NFSMNT_NOCONN;
629 		} else if (!strcmp(cp, "retry") && num > 0) {
630 			*retrycntp = num;
631 		} else if (!strcmp(cp, "rsize") && num > 0) {
632 			nfsargsp->rsize = num;
633 			nfsargsp->flags |= NFSMNT_RSIZE;
634 		} else if (!strcmp(cp, "wsize") && num > 0) {
635 			nfsargsp->wsize = num;
636 			nfsargsp->flags |= NFSMNT_WSIZE;
637 		} else if (!strcmp(cp, "timeo") && num > 0) {
638 			nfsargsp->timeo = num;
639 			nfsargsp->flags |= NFSMNT_TIMEO;
640 		} else if (!strcmp(cp, "retrans") && num > 0) {
641 			nfsargsp->retrans = num;
642 			nfsargsp->flags |= NFSMNT_RETRANS;
643 		}
644 		cp = nextcp;
645 	}
646 	if (nfsargsp->sotype == SOCK_DGRAM) {
647 		if (nfsargsp->rsize > NFS_MAXDGRAMDATA)
648 			nfsargsp->rsize = NFS_MAXDGRAMDATA;
649 		if (nfsargsp->wsize > NFS_MAXDGRAMDATA)
650 			nfsargsp->wsize = NFS_MAXDGRAMDATA;
651 	}
652 }
653 
654 char *
655 getnfsargs(spec, nfsargsp)
656 	char *spec;
657 	struct nfs_args *nfsargsp;
658 {
659 	register CLIENT *clp;
660 	struct hostent *hp;
661 	static struct sockaddr_in saddr;
662 	struct timeval pertry, try;
663 	enum clnt_stat clnt_stat;
664 	int so = RPC_ANYSOCK;
665 	char *fsp, *hostp, *delimp;
666 	u_short tport;
667 	static struct nfhret nfhret;
668 	static char nam[MNAMELEN + 1];
669 	char buf[MAXPATHLEN + 1];
670 
671 	strncpy(buf, spec, MAXPATHLEN);
672 	buf[MAXPATHLEN] = '\0';
673 	strncpy(nam, spec, MNAMELEN);
674 	nam[MNAMELEN] = '\0';
675 	if ((delimp = index(buf, '@')) != NULL) {
676 		hostp = delimp + 1;
677 		fsp = buf;
678 	} else if ((delimp = index(buf, ':')) != NULL) {
679 		hostp = buf;
680 		fsp = delimp + 1;
681 	} else {
682 		fprintf(stderr,
683 		    "No <host>:<dirpath> or <dirpath>@<host> spec\n");
684 		return (0);
685 	}
686 	*delimp = '\0';
687 	if ((hp = gethostbyname(hostp)) == NULL) {
688 		fprintf(stderr, "Can't get net id for host\n");
689 		return (0);
690 	}
691 	bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
692 	nfhret.stat = ETIMEDOUT;	/* Mark not yet successful */
693 	while (retrycnt > 0) {
694 		saddr.sin_family = AF_INET;
695 		saddr.sin_port = htons(PMAPPORT);
696 		if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
697 		    NFS_VER2, IPPROTO_UDP)) == 0) {
698 			if ((opflags & ISBGRND) == 0)
699 				clnt_pcreateerror("NFS Portmap");
700 		} else {
701 			saddr.sin_port = 0;
702 			pertry.tv_sec = 10;
703 			pertry.tv_usec = 0;
704 			if ((clp = clntudp_create(&saddr, RPCPROG_MNT,
705 			    RPCMNT_VER1, pertry, &so)) == NULL) {
706 				if ((opflags & ISBGRND) == 0)
707 					clnt_pcreateerror("Cannot MNT PRC");
708 			} else {
709 				clp->cl_auth = authunix_create_default();
710 				try.tv_sec = 10;
711 				try.tv_usec = 0;
712 				clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
713 				    xdr_dir, fsp, xdr_fh, &nfhret, try);
714 				if (clnt_stat != RPC_SUCCESS) {
715 					if ((opflags & ISBGRND) == 0)
716 						clnt_perror(clp, "Bad MNT RPC");
717 				} else {
718 					auth_destroy(clp->cl_auth);
719 					clnt_destroy(clp);
720 					retrycnt = 0;
721 				}
722 			}
723 		}
724 		if (--retrycnt > 0) {
725 			if (opflags & BGRND) {
726 				opflags &= ~BGRND;
727 				if (fork())
728 					return (0);
729 				else
730 					opflags |= ISBGRND;
731 			}
732 			sleep(10);
733 		}
734 	}
735 	if (nfhret.stat) {
736 		if (opflags & ISBGRND)
737 			exit(1);
738 		fprintf(stderr, "Mount RPC error on %s: ", spec);
739 		errno = nfhret.stat;
740 		perror((char *)NULL);
741 		return (0);
742 	}
743 	saddr.sin_port = htons(tport);
744 	nfsargsp->addr = (struct sockaddr *) &saddr;
745 	nfsargsp->fh = &nfhret.nfh;
746 	nfsargsp->hostname = nam;
747 	return ((caddr_t)nfsargsp);
748 }
749 
750 /*
751  * xdr routines for mount rpc's
752  */
753 xdr_dir(xdrsp, dirp)
754 	XDR *xdrsp;
755 	char *dirp;
756 {
757 	return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
758 }
759 
760 xdr_fh(xdrsp, np)
761 	XDR *xdrsp;
762 	struct nfhret *np;
763 {
764 	if (!xdr_u_long(xdrsp, &(np->stat)))
765 		return (0);
766 	if (np->stat)
767 		return (1);
768 	return (xdr_opaque(xdrsp, (caddr_t)&(np->nfh), NFSX_FH));
769 }
770 #endif /* NFS */
771