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