123291Sbde/*
223291Sbde * Copyright (c) 1995
323291Sbde *	The Regents of the University of California.  All rights reserved.
423291Sbde *
523291Sbde * Redistribution and use in source and binary forms, with or without
623291Sbde * modification, are permitted provided that the following conditions
723291Sbde * are met:
823291Sbde * 1. Redistributions of source code must retain the above copyright
923291Sbde *    notice, this list of conditions and the following disclaimer.
1023291Sbde * 2. Redistributions in binary form must reproduce the above copyright
1123291Sbde *    notice, this list of conditions and the following disclaimer in the
1223291Sbde *    documentation and/or other materials provided with the distribution.
1323291Sbde * 4. Neither the name of the University nor the names of its contributors
1423291Sbde *    may be used to endorse or promote products derived from this software
1523291Sbde *    without specific prior written permission.
1623291Sbde *
1723291Sbde * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1823291Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1923291Sbde * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2023291Sbde * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2123291Sbde * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2223291Sbde * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323291Sbde * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2423291Sbde * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2523291Sbde * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2623291Sbde * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2723291Sbde * SUCH DAMAGE.
2823291Sbde */
2923291Sbde
3090039Sobrien#if defined(LIBC_SCCS) && !defined(lint)
3123291Sbdestatic char sccsid[] = "@(#)kvm_getvfsbyname.c	8.1 (Berkeley) 4/3/95";
3290039Sobrien#endif /* LIBC_SCCS and not lint */
3390039Sobrien#include <sys/cdefs.h>
3490039Sobrien__FBSDID("$FreeBSD: releng/10.3/lib/libc/gen/getvfsbyname.c 165903 2007-01-09 00:28:16Z imp $");
3523291Sbde
3623291Sbde#include <sys/param.h>
3723291Sbde#include <sys/mount.h>
3823291Sbde#include <sys/sysctl.h>
3923291Sbde#include <errno.h>
40101651Smux#include <stdlib.h>
41101651Smux#include <string.h>
4223291Sbde
4323291Sbde/*
4423291Sbde * Given a filesystem name, determine if it is resident in the kernel,
45101651Smux * and if it is resident, return its xvfsconf structure.
4623291Sbde */
47101651Smuxint
4823291Sbdegetvfsbyname(fsname, vfcp)
4923291Sbde	const char *fsname;
50101651Smux	struct xvfsconf *vfcp;
5123291Sbde{
52101651Smux	struct xvfsconf *xvfsp;
5323291Sbde	size_t buflen;
54101651Smux	int cnt, i;
5523291Sbde
56101651Smux	if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
5723291Sbde		return (-1);
58101651Smux	xvfsp = malloc(buflen);
59101651Smux	if (xvfsp == NULL)
60101651Smux		return (-1);
61101651Smux	if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) {
62101651Smux		free(xvfsp);
63101651Smux		return (-1);
64101651Smux	}
65101651Smux	cnt = buflen / sizeof(struct xvfsconf);
66101651Smux	for (i = 0; i < cnt; i++) {
67101651Smux		if (strcmp(fsname, xvfsp[i].vfc_name) == 0) {
68101651Smux			memcpy(vfcp, xvfsp + i, sizeof(struct xvfsconf));
69101651Smux			free(xvfsp);
70101651Smux			return (0);
7123291Sbde		}
7223291Sbde	}
73101651Smux	free(xvfsp);
7423291Sbde	errno = ENOENT;
7523291Sbde	return (-1);
7623291Sbde}
77