summaryrefslogtreecommitdiff
path: root/src/user/driver
diff options
context:
space:
mode:
authordzwdz2022-07-17 20:28:53 +0200
committerdzwdz2022-07-17 20:28:53 +0200
commitc6bbf615e5c77ec273b954c11cef95df3d6f7286 (patch)
tree7b4539c9c5089a8b563d90444c388169fd093cf0 /src/user/driver
parent51cbabd0f40b041fa00203266afa046d14e88b22 (diff)
kernel/virt_cpy: error struct, better error handling
Diffstat (limited to 'src/user/driver')
-rw-r--r--src/user/driver/tmpfs.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/user/driver/tmpfs.c b/src/user/driver/tmpfs.c
index 80c0196..6e5b45e 100644
--- a/src/user/driver/tmpfs.c
+++ b/src/user/driver/tmpfs.c
@@ -23,6 +23,7 @@ static struct node *lookup(const char *path, size_t len) {
}
static struct node *tmpfs_open(const char *path, struct fs_wait_response *res) {
+ struct node *node;
if (res->len == 0) return NULL;
path++;
res->len--;
@@ -32,21 +33,19 @@ static struct node *tmpfs_open(const char *path, struct fs_wait_response *res) {
// no directory support (yet)
if (memchr(path, '/', res->len)) return NULL;
- if (res->flags & OPEN_CREATE) {
- if (lookup(path, res->len)) return NULL; /* already exists */
- struct node *new = malloc(sizeof *new);
- memset(new, 0, sizeof *new);
+ node = lookup(path, res->len);
+ if (!node && (res->flags & OPEN_CREATE)) {
+ node = malloc(sizeof *node);
+ memset(node, 0, sizeof *node);
char *namebuf = malloc(res->len);
memcpy(namebuf, path, res->len);
- new->name = namebuf;
- new->namelen = res->len;
- new->next = root;
- root = new;
- return new;
+ node->name = namebuf;
+ node->namelen = res->len;
+ node->next = root;
+ root = node;
}
-
- return lookup(path, res->len);
+ return node;
}
void tmpfs_drv(void) {