summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/driver/tmpfs.c21
-rw-r--r--src/user/tests/main.c18
2 files changed, 26 insertions, 13 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) {
diff --git a/src/user/tests/main.c b/src/user/tests/main.c
index 5bfd3aa..b4587f9 100644
--- a/src/user/tests/main.c
+++ b/src/user/tests/main.c
@@ -1,8 +1,9 @@
#define TEST_MACROS
-#include <user/lib/stdlib.h>
-#include <user/tests/main.h>
+#include <shared/errno.h>
#include <shared/flags.h>
#include <shared/syscalls.h>
+#include <user/lib/stdlib.h>
+#include <user/tests/main.h>
static void run_forked(void (*fn)()) {
if (!fork()) {
@@ -16,6 +17,7 @@ static void run_forked(void (*fn)()) {
}
+const char *tmpfilepath = "/tmp/.test_internal";
static void test_await(void) {
/* creates 16 child processes, each returning a different value. then checks
@@ -186,6 +188,17 @@ static void test_malloc(void) {
free(p1);
}
+static void test_efault(void) {
+ char *invalid = (void*)0x1000;
+ handle_t h;
+
+ assert((h = _syscall_open(tmpfilepath, strlen(tmpfilepath), OPEN_CREATE)));
+ assert(_syscall_write(h, "dzwdz sucks ass!", 16, 0) == 16);
+ assert(_syscall_write(h, invalid, 16, 0) == -EFAULT);
+ assert(_syscall_write(h, "dzwdz is cool!!!", 16, 0) == 16);
+ close(h);
+}
+
static void test_misc(void) {
assert(_syscall(~0, 0, 0, 0, 0) < 0); /* try making an invalid syscall */
}
@@ -201,5 +214,6 @@ void test_all(void) {
run_forked(test_malloc);
run_forked(test_pipe);
run_forked(test_semaphore);
+ run_forked(test_efault);
run_forked(test_misc);
}