xref: /freebsd/lib/libc/gen/getvfsbyname.c (revision 08f68ac6a66df647cee8640b16e4aa944c137968)
108f68ac6SBruce Evans /*
208f68ac6SBruce Evans  * Copyright (c) 1995
308f68ac6SBruce Evans  *	The Regents of the University of California.  All rights reserved.
408f68ac6SBruce Evans  *
508f68ac6SBruce Evans  * Redistribution and use in source and binary forms, with or without
608f68ac6SBruce Evans  * modification, are permitted provided that the following conditions
708f68ac6SBruce Evans  * are met:
808f68ac6SBruce Evans  * 1. Redistributions of source code must retain the above copyright
908f68ac6SBruce Evans  *    notice, this list of conditions and the following disclaimer.
1008f68ac6SBruce Evans  * 2. Redistributions in binary form must reproduce the above copyright
1108f68ac6SBruce Evans  *    notice, this list of conditions and the following disclaimer in the
1208f68ac6SBruce Evans  *    documentation and/or other materials provided with the distribution.
1308f68ac6SBruce Evans  * 3. All advertising materials mentioning features or use of this software
1408f68ac6SBruce Evans  *    must display the following acknowledgement:
1508f68ac6SBruce Evans  *	This product includes software developed by the University of
1608f68ac6SBruce Evans  *	California, Berkeley and its contributors.
1708f68ac6SBruce Evans  * 4. Neither the name of the University nor the names of its contributors
1808f68ac6SBruce Evans  *    may be used to endorse or promote products derived from this software
1908f68ac6SBruce Evans  *    without specific prior written permission.
2008f68ac6SBruce Evans  *
2108f68ac6SBruce Evans  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2208f68ac6SBruce Evans  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2308f68ac6SBruce Evans  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2408f68ac6SBruce Evans  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2508f68ac6SBruce Evans  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2608f68ac6SBruce Evans  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2708f68ac6SBruce Evans  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2808f68ac6SBruce Evans  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2908f68ac6SBruce Evans  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3008f68ac6SBruce Evans  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3108f68ac6SBruce Evans  * SUCH DAMAGE.
3208f68ac6SBruce Evans  */
3308f68ac6SBruce Evans 
3408f68ac6SBruce Evans #ifndef lint
3508f68ac6SBruce Evans static char sccsid[] = "@(#)kvm_getvfsbyname.c	8.1 (Berkeley) 4/3/95";
3608f68ac6SBruce Evans #endif /* not lint */
3708f68ac6SBruce Evans 
3808f68ac6SBruce Evans #include <sys/param.h>
3908f68ac6SBruce Evans #include <sys/mount.h>
4008f68ac6SBruce Evans #include <sys/sysctl.h>
4108f68ac6SBruce Evans #include <errno.h>
4208f68ac6SBruce Evans #include <kvm.h>
4308f68ac6SBruce Evans 
4408f68ac6SBruce Evans int getvfsbyname __P((const char *, struct vfsconf *));
4508f68ac6SBruce Evans 
4608f68ac6SBruce Evans /*
4708f68ac6SBruce Evans  * Given a filesystem name, determine if it is resident in the kernel,
4808f68ac6SBruce Evans  * and if it is resident, return its vfsconf structure.
4908f68ac6SBruce Evans  */
5008f68ac6SBruce Evans getvfsbyname(fsname, vfcp)
5108f68ac6SBruce Evans 	const char *fsname;
5208f68ac6SBruce Evans 	struct vfsconf *vfcp;
5308f68ac6SBruce Evans {
5408f68ac6SBruce Evans 	int name[4], maxtypenum, cnt;
5508f68ac6SBruce Evans 	size_t buflen;
5608f68ac6SBruce Evans 
5708f68ac6SBruce Evans 	name[0] = CTL_VFS;
5808f68ac6SBruce Evans 	name[1] = VFS_GENERIC;
5908f68ac6SBruce Evans 	name[2] = VFS_MAXTYPENUM;
6008f68ac6SBruce Evans 	buflen = 4;
6108f68ac6SBruce Evans 	if (sysctl(name, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0)
6208f68ac6SBruce Evans 		return (-1);
6308f68ac6SBruce Evans 	name[2] = VFS_CONF;
6408f68ac6SBruce Evans 	buflen = sizeof *vfcp;
6508f68ac6SBruce Evans 	for (cnt = 0; cnt < maxtypenum; cnt++) {
6608f68ac6SBruce Evans 		name[3] = cnt;
6708f68ac6SBruce Evans 		if (sysctl(name, 4, vfcp, &buflen, (void *)0, (size_t)0) < 0) {
6808f68ac6SBruce Evans 			if (errno != EOPNOTSUPP)
6908f68ac6SBruce Evans 				return (-1);
7008f68ac6SBruce Evans 			continue;
7108f68ac6SBruce Evans 		}
7208f68ac6SBruce Evans 		if (!strcmp(fsname, vfcp->vfc_name))
7308f68ac6SBruce Evans 			return (0);
7408f68ac6SBruce Evans 	}
7508f68ac6SBruce Evans 	errno = ENOENT;
7608f68ac6SBruce Evans 	return (-1);
7708f68ac6SBruce Evans }
78