diff options
Diffstat (limited to 'src/init/driver')
-rw-r--r-- | src/init/driver/ansiterm.c | 2 | ||||
-rw-r--r-- | src/init/driver/tmpfs.c | 21 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/init/driver/ansiterm.c b/src/init/driver/ansiterm.c index 4d98972..b7f0b04 100644 --- a/src/init/driver/ansiterm.c +++ b/src/init/driver/ansiterm.c @@ -83,7 +83,7 @@ void ansiterm_drv(void) { break; } // TODO check path - _syscall_fs_respond(NULL, 1, 0); + _syscall_fs_respond(NULL, 0, 0); break; case VFSOP_WRITE: diff --git a/src/init/driver/tmpfs.c b/src/init/driver/tmpfs.c index 4b639da..bbed095 100644 --- a/src/init/driver/tmpfs.c +++ b/src/init/driver/tmpfs.c @@ -10,6 +10,7 @@ struct node { }; struct node *root = NULL; +static struct node special_root; static struct node *lookup(const char *path, size_t len) { for (struct node *iter = root; iter; iter = iter->next) { @@ -19,18 +20,18 @@ static struct node *lookup(const char *path, size_t len) { return NULL; } -static int tmpfs_open(const char *path, struct fs_wait_response *res) { - if (res->len == 0) return -1; +static struct node *tmpfs_open(const char *path, struct fs_wait_response *res) { + if (res->len == 0) return NULL; path++; res->len--; - if (res->len == 0) return 0; /* root */ + if (res->len == 0) return &special_root; // no directory support (yet) - if (memchr(path, '/', res->len)) return -1; + if (memchr(path, '/', res->len)) return NULL; if (res->flags & OPEN_CREATE) { - if (lookup(path, res->len)) return -1; /* already exists */ + if (lookup(path, res->len)) return NULL; /* already exists */ struct node *new = malloc(sizeof *new); char *namebuf = malloc(res->len); memcpy(namebuf, path, res->len); @@ -38,24 +39,26 @@ static int tmpfs_open(const char *path, struct fs_wait_response *res) { new->len = res->len; new->next = root; root = new; - return 1; + return new; } - return lookup(path, res->len) != 0 ? 1 : -1; + return lookup(path, res->len); } void tmpfs_drv(void) { // TODO replace all the static allocations in drivers with mallocs static char buf[512]; struct fs_wait_response res; + struct node *ptr; while (!_syscall_fs_wait(buf, sizeof buf, &res)) { switch (res.op) { case VFSOP_OPEN: - _syscall_fs_respond(NULL, tmpfs_open(buf, &res), 0); + ptr = tmpfs_open(buf, &res); + _syscall_fs_respond(ptr, ptr ? 0 : -1, 0); break; case VFSOP_READ: - if (res.id != 0) { + if (res.id != &special_root) { // rw unimplemented _syscall_fs_respond(NULL, -1, 0); break; |