Home | History | Annotate | Line # | Download | only in mount
mount.c revision 1.1.1.2
      1      1.1      cgd /*
      2  1.1.1.2  mycroft  * Copyright (c) 1980, 1989, 1993, 1994
      3  1.1.1.2  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.1.1.2  mycroft static char copyright[] =
     36  1.1.1.2  mycroft "@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
     37  1.1.1.2  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.1.1.2  mycroft static char sccsid[] = "@(#)mount.c	8.19 (Berkeley) 4/19/94";
     42      1.1      cgd #endif /* not lint */
     43      1.1      cgd 
     44      1.1      cgd #include <sys/param.h>
     45      1.1      cgd #include <sys/mount.h>
     46  1.1.1.2  mycroft #include <sys/wait.h>
     47  1.1.1.2  mycroft 
     48  1.1.1.2  mycroft #include <err.h>
     49  1.1.1.2  mycroft #include <errno.h>
     50      1.1      cgd #include <fstab.h>
     51  1.1.1.2  mycroft #include <signal.h>
     52      1.1      cgd #include <stdio.h>
     53      1.1      cgd #include <stdlib.h>
     54  1.1.1.2  mycroft #include <string.h>
     55  1.1.1.2  mycroft #include <unistd.h>
     56      1.1      cgd 
     57  1.1.1.2  mycroft #include "pathnames.h"
     58      1.1      cgd 
     59  1.1.1.2  mycroft int debug, verbose, skipvfs;
     60      1.1      cgd 
     61  1.1.1.2  mycroft int	badvfsname __P((const char *, const char **));
     62  1.1.1.2  mycroft int	badvfstype __P((int, const char **));
     63  1.1.1.2  mycroft char   *catopt __P((char *, const char *));
     64  1.1.1.2  mycroft struct statfs
     65  1.1.1.2  mycroft        *getmntpt __P((const char *));
     66  1.1.1.2  mycroft const char
     67  1.1.1.2  mycroft       **makevfslist __P((char *));
     68  1.1.1.2  mycroft void	mangle __P((char *, int *, const char **));
     69  1.1.1.2  mycroft int	mountfs __P((const char *, const char *, const char *,
     70  1.1.1.2  mycroft 			int, const char *, const char *));
     71  1.1.1.2  mycroft void	prmount __P((const char *, const char *, int));
     72  1.1.1.2  mycroft void	usage __P((void));
     73  1.1.1.2  mycroft 
     74  1.1.1.2  mycroft /* From mount_ufs.c. */
     75  1.1.1.2  mycroft int	mount_ufs __P((int, char * const *));
     76  1.1.1.2  mycroft 
     77  1.1.1.2  mycroft /* Map from mount otions to printable formats. */
     78  1.1.1.2  mycroft static struct opt {
     79  1.1.1.2  mycroft 	int o_opt;
     80  1.1.1.2  mycroft 	const char *o_name;
     81  1.1.1.2  mycroft } optnames[] = {
     82  1.1.1.2  mycroft 	{ MNT_ASYNC,		"asynchronous" },
     83  1.1.1.2  mycroft 	{ MNT_EXPORTED,		"NFS exported" },
     84  1.1.1.2  mycroft 	{ MNT_LOCAL,		"local" },
     85  1.1.1.2  mycroft 	{ MNT_NODEV,		"nodev" },
     86  1.1.1.2  mycroft 	{ MNT_NOEXEC,		"noexec" },
     87  1.1.1.2  mycroft 	{ MNT_NOSUID,		"nosuid" },
     88  1.1.1.2  mycroft 	{ MNT_QUOTA,		"with quotas" },
     89  1.1.1.2  mycroft 	{ MNT_RDONLY,		"read-only" },
     90  1.1.1.2  mycroft 	{ MNT_SYNCHRONOUS,	"synchronous" },
     91  1.1.1.2  mycroft 	{ MNT_UNION,		"union" },
     92  1.1.1.2  mycroft 	{ MNT_USER,		"user mount" },
     93  1.1.1.2  mycroft 	{ NULL }
     94      1.1      cgd };
     95      1.1      cgd 
     96  1.1.1.2  mycroft int
     97  1.1.1.2  mycroft main(argc, argv)
     98      1.1      cgd 	int argc;
     99  1.1.1.2  mycroft 	char * const argv[];
    100      1.1      cgd {
    101  1.1.1.2  mycroft 	const char *mntonname, **vfslist, *vfstype;
    102  1.1.1.2  mycroft 	struct fstab *fs;
    103  1.1.1.2  mycroft 	struct statfs *mntbuf;
    104  1.1.1.2  mycroft 	FILE *mountdfp;
    105  1.1.1.2  mycroft 	pid_t pid;
    106  1.1.1.2  mycroft 	int all, ch, i, init_flags, mntsize, rval;
    107  1.1.1.2  mycroft 	char *options;
    108  1.1.1.2  mycroft 
    109  1.1.1.2  mycroft 	all = init_flags = 0;
    110  1.1.1.2  mycroft 	options = NULL;
    111  1.1.1.2  mycroft 	vfslist = NULL;
    112  1.1.1.2  mycroft 	vfstype = "ufs";
    113  1.1.1.2  mycroft 	while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
    114  1.1.1.2  mycroft 		switch (ch) {
    115      1.1      cgd 		case 'a':
    116      1.1      cgd 			all = 1;
    117      1.1      cgd 			break;
    118  1.1.1.2  mycroft 		case 'd':
    119  1.1.1.2  mycroft 			debug = 1;
    120  1.1.1.2  mycroft 			break;
    121      1.1      cgd 		case 'f':
    122  1.1.1.2  mycroft 			init_flags |= MNT_FORCE;
    123  1.1.1.2  mycroft 			break;
    124  1.1.1.2  mycroft 		case 'o':
    125  1.1.1.2  mycroft 			if (*optarg)
    126  1.1.1.2  mycroft 				options = catopt(options, optarg);
    127      1.1      cgd 			break;
    128      1.1      cgd 		case 'r':
    129  1.1.1.2  mycroft 			init_flags |= MNT_RDONLY;
    130  1.1.1.2  mycroft 			break;
    131  1.1.1.2  mycroft 		case 't':
    132  1.1.1.2  mycroft 			if (vfslist != NULL)
    133  1.1.1.2  mycroft 				errx(1, "only one -t option may be specified.");
    134  1.1.1.2  mycroft 			vfslist = makevfslist(optarg);
    135  1.1.1.2  mycroft 			vfstype = optarg;
    136      1.1      cgd 			break;
    137      1.1      cgd 		case 'u':
    138  1.1.1.2  mycroft 			init_flags |= MNT_UPDATE;
    139      1.1      cgd 			break;
    140      1.1      cgd 		case 'v':
    141      1.1      cgd 			verbose = 1;
    142      1.1      cgd 			break;
    143      1.1      cgd 		case 'w':
    144  1.1.1.2  mycroft 			init_flags &= ~MNT_RDONLY;
    145      1.1      cgd 			break;
    146      1.1      cgd 		case '?':
    147      1.1      cgd 		default:
    148      1.1      cgd 			usage();
    149      1.1      cgd 			/* NOTREACHED */
    150      1.1      cgd 		}
    151      1.1      cgd 	argc -= optind;
    152      1.1      cgd 	argv += optind;
    153      1.1      cgd 
    154  1.1.1.2  mycroft #define	BADTYPE(type)							\
    155  1.1.1.2  mycroft 	(strcmp(type, FSTAB_RO) &&					\
    156  1.1.1.2  mycroft 	    strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
    157  1.1.1.2  mycroft 
    158  1.1.1.2  mycroft 	rval = 0;
    159  1.1.1.2  mycroft 	switch (argc) {
    160  1.1.1.2  mycroft 	case 0:
    161  1.1.1.2  mycroft 		if (all)
    162  1.1.1.2  mycroft 			while ((fs = getfsent()) != NULL) {
    163  1.1.1.2  mycroft 				if (BADTYPE(fs->fs_type))
    164  1.1.1.2  mycroft 					continue;
    165  1.1.1.2  mycroft 				if (badvfsname(fs->fs_vfstype, vfslist))
    166  1.1.1.2  mycroft 					continue;
    167  1.1.1.2  mycroft 				if (mountfs(fs->fs_vfstype, fs->fs_spec,
    168  1.1.1.2  mycroft 				    fs->fs_file, init_flags, options,
    169  1.1.1.2  mycroft 				    fs->fs_mntops))
    170  1.1.1.2  mycroft 					rval = 1;
    171  1.1.1.2  mycroft 			}
    172  1.1.1.2  mycroft 		else {
    173  1.1.1.2  mycroft 			if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
    174  1.1.1.2  mycroft 				err(1, "getmntinfo");
    175  1.1.1.2  mycroft 			for (i = 0; i < mntsize; i++) {
    176  1.1.1.2  mycroft 				if (badvfstype(mntbuf[i].f_type, vfslist))
    177  1.1.1.2  mycroft 					continue;
    178  1.1.1.2  mycroft 				prmount(mntbuf[i].f_mntfromname,
    179  1.1.1.2  mycroft 				    mntbuf[i].f_mntonname, mntbuf[i].f_flags);
    180  1.1.1.2  mycroft 			}
    181      1.1      cgd 		}
    182      1.1      cgd 		exit(rval);
    183  1.1.1.2  mycroft 	case 1:
    184  1.1.1.2  mycroft 		if (vfslist != NULL)
    185      1.1      cgd 			usage();
    186      1.1      cgd 
    187  1.1.1.2  mycroft 		if (init_flags & MNT_UPDATE) {
    188  1.1.1.2  mycroft 			if ((mntbuf = getmntpt(*argv)) == NULL)
    189  1.1.1.2  mycroft 				errx(1,
    190  1.1.1.2  mycroft 				    "unknown special file or file system %s.",
    191  1.1.1.2  mycroft 				    *argv);
    192  1.1.1.2  mycroft 			if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
    193  1.1.1.2  mycroft 				errx(1, "can't find fstab entry for %s.",
    194  1.1.1.2  mycroft 				    *argv);
    195  1.1.1.2  mycroft 			/* If it's an update, ignore the fstab file options. */
    196  1.1.1.2  mycroft 			fs->fs_mntops = NULL;
    197  1.1.1.2  mycroft 			mntonname = mntbuf->f_mntonname;
    198  1.1.1.2  mycroft 		} else {
    199  1.1.1.2  mycroft 			if ((fs = getfsfile(*argv)) == NULL &&
    200  1.1.1.2  mycroft 			    (fs = getfsspec(*argv)) == NULL)
    201  1.1.1.2  mycroft 				errx(1,
    202  1.1.1.2  mycroft 				    "%s: unknown special file or file system.",
    203  1.1.1.2  mycroft 				    *argv);
    204  1.1.1.2  mycroft 			if (BADTYPE(fs->fs_type))
    205  1.1.1.2  mycroft 				errx(1, "%s has unknown file system type.",
    206  1.1.1.2  mycroft 				    *argv);
    207  1.1.1.2  mycroft 			mntonname = fs->fs_file;
    208      1.1      cgd 		}
    209  1.1.1.2  mycroft 		rval = mountfs(fs->fs_vfstype, fs->fs_spec,
    210  1.1.1.2  mycroft 		    mntonname, init_flags, options, fs->fs_mntops);
    211  1.1.1.2  mycroft 		break;
    212  1.1.1.2  mycroft 	case 2:
    213      1.1      cgd 		/*
    214  1.1.1.2  mycroft 		 * If -t flag has not been specified, and spec contains either
    215  1.1.1.2  mycroft 		 * a ':' or a '@' then assume that an NFS filesystem is being
    216  1.1.1.2  mycroft 		 * specified ala Sun.
    217      1.1      cgd 		 */
    218  1.1.1.2  mycroft 		if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
    219  1.1.1.2  mycroft 			vfstype = "nfs";
    220  1.1.1.2  mycroft 		rval = mountfs(vfstype,
    221  1.1.1.2  mycroft 		    argv[0], argv[1], init_flags, options, NULL);
    222  1.1.1.2  mycroft 		break;
    223  1.1.1.2  mycroft 	default:
    224  1.1.1.2  mycroft 		usage();
    225  1.1.1.2  mycroft 		/* NOTREACHED */
    226      1.1      cgd 	}
    227      1.1      cgd 
    228  1.1.1.2  mycroft 	/*
    229  1.1.1.2  mycroft 	 * If the mount was successfully, and done by root, tell mountd the
    230  1.1.1.2  mycroft 	 * good news.  Pid checks are probably unnecessary, but don't hurt.
    231  1.1.1.2  mycroft 	 */
    232  1.1.1.2  mycroft 	if (rval == 0 && getuid() == 0 &&
    233  1.1.1.2  mycroft 	    (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
    234  1.1.1.2  mycroft 		if (fscanf(mountdfp, "%ld", &pid) == 1 &&
    235  1.1.1.2  mycroft 		     pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
    236  1.1.1.2  mycroft 			err(1, "signal mountd");
    237  1.1.1.2  mycroft 		(void)fclose(mountdfp);
    238  1.1.1.2  mycroft 	}
    239  1.1.1.2  mycroft 
    240  1.1.1.2  mycroft 	exit(rval);
    241  1.1.1.2  mycroft }
    242  1.1.1.2  mycroft 
    243  1.1.1.2  mycroft int
    244  1.1.1.2  mycroft mountfs(vfstype, spec, name, flags, options, mntopts)
    245  1.1.1.2  mycroft 	const char *vfstype, *spec, *name, *options, *mntopts;
    246      1.1      cgd 	int flags;
    247      1.1      cgd {
    248  1.1.1.2  mycroft 	/* List of directories containing mount_xxx subcommands. */
    249  1.1.1.2  mycroft 	static const char *edirs[] = {
    250  1.1.1.2  mycroft 		_PATH_SBIN,
    251  1.1.1.2  mycroft 		_PATH_USRSBIN,
    252  1.1.1.2  mycroft 		NULL
    253  1.1.1.2  mycroft 	};
    254  1.1.1.2  mycroft 	const char *argv[100], **edir;
    255  1.1.1.2  mycroft 	struct statfs sf;
    256      1.1      cgd 	pid_t pid;
    257  1.1.1.2  mycroft 	int argc, i, status;
    258  1.1.1.2  mycroft 	char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
    259      1.1      cgd 
    260  1.1.1.2  mycroft 	if (realpath(name, mntpath) == NULL) {
    261  1.1.1.2  mycroft 		warn("%s", mntpath);
    262      1.1      cgd 		return (1);
    263      1.1      cgd 	}
    264      1.1      cgd 
    265  1.1.1.2  mycroft 	name = mntpath;
    266      1.1      cgd 
    267  1.1.1.2  mycroft 	if (options == NULL) {
    268  1.1.1.2  mycroft 		if (mntopts == NULL || *mntopts == '\0')
    269  1.1.1.2  mycroft 			options = "rw";
    270  1.1.1.2  mycroft 		else
    271  1.1.1.2  mycroft 			options = mntopts;
    272  1.1.1.2  mycroft 		mntopts = "";
    273  1.1.1.2  mycroft 	}
    274  1.1.1.2  mycroft 	optbuf = catopt(strdup(mntopts), options);
    275      1.1      cgd 
    276  1.1.1.2  mycroft 	if (strcmp(name, "/") == 0)
    277  1.1.1.2  mycroft 		flags |= MNT_UPDATE;
    278  1.1.1.2  mycroft 	if (flags & MNT_FORCE)
    279  1.1.1.2  mycroft 		optbuf = catopt(optbuf, "force");
    280  1.1.1.2  mycroft 	if (flags & MNT_RDONLY)
    281  1.1.1.2  mycroft 		optbuf = catopt(optbuf, "ro");
    282  1.1.1.2  mycroft 	/*
    283  1.1.1.2  mycroft 	 * XXX
    284  1.1.1.2  mycroft 	 * The mount_mfs (newfs) command uses -o to select the
    285  1.1.1.2  mycroft 	 * optimisation mode.  We don't pass the default "-o rw"
    286  1.1.1.2  mycroft 	 * for that reason.
    287  1.1.1.2  mycroft 	 */
    288  1.1.1.2  mycroft 	if (flags & MNT_UPDATE)
    289  1.1.1.2  mycroft 		optbuf = catopt(optbuf, "update");
    290  1.1.1.2  mycroft 
    291  1.1.1.2  mycroft 	argc = 0;
    292  1.1.1.2  mycroft 	argv[argc++] = vfstype;
    293  1.1.1.2  mycroft 	mangle(optbuf, &argc, argv);
    294  1.1.1.2  mycroft 	argv[argc++] = spec;
    295  1.1.1.2  mycroft 	argv[argc++] = name;
    296  1.1.1.2  mycroft 	argv[argc] = NULL;
    297  1.1.1.2  mycroft 
    298  1.1.1.2  mycroft 	if (debug) {
    299  1.1.1.2  mycroft 		(void)printf("exec: mount_%s", vfstype);
    300  1.1.1.2  mycroft 		for (i = 1; i < argc; i++)
    301  1.1.1.2  mycroft 			(void)printf(" %s", argv[i]);
    302      1.1      cgd 		(void)printf("\n");
    303  1.1.1.2  mycroft 		return (0);
    304      1.1      cgd 	}
    305      1.1      cgd 
    306  1.1.1.2  mycroft 	switch (pid = vfork()) {
    307  1.1.1.2  mycroft 	case -1:				/* Error. */
    308  1.1.1.2  mycroft 		warn("vfork");
    309  1.1.1.2  mycroft 		free(optbuf);
    310  1.1.1.2  mycroft 		return (1);
    311  1.1.1.2  mycroft 	case 0:					/* Child. */
    312  1.1.1.2  mycroft 		if (strcmp(vfstype, "ufs") == 0)
    313  1.1.1.2  mycroft 			exit(mount_ufs(argc, (char * const *) argv));
    314  1.1.1.2  mycroft 
    315  1.1.1.2  mycroft 		/* Go find an executable. */
    316  1.1.1.2  mycroft 		edir = edirs;
    317  1.1.1.2  mycroft 		do {
    318  1.1.1.2  mycroft 			(void)snprintf(execname,
    319  1.1.1.2  mycroft 			    sizeof(execname), "%s/mount_%s", *edir, vfstype);
    320  1.1.1.2  mycroft 			execv(execname, (char * const *)argv);
    321  1.1.1.2  mycroft 			if (errno != ENOENT)
    322  1.1.1.2  mycroft 				warn("exec %s for %s", execname, name);
    323  1.1.1.2  mycroft 		} while (*++edir != NULL);
    324      1.1      cgd 
    325  1.1.1.2  mycroft 		if (errno == ENOENT)
    326  1.1.1.2  mycroft 			warn("exec %s for %s", execname, name);
    327  1.1.1.2  mycroft 		exit(1);
    328  1.1.1.2  mycroft 		/* NOTREACHED */
    329  1.1.1.2  mycroft 	default:				/* Parent. */
    330  1.1.1.2  mycroft 		free(optbuf);
    331      1.1      cgd 
    332  1.1.1.2  mycroft 		if (waitpid(pid, &status, 0) < 0) {
    333  1.1.1.2  mycroft 			warn("waitpid");
    334  1.1.1.2  mycroft 			return (1);
    335      1.1      cgd 		}
    336  1.1.1.2  mycroft 
    337  1.1.1.2  mycroft 		if (WIFEXITED(status)) {
    338  1.1.1.2  mycroft 			if (WEXITSTATUS(status) != 0)
    339  1.1.1.2  mycroft 				return (WEXITSTATUS(status));
    340  1.1.1.2  mycroft 		} else if (WIFSIGNALED(status)) {
    341  1.1.1.2  mycroft 			warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
    342  1.1.1.2  mycroft 			return (1);
    343      1.1      cgd 		}
    344  1.1.1.2  mycroft 
    345  1.1.1.2  mycroft 		if (verbose) {
    346  1.1.1.2  mycroft 			if (statfs(name, &sf) < 0) {
    347  1.1.1.2  mycroft 				warn("%s", name);
    348  1.1.1.2  mycroft 				return (1);
    349  1.1.1.2  mycroft 			}
    350  1.1.1.2  mycroft 			prmount(sf.f_mntfromname, sf.f_mntonname, sf.f_flags);
    351      1.1      cgd 		}
    352  1.1.1.2  mycroft 		break;
    353      1.1      cgd 	}
    354      1.1      cgd 
    355  1.1.1.2  mycroft 	return (0);
    356      1.1      cgd }
    357      1.1      cgd 
    358  1.1.1.2  mycroft void
    359  1.1.1.2  mycroft prmount(spec, name, flags)
    360  1.1.1.2  mycroft 	const char *spec, *name;
    361  1.1.1.2  mycroft 	int flags;
    362      1.1      cgd {
    363  1.1.1.2  mycroft 	struct opt *o;
    364  1.1.1.2  mycroft 	int f;
    365      1.1      cgd 
    366  1.1.1.2  mycroft 	(void)printf("%s on %s", spec, name);
    367  1.1.1.2  mycroft 
    368  1.1.1.2  mycroft 	flags &= MNT_VISFLAGMASK;
    369  1.1.1.2  mycroft 	for (f = 0, o = optnames; flags && o->o_opt; o++)
    370  1.1.1.2  mycroft 		if (flags & o->o_opt) {
    371  1.1.1.2  mycroft 			(void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
    372  1.1.1.2  mycroft 			flags &= ~o->o_opt;
    373  1.1.1.2  mycroft 		}
    374  1.1.1.2  mycroft 	(void)printf(f ? ")\n" : "\n");
    375      1.1      cgd }
    376      1.1      cgd 
    377      1.1      cgd struct statfs *
    378      1.1      cgd getmntpt(name)
    379  1.1.1.2  mycroft 	const char *name;
    380      1.1      cgd {
    381      1.1      cgd 	struct statfs *mntbuf;
    382  1.1.1.2  mycroft 	int i, mntsize;
    383      1.1      cgd 
    384      1.1      cgd 	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
    385  1.1.1.2  mycroft 	for (i = 0; i < mntsize; i++)
    386  1.1.1.2  mycroft 		if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
    387  1.1.1.2  mycroft 		    strcmp(mntbuf[i].f_mntonname, name) == 0)
    388      1.1      cgd 			return (&mntbuf[i]);
    389  1.1.1.2  mycroft 	return (NULL);
    390      1.1      cgd }
    391      1.1      cgd 
    392  1.1.1.2  mycroft int
    393  1.1.1.2  mycroft badvfsname(vfsname, vfslist)
    394  1.1.1.2  mycroft 	const char *vfsname;
    395  1.1.1.2  mycroft 	const char **vfslist;
    396      1.1      cgd {
    397      1.1      cgd 
    398  1.1.1.2  mycroft 	if (vfslist == NULL)
    399  1.1.1.2  mycroft 		return (0);
    400  1.1.1.2  mycroft 	while (*vfslist != NULL) {
    401  1.1.1.2  mycroft 		if (strcmp(vfsname, *vfslist) == 0)
    402  1.1.1.2  mycroft 			return (skipvfs);
    403  1.1.1.2  mycroft 		++vfslist;
    404      1.1      cgd 	}
    405      1.1      cgd 	return (!skipvfs);
    406      1.1      cgd }
    407      1.1      cgd 
    408  1.1.1.2  mycroft int
    409  1.1.1.2  mycroft badvfstype(vfstype, vfslist)
    410  1.1.1.2  mycroft 	int vfstype;
    411  1.1.1.2  mycroft 	const char **vfslist;
    412      1.1      cgd {
    413  1.1.1.2  mycroft static const char *vfsnames[] = INITMOUNTNAMES;
    414      1.1      cgd 
    415  1.1.1.2  mycroft 	if ((vfstype < 0) || (vfstype > MOUNT_MAXTYPE))
    416  1.1.1.2  mycroft 		return (0);
    417  1.1.1.2  mycroft 
    418  1.1.1.2  mycroft 	return (badvfsname(vfsnames[vfstype], vfslist));
    419      1.1      cgd }
    420      1.1      cgd 
    421  1.1.1.2  mycroft const char **
    422      1.1      cgd makevfslist(fslist)
    423      1.1      cgd 	char *fslist;
    424      1.1      cgd {
    425  1.1.1.2  mycroft 	const char **av;
    426  1.1.1.2  mycroft 	int i;
    427  1.1.1.2  mycroft 	char *nextcp;
    428      1.1      cgd 
    429      1.1      cgd 	if (fslist == NULL)
    430      1.1      cgd 		return (NULL);
    431      1.1      cgd 	if (fslist[0] == 'n' && fslist[1] == 'o') {
    432      1.1      cgd 		fslist += 2;
    433      1.1      cgd 		skipvfs = 1;
    434      1.1      cgd 	}
    435      1.1      cgd 	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
    436      1.1      cgd 		if (*nextcp == ',')
    437      1.1      cgd 			i++;
    438  1.1.1.2  mycroft 	if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
    439  1.1.1.2  mycroft 		warn(NULL);
    440      1.1      cgd 		return (NULL);
    441  1.1.1.2  mycroft 	}
    442      1.1      cgd 	nextcp = fslist;
    443      1.1      cgd 	i = 0;
    444      1.1      cgd 	av[i++] = nextcp;
    445  1.1.1.2  mycroft 	while ((nextcp = strchr(nextcp, ',')) != NULL) {
    446      1.1      cgd 		*nextcp++ = '\0';
    447      1.1      cgd 		av[i++] = nextcp;
    448      1.1      cgd 	}
    449  1.1.1.2  mycroft 	av[i++] = NULL;
    450      1.1      cgd 	return (av);
    451      1.1      cgd }
    452      1.1      cgd 
    453  1.1.1.2  mycroft char *
    454  1.1.1.2  mycroft catopt(s0, s1)
    455  1.1.1.2  mycroft 	char *s0;
    456  1.1.1.2  mycroft 	const char *s1;
    457  1.1.1.2  mycroft {
    458  1.1.1.2  mycroft 	size_t i;
    459  1.1.1.2  mycroft 	char *cp;
    460  1.1.1.2  mycroft 
    461  1.1.1.2  mycroft 	if (s0 && *s0) {
    462  1.1.1.2  mycroft 		i = strlen(s0) + strlen(s1) + 1 + 1;
    463  1.1.1.2  mycroft 		if ((cp = malloc(i)) == NULL)
    464  1.1.1.2  mycroft 			err(1, NULL);
    465  1.1.1.2  mycroft 		(void)snprintf(cp, i, "%s,%s", s0, s1);
    466  1.1.1.2  mycroft 	} else
    467  1.1.1.2  mycroft 		cp = strdup(s1);
    468  1.1.1.2  mycroft 
    469  1.1.1.2  mycroft 	if (s0)
    470  1.1.1.2  mycroft 		free(s0);
    471  1.1.1.2  mycroft 	return (cp);
    472      1.1      cgd }
    473      1.1      cgd 
    474  1.1.1.2  mycroft void
    475  1.1.1.2  mycroft mangle(options, argcp, argv)
    476  1.1.1.2  mycroft 	char *options;
    477  1.1.1.2  mycroft 	int *argcp;
    478  1.1.1.2  mycroft 	const char **argv;
    479      1.1      cgd {
    480  1.1.1.2  mycroft 	char *p, *s;
    481  1.1.1.2  mycroft 	int argc;
    482      1.1      cgd 
    483  1.1.1.2  mycroft 	argc = *argcp;
    484  1.1.1.2  mycroft 	for (s = options; (p = strsep(&s, ",")) != NULL;)
    485  1.1.1.2  mycroft 		if (*p != '\0')
    486  1.1.1.2  mycroft 			if (*p == '-') {
    487  1.1.1.2  mycroft 				argv[argc++] = p;
    488  1.1.1.2  mycroft 				p = strchr(p, '=');
    489  1.1.1.2  mycroft 				if (p) {
    490  1.1.1.2  mycroft 					*p = '\0';
    491  1.1.1.2  mycroft 					argv[argc++] = p+1;
    492      1.1      cgd 				}
    493  1.1.1.2  mycroft 			} else if (strcmp(p, "rw") != 0) {
    494  1.1.1.2  mycroft 				argv[argc++] = "-o";
    495  1.1.1.2  mycroft 				argv[argc++] = p;
    496      1.1      cgd 			}
    497      1.1      cgd 
    498  1.1.1.2  mycroft 	*argcp = argc;
    499      1.1      cgd }
    500      1.1      cgd 
    501  1.1.1.2  mycroft void
    502  1.1.1.2  mycroft usage()
    503      1.1      cgd {
    504  1.1.1.2  mycroft 
    505  1.1.1.2  mycroft 	(void)fprintf(stderr,
    506  1.1.1.2  mycroft 		"usage: mount %s %s\n       mount %s\n       mount %s\n",
    507  1.1.1.2  mycroft 		"[-dfruvw] [-o options] [-t ufs | external_type]",
    508  1.1.1.2  mycroft 			"special node",
    509  1.1.1.2  mycroft 		"[-adfruvw] [-t ufs | external_type]",
    510  1.1.1.2  mycroft 		"[-dfruvw] special | node");
    511  1.1.1.2  mycroft 	exit(1);
    512      1.1      cgd }
    513