summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/shell/shell.c2
-rw-r--r--src/cmd/tests/kernel/miscsyscall.c6
-rw-r--r--src/kernel/handleset.c12
-rw-r--r--src/kernel/syscalls.c36
-rw-r--r--src/libc/fs/misc.c2
-rw-r--r--src/libk/include/camellia/flags.h4
6 files changed, 28 insertions, 34 deletions
diff --git a/src/cmd/shell/shell.c b/src/cmd/shell/shell.c
index 3aeaca1..9afdb5c 100644
--- a/src/cmd/shell/shell.c
+++ b/src/cmd/shell/shell.c
@@ -57,7 +57,7 @@ void run_args(int argc, char **argv, struct redir *redir) {
if (argc < 2) {
fprintf(stderr, "shadow: missing path\n");
} else {
- _sys_mount(HANDLE_NULLFS, argv[1], strlen(argv[1]));
+ _sys_mount(-1, argv[1], strlen(argv[1]));
}
} else if (!strcmp(argv[0], "procmnt")) {
if (argc < 2) {
diff --git a/src/cmd/tests/kernel/miscsyscall.c b/src/cmd/tests/kernel/miscsyscall.c
index c7ce9e0..1317720 100644
--- a/src/cmd/tests/kernel/miscsyscall.c
+++ b/src/cmd/tests/kernel/miscsyscall.c
@@ -316,7 +316,11 @@ static void test_getnull(void) {
test(_sys_getsize(h) == -ENOSYS);
test(_sys_remove(h) == -ENOSYS);
test(_sys_fs_respond(h, buf, 16, 0) == -EBADF);
- test(_sys_mount(h, "/asdf", 5) == -EGENERIC);
+
+ /* making some assumptions about the testing environment here... */
+ test(_sys_open("/test", 5, OPEN_READ) != -EGENERIC);
+ test(_sys_mount(h, "/test", 5) == 0);
+ test(_sys_open("/test", 5, OPEN_READ) == -EGENERIC);
close(h);
close(h2);
diff --git a/src/kernel/handleset.c b/src/kernel/handleset.c
index b52eaa0..a25f5c7 100644
--- a/src/kernel/handleset.c
+++ b/src/kernel/handleset.c
@@ -55,15 +55,7 @@ hs_findfree(HandleSet *hs, hid_t start)
Handle *
hs_get(HandleSet *hs, hid_t id)
{
- if (id == HANDLE_NULLFS) {
- // TODO get rid of this stupid hack
- static Handle h = (Handle){
- .type = HANDLE_FS_FRONT,
- .backend = NULL,
- .refcount = 2, /* never free */
- };
- return &h;
- } else if (0 <= id && id < HANDLE_MAX) {
+ if (0 <= id && id < HANDLE_MAX) {
return hs->h[id];
} else {
return NULL;
@@ -107,7 +99,7 @@ Handle *
hs_take(HandleSet *hs, hid_t hid)
{
if (hid < 0 || hid >= HANDLE_MAX) {
- return hs_get(hs, hid); // TODO can't this cause HANDLE_NULLFS to be freed?
+ return NULL;
}
Handle *h = hs->h[hid];
hs->h[hid] = NULL;
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index da6b48f..9b0746a 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -63,7 +63,7 @@ hid_t _sys_open(const char __user *path, long len, int flags) {
if (flags & ~(OPEN_RW | OPEN_CREATE)) SYSCALL_RETURN(-ENOSYS);
if (PATH_MAX < len)
- SYSCALL_RETURN(-1);
+ SYSCALL_RETURN(-ENAMETOOLONG);
/* Doesn't check for free handles. Another thread could use up all
* handles in the meantime anyways, or free some up. */
@@ -86,16 +86,16 @@ hid_t _sys_open(const char __user *path, long len, int flags) {
}
vfsreq_create((VfsReq) {
- .type = VFSOP_OPEN,
- .input = {
- .kern = true,
- .buf_kern = path_buf,
- .len = len,
- },
- .caller = proc_cur,
- .backend = mount->backend,
- .flags = flags,
- });
+ .type = VFSOP_OPEN,
+ .input = {
+ .kern = true,
+ .buf_kern = path_buf,
+ .len = len,
+ },
+ .caller = proc_cur,
+ .backend = mount->backend,
+ .flags = flags,
+ });
return -1; // dummy
fail:
kfree(path_buf);
@@ -125,12 +125,14 @@ long _sys_mount(hid_t hid, const char __user *path, long len) {
}
Handle *handle = hs_get(proc_cur->hs, hid);
- if (!handle || handle->type != HANDLE_FS_FRONT)
- goto fail;
- backend = handle->backend;
- if (backend) {
- assert(backend->usehcnt);
- backend->usehcnt++;
+ if (handle && handle->type == HANDLE_FS_FRONT) {
+ backend = handle->backend;
+ if (backend) {
+ assert(backend->usehcnt);
+ backend->usehcnt++;
+ }
+ } else {
+ backend = NULL;
}
// append to mount list
diff --git a/src/libc/fs/misc.c b/src/libc/fs/misc.c
index f0925ba..d7013e8 100644
--- a/src/libc/fs/misc.c
+++ b/src/libc/fs/misc.c
@@ -164,7 +164,7 @@ int mount_at(const char *path) {
_sys_mount(h, path, strlen(path));
close(h);
} else {
- _sys_mount(HANDLE_NULLFS, path, strlen(path));
+ _sys_mount(-1, path, strlen(path));
}
return ret;
}
diff --git a/src/libk/include/camellia/flags.h b/src/libk/include/camellia/flags.h
index bc34616..a708f73 100644
--- a/src/libk/include/camellia/flags.h
+++ b/src/libk/include/camellia/flags.h
@@ -28,7 +28,3 @@
* The idea is that if all flags which allow modifying the filesystem state require
* OPEN_WRITE to be set, filesystem handlers could just check for the OPEN_WRITE flag. */
#define OPEN_CREATE 4
-
-
-/* special handles */
-#define HANDLE_NULLFS -2