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 * 4. Neither the name of the University nor the names of its contributors 1408f68ac6SBruce Evans * may be used to endorse or promote products derived from this software 1508f68ac6SBruce Evans * without specific prior written permission. 1608f68ac6SBruce Evans * 1708f68ac6SBruce Evans * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1808f68ac6SBruce Evans * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1908f68ac6SBruce Evans * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2008f68ac6SBruce Evans * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2108f68ac6SBruce Evans * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2208f68ac6SBruce Evans * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2308f68ac6SBruce Evans * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2408f68ac6SBruce Evans * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2508f68ac6SBruce Evans * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2608f68ac6SBruce Evans * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2708f68ac6SBruce Evans * SUCH DAMAGE. 2808f68ac6SBruce Evans */ 2908f68ac6SBruce Evans 30ea8d448aSDavid E. O'Brien #if defined(LIBC_SCCS) && !defined(lint) 3108f68ac6SBruce Evans static char sccsid[] = "@(#)kvm_getvfsbyname.c 8.1 (Berkeley) 4/3/95"; 32ea8d448aSDavid E. O'Brien #endif /* LIBC_SCCS and not lint */ 33ea8d448aSDavid E. O'Brien #include <sys/cdefs.h> 34ea8d448aSDavid E. O'Brien __FBSDID("$FreeBSD$"); 3508f68ac6SBruce Evans 3608f68ac6SBruce Evans #include <sys/param.h> 3708f68ac6SBruce Evans #include <sys/mount.h> 3808f68ac6SBruce Evans #include <sys/sysctl.h> 3908f68ac6SBruce Evans #include <errno.h> 405965373eSMaxime Henrion #include <stdlib.h> 415965373eSMaxime Henrion #include <string.h> 4208f68ac6SBruce Evans 4308f68ac6SBruce Evans /* 4408f68ac6SBruce Evans * Given a filesystem name, determine if it is resident in the kernel, 455965373eSMaxime Henrion * and if it is resident, return its xvfsconf structure. 4608f68ac6SBruce Evans */ 475965373eSMaxime Henrion int 48*55b6b759SCraig Rodrigues getvfsbyname(const char *fsname, struct xvfsconf *vfcp) 4908f68ac6SBruce Evans { 505965373eSMaxime Henrion struct xvfsconf *xvfsp; 5108f68ac6SBruce Evans size_t buflen; 525965373eSMaxime Henrion int cnt, i; 5308f68ac6SBruce Evans 545965373eSMaxime Henrion if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) 5508f68ac6SBruce Evans return (-1); 565965373eSMaxime Henrion xvfsp = malloc(buflen); 575965373eSMaxime Henrion if (xvfsp == NULL) 5808f68ac6SBruce Evans return (-1); 595965373eSMaxime Henrion if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) { 605965373eSMaxime Henrion free(xvfsp); 615965373eSMaxime Henrion return (-1); 6208f68ac6SBruce Evans } 635965373eSMaxime Henrion cnt = buflen / sizeof(struct xvfsconf); 645965373eSMaxime Henrion for (i = 0; i < cnt; i++) { 655965373eSMaxime Henrion if (strcmp(fsname, xvfsp[i].vfc_name) == 0) { 665965373eSMaxime Henrion memcpy(vfcp, xvfsp + i, sizeof(struct xvfsconf)); 675965373eSMaxime Henrion free(xvfsp); 6808f68ac6SBruce Evans return (0); 6908f68ac6SBruce Evans } 705965373eSMaxime Henrion } 715965373eSMaxime Henrion free(xvfsp); 7208f68ac6SBruce Evans errno = ENOENT; 7308f68ac6SBruce Evans return (-1); 7408f68ac6SBruce Evans } 75