xref: /csrg-svn/sbin/mount/mount.c (revision 56841)
121156Sdist /*
239322Smckusick  * Copyright (c) 1980, 1989 The Regents of the University of California.
339322Smckusick  * All rights reserved.
439322Smckusick  *
542702Sbostic  * %sccs.include.redist.c%
621156Sdist  */
721156Sdist 
810811Ssam #ifndef lint
921156Sdist char copyright[] =
1039322Smckusick "@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
1121156Sdist  All rights reserved.\n";
1239322Smckusick #endif /* not lint */
131057Sbill 
1421156Sdist #ifndef lint
15*56841Smckusick static char sccsid[] = "@(#)mount.c	5.51 (Berkeley) 11/15/92";
1639322Smckusick #endif /* not lint */
1721156Sdist 
1812808Ssam #include <sys/param.h>
1935339Sbostic #include <sys/file.h>
2038445Smckusick #include <sys/time.h>
2139133Smckusick #include <sys/wait.h>
2245524Sbostic #include <sys/errno.h>
2345524Sbostic #include <sys/signal.h>
2452110Smckusick #include <sys/ucred.h>
2538445Smckusick #include <sys/mount.h>
2645524Sbostic #include <fstab.h>
2745524Sbostic #include <string.h>
2845524Sbostic #include <stdio.h>
2945524Sbostic #include <stdlib.h>
3045524Sbostic #include "pathnames.h"
311057Sbill 
3240369Smckusick #define DEFAULT_ROOTUID	-2
3340369Smckusick 
3435339Sbostic #define	BADTYPE(type) \
3535339Sbostic 	(strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \
3635339Sbostic 	    strcmp(type, FSTAB_RQ))
3735339Sbostic #define	SETTYPE(type) \
3835339Sbostic 	(!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ))
391057Sbill 
40*56841Smckusick int debug, force, verbose, updateflg, mnttype;
4139322Smckusick char *mntname, **envp;
4240051Smckusick char **vfslist, **makevfslist();
4346708Sbostic static void prmount();
4439131Smckusick 
4539131Smckusick main(argc, argv, arge)
465073Sroot 	int argc;
475073Sroot 	char **argv;
4839131Smckusick 	char **arge;
491057Sbill {
5035339Sbostic 	extern char *optarg;
5135339Sbostic 	extern int optind;
5235339Sbostic 	register struct fstab *fs;
5340496Smckusick 	int all, ch, rval, flags, ret, pid, i;
5438632Smckusick 	long mntsize;
5539465Smckusick 	struct statfs *mntbuf, *getmntpt();
5639131Smckusick 	char *type, *options = NULL;
5740496Smckusick 	FILE *pidfile;
581057Sbill 
5939131Smckusick 	envp = arge;
6035339Sbostic 	all = 0;
6135339Sbostic 	type = NULL;
6238445Smckusick 	mnttype = MOUNT_UFS;
6339322Smckusick 	mntname = "ufs";
64*56841Smckusick 	while ((ch = getopt(argc, argv, "adfrwuvt:o:")) != EOF)
6535339Sbostic 		switch((char)ch) {
6635339Sbostic 		case 'a':
6735339Sbostic 			all = 1;
6835339Sbostic 			break;
69*56841Smckusick 		case 'd':
70*56841Smckusick 			debug = 1;
71*56841Smckusick 			break;
7235339Sbostic 		case 'f':
73*56841Smckusick 			force = 1;
7435339Sbostic 			break;
7535339Sbostic 		case 'r':
7612808Ssam 			type = FSTAB_RO;
7735339Sbostic 			break;
7839333Smckusick 		case 'u':
7941403Smckusick 			updateflg = MNT_UPDATE;
8039333Smckusick 			break;
8135339Sbostic 		case 'v':
8235339Sbostic 			verbose = 1;
8335339Sbostic 			break;
8435339Sbostic 		case 'w':
8535339Sbostic 			type = FSTAB_RW;
8635339Sbostic 			break;
8739131Smckusick 		case 'o':
8839131Smckusick 			options = optarg;
8939131Smckusick 			break;
9038445Smckusick 		case 't':
9140051Smckusick 			vfslist = makevfslist(optarg);
9239322Smckusick 			mnttype = getmnttype(optarg);
9339322Smckusick 			break;
9435339Sbostic 		case '?':
9535339Sbostic 		default:
9635339Sbostic 			usage();
9739131Smckusick 			/* NOTREACHED */
985073Sroot 		}
9935339Sbostic 	argc -= optind;
10035339Sbostic 	argv += optind;
10135339Sbostic 
10235339Sbostic 	/* NOSTRICT */
10335339Sbostic 
1044460Sroot 	if (all) {
10535369Sbostic 		rval = 0;
10639333Smckusick 		while (fs = getfsent()) {
10735372Sbostic 			if (BADTYPE(fs->fs_type))
10835372Sbostic 				continue;
10940844Smckusick 			if (badvfsname(fs->fs_vfstype, vfslist))
11040051Smckusick 				continue;
11135372Sbostic 			/* `/' is special, it's always mounted */
11235372Sbostic 			if (!strcmp(fs->fs_file, "/"))
11341403Smckusick 				flags = MNT_UPDATE;
11439333Smckusick 			else
11539333Smckusick 				flags = updateflg;
11639333Smckusick 			mnttype = getmnttype(fs->fs_vfstype);
11739333Smckusick 			rval |= mountfs(fs->fs_spec, fs->fs_file, flags,
11839333Smckusick 			    type, options, fs->fs_mntops);
11935372Sbostic 		}
12035341Sbostic 		exit(rval);
12135339Sbostic 	}
1225073Sroot 
12335339Sbostic 	if (argc == 0) {
124*56841Smckusick 		if (verbose || debug || type)
12535339Sbostic 			usage();
12640337Smckusick 		if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
12745689Smckusick 			(void) fprintf(stderr,
12839319Smckusick 				"mount: cannot get mount information\n");
12938632Smckusick 			exit(1);
13038632Smckusick 		}
13140844Smckusick 		for (i = 0; i < mntsize; i++) {
13240844Smckusick 			if (badvfstype(mntbuf[i].f_type, vfslist))
13340844Smckusick 				continue;
13438632Smckusick 			prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname,
13539316Smckusick 				mntbuf[i].f_flags);
13640844Smckusick 		}
1374460Sroot 		exit(0);
1381057Sbill 	}
13912808Ssam 
14039465Smckusick 	if (argc == 1 && updateflg) {
14139465Smckusick 		if ((mntbuf = getmntpt(*argv)) == NULL) {
14245689Smckusick 			(void) fprintf(stderr,
14339465Smckusick 			    "mount: unknown special file or file system %s.\n",
14439465Smckusick 			    *argv);
14539465Smckusick 			exit(1);
14639465Smckusick 		}
14739465Smckusick 		mnttype = mntbuf->f_type;
14853711Smckusick 		if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL) {
14953711Smckusick 			(void) fprintf(stderr,
15053711Smckusick 			    "mount: can't find fstab entry for %s.\n", *argv);
15153711Smckusick 			exit(1);
15240124Smckusick 		}
15353711Smckusick 		mntname = fs->fs_vfstype;
15453711Smckusick 
15553711Smckusick 		/*
15653711Smckusick 		 * Default type to fstab version if none specified on the
15753711Smckusick 		 * command line.
15853711Smckusick 		 */
15953711Smckusick 		if (type == NULL)
16053711Smckusick 			type = fs->fs_type;
16153711Smckusick 
16253711Smckusick 		/*
16353711Smckusick 		 * Default options to fstab version if none specified on the
16453711Smckusick 		 * command line.
16553711Smckusick 		 */
16653711Smckusick 		if (options == NULL)
16753711Smckusick 			options = fs->fs_mntops;
16853711Smckusick 		else {
16953711Smckusick 			register char *cp;
17053711Smckusick 
17153711Smckusick 			/*
17253711Smckusick 			 * Concat the two strings with the command line
17353711Smckusick 			 * options last so that they will override the
17453711Smckusick 			 * fstab options.
17553711Smckusick 			 */
17653711Smckusick 			i = strlen(fs->fs_mntops) + strlen(options) + 2;
17753711Smckusick 			if ((cp = malloc((size_t)i)) == NULL) {
17853711Smckusick 				(void) fprintf(stderr,
17953711Smckusick 				    "mount: -u malloc failed\n");
18053711Smckusick 				exit(1);
18153711Smckusick 			}
18253711Smckusick 			sprintf(cp, "%s,%s", fs->fs_mntops, options);
18353711Smckusick 			options = cp;
18453711Smckusick 		}
18553711Smckusick 		ret = mountfs(fs->fs_spec, mntbuf->f_mntonname,
18642253Sbostic 		    updateflg, type, options, (char *)NULL);
18740496Smckusick 	} else if (argc == 1) {
18835339Sbostic 		if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
18945689Smckusick 			(void) fprintf(stderr,
19035339Sbostic 			    "mount: unknown special file or file system %s.\n",
19135339Sbostic 			    *argv);
19235339Sbostic 			exit(1);
19335339Sbostic 		}
19435339Sbostic 		if (BADTYPE(fs->fs_type)) {
19545689Smckusick 			(void) fprintf(stderr,
19635339Sbostic 			    "mount: %s has unknown file system type.\n", *argv);
19735339Sbostic 			exit(1);
19835339Sbostic 		}
19939333Smckusick 		mnttype = getmnttype(fs->fs_vfstype);
20040496Smckusick 		ret = mountfs(fs->fs_spec, fs->fs_file, updateflg,
20140496Smckusick 		    type, options, fs->fs_mntops);
20240496Smckusick 	} else if (argc != 2) {
20340496Smckusick 		usage();
20440496Smckusick 		ret = 1;
20540496Smckusick 	} else {
20642857Smckusick 		/*
20742857Smckusick 		 * If -t flag has not been specified, and spec
20842857Smckusick 		 * contains either a ':' or a '@' then assume that
20942857Smckusick 		 * an NFS filesystem is being specified ala Sun.
21042857Smckusick 		 */
21142857Smckusick 		if (vfslist == (char **)0 &&
21252182Smckusick 		    (index(argv[0], ':') || index(argv[0], '@'))) {
21342857Smckusick 			mnttype = MOUNT_NFS;
21452182Smckusick 			mntname = "nfs";
21552182Smckusick 		}
21642253Sbostic 		ret = mountfs(argv[0], argv[1], updateflg, type, options,
21742253Sbostic 		    (char *)NULL);
21812808Ssam 	}
21940496Smckusick 	if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
22040496Smckusick 		pid = 0;
22140496Smckusick 		fscanf(pidfile, "%d", &pid);
22240496Smckusick 		fclose(pidfile);
22340496Smckusick 		if (pid > 0)
22440496Smckusick 			kill(pid, SIGHUP);
22540496Smckusick 	}
22640496Smckusick 	exit (ret);
22712808Ssam }
22812808Ssam 
22939333Smckusick mountfs(spec, name, flags, type, options, mntopts)
23039131Smckusick 	char *spec, *name, *type, *options, *mntopts;
23139333Smckusick 	int flags;
23212808Ssam {
23342253Sbostic 	union wait status;
23442253Sbostic 	pid_t pid;
23542253Sbostic 	int argc, i;
23638070Smckusick 	struct ufs_args args;
23739131Smckusick 	char *argp, *argv[50];
23839322Smckusick 	char execname[MAXPATHLEN + 1], flagval[12];
2391057Sbill 
24039333Smckusick 	if (mntopts)
24139333Smckusick 		getstdopts(mntopts, &flags);
24239316Smckusick 	if (options)
24339316Smckusick 		getstdopts(options, &flags);
24439333Smckusick 	if (type)
24539333Smckusick 		getstdopts(type, &flags);
246*56841Smckusick 	if (force)
247*56841Smckusick 		flags |= MNT_FORCE;
24839316Smckusick 	switch (mnttype) {
24952097Sbostic 	case MOUNT_LFS:
25039316Smckusick 	case MOUNT_UFS:
25139333Smckusick 		if (mntopts)
25239333Smckusick 			getufsopts(mntopts, &flags);
25339316Smckusick 		if (options)
25439316Smckusick 			getufsopts(options, &flags);
25539316Smckusick 		args.fspec = spec;
25640369Smckusick 		args.exroot = DEFAULT_ROOTUID;
25741403Smckusick 		if (flags & MNT_RDONLY)
25841403Smckusick 			args.exflags = MNT_EXRDONLY;
25940496Smckusick 		else
26040496Smckusick 			args.exflags = 0;
26139316Smckusick 		argp = (caddr_t)&args;
26239316Smckusick 		break;
26338632Smckusick 
26452110Smckusick 	case MOUNT_MFS:
26539316Smckusick 	case MOUNT_NFS:
26639322Smckusick 	default:
26739322Smckusick 		argv[0] = mntname;
26839329Smckusick 		argc = 1;
26939322Smckusick 		if (flags) {
27039322Smckusick 			argv[argc++] = "-F";
27139322Smckusick 			sprintf(flagval, "%d", flags);
27239322Smckusick 			argv[argc++] = flagval;
27339322Smckusick 		}
27439333Smckusick 		if (mntopts)
27539333Smckusick 			argc += getexecopts(mntopts, &argv[argc]);
27639329Smckusick 		if (options)
27739329Smckusick 			argc += getexecopts(options, &argv[argc]);
27839316Smckusick 		argv[argc++] = spec;
27939316Smckusick 		argv[argc++] = name;
28039521Smckusick 		argv[argc++] = NULL;
28139603Smckusick 		sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
28239316Smckusick 		if (verbose) {
28342253Sbostic 			(void)printf("exec: %s", execname);
28442253Sbostic 			for (i = 1; i < argc - 1; i++)
28542253Sbostic 				(void)printf(" %s", argv[i]);
28642253Sbostic 			(void)printf("\n");
28739316Smckusick 		}
288*56841Smckusick 		if (debug)
28939316Smckusick 			break;
29042253Sbostic 		if (pid = vfork()) {
29142253Sbostic 			if (pid == -1) {
29239322Smckusick 				perror("mount: vfork starting file system");
29339316Smckusick 				return (1);
29439131Smckusick 			}
29546708Sbostic 			if (waitpid(pid, (int *)&status, 0) != -1 &&
29639316Smckusick 			    WIFEXITED(status) &&
29739316Smckusick 			    WEXITSTATUS(status) != 0)
29839316Smckusick 				return (WEXITSTATUS(status));
29939322Smckusick 			spec = mntname;
30039316Smckusick 			goto out;
30139316Smckusick 		}
30239322Smckusick 		execve(execname, argv, envp);
30345689Smckusick 		(void) fprintf(stderr, "mount: cannot exec %s for %s: ",
30439603Smckusick 			execname, name);
30542253Sbostic 		perror((char *)NULL);
30639316Smckusick 		exit (1);
30739316Smckusick 		/* NOTREACHED */
30838632Smckusick 
30939316Smckusick 	}
310*56841Smckusick 	if (!debug && mount(mnttype, name, flags, argp)) {
31145689Smckusick 		(void) fprintf(stderr, "%s on %s: ", spec, name);
31239316Smckusick 		switch (errno) {
31339316Smckusick 		case EMFILE:
31445689Smckusick 			(void) fprintf(stderr, "Mount table full\n");
31539316Smckusick 			break;
31639316Smckusick 		case EINVAL:
31741403Smckusick 			if (flags & MNT_UPDATE)
31845689Smckusick 				(void) fprintf(stderr, "Specified device %s\n",
31945689Smckusick 					"does not match mounted device");
32045569Skarels 			else if (mnttype == MOUNT_UFS)
32145689Smckusick 				(void) fprintf(stderr, "Bogus super block\n");
32239333Smckusick 			else
32345569Skarels 				perror((char *)NULL);
32439316Smckusick 			break;
32539316Smckusick 		default:
32639316Smckusick 			perror((char *)NULL);
32739316Smckusick 			break;
3284460Sroot 		}
32939316Smckusick 		return(1);
3304460Sroot 	}
33135339Sbostic 
33239131Smckusick out:
33312808Ssam 	if (verbose)
33439316Smckusick 		prmount(spec, name, flags);
33535339Sbostic 
33642253Sbostic 	return(0);
3371057Sbill }
33835339Sbostic 
33946708Sbostic static void
34039316Smckusick prmount(spec, name, flags)
34139316Smckusick 	char *spec, *name;
34242253Sbostic 	register short flags;
34335339Sbostic {
34442253Sbostic 	register int first;
34538632Smckusick 
34642253Sbostic 	(void)printf("%s on %s", spec, name);
34742253Sbostic 	if (!(flags & MNT_VISFLAGMASK)) {
34842253Sbostic 		(void)printf("\n");
34942253Sbostic 		return;
35042253Sbostic 	}
35142253Sbostic 	first = 0;
35242253Sbostic #define	PR(msg)	(void)printf("%s%s", !first++ ? " (" : ", ", msg)
35341403Smckusick 	if (flags & MNT_RDONLY)
35442253Sbostic 		PR("read-only");
35541403Smckusick 	if (flags & MNT_NOEXEC)
35642253Sbostic 		PR("noexec");
35741403Smckusick 	if (flags & MNT_NOSUID)
35842253Sbostic 		PR("nosuid");
35941403Smckusick 	if (flags & MNT_NODEV)
36042253Sbostic 		PR("nodev");
36141403Smckusick 	if (flags & MNT_SYNCHRONOUS)
36242253Sbostic 		PR("synchronous");
36341403Smckusick 	if (flags & MNT_QUOTA)
36442253Sbostic 		PR("with quotas");
36541403Smckusick 	if (flags & MNT_LOCAL)
36642253Sbostic 		PR("local");
36755394Spendry 	if (flags & MNT_UNION)
36855394Spendry 		PR("union");
36941403Smckusick 	if (flags & MNT_EXPORTED)
37052110Smckusick 		PR("NFS exported");
37142253Sbostic 	(void)printf(")\n");
37235339Sbostic }
37335339Sbostic 
37439133Smckusick getmnttype(fstype)
37539133Smckusick 	char *fstype;
37639133Smckusick {
37739133Smckusick 
37839322Smckusick 	mntname = fstype;
37939133Smckusick 	if (!strcmp(fstype, "ufs"))
38039133Smckusick 		return (MOUNT_UFS);
38139133Smckusick 	if (!strcmp(fstype, "nfs"))
38239133Smckusick 		return (MOUNT_NFS);
38339133Smckusick 	if (!strcmp(fstype, "mfs"))
38439133Smckusick 		return (MOUNT_MFS);
38552097Sbostic 	if (!strcmp(fstype, "lfs"))
38652097Sbostic 		return (MOUNT_LFS);
38739133Smckusick 	return (0);
38839133Smckusick }
38939133Smckusick 
39038632Smckusick usage()
39135339Sbostic {
39240871Smckusick 
39345689Smckusick 	(void) fprintf(stderr,
39445689Smckusick 		"usage:\n  mount %s %s\n  mount %s\n  mount %s\n",
39552110Smckusick 		"[ -frwu ] [ -t ufs | external_type ]",
39640871Smckusick 		"[ -o options ] special node",
39752110Smckusick 		"[ -afrwu ] [ -t ufs | external_type ]",
39840871Smckusick 		"[ -frwu ] special | node");
39935339Sbostic 	exit(1);
40035339Sbostic }
40135339Sbostic 
40239316Smckusick getstdopts(options, flagp)
40339316Smckusick 	char *options;
40442253Sbostic 	int *flagp;
40539316Smckusick {
40639316Smckusick 	register char *opt;
40739316Smckusick 	int negative;
40842253Sbostic 	char optbuf[BUFSIZ];
40939316Smckusick 
41042253Sbostic 	(void)strcpy(optbuf, options);
41142253Sbostic 	for (opt = strtok(optbuf, ","); opt; opt = strtok((char *)NULL, ",")) {
41239316Smckusick 		if (opt[0] == 'n' && opt[1] == 'o') {
41339316Smckusick 			negative++;
41439316Smckusick 			opt += 2;
41539316Smckusick 		} else {
41639316Smckusick 			negative = 0;
41739316Smckusick 		}
41839333Smckusick 		if (!negative && !strcasecmp(opt, FSTAB_RO)) {
41941403Smckusick 			*flagp |= MNT_RDONLY;
42039333Smckusick 			continue;
42139333Smckusick 		}
42239333Smckusick 		if (!negative && !strcasecmp(opt, FSTAB_RW)) {
42341403Smckusick 			*flagp &= ~MNT_RDONLY;
42439333Smckusick 			continue;
42539333Smckusick 		}
42639316Smckusick 		if (!strcasecmp(opt, "exec")) {
42739316Smckusick 			if (negative)
42841403Smckusick 				*flagp |= MNT_NOEXEC;
42939333Smckusick 			else
43041403Smckusick 				*flagp &= ~MNT_NOEXEC;
43139316Smckusick 			continue;
43239316Smckusick 		}
43339316Smckusick 		if (!strcasecmp(opt, "suid")) {
43439316Smckusick 			if (negative)
43541403Smckusick 				*flagp |= MNT_NOSUID;
43639333Smckusick 			else
43741403Smckusick 				*flagp &= ~MNT_NOSUID;
43839316Smckusick 			continue;
43939316Smckusick 		}
44039316Smckusick 		if (!strcasecmp(opt, "dev")) {
44139316Smckusick 			if (negative)
44241403Smckusick 				*flagp |= MNT_NODEV;
44339333Smckusick 			else
44441403Smckusick 				*flagp &= ~MNT_NODEV;
44539316Smckusick 			continue;
44639316Smckusick 		}
44739316Smckusick 		if (!strcasecmp(opt, "synchronous")) {
44839316Smckusick 			if (!negative)
44941403Smckusick 				*flagp |= MNT_SYNCHRONOUS;
45039333Smckusick 			else
45141403Smckusick 				*flagp &= ~MNT_SYNCHRONOUS;
45239316Smckusick 			continue;
45339316Smckusick 		}
45455394Spendry 		if (!strcasecmp(opt, "union")) {
45555394Spendry 			if (!negative)
45655394Spendry 				*flagp |= MNT_UNION;
45755394Spendry 			else
45855394Spendry 				*flagp &= ~MNT_UNION;
45955394Spendry 			continue;
46055394Spendry 		}
46139316Smckusick 	}
46239316Smckusick }
46339316Smckusick 
46442253Sbostic /* ARGSUSED */
46539131Smckusick getufsopts(options, flagp)
46639131Smckusick 	char *options;
46742253Sbostic 	int *flagp;
46839131Smckusick {
46939131Smckusick 	return;
47039131Smckusick }
47139131Smckusick 
47239329Smckusick getexecopts(options, argv)
47339131Smckusick 	char *options;
47439131Smckusick 	char **argv;
47539131Smckusick {
47639131Smckusick 	register int argc = 0;
47739131Smckusick 	register char *opt;
47839131Smckusick 
47942253Sbostic 	for (opt = strtok(options, ","); opt; opt = strtok((char *)NULL, ",")) {
48039131Smckusick 		if (opt[0] != '-')
48139131Smckusick 			continue;
48239131Smckusick 		argv[argc++] = opt;
48339131Smckusick 		if (opt[2] == '\0' || opt[2] != '=')
48439131Smckusick 			continue;
48539131Smckusick 		opt[2] = '\0';
48639131Smckusick 		argv[argc++] = &opt[3];
48739131Smckusick 	}
48839131Smckusick 	return (argc);
48939131Smckusick }
49039131Smckusick 
49139465Smckusick struct statfs *
49239465Smckusick getmntpt(name)
49339465Smckusick 	char *name;
49439465Smckusick {
49539465Smckusick 	long mntsize;
49639465Smckusick 	register long i;
49739465Smckusick 	struct statfs *mntbuf;
49839465Smckusick 
49940337Smckusick 	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
50039465Smckusick 	for (i = 0; i < mntsize; i++) {
50139465Smckusick 		if (!strcmp(mntbuf[i].f_mntfromname, name) ||
50239465Smckusick 		    !strcmp(mntbuf[i].f_mntonname, name))
50339465Smckusick 			return (&mntbuf[i]);
50439465Smckusick 	}
50539465Smckusick 	return ((struct statfs *)0);
50639465Smckusick }
50739465Smckusick 
50840051Smckusick static int skipvfs;
50940051Smckusick 
51040051Smckusick badvfstype(vfstype, vfslist)
51142253Sbostic 	short vfstype;
51240051Smckusick 	char **vfslist;
51340051Smckusick {
51440051Smckusick 
51540051Smckusick 	if (vfslist == 0)
51640051Smckusick 		return(0);
51740051Smckusick 	while (*vfslist) {
51840844Smckusick 		if (vfstype == getmnttype(*vfslist))
51940051Smckusick 			return(skipvfs);
52040051Smckusick 		vfslist++;
52140051Smckusick 	}
52240051Smckusick 	return (!skipvfs);
52340051Smckusick }
52440051Smckusick 
52540844Smckusick badvfsname(vfsname, vfslist)
52640844Smckusick 	char *vfsname;
52740844Smckusick 	char **vfslist;
52840844Smckusick {
52940844Smckusick 
53040844Smckusick 	if (vfslist == 0)
53140844Smckusick 		return(0);
53240844Smckusick 	while (*vfslist) {
53340844Smckusick 		if (strcmp(vfsname, *vfslist) == 0)
53440844Smckusick 			return(skipvfs);
53540844Smckusick 		vfslist++;
53640844Smckusick 	}
53740844Smckusick 	return (!skipvfs);
53840844Smckusick }
53940844Smckusick 
54040051Smckusick char **
54140051Smckusick makevfslist(fslist)
54240051Smckusick 	char *fslist;
54340051Smckusick {
54440051Smckusick 	register char **av, *nextcp;
54540051Smckusick 	register int i;
54640051Smckusick 
54740051Smckusick 	if (fslist == NULL)
54840051Smckusick 		return (NULL);
54940051Smckusick 	if (fslist[0] == 'n' && fslist[1] == 'o') {
55040051Smckusick 		fslist += 2;
55140051Smckusick 		skipvfs = 1;
55240051Smckusick 	}
55340051Smckusick 	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
55440051Smckusick 		if (*nextcp == ',')
55540051Smckusick 			i++;
55642253Sbostic 	av = (char **)malloc((size_t)(i+2) * sizeof(char *));
55740051Smckusick 	if (av == NULL)
55840051Smckusick 		return (NULL);
55940051Smckusick 	nextcp = fslist;
56040051Smckusick 	i = 0;
56140051Smckusick 	av[i++] = nextcp;
56240051Smckusick 	while (nextcp = index(nextcp, ',')) {
56340051Smckusick 		*nextcp++ = '\0';
56440051Smckusick 		av[i++] = nextcp;
56540051Smckusick 	}
56640051Smckusick 	av[i++] = 0;
56740051Smckusick 	return (av);
56840051Smckusick }
569