Introduce ukfs_vfstypes() which returns the available file system
types loaded into rump. Now it is possible to iterate over all file system types supported by a rump program in an attempt to access an unknown file system image instead of having to know beforehand which type of file system is on the image.
This commit is contained in:
parent
0b5af21c5a
commit
541195ef5d
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: ukfs.3,v 1.2 2008/08/01 14:47:28 pooka Exp $
|
||||
.\" $NetBSD: ukfs.3,v 1.3 2008/08/01 19:52:10 pooka Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2008 Antti Kantee. All rights reserved.
|
||||
.\"
|
||||
@ -74,6 +74,10 @@ which should be released after use.
|
||||
.br
|
||||
.Fn ukfs_modload_dir "const char *dirname"
|
||||
.Pp
|
||||
.Ft ssize_t
|
||||
.br
|
||||
.Fn ukfs_vfstypes "char *buf, size_t buflen"
|
||||
.Pp
|
||||
.Ft struct ukfs *
|
||||
.br
|
||||
.Fo ukfs_mount
|
||||
@ -127,6 +131,20 @@ not just a specific instance of
|
||||
It is preferable to call them from only one thread, as the underlying
|
||||
dynamic library interfaces may not be threadsafe.
|
||||
.Pp
|
||||
.Fn ukfs_vfstypes
|
||||
queries the available file system types and returns a nul-terminated
|
||||
list of types separated by spaces in
|
||||
.Fa buf .
|
||||
The format of the list is equivalent to the one returned by
|
||||
.Xr sysctl 3
|
||||
on the name
|
||||
.Pa vfs.generic.fstypes .
|
||||
The function returns the length of the string without the trailing nul
|
||||
or \-1 for error.
|
||||
Notably, the return value 0 means there are no file systems available.
|
||||
If there is not enough room in the caller's buffer for all file system
|
||||
types, as many as fit will be returned.
|
||||
.Pp
|
||||
.Fn ukfs_mount
|
||||
intializes a file system image.
|
||||
The handle resulting from the operation is passed to all other routines
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ukfs.c,v 1.3 2008/08/01 14:47:28 pooka Exp $ */
|
||||
/* $NetBSD: ukfs.c,v 1.4 2008/08/01 19:52:10 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved.
|
||||
@ -42,6 +42,8 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
@ -656,6 +658,47 @@ ukfs_modload_dir(const char *dir)
|
||||
return nloaded;
|
||||
}
|
||||
|
||||
/* XXX: this code uses definitions from NetBSD, needs rumpdefs */
|
||||
ssize_t
|
||||
ukfs_vfstypes(char *buf, size_t buflen)
|
||||
{
|
||||
int mib[3];
|
||||
struct sysctlnode q, ans[128];
|
||||
size_t alen;
|
||||
int error, i;
|
||||
|
||||
mib[0] = CTL_VFS;
|
||||
mib[1] = VFS_GENERIC;
|
||||
mib[2] = CTL_QUERY;
|
||||
alen = sizeof(ans);
|
||||
|
||||
memset(&q, 0, sizeof(q));
|
||||
q.sysctl_flags = SYSCTL_VERSION;
|
||||
|
||||
if (rump_sys___sysctl(mib, 3, ans, &alen, &q, sizeof(q), &error) == -1){
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < alen/sizeof(ans[0]); i++)
|
||||
if (strcmp("fstypes", ans[i].sysctl_name) == 0)
|
||||
break;
|
||||
if (i == alen/sizeof(ans[0])) {
|
||||
errno = ENXIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mib[0] = CTL_VFS;
|
||||
mib[1] = VFS_GENERIC;
|
||||
mib[2] = ans[i].sysctl_num;
|
||||
|
||||
if (rump_sys___sysctl(mib, 3, buf, &buflen, NULL, 0, &error) == -1) {
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return buflen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Utilities
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ukfs.h,v 1.5 2008/08/01 14:50:28 pooka Exp $ */
|
||||
/* $NetBSD: ukfs.h,v 1.6 2008/08/01 19:52:11 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved.
|
||||
@ -95,6 +95,7 @@ struct vnode *ukfs_getrvp(struct ukfs *);
|
||||
/* dynamic loading of library modules */
|
||||
int ukfs_modload(const char *);
|
||||
int ukfs_modload_dir(const char *);
|
||||
ssize_t ukfs_vfstypes(char *, size_t);
|
||||
|
||||
/* Utilities */
|
||||
int ukfs_util_builddirs(struct ukfs *, const char *, mode_t);
|
||||
|
Loading…
Reference in New Issue
Block a user