summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/fd.c17
-rw-r--r--src/kernel/fd.h13
-rw-r--r--src/kernel/syscalls.c17
3 files changed, 35 insertions, 12 deletions
diff --git a/src/kernel/fd.c b/src/kernel/fd.c
index c495c8c..77fea05 100644
--- a/src/kernel/fd.c
+++ b/src/kernel/fd.c
@@ -3,34 +3,35 @@
#include <kernel/panic.h>
#include <kernel/proc.h>
-static int fdop_special_tty(enum fdop fdop, struct fd *fd, user_ptr ptr, size_t len);
+static int fdop_special_tty(struct fdop_args *args);
-int fdop_dispatch(enum fdop fdop, struct fd *fd, user_ptr ptr, size_t len) {
- switch(fd->type) {
+int fdop_dispatch(struct fdop_args args) {
+ switch(args.fd->type) {
case FD_EMPTY:
return -1;
case FD_SPECIAL_TTY:
- return fdop_special_tty(fdop, fd, ptr, len);
+ return fdop_special_tty(&args);
default:
panic();
}
}
-static int fdop_special_tty(enum fdop fdop, struct fd *fd, user_ptr ptr, size_t len) {
- switch(fdop) {
+static int fdop_special_tty(struct fdop_args *args) {
+ switch(args->type) {
case FDOP_READ:
return -1; // input not implemented yet
case FDOP_WRITE: {
struct virt_iter iter;
- virt_iter_new(&iter, ptr, len, process_current->pages, true, false);
+ virt_iter_new(&iter, args->rw.ptr, args->rw.len,
+ process_current->pages, true, false);
while (virt_iter_next(&iter))
tty_write(iter.frag, iter.frag_len);
return iter.prior;
}
case FDOP_CLOSE:
- fd->type = FD_EMPTY;
+ args->fd->type = FD_EMPTY;
return 0;
default: panic();
diff --git a/src/kernel/fd.h b/src/kernel/fd.h
index 90ce717..b35c979 100644
--- a/src/kernel/fd.h
+++ b/src/kernel/fd.h
@@ -22,4 +22,15 @@ enum fdop { // describes the operations which can be done on file descriptors
FDOP_CLOSE,
};
-int fdop_dispatch(enum fdop fdop, struct fd *fd, user_ptr ptr, size_t len);
+struct fdop_args {
+ enum fdop type;
+ struct fd *fd;
+ union {
+ struct { // FDOP_READ, FDOP_WRITE
+ user_ptr ptr;
+ size_t len;
+ } rw;
+ };
+};
+
+int fdop_dispatch(struct fdop_args args);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index e0fb08b..bf17fd3 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -133,17 +133,28 @@ fail:
int _syscall_fd_read(fd_t fd, user_ptr buf, int len) {
if (fd < 0 || fd >= FD_MAX) return -1;
- return fdop_dispatch(FDOP_READ, &process_current->fds[fd], buf, len);
+ return fdop_dispatch((struct fdop_args){
+ .type = FDOP_READ,
+ .fd = &process_current->fds[fd],
+ .rw = {buf, len}
+ });
}
int _syscall_fd_write(fd_t fd, user_ptr buf, int len) {
if (fd < 0 || fd >= FD_MAX) return -1;
- return fdop_dispatch(FDOP_WRITE, &process_current->fds[fd], buf, len);
+ return fdop_dispatch((struct fdop_args){
+ .type = FDOP_WRITE,
+ .fd = &process_current->fds[fd],
+ .rw = {buf, len}
+ });
}
int _syscall_fd_close(fd_t fd) {
if (fd < 0 || fd >= FD_MAX) return -1;
- return fdop_dispatch(FDOP_CLOSE, &process_current->fds[fd], 0, 0);
+ return fdop_dispatch((struct fdop_args){
+ .type = FDOP_CLOSE,
+ .fd = &process_current->fds[fd],
+ });
}
int syscall_handler(int num, int a, int b, int c) {