summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/driver/fsroot.c
diff options
context:
space:
mode:
authordzwdz2023-08-06 01:16:14 +0200
committerdzwdz2023-08-06 01:16:14 +0200
commit0ddd4d1dab8dc2ba092c7351cfb2e054fce1f429 (patch)
treedfa378e88be27c189c739190dc3ec7beb8e26aba /src/kernel/arch/amd64/driver/fsroot.c
parenta71120adf590f699c4b8d6249a340976575ea530 (diff)
kernel: put every driver in /kdev/
there's no real reason for bootstrap to be doing that, and this brings it closer to only doing the elf loading
Diffstat (limited to 'src/kernel/arch/amd64/driver/fsroot.c')
-rw-r--r--src/kernel/arch/amd64/driver/fsroot.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c
index 0b0e2ef..d59edf3 100644
--- a/src/kernel/arch/amd64/driver/fsroot.c
+++ b/src/kernel/arch/amd64/driver/fsroot.c
@@ -8,26 +8,48 @@
#include <kernel/vfs/request.h>
#include <shared/mem.h>
-static int handle(VfsReq *req) {
+static long handle(VfsReq *req) {
// TODO document directory read format
// TODO don't hardcode
- const char dir[] =
+ static const char base[] = "kdev/";
+ static const char dir[] =
"com1\0"
"ps2/\0"
"ata/\0"
"eth/\0"
"video/";
+ const char *id;
+ int len;
+
if (!req->caller) return -1;
+ if (req->type != VFSOP_OPEN) {
+ /* otherwise, uninitialized, to cause compiler warnings if used */
+ /* this operates under the assumption that base and dir never change
+ * but even if they do, that will just result in a crash. */
+ id = (void *__force)req->id;
+ if (id == base) {
+ len = sizeof base;
+ } else if (id == dir) {
+ len = sizeof dir;
+ } else {
+ kprintf("%p %p %p\n", base, dir, id);
+ assert(false);
+ }
+ }
+
switch (req->type) {
case VFSOP_OPEN:
- return req->input.len == 1 ? 0 : -1;
+ if (reqpathcmp(req, "/")) return (long)base;
+ if (reqpathcmp(req, "/kdev/")) return (long)dir;
+ return -ENOENT;
case VFSOP_READ:
- return req_readcopy(req, dir, sizeof dir);
-
+ return req_readcopy(req, id, len);
// TODO getsize for the other kernel provided directories
- case VFSOP_GETSIZE: return sizeof dir;
- default: return -ENOSYS;
+ case VFSOP_GETSIZE:
+ return len;
+ default:
+ return -ENOSYS;
}
}