From 5b6085504086f72939306337dfec01698b1a92cb Mon Sep 17 00:00:00 2001 From: Kaimakan71 Date: Sat, 27 Apr 2024 09:21:31 -0400 Subject: kernel: vfs: Implement sys_mount() Signed-off-by: Kaimakan71 Signed-off-by: Ian Moffett --- sys/include/sys/syscall.h | 1 + sys/include/sys/vfs.h | 2 ++ sys/kern/kern_syscall.c | 2 ++ sys/kern/vfs_mount.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) (limited to 'sys') diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h index a2ca992..6a102aa 100644 --- a/sys/include/sys/syscall.h +++ b/sys/include/sys/syscall.h @@ -47,6 +47,7 @@ enum { SYS_munmap, SYS_ioctl, SYS_execv, + SYS_mount, __MAX_SYSCALLS }; diff --git a/sys/include/sys/vfs.h b/sys/include/sys/vfs.h index a55af12..98c784f 100644 --- a/sys/include/sys/vfs.h +++ b/sys/include/sys/vfs.h @@ -55,6 +55,8 @@ ssize_t vfs_read(struct vnode *vp, struct sio_txn *sio); ssize_t vfs_write(struct vnode *vp, struct sio_txn *sio); int vfs_getattr(struct vnode *vp, struct vattr *vattr); +uint64_t sys_mount(struct syscall_args *args); + #endif /* defined(_KERNEL) */ #endif /* !_SYS_VFS_H_ */ diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c index 0461977..9faa5af 100644 --- a/sys/kern/kern_syscall.c +++ b/sys/kern/kern_syscall.c @@ -34,6 +34,7 @@ #include #include #include +#include #include uint64_t(*g_syscall_table[__MAX_SYSCALLS])(struct syscall_args *args) = { @@ -47,4 +48,5 @@ uint64_t(*g_syscall_table[__MAX_SYSCALLS])(struct syscall_args *args) = { sys_munmap, sys_ioctl, sys_execv, + sys_mount }; diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 84985bf..25ad17d 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -34,6 +34,7 @@ #include #include #include +#include /* TODO: Make this more flexible */ #define MOUNTLIST_SIZE 8 @@ -60,6 +61,49 @@ vfs_create_mp(const char *path, int mntflags, struct mount **mp_out) return 0; } +static int +mount(const char *source, const char *target, const char *filesystemtype, + unsigned long mountflags, const void *data) +{ + struct fs_info *info; + int status; + + if (source == NULL || target == NULL || filesystemtype == NULL) + return -EFAULT; + + /* + * Check mount flags. + * + * XXX: No flags implemented yet. + */ + if (mountflags != 0) + return -EINVAL; + + /* + * Locate source. + * + * XXX: Only "none" is currently supported. + */ + if (strcmp(source, "none") != 0) + return -ENOENT; + + /* Locate filesystem */ + info = vfs_byname(filesystemtype); + if (info == NULL) + return -ENODEV; + + /* Create mount point */ + status = vfs_mount(target, 0, info); + if (status != 0) + return status; + + /* Initialize filesystem if needed */ + if (info->vfsops->init != NULL) + return info->vfsops->init(info); + + return 0; +} + /* * Mount a mountpoint * @@ -162,3 +206,10 @@ vfs_mount_init(void) TAILQ_INIT(&mountlist[i].buckets); } } + +uint64_t +sys_mount(struct syscall_args *args) +{ + return mount((void *)args->arg0, (void *)args->arg1, (void *)args->arg2, + (unsigned long)args->arg3, (void *)args->arg4); +} -- cgit v1.2.3