summaryrefslogtreecommitdiff
path: root/src/kernel/fd.c
diff options
context:
space:
mode:
authordzwdz2021-08-24 16:39:35 +0200
committerdzwdz2021-08-24 16:39:35 +0200
commit9958bdacfa51b5d8eee386b863cdcc2d76f44f4a (patch)
tree8685b3dd5a96b225acfc76314e1ed4f2cfeccaf6 /src/kernel/fd.c
parente6b76a8556e00c6f143679af8056c1b62e1c57a8 (diff)
implement FD_SPECIAL_TTY, an stdout equalivent
Diffstat (limited to 'src/kernel/fd.c')
-rw-r--r--src/kernel/fd.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/kernel/fd.c b/src/kernel/fd.c
index 7d448eb..e99fb7d 100644
--- a/src/kernel/fd.c
+++ b/src/kernel/fd.c
@@ -1,12 +1,39 @@
#include <kernel/fd.h>
+#include <kernel/mem.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
+static int fdop_special_tty(enum fdop fdop, struct fd *fd, void *ptr, size_t len);
+
int fdop_dispatch(enum fdop fdop, struct fd *fd, void *ptr, size_t len) {
switch(fd->type) {
case FD_EMPTY:
return -1;
+ case FD_SPECIAL_TTY:
+ return fdop_special_tty(fdop, fd, ptr, len);
default:
panic();
}
}
+
+static int fdop_special_tty(enum fdop fdop, struct fd *fd, void *ptr, size_t len) {
+ switch(fdop) {
+ case FDOP_READ:
+ return -1; // input not implemented yet
+
+ case FDOP_WRITE: {
+ struct virt_iter iter;
+ virt_iter_new(&iter, (void*)ptr, 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;
+ return 0;
+
+ default: panic();
+ }
+}