diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-15 13:01:39 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-15 13:01:39 -0400 |
commit | b9e8dbfd957337ff064c4cb8bb5bd7b23ac88b8d (patch) | |
tree | 888d6e5c69a0178c4b00e11c80fdd96c22dfa53a /src/sys/compat | |
parent | 9970641f0ee8c80be660e2b49e63f6ed4e3b8859 (diff) |
kern: Add SYS_read system call for file I/O
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/compat')
-rw-r--r-- | src/sys/compat/unix/os/os_filedesc.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/sys/compat/unix/os/os_filedesc.c b/src/sys/compat/unix/os/os_filedesc.c index 48ea6be..673701f 100644 --- a/src/sys/compat/unix/os/os_filedesc.c +++ b/src/sys/compat/unix/os/os_filedesc.c @@ -33,6 +33,7 @@ #include <sys/mount.h> #include <sys/errno.h> #include <sys/types.h> +#include <os/kalloc.h> #include <os/systm.h> #include <os/filedesc.h> #include <compat/unix/syscall.h> @@ -105,3 +106,35 @@ sys_mount(struct syscall_args *scargs) args.fstype = fstype; return kmount(&args, u_mountflags); } + +/* + * ARG0: fd + * ARG1: buf[] + * ARG2: count + */ +scret_t +sys_read(struct syscall_args *scargs) +{ + int fd = SCARG(scargs, int, 0); + char *u_buf = SCARG(scargs, char *, 1); + size_t count = SCARG(scargs, size_t, 2); + char *kbuf; + ssize_t retval; + int error; + + /* Do we have enough memory to fulfill this */ + kbuf = kalloc(count); + if (kbuf == NULL) { + return -ENOMEM; + } + + retval = read(fd, kbuf, count); + if (retval < 0) { + kfree(kbuf); + return retval; + } + + error = copyout(kbuf, u_buf, count); + kfree(kbuf); + return (error == 0) ? retval : error; +} |