From 017a6a964c06eb8a3dbe30281d5a3bb3ac8f3ca5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 19 Sep 2025 01:41:56 -0400 Subject: kernel: mount: Add mountpoint allocation Signed-off-by: Ian Moffett --- src/sys/include/sys/mount.h | 11 +++++++++++ src/sys/os/vfs_mount.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'src') diff --git a/src/sys/include/sys/mount.h b/src/sys/include/sys/mount.h index c2beb8d..0296b70 100644 --- a/src/sys/include/sys/mount.h +++ b/src/sys/include/sys/mount.h @@ -133,5 +133,16 @@ int mount(struct mount_args *margs, uint32_t flags); */ int mountlist_init(struct mountlist *mlp); +/* + * Allocate a new mountpoint + * + * @name: The name to allocate mountpoint as + * @mp_res: Result pointer is written here + * + * Returns zero on success, otherwise a less than + * zero value to indicate failure. + */ +int mount_alloc(const char *name, struct mount **mp_res); + #endif /* !_KERNEL */ #endif /* !_SYS_MOUNT_H_ */ diff --git a/src/sys/os/vfs_mount.c b/src/sys/os/vfs_mount.c index f1d7ffd..69aec10 100644 --- a/src/sys/os/vfs_mount.c +++ b/src/sys/os/vfs_mount.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,34 @@ */ static struct mountlist root; + +/* + * Allocate a new mountpoint + */ +int +mount_alloc(const char *name, struct mount **mp_res) +{ + struct mount *mp; + size_t len, slen; + + if (mp_res == NULL || name == NULL) { + return -EINVAL; + } + + mp = kalloc(sizeof(*mp)); + if (mp == NULL) { + printf("mount_alloc: allocation failure\n"); + return -ENOMEM; + } + + slen = strlen(name); + len = MIN(sizeof(mp->name), slen); + memcpy(mp->name, name, len); + + *mp_res = mp; + return 0; +} + /* * Mount a filesystem */ -- cgit v1.2.3