xref: /original-bsd/sbin/mount/mount.c (revision acda45c0)
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.44 (Berkeley) 02/26/91";
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 static void prmount();
54 
55 #ifdef NFS
56 int xdr_dir(), xdr_fh();
57 char *getnfsargs();
58 struct nfs_args nfsdefargs = {
59 	(struct sockaddr *)0,
60 	SOCK_DGRAM,
61 	0,
62 	(nfsv2fh_t *)0,
63 	0,
64 	NFS_WSIZE,
65 	NFS_RSIZE,
66 	NFS_TIMEO,
67 	NFS_RETRANS,
68 	(char *)0,
69 };
70 
71 struct nfhret {
72 	u_long	stat;
73 	nfsv2fh_t nfh;
74 };
75 #define	DEF_RETRY	10000
76 int retrycnt;
77 #define	BGRND	1
78 #define	ISBGRND	2
79 int opflags = 0;
80 #endif
81 
82 main(argc, argv, arge)
83 	int argc;
84 	char **argv;
85 	char **arge;
86 {
87 	extern char *optarg;
88 	extern int optind;
89 	register struct fstab *fs;
90 	int all, ch, rval, flags, ret, pid, i;
91 	long mntsize;
92 	struct statfs *mntbuf, *getmntpt();
93 	char *type, *options = NULL;
94 	FILE *pidfile;
95 
96 	envp = arge;
97 	all = 0;
98 	type = NULL;
99 	mnttype = MOUNT_UFS;
100 	mntname = "ufs";
101 	while ((ch = getopt(argc, argv, "afrwuvt:o:")) != EOF)
102 		switch((char)ch) {
103 		case 'a':
104 			all = 1;
105 			break;
106 		case 'f':
107 			fake = 1;
108 			break;
109 		case 'r':
110 			type = FSTAB_RO;
111 			break;
112 		case 'u':
113 			updateflg = MNT_UPDATE;
114 			break;
115 		case 'v':
116 			verbose = 1;
117 			break;
118 		case 'w':
119 			type = FSTAB_RW;
120 			break;
121 		case 'o':
122 			options = optarg;
123 			break;
124 		case 't':
125 			vfslist = makevfslist(optarg);
126 			mnttype = getmnttype(optarg);
127 			break;
128 		case '?':
129 		default:
130 			usage();
131 			/* NOTREACHED */
132 		}
133 	argc -= optind;
134 	argv += optind;
135 
136 	/* NOSTRICT */
137 
138 	if (all) {
139 		rval = 0;
140 		while (fs = getfsent()) {
141 			if (BADTYPE(fs->fs_type))
142 				continue;
143 			if (badvfsname(fs->fs_vfstype, vfslist))
144 				continue;
145 			/* `/' is special, it's always mounted */
146 			if (!strcmp(fs->fs_file, "/"))
147 				flags = MNT_UPDATE;
148 			else
149 				flags = updateflg;
150 			mnttype = getmnttype(fs->fs_vfstype);
151 			rval |= mountfs(fs->fs_spec, fs->fs_file, flags,
152 			    type, options, fs->fs_mntops);
153 		}
154 		exit(rval);
155 	}
156 
157 	if (argc == 0) {
158 		if (verbose || fake || type)
159 			usage();
160 		if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
161 			(void) fprintf(stderr,
162 				"mount: cannot get mount information\n");
163 			exit(1);
164 		}
165 		for (i = 0; i < mntsize; i++) {
166 			if (badvfstype(mntbuf[i].f_type, vfslist))
167 				continue;
168 			prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname,
169 				mntbuf[i].f_flags);
170 		}
171 		exit(0);
172 	}
173 
174 	if (argc == 1 && updateflg) {
175 		if ((mntbuf = getmntpt(*argv)) == NULL) {
176 			(void) fprintf(stderr,
177 			    "mount: unknown special file or file system %s.\n",
178 			    *argv);
179 			exit(1);
180 		}
181 		mnttype = mntbuf->f_type;
182 		if (!strcmp(mntbuf->f_mntfromname, "root_device")) {
183 			fs = getfsfile("/");
184 			strcpy(mntbuf->f_mntfromname, fs->fs_spec);
185 		}
186 		ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
187 		    updateflg, type, options, (char *)NULL);
188 	} else if (argc == 1) {
189 		if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
190 			(void) fprintf(stderr,
191 			    "mount: unknown special file or file system %s.\n",
192 			    *argv);
193 			exit(1);
194 		}
195 		if (BADTYPE(fs->fs_type)) {
196 			(void) fprintf(stderr,
197 			    "mount: %s has unknown file system type.\n", *argv);
198 			exit(1);
199 		}
200 		mnttype = getmnttype(fs->fs_vfstype);
201 		ret = mountfs(fs->fs_spec, fs->fs_file, updateflg,
202 		    type, options, fs->fs_mntops);
203 	} else if (argc != 2) {
204 		usage();
205 		ret = 1;
206 	} else {
207 		/*
208 		 * If -t flag has not been specified, and spec
209 		 * contains either a ':' or a '@' then assume that
210 		 * an NFS filesystem is being specified ala Sun.
211 		 */
212 		if (vfslist == (char **)0 &&
213 		    (index(argv[0], ':') || index(argv[0], '@')))
214 			mnttype = MOUNT_NFS;
215 		ret = mountfs(argv[0], argv[1], updateflg, type, options,
216 		    (char *)NULL);
217 	}
218 	if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
219 		pid = 0;
220 		fscanf(pidfile, "%d", &pid);
221 		fclose(pidfile);
222 		if (pid > 0)
223 			kill(pid, SIGHUP);
224 	}
225 	exit (ret);
226 }
227 
228 mountfs(spec, name, flags, type, options, mntopts)
229 	char *spec, *name, *type, *options, *mntopts;
230 	int flags;
231 {
232 	union wait status;
233 	pid_t pid;
234 	int argc, i;
235 	struct ufs_args args;
236 	struct nfs_args nfsargs;
237 	char *argp, *argv[50];
238 	char execname[MAXPATHLEN + 1], flagval[12];
239 
240 	nfsargs = nfsdefargs;
241 	if (mntopts)
242 		getstdopts(mntopts, &flags);
243 	if (options)
244 		getstdopts(options, &flags);
245 	if (type)
246 		getstdopts(type, &flags);
247 	switch (mnttype) {
248 	case MOUNT_UFS:
249 		if (mntopts)
250 			getufsopts(mntopts, &flags);
251 		if (options)
252 			getufsopts(options, &flags);
253 		args.fspec = spec;
254 		args.exroot = DEFAULT_ROOTUID;
255 		if (flags & MNT_RDONLY)
256 			args.exflags = MNT_EXRDONLY;
257 		else
258 			args.exflags = 0;
259 		argp = (caddr_t)&args;
260 		break;
261 
262 #ifdef NFS
263 	case MOUNT_NFS:
264 		retrycnt = DEF_RETRY;
265 		if (mntopts)
266 			getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
267 		if (options)
268 			getnfsopts(options, &nfsargs, &opflags, &retrycnt);
269 		if (argp = getnfsargs(spec, &nfsargs))
270 			break;
271 		return (1);
272 #endif /* NFS */
273 
274 	case MOUNT_MFS:
275 	default:
276 		argv[0] = mntname;
277 		argc = 1;
278 		if (flags) {
279 			argv[argc++] = "-F";
280 			sprintf(flagval, "%d", flags);
281 			argv[argc++] = flagval;
282 		}
283 		if (mntopts)
284 			argc += getexecopts(mntopts, &argv[argc]);
285 		if (options)
286 			argc += getexecopts(options, &argv[argc]);
287 		argv[argc++] = spec;
288 		argv[argc++] = name;
289 		argv[argc++] = NULL;
290 		sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
291 		if (verbose) {
292 			(void)printf("exec: %s", execname);
293 			for (i = 1; i < argc - 1; i++)
294 				(void)printf(" %s", argv[i]);
295 			(void)printf("\n");
296 		}
297 		if (fake)
298 			break;
299 		if (pid = vfork()) {
300 			if (pid == -1) {
301 				perror("mount: vfork starting file system");
302 				return (1);
303 			}
304 			if (waitpid(pid, (int *)&status, 0) != -1 &&
305 			    WIFEXITED(status) &&
306 			    WEXITSTATUS(status) != 0)
307 				return (WEXITSTATUS(status));
308 			spec = mntname;
309 			goto out;
310 		}
311 		execve(execname, argv, envp);
312 		(void) fprintf(stderr, "mount: cannot exec %s for %s: ",
313 			execname, name);
314 		perror((char *)NULL);
315 		exit (1);
316 		/* NOTREACHED */
317 
318 	}
319 	if (!fake && mount(mnttype, name, flags, argp)) {
320 		if (opflags & ISBGRND)
321 			exit(1);
322 		(void) fprintf(stderr, "%s on %s: ", spec, name);
323 		switch (errno) {
324 		case EMFILE:
325 			(void) fprintf(stderr, "Mount table full\n");
326 			break;
327 		case EINVAL:
328 			if (flags & MNT_UPDATE)
329 				(void) fprintf(stderr, "Specified device %s\n",
330 					"does not match mounted device");
331 			else if (mnttype == MOUNT_UFS)
332 				(void) fprintf(stderr, "Bogus super block\n");
333 			else
334 				perror((char *)NULL);
335 			break;
336 		default:
337 			perror((char *)NULL);
338 			break;
339 		}
340 		return(1);
341 	}
342 
343 out:
344 	if (verbose)
345 		prmount(spec, name, flags);
346 
347 	if (opflags & ISBGRND)
348 		exit(1);
349 	return(0);
350 }
351 
352 static void
353 prmount(spec, name, flags)
354 	char *spec, *name;
355 	register short flags;
356 {
357 	register int first;
358 
359 	if (opflags & ISBGRND)
360 		return;
361 	(void)printf("%s on %s", spec, name);
362 	if (!(flags & MNT_VISFLAGMASK)) {
363 		(void)printf("\n");
364 		return;
365 	}
366 	first = 0;
367 #define	PR(msg)	(void)printf("%s%s", !first++ ? " (" : ", ", msg)
368 	if (flags & MNT_RDONLY)
369 		PR("read-only");
370 	if (flags & MNT_NOEXEC)
371 		PR("noexec");
372 	if (flags & MNT_NOSUID)
373 		PR("nosuid");
374 	if (flags & MNT_NODEV)
375 		PR("nodev");
376 	if (flags & MNT_SYNCHRONOUS)
377 		PR("synchronous");
378 	if (flags & MNT_QUOTA)
379 		PR("with quotas");
380 	if (flags & MNT_LOCAL)
381 		PR("local");
382 	if (flags & MNT_EXPORTED)
383 		if (flags & MNT_EXRDONLY)
384 			PR("NFS exported read-only");
385 		else
386 			PR("NFS exported");
387 	(void)printf(")\n");
388 }
389 
390 getmnttype(fstype)
391 	char *fstype;
392 {
393 
394 	mntname = fstype;
395 	if (!strcmp(fstype, "ufs"))
396 		return (MOUNT_UFS);
397 	if (!strcmp(fstype, "nfs"))
398 		return (MOUNT_NFS);
399 	if (!strcmp(fstype, "mfs"))
400 		return (MOUNT_MFS);
401 	return (0);
402 }
403 
404 usage()
405 {
406 
407 	(void) fprintf(stderr,
408 		"usage:\n  mount %s %s\n  mount %s\n  mount %s\n",
409 		"[ -frwu ] [ -t nfs | ufs | external_type ]",
410 		"[ -o options ] special node",
411 		"[ -afrwu ] [ -t nfs | ufs | external_type ]",
412 		"[ -frwu ] special | node");
413 	exit(1);
414 }
415 
416 getstdopts(options, flagp)
417 	char *options;
418 	int *flagp;
419 {
420 	register char *opt;
421 	int negative;
422 	char optbuf[BUFSIZ];
423 
424 	(void)strcpy(optbuf, options);
425 	for (opt = strtok(optbuf, ","); opt; opt = strtok((char *)NULL, ",")) {
426 		if (opt[0] == 'n' && opt[1] == 'o') {
427 			negative++;
428 			opt += 2;
429 		} else {
430 			negative = 0;
431 		}
432 		if (!negative && !strcasecmp(opt, FSTAB_RO)) {
433 			*flagp |= MNT_RDONLY;
434 			continue;
435 		}
436 		if (!negative && !strcasecmp(opt, FSTAB_RW)) {
437 			*flagp &= ~MNT_RDONLY;
438 			continue;
439 		}
440 		if (!strcasecmp(opt, "exec")) {
441 			if (negative)
442 				*flagp |= MNT_NOEXEC;
443 			else
444 				*flagp &= ~MNT_NOEXEC;
445 			continue;
446 		}
447 		if (!strcasecmp(opt, "suid")) {
448 			if (negative)
449 				*flagp |= MNT_NOSUID;
450 			else
451 				*flagp &= ~MNT_NOSUID;
452 			continue;
453 		}
454 		if (!strcasecmp(opt, "dev")) {
455 			if (negative)
456 				*flagp |= MNT_NODEV;
457 			else
458 				*flagp &= ~MNT_NODEV;
459 			continue;
460 		}
461 		if (!strcasecmp(opt, "synchronous")) {
462 			if (!negative)
463 				*flagp |= MNT_SYNCHRONOUS;
464 			else
465 				*flagp &= ~MNT_SYNCHRONOUS;
466 			continue;
467 		}
468 	}
469 }
470 
471 /* ARGSUSED */
472 getufsopts(options, flagp)
473 	char *options;
474 	int *flagp;
475 {
476 	return;
477 }
478 
479 getexecopts(options, argv)
480 	char *options;
481 	char **argv;
482 {
483 	register int argc = 0;
484 	register char *opt;
485 
486 	for (opt = strtok(options, ","); opt; opt = strtok((char *)NULL, ",")) {
487 		if (opt[0] != '-')
488 			continue;
489 		argv[argc++] = opt;
490 		if (opt[2] == '\0' || opt[2] != '=')
491 			continue;
492 		opt[2] = '\0';
493 		argv[argc++] = &opt[3];
494 	}
495 	return (argc);
496 }
497 
498 struct statfs *
499 getmntpt(name)
500 	char *name;
501 {
502 	long mntsize;
503 	register long i;
504 	struct statfs *mntbuf;
505 
506 	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
507 	for (i = 0; i < mntsize; i++) {
508 		if (!strcmp(mntbuf[i].f_mntfromname, name) ||
509 		    !strcmp(mntbuf[i].f_mntonname, name))
510 			return (&mntbuf[i]);
511 	}
512 	return ((struct statfs *)0);
513 }
514 
515 static int skipvfs;
516 
517 badvfstype(vfstype, vfslist)
518 	short vfstype;
519 	char **vfslist;
520 {
521 
522 	if (vfslist == 0)
523 		return(0);
524 	while (*vfslist) {
525 		if (vfstype == getmnttype(*vfslist))
526 			return(skipvfs);
527 		vfslist++;
528 	}
529 	return (!skipvfs);
530 }
531 
532 badvfsname(vfsname, vfslist)
533 	char *vfsname;
534 	char **vfslist;
535 {
536 
537 	if (vfslist == 0)
538 		return(0);
539 	while (*vfslist) {
540 		if (strcmp(vfsname, *vfslist) == 0)
541 			return(skipvfs);
542 		vfslist++;
543 	}
544 	return (!skipvfs);
545 }
546 
547 char **
548 makevfslist(fslist)
549 	char *fslist;
550 {
551 	register char **av, *nextcp;
552 	register int i;
553 
554 	if (fslist == NULL)
555 		return (NULL);
556 	if (fslist[0] == 'n' && fslist[1] == 'o') {
557 		fslist += 2;
558 		skipvfs = 1;
559 	}
560 	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
561 		if (*nextcp == ',')
562 			i++;
563 	av = (char **)malloc((size_t)(i+2) * sizeof(char *));
564 	if (av == NULL)
565 		return (NULL);
566 	nextcp = fslist;
567 	i = 0;
568 	av[i++] = nextcp;
569 	while (nextcp = index(nextcp, ',')) {
570 		*nextcp++ = '\0';
571 		av[i++] = nextcp;
572 	}
573 	av[i++] = 0;
574 	return (av);
575 }
576 
577 #ifdef NFS
578 exclusive(a, b)
579 	char *a, *b;
580 {
581 
582 	(void) fprintf(stderr, "mount: Options %s, %s mutually exclusive\n",
583 	    a, b);
584 	exit(1);
585 }
586 
587 /*
588  * Handle the getoption arg.
589  * Essentially update "opflags", "retrycnt" and "nfsargs"
590  */
591 getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
592 	char *optarg;
593 	register struct nfs_args *nfsargsp;
594 	int *opflagsp;
595 	int *retrycntp;
596 {
597 	register char *cp, *nextcp;
598 	int num;
599 	char *nump;
600 
601 	for (cp = optarg; cp != NULL && *cp != '\0'; cp = nextcp) {
602 		if ((nextcp = index(cp, ',')) != NULL)
603 			*nextcp++ = '\0';
604 		if ((nump = index(cp, '=')) != NULL) {
605 			*nump++ = '\0';
606 			num = atoi(nump);
607 		} else
608 			num = -1;
609 		/*
610 		 * Just test for a string match and do it
611 		 */
612 		if (!strcmp(cp, "bg")) {
613 			*opflagsp |= BGRND;
614 		} else if (!strcmp(cp, "soft")) {
615 			if (nfsargsp->flags & NFSMNT_SPONGY)
616 				exclusive("soft, spongy");
617 			nfsargsp->flags |= NFSMNT_SOFT;
618 		} else if (!strcmp(cp, "spongy")) {
619 			if (nfsargsp->flags & NFSMNT_SOFT)
620 				exclusive("soft, spongy");
621 			nfsargsp->flags |= NFSMNT_SPONGY;
622 		} else if (!strcmp(cp, "compress")) {
623 			nfsargsp->flags |= NFSMNT_COMPRESS;
624 		} else if (!strcmp(cp, "intr")) {
625 			nfsargsp->flags |= NFSMNT_INT;
626 		} else if (!strcmp(cp, "tcp")) {
627 			nfsargsp->sotype = SOCK_STREAM;
628 		} else if (!strcmp(cp, "noconn")) {
629 			nfsargsp->flags |= NFSMNT_NOCONN;
630 		} else if (!strcmp(cp, "retry") && num > 0) {
631 			*retrycntp = num;
632 		} else if (!strcmp(cp, "rsize") && num > 0) {
633 			nfsargsp->rsize = num;
634 			nfsargsp->flags |= NFSMNT_RSIZE;
635 		} else if (!strcmp(cp, "wsize") && num > 0) {
636 			nfsargsp->wsize = num;
637 			nfsargsp->flags |= NFSMNT_WSIZE;
638 		} else if (!strcmp(cp, "timeo") && num > 0) {
639 			nfsargsp->timeo = num;
640 			nfsargsp->flags |= NFSMNT_TIMEO;
641 		} else if (!strcmp(cp, "retrans") && num > 0) {
642 			nfsargsp->retrans = num;
643 			nfsargsp->flags |= NFSMNT_RETRANS;
644 		}
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 		(void) fprintf(stderr,
683 		    "mount: No <host>:<dirpath> or <dirpath>@<host> spec\n");
684 		return (0);
685 	}
686 	*delimp = '\0';
687 	if ((hp = gethostbyname(hostp)) == NULL) {
688 		(void) fprintf(stderr, "mount: 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 		(void) 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