From f95dcdd6179cc05aea6cf9ed83c94d7259d0f460 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 21 Nov 2025 12:51:59 -0500 Subject: kern: vfs: Add initial mountpoint lookup helper Signed-off-by: Ian Moffett --- sys/inc/os/mount.h | 10 ++++++++++ sys/kern/vfs_mount.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/sys/inc/os/mount.h b/sys/inc/os/mount.h index 799c14f..1c3dde6 100644 --- a/sys/inc/os/mount.h +++ b/sys/inc/os/mount.h @@ -93,4 +93,14 @@ struct mount { */ int mount(struct mount_args *margs); +/* + * Lookup an entry within the mount table + * + * @name: Name to lookup + * @mres: Result pointer is written here + * + * Returns zero on success + */ +int mount_lookup(const char *name, struct mount **mres); + #endif /* !_OS_MOUNT_H_ */ diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 909a618..02c7308 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -35,6 +35,7 @@ #include #include #include +#include #include /* @@ -114,3 +115,40 @@ mount(struct mount_args *margs) spinlock_release(&mount_lock, false); return 0; } + +/* + * XXX: Currently we are looking up entries by the fstype. + * This must be updated to actual name-based lookups + * in future revisions of rv7 + */ +int +mount_lookup(const char *name, struct mount **mres) +{ + struct fs_info *fip; + struct mount *iter, *mount = NULL; + + if (name == NULL || mres == NULL) { + return -EINVAL; + } + + spinlock_acquire(&mount_lock, false); + TAILQ_FOREACH(iter, &mountlist, link) { + fip = iter->fip; + if (__likely(*name != *fip->name)) { + continue; + } + + if (strcmp(fip->name, name) == 0) { + mount = iter; + break; + } + } + + spinlock_release(&mount_lock, false); + if (mount == NULL) { + return -ENOENT; + } + + *mres = mount; + return 0; +} -- cgit v1.2.3