Home | History | Annotate | Line # | Download | only in mount
vfslist.c revision 1.6.24.1
      1  1.6.24.1  wrstuden /*	$NetBSD: vfslist.c,v 1.6.24.1 2008/09/18 04:28:26 wrstuden Exp $	*/
      2       1.2     lukem 
      3       1.1     lukem /*
      4       1.1     lukem  * Copyright (c) 1995
      5       1.1     lukem  *	The Regents of the University of California.  All rights reserved.
      6       1.1     lukem  *
      7       1.1     lukem  * Redistribution and use in source and binary forms, with or without
      8       1.1     lukem  * modification, are permitted provided that the following conditions
      9       1.1     lukem  * are met:
     10       1.1     lukem  * 1. Redistributions of source code must retain the above copyright
     11       1.1     lukem  *    notice, this list of conditions and the following disclaimer.
     12       1.1     lukem  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1     lukem  *    notice, this list of conditions and the following disclaimer in the
     14       1.1     lukem  *    documentation and/or other materials provided with the distribution.
     15       1.4       agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.1     lukem  *    may be used to endorse or promote products derived from this software
     17       1.1     lukem  *    without specific prior written permission.
     18       1.1     lukem  *
     19       1.1     lukem  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1     lukem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1     lukem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1     lukem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1     lukem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1     lukem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1     lukem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1     lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1     lukem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1     lukem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1     lukem  * SUCH DAMAGE.
     30       1.1     lukem  */
     31       1.1     lukem 
     32       1.2     lukem #include <sys/cdefs.h>
     33       1.1     lukem #ifndef lint
     34       1.2     lukem #if 0
     35       1.1     lukem static char sccsid[] = "@(#)vfslist.c	8.1 (Berkeley) 5/8/95";
     36       1.2     lukem #else
     37  1.6.24.1  wrstuden __RCSID("$NetBSD: vfslist.c,v 1.6.24.1 2008/09/18 04:28:26 wrstuden Exp $");
     38       1.2     lukem #endif
     39       1.1     lukem #endif /* not lint */
     40       1.1     lukem 
     41       1.2     lukem #include <err.h>
     42       1.1     lukem #include <stdlib.h>
     43       1.1     lukem #include <string.h>
     44       1.1     lukem #include <unistd.h>
     45       1.1     lukem 
     46  1.6.24.1  wrstuden #include "mountprog.h"
     47       1.3     enami 
     48       1.1     lukem static int	  skipvfs;
     49       1.1     lukem 
     50       1.1     lukem int
     51       1.5   xtraeme checkvfsname(const char *vfsname, const char **vfslist)
     52       1.1     lukem {
     53       1.1     lukem 
     54       1.1     lukem 	if (vfslist == NULL)
     55       1.1     lukem 		return (0);
     56       1.1     lukem 	while (*vfslist != NULL) {
     57       1.1     lukem 		if (strcmp(vfsname, *vfslist) == 0)
     58       1.1     lukem 			return (skipvfs);
     59       1.1     lukem 		++vfslist;
     60       1.1     lukem 	}
     61       1.1     lukem 	return (!skipvfs);
     62       1.1     lukem }
     63       1.1     lukem 
     64       1.1     lukem const char **
     65       1.6  christos makevfslist(const char *fslist)
     66       1.1     lukem {
     67       1.1     lukem 	const char **av;
     68       1.6  christos 	size_t i;
     69       1.6  christos 	char *nextcp, *fsl;
     70       1.1     lukem 
     71       1.1     lukem 	if (fslist == NULL)
     72       1.6  christos 		return NULL;
     73       1.6  christos 
     74       1.1     lukem 	if (fslist[0] == 'n' && fslist[1] == 'o') {
     75       1.1     lukem 		fslist += 2;
     76       1.1     lukem 		skipvfs = 1;
     77       1.1     lukem 	}
     78       1.6  christos 	if ((fsl = strdup(fslist)) == NULL) {
     79       1.6  christos 		warn("strdup");
     80       1.6  christos 		return NULL;
     81       1.6  christos 	}
     82       1.6  christos 	for (i = 0, nextcp = fsl; *nextcp; nextcp++)
     83       1.1     lukem 		if (*nextcp == ',')
     84       1.1     lukem 			i++;
     85       1.6  christos 	if ((av = malloc((i + 2) * sizeof(char *))) == NULL) {
     86       1.2     lukem 		warn("malloc");
     87       1.6  christos 		free(fsl);
     88       1.6  christos 		return NULL;
     89       1.1     lukem 	}
     90       1.6  christos 	nextcp = fsl;
     91       1.1     lukem 	i = 0;
     92       1.1     lukem 	av[i++] = nextcp;
     93       1.1     lukem 	while ((nextcp = strchr(nextcp, ',')) != NULL) {
     94       1.1     lukem 		*nextcp++ = '\0';
     95       1.1     lukem 		av[i++] = nextcp;
     96       1.1     lukem 	}
     97       1.1     lukem 	av[i++] = NULL;
     98       1.6  christos 	return av;
     99       1.1     lukem }
    100