summaryrefslogtreecommitdiff
path: root/os/src/fio.c
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2011-01-29 03:15:44 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2011-01-29 03:15:44 +0100
commit499e349afa57536ce80497aa99f61c5492e3733e (patch)
treefe3308c344659e800172cfaad9793918f24ae4b1 /os/src/fio.c
parent5754656f65205ff1fd9b23c2a85778b3671caf68 (diff)
More filesystem stuff working. devfs is now in place with stdin, stdout, and stderr.
Diffstat (limited to 'os/src/fio.c')
-rw-r--r--os/src/fio.c37
1 files changed, 37 insertions, 0 deletions
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 <string.h>
#include <FreeRTOS.h>
#include <semphr.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#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);
+}