vfslist.c revision 114589
128671Ssteve/*-
223412Sbde * Copyright (c) 1995
323412Sbde *	The Regents of the University of California.  All rights reserved.
423412Sbde *
523412Sbde * Redistribution and use in source and binary forms, with or without
623412Sbde * modification, are permitted provided that the following conditions
723412Sbde * are met:
823412Sbde * 1. Redistributions of source code must retain the above copyright
923412Sbde *    notice, this list of conditions and the following disclaimer.
1023412Sbde * 2. Redistributions in binary form must reproduce the above copyright
1123412Sbde *    notice, this list of conditions and the following disclaimer in the
1223412Sbde *    documentation and/or other materials provided with the distribution.
1323412Sbde * 3. All advertising materials mentioning features or use of this software
1423412Sbde *    must display the following acknowledgement:
1523412Sbde *	This product includes software developed by the University of
1623412Sbde *	California, Berkeley and its contributors.
1723412Sbde * 4. Neither the name of the University nor the names of its contributors
1823412Sbde *    may be used to endorse or promote products derived from this software
1923412Sbde *    without specific prior written permission.
2023412Sbde *
2123412Sbde * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2223412Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2323412Sbde * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2423412Sbde * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2523412Sbde * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2623412Sbde * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2723412Sbde * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2823412Sbde * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2923412Sbde * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3023412Sbde * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3123412Sbde * SUCH DAMAGE.
3223412Sbde */
3323412Sbde
3423412Sbde#ifndef lint
3528671Ssteve#if 0
3623412Sbdestatic char sccsid[] = "@(#)vfslist.c	8.1 (Berkeley) 5/8/95";
3737425Scharnier#endif
3823412Sbde#endif /* not lint */
39114589Sobrien#include <sys/cdefs.h>
40114589Sobrien__FBSDID("$FreeBSD: head/sbin/mount/vfslist.c 114589 2003-05-03 18:41:59Z obrien $");
4123412Sbde
4228671Ssteve#include <err.h>
4323412Sbde#include <stdlib.h>
4423412Sbde#include <string.h>
4523412Sbde
4628671Ssteve#include "extern.h"
4728671Ssteve
4823412Sbdestatic int	  skipvfs;
4923412Sbde
5023412Sbdeint
5123412Sbdecheckvfsname(vfsname, vfslist)
5223412Sbde	const char *vfsname;
5323412Sbde	const char **vfslist;
5423412Sbde{
5523412Sbde
5623412Sbde	if (vfslist == NULL)
5723412Sbde		return (0);
5823412Sbde	while (*vfslist != NULL) {
5923412Sbde		if (strcmp(vfsname, *vfslist) == 0)
6023412Sbde			return (skipvfs);
6123412Sbde		++vfslist;
6223412Sbde	}
6323412Sbde	return (!skipvfs);
6423412Sbde}
6523412Sbde
6623412Sbdeconst char **
6723412Sbdemakevfslist(fslist)
6823412Sbde	char *fslist;
6923412Sbde{
7023412Sbde	const char **av;
7123412Sbde	int i;
7223412Sbde	char *nextcp;
7323412Sbde
7423412Sbde	if (fslist == NULL)
7523412Sbde		return (NULL);
7623412Sbde	if (fslist[0] == 'n' && fslist[1] == 'o') {
7723412Sbde		fslist += 2;
7823412Sbde		skipvfs = 1;
7923412Sbde	}
8023412Sbde	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
8123412Sbde		if (*nextcp == ',')
8223412Sbde			i++;
8323412Sbde	if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
8437425Scharnier		warnx("malloc failed");
8523412Sbde		return (NULL);
8623412Sbde	}
8723412Sbde	nextcp = fslist;
8823412Sbde	i = 0;
8923412Sbde	av[i++] = nextcp;
9023412Sbde	while ((nextcp = strchr(nextcp, ',')) != NULL) {
9123412Sbde		*nextcp++ = '\0';
9223412Sbde		av[i++] = nextcp;
9323412Sbde	}
9423412Sbde	av[i++] = NULL;
9523412Sbde	return (av);
9623412Sbde}
97