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