summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-21 19:15:04 -0400
committerIan Moffett <ian@osmora.org>2025-09-21 19:15:04 -0400
commiteb2f777e0c1bd727b6064d5f0623790ca341d6df (patch)
tree7c5e9ae7cde61c974f2a4589daa421bdbdba6040
parente6e0bb0d435b3410d520baea60652af05cae8232 (diff)
kern: vfs: Add lookup by name helper
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--src/sys/include/os/vfs.h11
-rw-r--r--src/sys/os/vfs_init.c26
2 files changed, 37 insertions, 0 deletions
diff --git a/src/sys/include/os/vfs.h b/src/sys/include/os/vfs.h
index a46bb18..e08a9f0 100644
--- a/src/sys/include/os/vfs.h
+++ b/src/sys/include/os/vfs.h
@@ -43,6 +43,17 @@
int vfs_init(void);
/*
+ * Get a VFS file table entry by name
+ *
+ * @name: Name of desired entry
+ * @resp: Result pointer is written here
+ *
+ * Returns zero on success, otherwise a less than zero
+ * value upon failure.
+ */
+int vfs_by_name(const char *name, struct fs_info **resp);
+
+/*
* Get a VFS file table entry by index.
*
* @index: Index to desired entry
diff --git a/src/sys/os/vfs_init.c b/src/sys/os/vfs_init.c
index b40b74d..496fb67 100644
--- a/src/sys/os/vfs_init.c
+++ b/src/sys/os/vfs_init.c
@@ -32,6 +32,7 @@
#include <sys/param.h>
#include <sys/mount.h>
#include <os/vfs.h>
+#include <string.h>
/*
* The filesystem table
@@ -41,6 +42,31 @@ static struct fs_info fstab[] = {
};
/*
+ * Get entry by name
+ */
+int
+vfs_by_name(const char *name, struct fs_info **resp)
+{
+ size_t nelem;
+ int retval = -ENOENT;
+
+ if (name == NULL || resp == NULL) {
+ return -EINVAL;
+ }
+
+ nelem = NELEM(fstab);
+ for (int i = 0; i < nelem; ++i) {
+ if (strcmp(fstab[i].name, name) == 0) {
+ *resp = &fstab[i];
+ retval = 0;
+ break;
+ }
+ }
+
+ return retval;
+}
+
+/*
* Get entry by index
*/
int