Home | History | Annotate | Line # | Download | only in mount
mount.c revision 1.13
      1   1.1      cgd /*
      2  1.12  mycroft  * Copyright (c) 1980, 1989, 1993, 1994
      3  1.12  mycroft  *	The Regents of the University of California.  All rights reserved.
      4   1.1      cgd  *
      5   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6   1.1      cgd  * modification, are permitted provided that the following conditions
      7   1.1      cgd  * are met:
      8   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14   1.1      cgd  *    must display the following acknowledgement:
     15   1.1      cgd  *	This product includes software developed by the University of
     16   1.1      cgd  *	California, Berkeley and its contributors.
     17   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18   1.1      cgd  *    may be used to endorse or promote products derived from this software
     19   1.1      cgd  *    without specific prior written permission.
     20   1.1      cgd  *
     21   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31   1.1      cgd  * SUCH DAMAGE.
     32   1.1      cgd  */
     33   1.1      cgd 
     34   1.1      cgd #ifndef lint
     35  1.12  mycroft static char copyright[] =
     36  1.12  mycroft "@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
     37  1.12  mycroft 	The Regents of the University of California.  All rights reserved.\n";
     38   1.1      cgd #endif /* not lint */
     39   1.1      cgd 
     40   1.1      cgd #ifndef lint
     41  1.12  mycroft /*static char sccsid[] = "from: @(#)mount.c	8.19 (Berkeley) 4/19/94";*/
     42  1.13  mycroft static char *rcsid = "$Id: mount.c,v 1.13 1994/08/29 02:38:00 mycroft Exp $";
     43   1.1      cgd #endif /* not lint */
     44   1.1      cgd 
     45   1.1      cgd #include <sys/param.h>
     46  1.12  mycroft #include <sys/mount.h>
     47   1.1      cgd #include <sys/wait.h>
     48  1.12  mycroft 
     49  1.12  mycroft #include <err.h>
     50  1.12  mycroft #include <errno.h>
     51   1.1      cgd #include <fstab.h>
     52  1.12  mycroft #include <signal.h>
     53   1.1      cgd #include <stdio.h>
     54   1.1      cgd #include <stdlib.h>
     55  1.12  mycroft #include <string.h>
     56  1.12  mycroft #include <unistd.h>
     57  1.12  mycroft 
     58   1.1      cgd #include "pathnames.h"
     59   1.1      cgd 
     60  1.12  mycroft int debug, verbose, skipvfs;
     61   1.1      cgd 
     62  1.12  mycroft int	badvfsname __P((const char *, const char **));
     63  1.12  mycroft char   *catopt __P((char *, const char *));
     64  1.12  mycroft struct statfs
     65  1.12  mycroft        *getmntpt __P((const char *));
     66  1.12  mycroft int	hasopt __P((const char *, const char *));
     67  1.12  mycroft const char
     68  1.12  mycroft       **makevfslist __P((char *));
     69  1.12  mycroft void	mangle __P((char *, int *, const char **));
     70  1.12  mycroft int	mountfs __P((const char *, const char *, const char *,
     71  1.12  mycroft 			int, const char *, const char *));
     72  1.13  mycroft void	prmount __P((struct statfs *));
     73  1.12  mycroft void	usage __P((void));
     74  1.12  mycroft 
     75  1.12  mycroft /* From mount_ufs.c. */
     76  1.12  mycroft int	mount_ufs __P((int, char * const *));
     77  1.12  mycroft 
     78  1.12  mycroft /* Map from mount otions to printable formats. */
     79  1.12  mycroft static struct opt {
     80  1.12  mycroft 	int o_opt;
     81  1.12  mycroft 	const char *o_name;
     82  1.12  mycroft } optnames[] = {
     83  1.12  mycroft 	{ MNT_ASYNC,		"asynchronous" },
     84  1.12  mycroft 	{ MNT_EXPORTED,		"NFS exported" },
     85  1.12  mycroft 	{ MNT_LOCAL,		"local" },
     86  1.12  mycroft 	{ MNT_NODEV,		"nodev" },
     87  1.12  mycroft 	{ MNT_NOEXEC,		"noexec" },
     88  1.12  mycroft 	{ MNT_NOSUID,		"nosuid" },
     89  1.12  mycroft 	{ MNT_QUOTA,		"with quotas" },
     90  1.12  mycroft 	{ MNT_RDONLY,		"read-only" },
     91  1.12  mycroft 	{ MNT_SYNCHRONOUS,	"synchronous" },
     92  1.12  mycroft 	{ MNT_UNION,		"union" },
     93  1.12  mycroft 	{ MNT_USER,		"user mount" },
     94  1.12  mycroft 	{ NULL }
     95   1.1      cgd };
     96   1.1      cgd 
     97  1.12  mycroft int
     98  1.12  mycroft main(argc, argv)
     99   1.1      cgd 	int argc;
    100  1.12  mycroft 	char * const argv[];
    101   1.1      cgd {
    102  1.12  mycroft 	const char *mntonname, **vfslist, *vfstype;
    103  1.12  mycroft 	struct fstab *fs;
    104   1.9      cgd 	struct statfs *mntbuf;
    105  1.12  mycroft 	FILE *mountdfp;
    106  1.12  mycroft 	pid_t pid;
    107  1.12  mycroft 	int all, ch, i, init_flags, mntsize, rval;
    108  1.12  mycroft 	char *options;
    109   1.1      cgd 
    110  1.12  mycroft 	all = init_flags = 0;
    111  1.12  mycroft 	options = NULL;
    112  1.12  mycroft 	vfslist = NULL;
    113  1.12  mycroft 	vfstype = "ufs";
    114  1.12  mycroft 	while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
    115  1.12  mycroft 		switch (ch) {
    116   1.1      cgd 		case 'a':
    117   1.1      cgd 			all = 1;
    118   1.1      cgd 			break;
    119  1.12  mycroft 		case 'd':
    120  1.12  mycroft 			debug = 1;
    121  1.12  mycroft 			break;
    122   1.1      cgd 		case 'f':
    123  1.12  mycroft 			init_flags |= MNT_FORCE;
    124  1.12  mycroft 			break;
    125  1.12  mycroft 		case 'o':
    126  1.12  mycroft 			if (*optarg)
    127  1.12  mycroft 				options = catopt(options, optarg);
    128   1.1      cgd 			break;
    129   1.1      cgd 		case 'r':
    130  1.12  mycroft 			init_flags |= MNT_RDONLY;
    131  1.12  mycroft 			break;
    132  1.12  mycroft 		case 't':
    133  1.12  mycroft 			if (vfslist != NULL)
    134  1.12  mycroft 				errx(1, "only one -t option may be specified.");
    135  1.12  mycroft 			vfslist = makevfslist(optarg);
    136  1.12  mycroft 			vfstype = optarg;
    137   1.1      cgd 			break;
    138   1.1      cgd 		case 'u':
    139  1.12  mycroft 			init_flags |= MNT_UPDATE;
    140   1.1      cgd 			break;
    141   1.1      cgd 		case 'v':
    142   1.1      cgd 			verbose = 1;
    143   1.1      cgd 			break;
    144   1.1      cgd 		case 'w':
    145  1.12  mycroft 			init_flags &= ~MNT_RDONLY;
    146   1.1      cgd 			break;
    147   1.1      cgd 		case '?':
    148   1.1      cgd 		default:
    149   1.1      cgd 			usage();
    150   1.1      cgd 			/* NOTREACHED */
    151   1.1      cgd 		}
    152   1.1      cgd 	argc -= optind;
    153   1.1      cgd 	argv += optind;
    154   1.1      cgd 
    155  1.12  mycroft #define	BADTYPE(type)							\
    156  1.12  mycroft 	(strcmp(type, FSTAB_RO) &&					\
    157  1.12  mycroft 	    strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
    158  1.12  mycroft 
    159  1.12  mycroft 	rval = 0;
    160  1.12  mycroft 	switch (argc) {
    161  1.12  mycroft 	case 0:
    162  1.12  mycroft 		if (all)
    163  1.12  mycroft 			while ((fs = getfsent()) != NULL) {
    164  1.12  mycroft 				if (BADTYPE(fs->fs_type))
    165  1.12  mycroft 					continue;
    166  1.12  mycroft 				if (badvfsname(fs->fs_vfstype, vfslist))
    167  1.12  mycroft 					continue;
    168  1.12  mycroft 				if (hasopt(fs->fs_mntops, "noauto"))
    169  1.12  mycroft 					continue;
    170  1.12  mycroft 				if (mountfs(fs->fs_vfstype, fs->fs_spec,
    171  1.12  mycroft 				    fs->fs_file, init_flags, options,
    172  1.12  mycroft 				    fs->fs_mntops))
    173  1.12  mycroft 					rval = 1;
    174  1.12  mycroft 			}
    175  1.12  mycroft 		else {
    176  1.12  mycroft 			if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
    177  1.12  mycroft 				err(1, "getmntinfo");
    178  1.12  mycroft 			for (i = 0; i < mntsize; i++) {
    179  1.12  mycroft 				if (badvfsname(mntbuf[i].f_fstypename, vfslist))
    180  1.12  mycroft 					continue;
    181  1.13  mycroft 				prmount(&mntbuf[i]);
    182  1.12  mycroft 			}
    183   1.1      cgd 		}
    184   1.1      cgd 		exit(rval);
    185  1.12  mycroft 	case 1:
    186  1.12  mycroft 		if (vfslist != NULL)
    187   1.1      cgd 			usage();
    188   1.1      cgd 
    189  1.12  mycroft 		if (init_flags & MNT_UPDATE) {
    190  1.12  mycroft 			if ((mntbuf = getmntpt(*argv)) == NULL)
    191  1.12  mycroft 				errx(1,
    192  1.12  mycroft 				    "unknown special file or file system %s.",
    193  1.12  mycroft 				    *argv);
    194  1.12  mycroft 			if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
    195  1.12  mycroft 				errx(1, "can't find fstab entry for %s.",
    196  1.12  mycroft 				    *argv);
    197  1.12  mycroft 			/* If it's an update, ignore the fstab file options. */
    198  1.12  mycroft 			fs->fs_mntops = NULL;
    199  1.12  mycroft 			mntonname = mntbuf->f_mntonname;
    200  1.12  mycroft 		} else {
    201  1.12  mycroft 			if ((fs = getfsfile(*argv)) == NULL &&
    202  1.12  mycroft 			    (fs = getfsspec(*argv)) == NULL)
    203  1.12  mycroft 				errx(1,
    204  1.12  mycroft 				    "%s: unknown special file or file system.",
    205  1.12  mycroft 				    *argv);
    206  1.12  mycroft 			if (BADTYPE(fs->fs_type))
    207  1.12  mycroft 				errx(1, "%s has unknown file system type.",
    208  1.12  mycroft 				    *argv);
    209  1.12  mycroft 			mntonname = fs->fs_file;
    210  1.12  mycroft 		}
    211  1.12  mycroft 		rval = mountfs(fs->fs_vfstype, fs->fs_spec,
    212  1.12  mycroft 		    mntonname, init_flags, options, fs->fs_mntops);
    213  1.12  mycroft 		break;
    214  1.12  mycroft 	case 2:
    215   1.1      cgd 		/*
    216  1.12  mycroft 		 * If -t flag has not been specified, and spec contains either
    217  1.12  mycroft 		 * a ':' or a '@' then assume that an NFS filesystem is being
    218  1.12  mycroft 		 * specified ala Sun.
    219   1.1      cgd 		 */
    220  1.12  mycroft 		if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
    221  1.12  mycroft 			vfstype = "nfs";
    222  1.12  mycroft 		rval = mountfs(vfstype,
    223  1.12  mycroft 		    argv[0], argv[1], init_flags, options, NULL);
    224  1.12  mycroft 		break;
    225  1.12  mycroft 	default:
    226  1.12  mycroft 		usage();
    227  1.12  mycroft 		/* NOTREACHED */
    228   1.1      cgd 	}
    229   1.1      cgd 
    230  1.12  mycroft 	/*
    231  1.12  mycroft 	 * If the mount was successfully, and done by root, tell mountd the
    232  1.12  mycroft 	 * good news.  Pid checks are probably unnecessary, but don't hurt.
    233  1.12  mycroft 	 */
    234  1.12  mycroft 	if (rval == 0 && getuid() == 0 &&
    235  1.12  mycroft 	    (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
    236  1.12  mycroft 		if (fscanf(mountdfp, "%ld", &pid) == 1 &&
    237  1.12  mycroft 		     pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
    238  1.12  mycroft 			err(1, "signal mountd");
    239  1.12  mycroft 		(void)fclose(mountdfp);
    240   1.1      cgd 	}
    241   1.1      cgd 
    242  1.12  mycroft 	exit(rval);
    243   1.1      cgd }
    244   1.1      cgd 
    245  1.12  mycroft int
    246  1.12  mycroft hasopt(mntopts, option)
    247  1.12  mycroft 	const char *mntopts, *option;
    248   1.1      cgd {
    249  1.12  mycroft 	int negative, found;
    250  1.12  mycroft 	char *opt, *optbuf;
    251   1.1      cgd 
    252  1.12  mycroft 	if (option[0] == 'n' && option[1] == 'o') {
    253  1.12  mycroft 		negative = 1;
    254  1.12  mycroft 		option += 2;
    255  1.12  mycroft 	} else
    256  1.12  mycroft 		negative = 0;
    257  1.12  mycroft 	optbuf = strdup(mntopts);
    258  1.12  mycroft 	found = 0;
    259  1.12  mycroft 	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
    260  1.12  mycroft 		if (opt[0] == 'n' && opt[1] == 'o') {
    261  1.12  mycroft 			if (!strcasecmp(opt + 2, option))
    262  1.12  mycroft 				found = negative;
    263  1.12  mycroft 		} else if (!strcasecmp(opt, option))
    264  1.12  mycroft 			found = !negative;
    265  1.12  mycroft 	}
    266  1.12  mycroft 	free(optbuf);
    267  1.12  mycroft 	return (found);
    268   1.1      cgd }
    269   1.1      cgd 
    270  1.12  mycroft int
    271  1.12  mycroft mountfs(vfstype, spec, name, flags, options, mntopts)
    272  1.12  mycroft 	const char *vfstype, *spec, *name, *options, *mntopts;
    273  1.12  mycroft 	int flags;
    274   1.1      cgd {
    275  1.12  mycroft 	/* List of directories containing mount_xxx subcommands. */
    276  1.12  mycroft 	static const char *edirs[] = {
    277  1.12  mycroft 		_PATH_SBIN,
    278  1.12  mycroft 		_PATH_USRSBIN,
    279  1.12  mycroft 		NULL
    280  1.12  mycroft 	};
    281  1.12  mycroft 	const char *argv[100], **edir;
    282  1.12  mycroft 	struct statfs sf;
    283  1.12  mycroft 	pid_t pid;
    284  1.12  mycroft 	int argc, i, status;
    285  1.12  mycroft 	char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
    286   1.1      cgd 
    287  1.12  mycroft 	if (realpath(name, mntpath) == NULL) {
    288  1.12  mycroft 		warn("realpath %s", mntpath);
    289  1.12  mycroft 		return (1);
    290  1.12  mycroft 	}
    291   1.1      cgd 
    292  1.12  mycroft 	name = mntpath;
    293   1.1      cgd 
    294  1.12  mycroft 	if (mntopts == NULL)
    295  1.12  mycroft 		mntopts = "";
    296  1.12  mycroft 	if (options == NULL) {
    297  1.12  mycroft 		if (*mntopts == '\0')
    298  1.12  mycroft 			options = "rw";
    299  1.12  mycroft 		else {
    300  1.12  mycroft 			options = mntopts;
    301  1.12  mycroft 			mntopts = "";
    302  1.12  mycroft 		}
    303  1.12  mycroft 	}
    304  1.12  mycroft 	optbuf = catopt(strdup(mntopts), options);
    305  1.12  mycroft 
    306  1.12  mycroft 	if (strcmp(name, "/") == 0)
    307  1.12  mycroft 		flags |= MNT_UPDATE;
    308  1.12  mycroft 	if (flags & MNT_FORCE)
    309  1.12  mycroft 		optbuf = catopt(optbuf, "force");
    310  1.12  mycroft 	if (flags & MNT_RDONLY)
    311  1.12  mycroft 		optbuf = catopt(optbuf, "ro");
    312  1.12  mycroft 	/*
    313  1.12  mycroft 	 * XXX
    314  1.12  mycroft 	 * The mount_mfs (newfs) command uses -o to select the
    315  1.12  mycroft 	 * optimisation mode.  We don't pass the default "-o rw"
    316  1.12  mycroft 	 * for that reason.
    317  1.12  mycroft 	 */
    318  1.12  mycroft 	if (flags & MNT_UPDATE)
    319  1.12  mycroft 		optbuf = catopt(optbuf, "update");
    320  1.12  mycroft 
    321  1.12  mycroft 	argc = 0;
    322  1.12  mycroft 	argv[argc++] = vfstype;
    323  1.12  mycroft 	mangle(optbuf, &argc, argv);
    324  1.12  mycroft 	argv[argc++] = spec;
    325  1.12  mycroft 	argv[argc++] = name;
    326  1.12  mycroft 	argv[argc] = NULL;
    327  1.12  mycroft 
    328  1.12  mycroft 	if (debug) {
    329  1.12  mycroft 		(void)printf("exec: mount_%s", vfstype);
    330  1.12  mycroft 		for (i = 1; i < argc; i++)
    331  1.12  mycroft 			(void)printf(" %s", argv[i]);
    332  1.12  mycroft 		(void)printf("\n");
    333  1.12  mycroft 		return (0);
    334  1.12  mycroft 	}
    335   1.5  mycroft 
    336  1.12  mycroft 	switch (pid = vfork()) {
    337  1.12  mycroft 	case -1:				/* Error. */
    338  1.12  mycroft 		warn("vfork");
    339  1.12  mycroft 		free(optbuf);
    340  1.12  mycroft 		return (1);
    341  1.12  mycroft 	case 0:					/* Child. */
    342  1.12  mycroft 		if (strcmp(vfstype, "ufs") == 0)
    343  1.12  mycroft 			exit(mount_ufs(argc, (char * const *) argv));
    344  1.12  mycroft 
    345  1.12  mycroft 		/* Go find an executable. */
    346  1.12  mycroft 		edir = edirs;
    347  1.12  mycroft 		do {
    348  1.12  mycroft 			(void)snprintf(execname,
    349  1.12  mycroft 			    sizeof(execname), "%s/mount_%s", *edir, vfstype);
    350  1.12  mycroft 			execv(execname, (char * const *)argv);
    351  1.12  mycroft 			if (errno != ENOENT)
    352  1.12  mycroft 				warn("exec %s for %s", execname, name);
    353  1.12  mycroft 		} while (*++edir != NULL);
    354   1.1      cgd 
    355  1.12  mycroft 		if (errno == ENOENT)
    356  1.12  mycroft 			warn("exec %s for %s", execname, name);
    357  1.12  mycroft 		exit(1);
    358  1.12  mycroft 		/* NOTREACHED */
    359  1.12  mycroft 	default:				/* Parent. */
    360  1.12  mycroft 		free(optbuf);
    361   1.1      cgd 
    362  1.12  mycroft 		if (waitpid(pid, &status, 0) < 0) {
    363  1.12  mycroft 			warn("waitpid");
    364  1.12  mycroft 			return (1);
    365   1.1      cgd 		}
    366  1.12  mycroft 
    367  1.12  mycroft 		if (WIFEXITED(status)) {
    368  1.12  mycroft 			if (WEXITSTATUS(status) != 0)
    369  1.12  mycroft 				return (WEXITSTATUS(status));
    370  1.12  mycroft 		} else if (WIFSIGNALED(status)) {
    371  1.12  mycroft 			warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
    372  1.12  mycroft 			return (1);
    373   1.1      cgd 		}
    374  1.12  mycroft 
    375  1.12  mycroft 		if (verbose) {
    376  1.12  mycroft 			if (statfs(name, &sf) < 0) {
    377  1.12  mycroft 				warn("statfs %s", name);
    378  1.12  mycroft 				return (1);
    379  1.12  mycroft 			}
    380  1.13  mycroft 			prmount(&sf);
    381   1.1      cgd 		}
    382  1.12  mycroft 		break;
    383   1.1      cgd 	}
    384  1.12  mycroft 
    385  1.12  mycroft 	return (0);
    386   1.1      cgd }
    387   1.1      cgd 
    388  1.12  mycroft void
    389  1.13  mycroft prmount(sf)
    390  1.13  mycroft 	struct statfs *sf;
    391  1.13  mycroft {
    392  1.12  mycroft 	int flags;
    393  1.12  mycroft 	struct opt *o;
    394  1.12  mycroft 	int f;
    395   1.1      cgd 
    396  1.13  mycroft 	(void)printf("%s on %s type %s", sf->f_mntfromname, sf->f_mntonname,
    397  1.13  mycroft 	    sf->f_fstypename);
    398   1.1      cgd 
    399  1.13  mycroft 	flags = sf->f_flags & MNT_VISFLAGMASK;
    400  1.12  mycroft 	for (f = 0, o = optnames; flags && o->o_opt; o++)
    401  1.12  mycroft 		if (flags & o->o_opt) {
    402  1.12  mycroft 			(void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
    403  1.12  mycroft 			flags &= ~o->o_opt;
    404  1.12  mycroft 		}
    405  1.12  mycroft 	(void)printf(f ? ")\n" : "\n");
    406   1.1      cgd }
    407   1.1      cgd 
    408   1.1      cgd struct statfs *
    409   1.1      cgd getmntpt(name)
    410  1.12  mycroft 	const char *name;
    411   1.1      cgd {
    412   1.1      cgd 	struct statfs *mntbuf;
    413  1.12  mycroft 	int i, mntsize;
    414   1.1      cgd 
    415   1.1      cgd 	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
    416  1.12  mycroft 	for (i = 0; i < mntsize; i++)
    417  1.12  mycroft 		if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
    418  1.12  mycroft 		    strcmp(mntbuf[i].f_mntonname, name) == 0)
    419   1.1      cgd 			return (&mntbuf[i]);
    420  1.12  mycroft 	return (NULL);
    421   1.1      cgd }
    422   1.1      cgd 
    423  1.12  mycroft int
    424   1.1      cgd badvfsname(vfsname, vfslist)
    425  1.12  mycroft 	const char *vfsname;
    426  1.12  mycroft 	const char **vfslist;
    427   1.1      cgd {
    428   1.1      cgd 
    429  1.12  mycroft 	if (vfslist == NULL)
    430  1.12  mycroft 		return (0);
    431  1.12  mycroft 	while (*vfslist != NULL) {
    432   1.1      cgd 		if (strcmp(vfsname, *vfslist) == 0)
    433  1.12  mycroft 			return (skipvfs);
    434  1.12  mycroft 		++vfslist;
    435   1.1      cgd 	}
    436   1.1      cgd 	return (!skipvfs);
    437   1.1      cgd }
    438   1.1      cgd 
    439  1.12  mycroft const char **
    440   1.1      cgd makevfslist(fslist)
    441   1.1      cgd 	char *fslist;
    442   1.1      cgd {
    443  1.12  mycroft 	const char **av;
    444  1.12  mycroft 	int i;
    445  1.12  mycroft 	char *nextcp;
    446   1.1      cgd 
    447   1.1      cgd 	if (fslist == NULL)
    448   1.1      cgd 		return (NULL);
    449   1.1      cgd 	if (fslist[0] == 'n' && fslist[1] == 'o') {
    450   1.1      cgd 		fslist += 2;
    451   1.1      cgd 		skipvfs = 1;
    452   1.1      cgd 	}
    453   1.1      cgd 	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
    454   1.1      cgd 		if (*nextcp == ',')
    455   1.1      cgd 			i++;
    456  1.12  mycroft 	if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
    457  1.12  mycroft 		warn(NULL);
    458   1.1      cgd 		return (NULL);
    459  1.12  mycroft 	}
    460   1.1      cgd 	nextcp = fslist;
    461   1.1      cgd 	i = 0;
    462   1.1      cgd 	av[i++] = nextcp;
    463  1.12  mycroft 	while ((nextcp = strchr(nextcp, ',')) != NULL) {
    464   1.1      cgd 		*nextcp++ = '\0';
    465   1.1      cgd 		av[i++] = nextcp;
    466   1.1      cgd 	}
    467  1.12  mycroft 	av[i++] = NULL;
    468   1.1      cgd 	return (av);
    469   1.1      cgd }
    470   1.1      cgd 
    471  1.12  mycroft char *
    472  1.12  mycroft catopt(s0, s1)
    473  1.12  mycroft 	char *s0;
    474  1.12  mycroft 	const char *s1;
    475  1.12  mycroft {
    476  1.12  mycroft 	size_t i;
    477  1.12  mycroft 	char *cp;
    478  1.12  mycroft 
    479  1.12  mycroft 	if (s0 && *s0) {
    480  1.12  mycroft 		i = strlen(s0) + strlen(s1) + 1 + 1;
    481  1.12  mycroft 		if ((cp = malloc(i)) == NULL)
    482  1.12  mycroft 			err(1, NULL);
    483  1.12  mycroft 		(void)snprintf(cp, i, "%s,%s", s0, s1);
    484  1.12  mycroft 	} else
    485  1.12  mycroft 		cp = strdup(s1);
    486   1.1      cgd 
    487  1.12  mycroft 	if (s0)
    488  1.12  mycroft 		free(s0);
    489  1.12  mycroft 	return (cp);
    490   1.1      cgd }
    491   1.1      cgd 
    492  1.12  mycroft void
    493  1.12  mycroft mangle(options, argcp, argv)
    494  1.12  mycroft 	char *options;
    495  1.12  mycroft 	int *argcp;
    496  1.12  mycroft 	const char **argv;
    497   1.1      cgd {
    498  1.12  mycroft 	char *p, *s;
    499  1.12  mycroft 	int argc;
    500   1.1      cgd 
    501  1.12  mycroft 	argc = *argcp;
    502  1.12  mycroft 	for (s = options; (p = strsep(&s, ",")) != NULL;)
    503  1.12  mycroft 		if (*p != '\0')
    504  1.12  mycroft 			if (*p == '-') {
    505  1.12  mycroft 				argv[argc++] = p;
    506  1.12  mycroft 				p = strchr(p, '=');
    507  1.12  mycroft 				if (p) {
    508  1.12  mycroft 					*p = '\0';
    509  1.12  mycroft 					argv[argc++] = p+1;
    510   1.1      cgd 				}
    511  1.12  mycroft 			} else if (strcmp(p, "rw") != 0) {
    512  1.12  mycroft 				argv[argc++] = "-o";
    513  1.12  mycroft 				argv[argc++] = p;
    514   1.1      cgd 			}
    515  1.12  mycroft 
    516  1.12  mycroft 	*argcp = argc;
    517   1.1      cgd }
    518   1.1      cgd 
    519  1.12  mycroft void
    520  1.12  mycroft usage()
    521   1.1      cgd {
    522   1.1      cgd 
    523  1.12  mycroft 	(void)fprintf(stderr,
    524  1.12  mycroft 		"usage: mount %s %s\n       mount %s\n       mount %s\n",
    525  1.12  mycroft 		"[-dfruvw] [-o options] [-t ufs | external_type]",
    526  1.12  mycroft 			"special node",
    527  1.12  mycroft 		"[-adfruvw] [-t ufs | external_type]",
    528  1.12  mycroft 		"[-dfruvw] special | node");
    529  1.12  mycroft 	exit(1);
    530   1.1      cgd }
    531