1994-09-22 01:07:37 +00:00
|
|
|
/*
|
|
|
|
* getvfsent.c - get a listing of installed filesystems
|
|
|
|
* Written September 1994 by Garrett A. Wollman
|
|
|
|
* This file is in the public domain.
|
2001-01-24 13:01:12 +00:00
|
|
|
*
|
1994-09-22 01:07:37 +00:00
|
|
|
*/
|
|
|
|
|
2002-02-01 00:57:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-09-22 01:07:37 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <paths.h>
|
|
|
|
|
1998-01-20 10:36:24 +00:00
|
|
|
/* XXX hide some compatibility problems. */
|
|
|
|
#define vfsconf ovfsconf
|
|
|
|
|
1994-09-22 01:07:37 +00:00
|
|
|
static struct vfsconf *_vfslist = 0;
|
|
|
|
static struct vfsconf _vfsconf;
|
|
|
|
static size_t _vfslistlen = 0;
|
|
|
|
static int _vfs_keeplist = 0;
|
|
|
|
static int _vfs_index = 0;
|
|
|
|
|
|
|
|
static int
|
|
|
|
initvfs(void)
|
|
|
|
{
|
1996-03-11 03:06:45 +00:00
|
|
|
int mib[2] = { CTL_VFS, VFS_VFSCONF };
|
1994-09-22 01:07:37 +00:00
|
|
|
size_t size = 0;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = sysctl(mib, 2, (void *)0, &size, (void *)0, (size_t)0);
|
|
|
|
if(rv < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(_vfslist)
|
|
|
|
free(_vfslist);
|
|
|
|
_vfslist = malloc(size);
|
|
|
|
if(!_vfslist)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rv = sysctl(mib, 2, _vfslist, &size, (void *)0, (size_t)0);
|
|
|
|
if(rv < 0) {
|
|
|
|
free(_vfslist);
|
|
|
|
_vfslist = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vfslistlen = size / sizeof _vfslist[0];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct vfsconf *
|
|
|
|
getvfsent(void)
|
|
|
|
{
|
|
|
|
if(!_vfslist && !initvfs()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
1996-10-26 21:53:21 +00:00
|
|
|
if(_vfs_index >= _vfslistlen) {
|
1994-09-22 01:07:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vfsconf = _vfslist[_vfs_index++];
|
|
|
|
} while(!_vfsconf.vfc_vfsops);
|
|
|
|
|
|
|
|
if(!_vfs_keeplist) {
|
|
|
|
free(_vfslist);
|
|
|
|
_vfslist = 0;
|
|
|
|
}
|
|
|
|
return &_vfsconf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct vfsconf *
|
|
|
|
getvfsbytype(int type)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!_vfslist && !initvfs()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < _vfslistlen; i++) {
|
1997-03-03 05:53:54 +00:00
|
|
|
if(_vfslist[i].vfc_index == type)
|
1994-09-22 01:07:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1994-09-22 02:17:26 +00:00
|
|
|
if(i < _vfslistlen) {
|
|
|
|
_vfsconf = _vfslist[i];
|
|
|
|
}
|
|
|
|
|
1994-09-22 01:07:37 +00:00
|
|
|
if(!_vfs_keeplist) {
|
|
|
|
free(_vfslist);
|
|
|
|
_vfslist = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i < _vfslistlen) {
|
|
|
|
return &_vfsconf;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setvfsent(int keep)
|
|
|
|
{
|
|
|
|
if(_vfslist && !keep) {
|
|
|
|
free(_vfslist);
|
|
|
|
_vfslist = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vfs_keeplist = keep;
|
|
|
|
_vfs_index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
endvfsent(void)
|
|
|
|
{
|
|
|
|
if(_vfslist) {
|
|
|
|
free(_vfslist);
|
|
|
|
_vfslist = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vfs_index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vfsisloadable(const char *name)
|
|
|
|
{
|
1998-11-03 15:02:29 +00:00
|
|
|
return 1;
|
1994-09-22 01:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vfsload(const char *name)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
1998-11-03 15:02:29 +00:00
|
|
|
status = kldload(name);
|
1999-04-19 14:28:45 +00:00
|
|
|
return status == -1 ? status : 0;
|
1994-09-22 01:07:37 +00:00
|
|
|
}
|
|
|
|
|