From 499e349afa57536ce80497aa99f61c5492e3733e Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 29 Jan 2011 03:15:44 +0100 Subject: More filesystem stuff working. devfs is now in place with stdin, stdout, and stderr. --- os/src/fio.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'os/src/fio.c') diff --git a/os/src/fio.c b/os/src/fio.c index bd3f8ae..b7e225a 100644 --- a/os/src/fio.c +++ b/os/src/fio.c @@ -2,7 +2,14 @@ #include #include #include +#include +#include +#include +#include #include "fio.h" +#include "filesystem.h" +#include "osdebug.h" +#include "hash-djb2.h" static struct fddef_t fio_fds[MAX_FDS]; @@ -138,3 +145,33 @@ int fio_close(int fd) { } return r; } + +#define stdin_hash 0x0BA00421 +#define stdout_hash 0x7FA08308 +#define stderr_hash 0x7FA058A3 + +static int devfs_open(void * opaque, const char * path, int flags, int mode) { + uint32_t h = hash_djb2((const uint8_t *) path, -1); + switch (h) { + case stdin_hash: + if (flags & (O_WRONLY | O_RDWR)) + return -1; + return fio_open(stdin_read, NULL, NULL, NULL, NULL); + break; + case stdout_hash: + if (flags & O_RDONLY) + return -1; + return fio_open(NULL, stdout_write, NULL, NULL, NULL); + break; + case stderr_hash: + if (flags & O_RDONLY) + return -1; + return fio_open(NULL, stdout_write, NULL, NULL, NULL); + break; + } + return -1; +} + +void register_devfs() { + register_fs("dev", devfs_open, NULL); +} -- cgit v1.2.3