xref: /freebsd/sbin/mount/vfslist.c (revision ac413189f53524e489c900b3cfaa80a1552875ca)
1fba1c154SSteve Price /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
492e2d9beSBruce Evans  * Copyright (c) 1995
592e2d9beSBruce Evans  *	The Regents of the University of California.  All rights reserved.
692e2d9beSBruce Evans  *
792e2d9beSBruce Evans  * Redistribution and use in source and binary forms, with or without
892e2d9beSBruce Evans  * modification, are permitted provided that the following conditions
992e2d9beSBruce Evans  * are met:
1092e2d9beSBruce Evans  * 1. Redistributions of source code must retain the above copyright
1192e2d9beSBruce Evans  *    notice, this list of conditions and the following disclaimer.
1292e2d9beSBruce Evans  * 2. Redistributions in binary form must reproduce the above copyright
1392e2d9beSBruce Evans  *    notice, this list of conditions and the following disclaimer in the
1492e2d9beSBruce Evans  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
1692e2d9beSBruce Evans  *    may be used to endorse or promote products derived from this software
1792e2d9beSBruce Evans  *    without specific prior written permission.
1892e2d9beSBruce Evans  *
1992e2d9beSBruce Evans  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2092e2d9beSBruce Evans  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2192e2d9beSBruce Evans  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2292e2d9beSBruce Evans  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2392e2d9beSBruce Evans  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2492e2d9beSBruce Evans  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2592e2d9beSBruce Evans  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2692e2d9beSBruce Evans  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2792e2d9beSBruce Evans  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2892e2d9beSBruce Evans  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2992e2d9beSBruce Evans  * SUCH DAMAGE.
3092e2d9beSBruce Evans  */
3192e2d9beSBruce Evans 
3292e2d9beSBruce Evans #ifndef lint
33fba1c154SSteve Price #if 0
3492e2d9beSBruce Evans static char sccsid[] = "@(#)vfslist.c	8.1 (Berkeley) 5/8/95";
35bcb1d846SPhilippe Charnier #endif
3692e2d9beSBruce Evans #endif /* not lint */
37c69284caSDavid E. O'Brien #include <sys/cdefs.h>
38c69284caSDavid E. O'Brien __FBSDID("$FreeBSD$");
3992e2d9beSBruce Evans 
40fba1c154SSteve Price #include <err.h>
4192e2d9beSBruce Evans #include <stdlib.h>
4292e2d9beSBruce Evans #include <string.h>
4392e2d9beSBruce Evans 
44fba1c154SSteve Price #include "extern.h"
45fba1c154SSteve Price 
4692e2d9beSBruce Evans static int	  skipvfs;
4792e2d9beSBruce Evans 
4892e2d9beSBruce Evans int
4910bc3a7fSEd Schouten checkvfsname(const char *vfsname, const char **vfslist)
5092e2d9beSBruce Evans {
5192e2d9beSBruce Evans 
5292e2d9beSBruce Evans 	if (vfslist == NULL)
5392e2d9beSBruce Evans 		return (0);
5492e2d9beSBruce Evans 	while (*vfslist != NULL) {
5592e2d9beSBruce Evans 		if (strcmp(vfsname, *vfslist) == 0)
5692e2d9beSBruce Evans 			return (skipvfs);
5792e2d9beSBruce Evans 		++vfslist;
5892e2d9beSBruce Evans 	}
5992e2d9beSBruce Evans 	return (!skipvfs);
6092e2d9beSBruce Evans }
6192e2d9beSBruce Evans 
6292e2d9beSBruce Evans const char **
6310bc3a7fSEd Schouten makevfslist(char *fslist)
6492e2d9beSBruce Evans {
6592e2d9beSBruce Evans 	const char **av;
6692e2d9beSBruce Evans 	int i;
6792e2d9beSBruce Evans 	char *nextcp;
6892e2d9beSBruce Evans 
6992e2d9beSBruce Evans 	if (fslist == NULL)
7092e2d9beSBruce Evans 		return (NULL);
71*ac413189SStefan Eßer 	skipvfs = 0;
7292e2d9beSBruce Evans 	if (fslist[0] == 'n' && fslist[1] == 'o') {
7392e2d9beSBruce Evans 		fslist += 2;
7492e2d9beSBruce Evans 		skipvfs = 1;
7592e2d9beSBruce Evans 	}
7692e2d9beSBruce Evans 	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
7792e2d9beSBruce Evans 		if (*nextcp == ',')
7892e2d9beSBruce Evans 			i++;
7992e2d9beSBruce Evans 	if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
80bcb1d846SPhilippe Charnier 		warnx("malloc failed");
8192e2d9beSBruce Evans 		return (NULL);
8292e2d9beSBruce Evans 	}
8392e2d9beSBruce Evans 	nextcp = fslist;
8492e2d9beSBruce Evans 	i = 0;
8592e2d9beSBruce Evans 	av[i++] = nextcp;
8692e2d9beSBruce Evans 	while ((nextcp = strchr(nextcp, ',')) != NULL) {
8792e2d9beSBruce Evans 		*nextcp++ = '\0';
8892e2d9beSBruce Evans 		av[i++] = nextcp;
8992e2d9beSBruce Evans 	}
9092e2d9beSBruce Evans 	av[i++] = NULL;
9192e2d9beSBruce Evans 	return (av);
9292e2d9beSBruce Evans }
93