summaryrefslogtreecommitdiff
path: root/os/src/filesystem.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/filesystem.c
parent5754656f65205ff1fd9b23c2a85778b3671caf68 (diff)
More filesystem stuff working. devfs is now in place with stdin, stdout, and stderr.
Diffstat (limited to 'os/src/filesystem.c')
-rw-r--r--os/src/filesystem.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/os/src/filesystem.c b/os/src/filesystem.c
new file mode 100644
index 0000000..64d7e0d
--- /dev/null
+++ b/os/src/filesystem.c
@@ -0,0 +1,60 @@
+#include "filesystem.h"
+#include "fio.h"
+#include "osdebug.h"
+
+#include <stdint.h>
+#include <string.h>
+#include <hash-djb2.h>
+
+#define MAX_FS 16
+
+struct fs_t {
+ uint32_t hash;
+ fs_open_t cb;
+ void * opaque;
+};
+
+static struct fs_t fss[MAX_FS];
+
+__attribute__((constructor)) void fs_init() {
+ memset(fss, 0, sizeof(fss));
+}
+
+int register_fs(const char * mountpoint, fs_open_t callback, void * opaque) {
+ int i;
+
+ for (i = 0; i < MAX_FS; i++) {
+ if (!fss[i].cb) {
+ fss[i].hash = hash_djb2((const uint8_t *) mountpoint, -1);
+ fss[i].cb = callback;
+ fss[i].opaque = opaque;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int fs_open(const char * path, int flags, int mode) {
+ const char * slash;
+ uint32_t hash;
+ int i;
+
+ while (path[0] == '/')
+ path++;
+
+ slash = strchr(path, '/');
+
+ if (!slash)
+ return -2;
+
+ hash = hash_djb2((const uint8_t *) path, slash - path);
+ path = slash + 1;
+
+ for (i = 0; i < MAX_FS; i++) {
+ if (fss[i].hash == hash)
+ return fss[i].cb(fss[i].opaque, path, flags, mode);
+ }
+
+ return -2;
+}