summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2021-08-24 16:34:18 +0200
committerdzwdz2021-08-24 16:34:18 +0200
commite6b76a8556e00c6f143679af8056c1b62e1c57a8 (patch)
tree16fff1c5976dd50ae4b0133ef9e8d1c29ea437a0
parent83fa1f34ea744da7d26997179a0dd6af751dd8b0 (diff)
fdop_dispatch: pass the fd struct instead of index
-rw-r--r--src/kernel/fd.c5
-rw-r--r--src/kernel/fd.h2
-rw-r--r--src/kernel/syscalls.c9
3 files changed, 9 insertions, 7 deletions
diff --git a/src/kernel/fd.c b/src/kernel/fd.c
index 54f1c72..7d448eb 100644
--- a/src/kernel/fd.c
+++ b/src/kernel/fd.c
@@ -2,9 +2,8 @@
#include <kernel/panic.h>
#include <kernel/proc.h>
-int fdop_dispatch(enum fdop fdop, fd_t fd, void *ptr, size_t len) {
- if (fd < 0 || fd >= FD_MAX) return -1;
- switch(process_current->fds[fd].type) {
+int fdop_dispatch(enum fdop fdop, struct fd *fd, void *ptr, size_t len) {
+ switch(fd->type) {
case FD_EMPTY:
return -1;
default:
diff --git a/src/kernel/fd.h b/src/kernel/fd.h
index 4976c7d..7f7cbdd 100644
--- a/src/kernel/fd.h
+++ b/src/kernel/fd.h
@@ -20,4 +20,4 @@ enum fdop { // describes the operations which can be done on file descriptors
FDOP_CLOSE,
};
-int fdop_dispatch(enum fdop fdop, fd_t fd, void *ptr, size_t len);
+int fdop_dispatch(enum fdop fdop, struct fd *fd, void *ptr, size_t len);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 4da5261..015bb17 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -131,15 +131,18 @@ fail:
}
int _syscall_fd_read(fd_t fd, char *buf, int len) {
- return fdop_dispatch(FDOP_READ, fd, buf, len);
+ if (fd < 0 || fd >= FD_MAX) return -1;
+ return fdop_dispatch(FDOP_READ, &process_current->fds[fd], buf, len);
}
int _syscall_fd_write(fd_t fd, char *buf, int len) {
- return fdop_dispatch(FDOP_WRITE, fd, buf, len);
+ if (fd < 0 || fd >= FD_MAX) return -1;
+ return fdop_dispatch(FDOP_WRITE, &process_current->fds[fd], buf, len);
}
int _syscall_fd_close(fd_t fd) {
- return fdop_dispatch(FDOP_CLOSE, fd, 0, 0);
+ if (fd < 0 || fd >= FD_MAX) return -1;
+ return fdop_dispatch(FDOP_CLOSE, &process_current->fds[fd], 0, 0);
}
int _syscall_debuglog(const char *msg, size_t len) {