xref: /csrg-svn/sbin/mount/mount.c (revision 39133)
121156Sdist /*
221156Sdist  * Copyright (c) 1980 Regents of the University of California.
321156Sdist  * All rights reserved.  The Berkeley software License Agreement
421156Sdist  * specifies the terms and conditions for redistribution.
521156Sdist  */
621156Sdist 
710811Ssam #ifndef lint
821156Sdist char copyright[] =
921156Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1021156Sdist  All rights reserved.\n";
1121156Sdist #endif not lint
121057Sbill 
1321156Sdist #ifndef lint
14*39133Smckusick static char sccsid[] = "@(#)mount.c	5.12 (Berkeley) 09/12/89";
1521156Sdist #endif not lint
1621156Sdist 
1739131Smckusick #include "pathnames.h"
1812808Ssam #include <sys/param.h>
1935339Sbostic #include <sys/file.h>
2038445Smckusick #include <sys/time.h>
21*39133Smckusick #include <sys/wait.h>
2210811Ssam #include <fstab.h>
2316669Ssam #include <errno.h>
2435339Sbostic #include <stdio.h>
2538445Smckusick #include <strings.h>
2638445Smckusick #include <sys/dir.h>
2738445Smckusick #include <sys/uio.h>
2838445Smckusick #include <sys/namei.h>
2938445Smckusick #include <sys/mount.h>
3038445Smckusick #ifdef NFS
3138445Smckusick #include <sys/socket.h>
3238445Smckusick #include <sys/socketvar.h>
3338445Smckusick #include <netdb.h>
3438445Smckusick #include <rpc/rpc.h>
3538445Smckusick #include <rpc/pmap_clnt.h>
3638445Smckusick #include <rpc/pmap_prot.h>
3738445Smckusick #include <nfs/rpcv2.h>
3838445Smckusick #include <nfs/nfsv2.h>
3938445Smckusick #include <nfs/nfs.h>
4038445Smckusick #endif
411057Sbill 
4235339Sbostic #define	BADTYPE(type) \
4335339Sbostic 	(strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \
4435339Sbostic 	    strcmp(type, FSTAB_RQ))
4535339Sbostic #define	SETTYPE(type) \
4635339Sbostic 	(!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ))
471057Sbill 
4838445Smckusick static int fake, verbose, mnttype;
4939131Smckusick char **envp;
5039131Smckusick 
5138445Smckusick #ifdef NFS
5238445Smckusick int xdr_dir(), xdr_fh();
5338632Smckusick char *getnfsargs();
5438445Smckusick struct nfs_args nfsargs = {
5538445Smckusick 	(struct sockaddr_in *)0,
5638445Smckusick 	(nfsv2fh_t *)0,
5738445Smckusick 	0,
5838445Smckusick 	NFS_WSIZE,
5938445Smckusick 	NFS_RSIZE,
6038445Smckusick 	NFS_TIMEO,
6138445Smckusick 	NFS_RETRANS,
6238445Smckusick 	(char *)0,
6338445Smckusick };
645073Sroot 
6538445Smckusick struct nfhret {
6638445Smckusick 	u_long	stat;
6738445Smckusick 	nfsv2fh_t nfh;
6838445Smckusick };
6938445Smckusick int retrycnt = 10000;
7038445Smckusick #define	BGRND	1
7138445Smckusick #define	ISBGRND	2
7238445Smckusick int opflags = 0;
7338445Smckusick #endif
7438445Smckusick 
7539131Smckusick main(argc, argv, arge)
765073Sroot 	int argc;
775073Sroot 	char **argv;
7839131Smckusick 	char **arge;
791057Sbill {
8035339Sbostic 	extern char *optarg;
8135339Sbostic 	extern int optind;
8235339Sbostic 	register struct fstab *fs;
8335339Sbostic 	register int cnt;
8438632Smckusick 	int all, ch, rval, sfake, i;
8538632Smckusick 	long mntsize;
8638632Smckusick 	struct statfs statfsbuf, *mntbuf;
8739131Smckusick 	char *type, *options = NULL;
881057Sbill 
8939131Smckusick 	envp = arge;
9035339Sbostic 	all = 0;
9135339Sbostic 	type = NULL;
9238445Smckusick 	mnttype = MOUNT_UFS;
9338445Smckusick 	while ((ch = getopt(argc, argv, "afrwvt:o:")) != EOF)
9435339Sbostic 		switch((char)ch) {
9535339Sbostic 		case 'a':
9635339Sbostic 			all = 1;
9735339Sbostic 			break;
9835339Sbostic 		case 'f':
9935339Sbostic 			fake = 1;
10035339Sbostic 			break;
10135339Sbostic 		case 'r':
10212808Ssam 			type = FSTAB_RO;
10335339Sbostic 			break;
10435339Sbostic 		case 'v':
10535339Sbostic 			verbose = 1;
10635339Sbostic 			break;
10735339Sbostic 		case 'w':
10835339Sbostic 			type = FSTAB_RW;
10935339Sbostic 			break;
11039131Smckusick 		case 'o':
11139131Smckusick 			options = optarg;
11239131Smckusick 			break;
11338445Smckusick 		case 't':
114*39133Smckusick 			if (mnttype = getmnttype(optarg))
11539131Smckusick 				break;
11639131Smckusick 			/* fall through */
11735339Sbostic 		case '?':
11835339Sbostic 		default:
11935339Sbostic 			usage();
12039131Smckusick 			/* NOTREACHED */
1215073Sroot 		}
12235339Sbostic 	argc -= optind;
12335339Sbostic 	argv += optind;
12435339Sbostic 
12535339Sbostic 	/* NOSTRICT */
12635339Sbostic 
1274460Sroot 	if (all) {
12835369Sbostic 		rval = 0;
12935372Sbostic 		for (sfake = fake; fs = getfsent(); fake = sfake) {
13035372Sbostic 			if (BADTYPE(fs->fs_type))
13135372Sbostic 				continue;
13235372Sbostic 			/* `/' is special, it's always mounted */
13335372Sbostic 			if (!strcmp(fs->fs_file, "/"))
13435372Sbostic 				fake = 1;
135*39133Smckusick 			if ((mnttype = getmnttype(fs->fs_vfstype)) == 0) {
136*39133Smckusick 				fprintf(stderr,
137*39133Smckusick 				    "%s %s type of file system is unknown.\n",
138*39133Smckusick 				    "mount:", fs->fs_vfstype);
139*39133Smckusick 				continue;
140*39133Smckusick 			}
14135372Sbostic 			rval |= mountfs(fs->fs_spec, fs->fs_file,
14239131Smckusick 			    type ? type : fs->fs_type, options, fs->fs_mntops);
14335372Sbostic 		}
14435341Sbostic 		exit(rval);
14535339Sbostic 	}
1465073Sroot 
14735339Sbostic 	if (argc == 0) {
14835339Sbostic 		if (verbose || fake || type)
14935339Sbostic 			usage();
15038632Smckusick 		if ((mntsize = getfsstat(0, 0)) < 0) {
15138632Smckusick 			perror("mount");
15238632Smckusick 			exit(1);
15338632Smckusick 		}
15438632Smckusick 		mntbuf = 0;
15538632Smckusick 		do {
15638632Smckusick 			if (mntbuf)
15738632Smckusick 				free(mntbuf);
15838632Smckusick 			i = (mntsize + 1) * sizeof(struct statfs);
15938632Smckusick 			if ((mntbuf = (struct statfs *)malloc(i)) == 0) {
16038632Smckusick 				fprintf(stderr,
16138632Smckusick 					"no space for mount table buffer\n");
16238632Smckusick 				exit(1);
16338632Smckusick 			}
16438632Smckusick 			if ((mntsize = getfsstat(mntbuf, i)) < 0) {
16539131Smckusick 				perror("mount");
16638632Smckusick 				exit(1);
16738632Smckusick 			}
16838632Smckusick 		} while (i == mntsize * sizeof(struct statfs));
16938632Smckusick 		for (i = 0; i < mntsize; i++) {
17038632Smckusick 			if (mntbuf[i].f_flags & M_RDONLY)
17138632Smckusick 				type = "ro";
17238632Smckusick 			else
17338632Smckusick 				type = "rw";
17438632Smckusick 			prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname,
17538632Smckusick 				type);
17638632Smckusick 		}
1774460Sroot 		exit(0);
1781057Sbill 	}
17912808Ssam 
18035339Sbostic 	if (argc == 1) {
18135339Sbostic 		if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
18235339Sbostic 			fprintf(stderr,
18335339Sbostic 			    "mount: unknown special file or file system %s.\n",
18435339Sbostic 			    *argv);
18535339Sbostic 			exit(1);
18635339Sbostic 		}
18735339Sbostic 		if (BADTYPE(fs->fs_type)) {
18835339Sbostic 			fprintf(stderr,
18935339Sbostic 			    "mount: %s has unknown file system type.\n", *argv);
19035339Sbostic 			exit(1);
19135339Sbostic 		}
192*39133Smckusick 		if ((mnttype = getmnttype(fs->fs_vfstype)) == 0) {
193*39133Smckusick 			fprintf(stderr,
194*39133Smckusick 			    "mount: %s type of file system is unknown.\n",
195*39133Smckusick 			    fs->fs_vfstype);
196*39133Smckusick 			exit(1);
197*39133Smckusick 		}
19835369Sbostic 		exit(mountfs(fs->fs_spec, fs->fs_file,
19939131Smckusick 		    type ? type : fs->fs_type, options, fs->fs_mntops));
20012808Ssam 	}
2011057Sbill 
20235339Sbostic 	if (argc != 2)
20335339Sbostic 		usage();
20412808Ssam 
20539131Smckusick 	exit(mountfs(argv[0], argv[1], type ? type : "rw", options, NULL));
20612808Ssam }
20712808Ssam 
20839131Smckusick mountfs(spec, name, type, options, mntopts)
20939131Smckusick 	char *spec, *name, *type, *options, *mntopts;
21012808Ssam {
21135339Sbostic 	extern int errno;
21235339Sbostic 	register int cnt;
21339131Smckusick 	int flags, argc, status, i;
21438070Smckusick 	struct ufs_args args;
21539131Smckusick 	char *argp, *argv[50];
2161057Sbill 
21712808Ssam 	if (!fake) {
21838070Smckusick 		flags = 0;
21938070Smckusick 		if (!strcmp(type, FSTAB_RO))
22038070Smckusick 			flags |= M_RDONLY;
22138445Smckusick 		switch (mnttype) {
22238445Smckusick 		case MOUNT_UFS:
22339131Smckusick 			if (options)
22439131Smckusick 				getufsopts(options, &flags);
22539131Smckusick 			if (mntopts)
22639131Smckusick 				getufsopts(mntopts, &flags);
22738445Smckusick 			args.fspec = spec;
22838445Smckusick 			argp = (caddr_t)&args;
22938445Smckusick 			break;
23038632Smckusick 
23138632Smckusick #ifdef NFS
23238445Smckusick 		case MOUNT_NFS:
23339131Smckusick 			if (options)
23439131Smckusick 				getnfsopts(options, &nfsargs, &opflags,
23539131Smckusick 					&retrycnt);
23639131Smckusick 			if (mntopts)
23739131Smckusick 				getnfsopts(mntopts, &nfsargs, &opflags,
23839131Smckusick 					&retrycnt);
23938632Smckusick 			if (argp = getnfsargs(spec, name, type))
24038632Smckusick 				break;
24138632Smckusick 			return (1);
24238632Smckusick #endif /* NFS */
24338632Smckusick 
24439131Smckusick #ifdef MFS
24539131Smckusick 		case MOUNT_MFS:
24639131Smckusick 			argv[0] = "memfs";
24739131Smckusick 			argc = 1;
24839131Smckusick 			if (options)
24939131Smckusick 				argc += getmfsopts(options, &argv[argc]);
25039131Smckusick 			if (mntopts)
25139131Smckusick 				argc += getmfsopts(mntopts, &argv[argc]);
25239131Smckusick 			argv[argc++] = spec;
25339131Smckusick 			argv[argc++] = name;
25439131Smckusick 			if (i = vfork()) {
25539131Smckusick 				if (i == -1) {
25639131Smckusick 					perror("mount: vfork for memfs");
25739131Smckusick 					return (1);
25839131Smckusick 				}
25939131Smckusick 				if (waitpid(i, &status, 0) != -1 &&
26039131Smckusick 				    WIFEXITED(status) &&
26139131Smckusick 				    WEXITSTATUS(status) != 0)
26239131Smckusick 					return (WEXITSTATUS(status));
26339131Smckusick 				spec = "memfs";
26439131Smckusick 				goto out;
26539131Smckusick 			}
26639131Smckusick 			execve(_PATH_MEMFS, argv, envp);
26739131Smckusick 			perror(_PATH_MEMFS);
26839131Smckusick 			exit (1);
26939131Smckusick #endif /* MFS */
27039131Smckusick 
27138632Smckusick 		default:
27238632Smckusick 			if (opflags & ISBGRND)
27338632Smckusick 				exit(1);
27438632Smckusick 			fprintf(stderr, "%d: unknown mount type\n", mnttype);
27538632Smckusick 			exit(1);
27638632Smckusick 			/* NOTREACHED */
27738632Smckusick 
27838445Smckusick 		};
27938445Smckusick 		if (mount(mnttype, name, flags, argp)) {
28038445Smckusick 			if (opflags & ISBGRND)
28138445Smckusick 				exit(1);
28235339Sbostic 			fprintf(stderr, "%s on %s: ", spec, name);
28316669Ssam 			switch (errno) {
28416669Ssam 			case EMFILE:
28535339Sbostic 				fprintf(stderr, "Mount table full\n");
28616669Ssam 				break;
28716669Ssam 			case EINVAL:
28835339Sbostic 				fprintf(stderr, "Bogus super block\n");
28916669Ssam 				break;
29016669Ssam 			default:
29135339Sbostic 				perror((char *)NULL);
29235339Sbostic 				break;
29316669Ssam 			}
29435369Sbostic 			return(1);
2954460Sroot 		}
2964460Sroot 	}
29735339Sbostic 
29839131Smckusick out:
29912808Ssam 	if (verbose)
30038632Smckusick 		prmount(spec, name, type);
30135339Sbostic 
30238445Smckusick 	if (opflags & ISBGRND)
30338445Smckusick 		exit();
30438445Smckusick 	else
30538445Smckusick 		return(0);
3061057Sbill }
30735339Sbostic 
30835339Sbostic static
30938632Smckusick prmount(spec, name, type)
31038632Smckusick 	char *spec, *name, *type;
31135339Sbostic {
31238632Smckusick 	register char *root;
31338632Smckusick 
31438445Smckusick 	if (opflags & ISBGRND)
31538445Smckusick 		return;
31638632Smckusick 	/*
31738632Smckusick 	 * trim trailing /'s and find last component of name
31838632Smckusick 	 */
31938632Smckusick 	for (root = index(spec, '\0'); *--root == '/';)
32038632Smckusick 		/* void */;
32138632Smckusick 	*++root = '\0';
32238632Smckusick 	if (root = rindex(spec, '/'))
32338632Smckusick 		spec = root + 1;
32438632Smckusick 	printf("%s on %s", spec, name);
32538632Smckusick 	if (!strcmp(type, FSTAB_RO))
32635339Sbostic 		printf("\t(read-only)");
32738632Smckusick 	else if (!strcmp(type, FSTAB_RQ))
32835339Sbostic 		printf("\t(with quotas)");
32935339Sbostic 	printf("\n");
33035339Sbostic }
33135339Sbostic 
332*39133Smckusick getmnttype(fstype)
333*39133Smckusick 	char *fstype;
334*39133Smckusick {
335*39133Smckusick 
336*39133Smckusick 	if (!strcmp(fstype, "ufs"))
337*39133Smckusick 		return (MOUNT_UFS);
338*39133Smckusick 	if (!strcmp(fstype, "nfs"))
339*39133Smckusick 		return (MOUNT_NFS);
340*39133Smckusick 	if (!strcmp(fstype, "mfs"))
341*39133Smckusick 		return (MOUNT_MFS);
342*39133Smckusick 	return (0);
343*39133Smckusick }
344*39133Smckusick 
34538632Smckusick usage()
34635339Sbostic {
34738632Smckusick 	fprintf(stderr, "usage: mount [-afrw]\nor mount [-frw] special | node\nor mount [-frw] special node\n");
34835339Sbostic 	exit(1);
34935339Sbostic }
35035339Sbostic 
35139131Smckusick getufsopts(options, flagp)
35239131Smckusick 	char *options;
35339131Smckusick 	long *flagp;
35439131Smckusick {
35539131Smckusick 
35639131Smckusick 	return;
35739131Smckusick }
35839131Smckusick 
35939131Smckusick #ifdef MFS
36039131Smckusick getmfsopts(options, argv)
36139131Smckusick 	char *options;
36239131Smckusick 	char **argv;
36339131Smckusick {
36439131Smckusick 	register int argc = 0;
36539131Smckusick 	register char *opt;
36639131Smckusick 	char *strtok();
36739131Smckusick 
36839131Smckusick 	for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) {
36939131Smckusick 		if (opt[0] != '-')
37039131Smckusick 			continue;
37139131Smckusick 		argv[argc++] = opt;
37239131Smckusick 		if (opt[2] == '\0' || opt[2] != '=')
37339131Smckusick 			continue;
37439131Smckusick 		opt[2] = '\0';
37539131Smckusick 		argv[argc++] = &opt[3];
37639131Smckusick 	}
37739131Smckusick 	return (argc);
37839131Smckusick }
37939131Smckusick #endif /* MFS */
38039131Smckusick 
38138632Smckusick #ifdef NFS
38239131Smckusick /*
38339131Smckusick  * Handle the getoption arg.
38439131Smckusick  * Essentially update "opflags", "retrycnt" and "nfsargs"
38539131Smckusick  */
38639131Smckusick getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
38739131Smckusick 	char *optarg;
38839131Smckusick 	struct nfs_args *nfsargsp;
38939131Smckusick 	int *opflagsp;
39039131Smckusick 	int *retrycntp;
39139131Smckusick {
39239131Smckusick 	register char *cp, *nextcp;
39339131Smckusick 	int num;
39439131Smckusick 	char *nump;
39539131Smckusick 
39639131Smckusick 	cp = optarg;
39739131Smckusick 	while (cp != NULL && *cp != '\0') {
39839131Smckusick 		if ((nextcp = index(cp, ',')) != NULL)
39939131Smckusick 			*nextcp++ = '\0';
40039131Smckusick 		if ((nump = index(cp, '=')) != NULL) {
40139131Smckusick 			*nump++ = '\0';
40239131Smckusick 			num = atoi(nump);
40339131Smckusick 		} else
40439131Smckusick 			num = -1;
40539131Smckusick 		/*
40639131Smckusick 		 * Just test for a string match and do it
40739131Smckusick 		 */
40839131Smckusick 		if (!strcmp(cp, "bg")) {
40939131Smckusick 			*opflagsp |= BGRND;
41039131Smckusick 		} else if (!strcmp(cp, "soft")) {
41139131Smckusick 			nfsargsp->flags |= NFSMNT_SOFT;
41239131Smckusick 		} else if (!strcmp(cp, "intr")) {
41339131Smckusick 			nfsargsp->flags |= NFSMNT_INT;
41439131Smckusick 		} else if (!strcmp(cp, "retry") && num > 0) {
41539131Smckusick 			*retrycntp = num;
41639131Smckusick 		} else if (!strcmp(cp, "rsize") && num > 0) {
41739131Smckusick 			nfsargsp->rsize = num;
41839131Smckusick 			nfsargsp->flags |= NFSMNT_RSIZE;
41939131Smckusick 		} else if (!strcmp(cp, "wsize") && num > 0) {
42039131Smckusick 			nfsargsp->wsize = num;
42139131Smckusick 			nfsargsp->flags |= NFSMNT_WSIZE;
42239131Smckusick 		} else if (!strcmp(cp, "timeo") && num > 0) {
42339131Smckusick 			nfsargsp->timeo = num;
42439131Smckusick 			nfsargsp->flags |= NFSMNT_TIMEO;
42539131Smckusick 		} else if (!strcmp(cp, "retrans") && num > 0) {
42639131Smckusick 			nfsargsp->retrans = num;
42739131Smckusick 			nfsargsp->flags |= NFSMNT_RETRANS;
42839131Smckusick 		}
42939131Smckusick 		cp = nextcp;
43039131Smckusick 	}
43139131Smckusick }
43239131Smckusick 
43338632Smckusick char *
43438632Smckusick getnfsargs(spec)
43538632Smckusick 	char *spec;
43635339Sbostic {
43738632Smckusick 	register CLIENT *clp;
43838632Smckusick 	struct hostent *hp;
43938632Smckusick 	struct sockaddr_in saddr;
44038632Smckusick 	struct timeval pertry, try;
44138632Smckusick 	enum clnt_stat clnt_stat;
44238632Smckusick 	int so = RPC_ANYSOCK;
44338632Smckusick 	char *hostp, *delimp;
44438632Smckusick 	u_short tport;
44538632Smckusick 	struct nfhret nfhret;
44638632Smckusick 	char nam[MNAMELEN + 1];
44738632Smckusick 
44838632Smckusick 	strncpy(nam, spec, MNAMELEN);
44938632Smckusick 	nam[MNAMELEN] = '\0';
45038632Smckusick 	if ((delimp = index(spec, '@')) != NULL) {
45138632Smckusick 		hostp = delimp + 1;
45238632Smckusick 	} else if ((delimp = index(spec, ':')) != NULL) {
45338632Smckusick 		hostp = spec;
45438632Smckusick 		spec = delimp + 1;
45538632Smckusick 	} else {
45638632Smckusick 		fprintf(stderr,
45738632Smckusick 		    "No <host>:<dirpath> or <dirpath>@<host> spec\n");
45838632Smckusick 		return (0);
45938632Smckusick 	}
46038632Smckusick 	*delimp = '\0';
46138632Smckusick 	if ((hp = gethostbyname(hostp)) == NULL) {
46238632Smckusick 		fprintf(stderr, "Can't get net id for host\n");
46338632Smckusick 		return (0);
46438632Smckusick 	}
46538632Smckusick 	bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
46638632Smckusick 	nfhret.stat = EACCES;	/* Mark not yet successful */
46738632Smckusick 	while (retrycnt > 0) {
46838632Smckusick 		saddr.sin_family = AF_INET;
46938632Smckusick 		saddr.sin_port = htons(PMAPPORT);
47038632Smckusick 		if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
47138632Smckusick 		    NFS_VER2, IPPROTO_UDP)) == 0) {
47238632Smckusick 			if ((opflags & ISBGRND) == 0)
47338632Smckusick 				clnt_pcreateerror("NFS Portmap");
47438632Smckusick 		} else {
47538632Smckusick 			saddr.sin_port = 0;
47638632Smckusick 			pertry.tv_sec = 10;
47738632Smckusick 			pertry.tv_usec = 0;
47838632Smckusick 			if ((clp = clntudp_create(&saddr, RPCPROG_MNT,
47938632Smckusick 			    RPCMNT_VER1, pertry, &so)) == NULL) {
48038632Smckusick 				if ((opflags & ISBGRND) == 0)
48138632Smckusick 					clnt_pcreateerror("Cannot MNT PRC");
48238632Smckusick 			} else {
48338632Smckusick 				clp->cl_auth = authunix_create_default();
48438632Smckusick 				try.tv_sec = 10;
48538632Smckusick 				try.tv_usec = 0;
48638632Smckusick 				clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
48738632Smckusick 				    xdr_dir, spec, xdr_fh, &nfhret, try);
48838632Smckusick 				if (clnt_stat != RPC_SUCCESS) {
48938632Smckusick 					if ((opflags & ISBGRND) == 0)
49038632Smckusick 						clnt_perror(clp, "Bad MNT RPC");
49138632Smckusick 				} else {
49238632Smckusick 					auth_destroy(clp->cl_auth);
49338632Smckusick 					clnt_destroy(clp);
49438632Smckusick 					retrycnt = 0;
49538632Smckusick 				}
49638632Smckusick 			}
49738632Smckusick 		}
49838632Smckusick 		if (--retrycnt > 0) {
49938632Smckusick 			if (opflags & BGRND) {
50038632Smckusick 				opflags &= ~BGRND;
50138632Smckusick 				if (fork())
50238632Smckusick 					return (0);
50338632Smckusick 				else
50438632Smckusick 					opflags |= ISBGRND;
50538632Smckusick 			}
50638632Smckusick 			sleep(10);
50738632Smckusick 		}
50838632Smckusick 	}
50938632Smckusick 	if (nfhret.stat) {
51038632Smckusick 		if (opflags & ISBGRND)
51138632Smckusick 			exit(1);
51238632Smckusick 		fprintf(stderr, "Can't access %s, errno=%d\n", spec,
51338632Smckusick 		    nfhret.stat);
51438632Smckusick 		return (0);
51538632Smckusick 	}
51638632Smckusick 	saddr.sin_port = htons(tport);
51738632Smckusick 	nfsargs.addr = &saddr;
51838632Smckusick 	nfsargs.fh = &nfhret.nfh;
51938632Smckusick 	nfsargs.hostname = nam;
52038632Smckusick 	return ((caddr_t)&nfsargs);
52135339Sbostic }
52238445Smckusick 
52338445Smckusick /*
52438445Smckusick  * xdr routines for mount rpc's
52538445Smckusick  */
52638445Smckusick xdr_dir(xdrsp, dirp)
52738445Smckusick 	XDR *xdrsp;
52838445Smckusick 	char *dirp;
52938445Smckusick {
53038445Smckusick 	return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
53138445Smckusick }
53238445Smckusick 
53338445Smckusick xdr_fh(xdrsp, np)
53438445Smckusick 	XDR *xdrsp;
53538445Smckusick 	struct nfhret *np;
53638445Smckusick {
53738445Smckusick 	if (!xdr_u_long(xdrsp, &(np->stat)))
53838445Smckusick 		return (0);
53938445Smckusick 	if (np->stat)
54038445Smckusick 		return (1);
54138445Smckusick 	return (xdr_opaque(xdrsp, (caddr_t)&(np->nfh), NFSX_FH));
54238445Smckusick }
54338632Smckusick #endif /* NFS */
544