summaryrefslogtreecommitdiff
path: root/src/init/fs
diff options
context:
space:
mode:
authordzwdz2021-11-16 20:39:26 +0100
committerdzwdz2021-11-16 20:39:26 +0100
commitac88b6add9f26e71ed41ef0fbc61c96a25375095 (patch)
tree7b0e215d24d4d7a506836e424697b6727149d0fb /src/init/fs
parentfefca619c1b98f9fe27cfff0c32f39b751ee6a60 (diff)
init: implement a halfassed passthrough fs
Diffstat (limited to 'src/init/fs')
-rw-r--r--src/init/fs/misc.c33
-rw-r--r--src/init/fs/misc.h3
2 files changed, 36 insertions, 0 deletions
diff --git a/src/init/fs/misc.c b/src/init/fs/misc.c
new file mode 100644
index 0000000..134c311
--- /dev/null
+++ b/src/init/fs/misc.c
@@ -0,0 +1,33 @@
+#include <init/stdlib.h>
+#include <shared/flags.h>
+#include <shared/syscalls.h>
+
+void fs_passthru() {
+ struct fs_wait_response res;
+ int buf_size = 64;
+ char buf[ 64];
+ int ret;
+
+ for (;;) {
+ switch (_syscall_fs_wait(buf, buf_size, &res)) {
+ case VFSOP_OPEN:
+ ret = _syscall_open(buf, res.len);
+ _syscall_fs_respond(NULL, ret);
+ break;
+
+ case VFSOP_READ:
+ if (res.capacity > buf_size)
+ res.capacity = buf_size; /* don't overflow the buffer */
+ ret = _syscall_read(res.id, buf, res.capacity, res.offset);
+ _syscall_fs_respond(buf, ret);
+ break;
+
+ // temporarily doesn't support writing
+ // also TODO closing
+
+ default:
+ _syscall_fs_respond(NULL, -1);
+ break;
+ }
+ }
+}
diff --git a/src/init/fs/misc.h b/src/init/fs/misc.h
new file mode 100644
index 0000000..6afca79
--- /dev/null
+++ b/src/init/fs/misc.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void fs_passthru();