summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-06 17:46:47 -0400
committerIan Moffett <ian@osmora.org>2025-10-06 17:47:12 -0400
commit059b2450fb71520e9d0ee1e26dd5bb48c9b6ddf7 (patch)
tree320dc8ad1205bacc86143a7bbb3918bb1925318b /src/sys
parente8723abcad202fc12c3e32879c9865bae524e9ce (diff)
kern: syscall: Add SYS_mount syscall
This commit introduces the system call for mounting filesystems. As of now, only the fstype and target params are supported Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/compat/unix/os/os_filedesc.c49
-rw-r--r--src/sys/include/compat/unix/syscall.h4
-rw-r--r--src/sys/include/sys/mount.h31
-rw-r--r--src/sys/include/sys/syscall.h1
-rw-r--r--src/sys/os/vfs_mount.c4
5 files changed, 76 insertions, 13 deletions
diff --git a/src/sys/compat/unix/os/os_filedesc.c b/src/sys/compat/unix/os/os_filedesc.c
index 86bb62b..48ea6be 100644
--- a/src/sys/compat/unix/os/os_filedesc.c
+++ b/src/sys/compat/unix/os/os_filedesc.c
@@ -28,14 +28,15 @@
*/
#include <sys/syscall.h>
+#include <sys/limits.h>
+#include <sys/syslog.h>
+#include <sys/mount.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <os/systm.h>
#include <os/filedesc.h>
#include <compat/unix/syscall.h>
-#include <sys/syslog.h>
-
/*
* Write syscall
*
@@ -60,3 +61,47 @@ sys_write(struct syscall_args *scargs)
return write(fd, kbuf, count);
}
+
+/*
+ * ARG0: Source
+ * ARG1: Target
+ * ARG2: Filesystem type
+ * ARG3: Mountflags
+ * ARG4: Data
+ */
+scret_t
+sys_mount(struct syscall_args *scargs)
+{
+ struct mount_args args;
+ char source[NAME_MAX];
+ char target[NAME_MAX];
+ char fstype[FSNAME_MAX];
+ const char *u_source = SCARG(scargs, const char *, 0);
+ const char *u_target = SCARG(scargs, const char *, 1);
+ const char *u_fstype = SCARG(scargs, const char *, 2);
+ unsigned long u_mountflags = SCARG(scargs, unsigned long, 3);
+ int error;
+
+ /* Get the filesystem source */
+ error = copyinstr(u_source, source, sizeof(source));
+ if (error < 0) {
+ source[0] = '\0';
+ }
+
+ /* Get the filesystem target */
+ error = copyinstr(u_target, target, sizeof(target));
+ if (error < 0) {
+ return error;
+ }
+
+ /* Get the filesystem type */
+ error = copyinstr(u_fstype, fstype, sizeof(u_fstype));
+ if (error < 0) {
+ return error;
+ }
+
+ args.source = source;
+ args.target = target;
+ args.fstype = fstype;
+ return kmount(&args, u_mountflags);
+}
diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h
index ab464c4..5339d47 100644
--- a/src/sys/include/compat/unix/syscall.h
+++ b/src/sys/include/compat/unix/syscall.h
@@ -32,6 +32,7 @@
#include <sys/proc.h>
#include <sys/param.h>
+#include <sys/mount.h>
#include <sys/syscall.h>
/*
@@ -61,7 +62,8 @@ scret_t(*g_unix_sctab[])(struct syscall_args *) = {
[SYS_write] = sys_write,
[SYS_cross] = sys_cross,
[SYS_query] = sys_query,
- [SYS_spawn] = sys_spawn
+ [SYS_spawn] = sys_spawn,
+ [SYS_mount] = sys_mount
};
#endif /* !_NEED_UNIX_SCTAB */
diff --git a/src/sys/include/sys/mount.h b/src/sys/include/sys/mount.h
index 4e39279..6d041ee 100644
--- a/src/sys/include/sys/mount.h
+++ b/src/sys/include/sys/mount.h
@@ -31,22 +31,32 @@
#define _SYS_MOUNT_H_
#include <sys/queue.h>
+#include <sys/syscall.h>
#include <sys/types.h>
+#if defined(_KERNEL)
#include <os/vnode.h>
+#endif /* defined(_KERNEL) */
-#if defined(_KERNEL)
+/*
+ * Mount filesystem string names
+ */
+#define MOUNT_INITRD "initrd" /* Initial ramdisk */
+#define MOUNT_DEVFS "devfs" /* Device filesystem */
/*
- * Number of bytes allowed in a filesystem
- * name including the null termination
+ * The mount system call
*/
-#define FSNAME_MAX 16
+int mount(
+ const char *source, const char *target, const char *fstype,
+ unsigned long mountflags, void *data
+);
+#if defined(_KERNEL)
/*
- * Mount filesystem string names
+ * Number of bytes allowed in a filesystem
+ * name including the null termination
*/
-#define MOUNT_INITRD "initrd" /* Initial ramdisk */
-#define MOUNT_DEVFS "devfs" /* Device filesystem */
+#define FSNAME_MAX 16
/* Forward declarations */
struct fs_info;
@@ -155,7 +165,7 @@ int mount_lookup(const char *name, struct mount **mp_res);
* Returns zero on success, otherwise a less than zero
* failure upon failure.
*/
-int mount(struct mount_args *margs, uint32_t flags);
+int kmount(struct mount_args *margs, uint32_t flags);
/*
* Initialize a mountpoint to a known state
@@ -178,5 +188,10 @@ int mountlist_init(struct mountlist *mlp);
*/
int mount_alloc(const char *name, struct mount **mp_res);
+/*
+ * Mount system call
+ */
+scret_t sys_mount(struct syscall_args *scargs);
+
#endif /* !_KERNEL */
#endif /* !_SYS_MOUNT_H_ */
diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h
index c1c06bb..4121d54 100644
--- a/src/sys/include/sys/syscall.h
+++ b/src/sys/include/sys/syscall.h
@@ -49,6 +49,7 @@
#define SYS_sigaction 0x04
#define SYS_query 0x05 /* query a border (mandatory) */
#define SYS_spawn 0x06 /* spawn a process */
+#define SYS_mount 0x07 /* mount a filesystem */
typedef __ssize_t scret_t;
typedef __ssize_t scarg_t;
diff --git a/src/sys/os/vfs_mount.c b/src/sys/os/vfs_mount.c
index 034b324..8048352 100644
--- a/src/sys/os/vfs_mount.c
+++ b/src/sys/os/vfs_mount.c
@@ -165,7 +165,7 @@ mount_alloc(const char *name, struct mount **mp_res)
* Mount a filesystem
*/
int
-mount(struct mount_args *margs, uint32_t flags)
+kmount(struct mount_args *margs, uint32_t flags)
{
const struct vfsops *vfsops;
struct mount *mpp;
@@ -256,6 +256,6 @@ mountlist_init(struct mountlist *mlp)
TAILQ_INIT(&mlp->list);
mlp->i = 1;
- mount(&margs, 0);
+ kmount(&margs, 0);
return 0;
}