summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-07-11 21:30:28 -0400
committerIan Moffett <ian@osmora.org>2024-07-11 21:30:28 -0400
commitb0af158b666cf58bbdc6c6a73328052be43d99bf (patch)
tree79104dd5f247e5083d605f18befd7f23004bbaee /sys
parent45ad7c0c7b86f7abbc5ce0d13fb947dca1645316 (diff)
kernel: vfs: Implement mountpoint naming
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/include/sys/mount.h4
-rw-r--r--sys/kern/vfs_subr.c23
2 files changed, 27 insertions, 0 deletions
diff --git a/sys/include/sys/mount.h b/sys/include/sys/mount.h
index e46cda9..e12b880 100644
--- a/sys/include/sys/mount.h
+++ b/sys/include/sys/mount.h
@@ -39,6 +39,7 @@
#if defined(_KERNEL)
#define FS_NAME_MAX 16 /* Length of fs name including nul */
+#define NAME_MAX 256 /* Max name of filename (not including nul) */
/*
* Filesystem types.
@@ -56,6 +57,7 @@ extern mountlist_t g_mountlist;
extern const struct vfsops g_initramfs_vfsops;
struct mount {
+ char *name;
struct spinlock lock;
struct vnode *vp;
const struct vfsops *mnt_ops;
@@ -77,6 +79,8 @@ struct vfsops {
};
void vfs_init(void);
+int vfs_name_mount(struct mount *mp, const char *name);
+
struct mount *vfs_alloc_mount(struct vnode *vp, struct fs_info *fip);
struct fs_info *vfs_byname(const char *name);
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 0d4be72..cbcf7c5 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -74,6 +74,29 @@ vfs_alloc_mount(struct vnode *vp, struct fs_info *fip)
}
/*
+ * Assign a name to a mountpoint.
+ *
+ * @mp: Mountpoint to name.
+ * @name: Name to give.
+ */
+int
+vfs_name_mount(struct mount *mp, const char *name)
+{
+ size_t name_len = strlen(name);
+
+ if (name_len > NAME_MAX)
+ return -ENAMETOOLONG;
+
+ mp->name = dynalloc(sizeof(char) * name_len + 1);
+ if (mp->name == NULL)
+ return -ENOMEM;
+
+ memcpy(mp->name, name, name_len);
+ mp->name[name_len] = '\0';
+ return 0;
+}
+
+/*
* Release a vnode and its resources from
* memory.
*/