diff options
author | dzwdz | 2022-07-08 14:40:44 +0200 |
---|---|---|
committer | dzwdz | 2022-07-08 14:40:44 +0200 |
commit | 1f7e7501660123ff8f26e8c65e75c2b282b933ef (patch) | |
tree | 5ba6cee10ac656b20dcabc9c9f7b079dcd952a45 /src/init/driver/tmpfs.c | |
parent | e567ebeee5ea196128f15adcf30cec5dd1137f90 (diff) |
syscall/fs_respond: get the file id from the buf argument
Previously, file ids could only be positive integers, so their range
was 31 bits - not enough to represent the entire memory. Now, pointers
can be safely used as file ids.
Diffstat (limited to 'src/init/driver/tmpfs.c')
-rw-r--r-- | src/init/driver/tmpfs.c | 21 |
1 files changed, 12 insertions, 9 deletions
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; |