diff --git a/lib/libukfs/ukfs.3 b/lib/libukfs/ukfs.3 index fa78c6738d05..4f6ff1d9d3ef 100644 --- a/lib/libukfs/ukfs.3 +++ b/lib/libukfs/ukfs.3 @@ -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 diff --git a/lib/libukfs/ukfs.c b/lib/libukfs/ukfs.c index 5219cde0232f..f7080e978f23 100644 --- a/lib/libukfs/ukfs.c +++ b/lib/libukfs/ukfs.c @@ -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 #include #include +#include +#include #include #include @@ -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 diff --git a/lib/libukfs/ukfs.h b/lib/libukfs/ukfs.h index d9168dbe3414..e1717c8b1478 100644 --- a/lib/libukfs/ukfs.h +++ b/lib/libukfs/ukfs.h @@ -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);