diff options
author | dzwdz | 2022-10-02 19:25:17 +0200 |
---|---|---|
committer | dzwdz | 2022-10-02 19:25:17 +0200 |
commit | 710e9b2b5c16f74f66420c66d12455ad518d42c7 (patch) | |
tree | 82b88cc07ef3f122512354d649af68584bd4da4d /src/user/app | |
parent | 503d9ff758f8b83295830bdfc8c2ea56837d25e5 (diff) |
syscall/open: add the full suite of READ/WRITE flags
Diffstat (limited to 'src/user/app')
-rw-r--r-- | src/user/app/drawmouse/drawmouse.c | 3 | ||||
-rw-r--r-- | src/user/app/httpd/httpd.c | 4 | ||||
-rw-r--r-- | src/user/app/iochk/iochk.c | 3 | ||||
-rw-r--r-- | src/user/app/login/login.c | 4 | ||||
-rw-r--r-- | src/user/app/netdog/nd.c | 3 | ||||
-rw-r--r-- | src/user/app/netstack/fs.c | 3 | ||||
-rw-r--r-- | src/user/app/netstack/netstack.c | 3 | ||||
-rw-r--r-- | src/user/app/shell/builtins.c | 3 | ||||
-rw-r--r-- | src/user/app/tests/kernel/misc.c | 2 | ||||
-rw-r--r-- | src/user/app/tests/kernel/miscsyscall.c | 6 |
10 files changed, 24 insertions, 10 deletions
diff --git a/src/user/app/drawmouse/drawmouse.c b/src/user/app/drawmouse/drawmouse.c index 47e8e8a..6ddfc79 100644 --- a/src/user/app/drawmouse/drawmouse.c +++ b/src/user/app/drawmouse/drawmouse.c @@ -1,3 +1,4 @@ +#include <camellia/flags.h> #include <camellia/syscalls.h> #include <shared/container/ring.h> #include <stdbool.h> @@ -49,7 +50,7 @@ struct packet { int main(void) { char buf[64]; - handle_t fd = _syscall_open("/kdev/ps2/mouse", 15, 0); + handle_t fd = _syscall_open("/kdev/ps2/mouse", 15, OPEN_READ); if (fd < 0) { eprintf("couldn't open mouse"); return 1; diff --git a/src/user/app/httpd/httpd.c b/src/user/app/httpd/httpd.c index 9141a39..2ffc2ba 100644 --- a/src/user/app/httpd/httpd.c +++ b/src/user/app/httpd/httpd.c @@ -21,7 +21,7 @@ static void handle(FILE *c) { char *end = strchr(path, ' '); if (end) *end = '\0'; - handle_t h = _syscall_open(path, strlen(path), OPEN_RO); + handle_t h = _syscall_open(path, strlen(path), OPEN_READ); if (h < 0) { fprintf(c, "HTTP/1.1 404 Not Found\r\n\r\n"); return; @@ -68,7 +68,7 @@ int main(int argc, char **argv) { const char *path = (argc > 1) ? argv[1] : "/net/listen/0.0.0.0/tcp/80"; handle_t conn; for (;;) { - conn = _syscall_open(path, strlen(path), 0); + conn = _syscall_open(path, strlen(path), OPEN_RW); if (conn < 0) { eprintf("open('%s') failed, %d", path, conn); return 1; diff --git a/src/user/app/iochk/iochk.c b/src/user/app/iochk/iochk.c index 38e0473..92975be 100644 --- a/src/user/app/iochk/iochk.c +++ b/src/user/app/iochk/iochk.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdbool.h> #include <stdio.h> @@ -84,7 +85,7 @@ int main(int argc, char **argv) { for (; optind < argc; optind++) { const char *path = argv[optind]; verbosef("checking %s...\n", path); - handle_t h = _syscall_open(path, strlen(path), 0); + handle_t h = _syscall_open(path, strlen(path), OPEN_READ); if (h < 0) { eprintf("couldn't open %s", path); continue; diff --git a/src/user/app/login/login.c b/src/user/app/login/login.c index 5d9eb36..af6e19c 100644 --- a/src/user/app/login/login.c +++ b/src/user/app/login/login.c @@ -44,8 +44,10 @@ static void drv(const char *user) { forward_open(reqh, buf, req.len, req.flags); } else if (segcmp(buf, 1, "Users") && segcmp(buf, 3, "private")) { // /Users/*/private/** _syscall_fs_respond(reqh, NULL, -EACCES, 0); + } else if (!OPEN_WRITEABLE(req.flags)) { + forward_open(reqh, buf, req.len, req.flags); } else { - forward_open(reqh, buf, req.len, req.flags | OPEN_RO); + _syscall_fs_respond(reqh, NULL, -EACCES, 0); } break; diff --git a/src/user/app/netdog/nd.c b/src/user/app/netdog/nd.c index 363c6c6..8c16bb0 100644 --- a/src/user/app/netdog/nd.c +++ b/src/user/app/netdog/nd.c @@ -1,3 +1,4 @@ +#include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdio.h> #include <string.h> @@ -34,7 +35,7 @@ int main(int argc, char **argv) { return 1; } - conn = _syscall_open(argv[1], strlen(argv[1]), 0); + conn = _syscall_open(argv[1], strlen(argv[1]), OPEN_RW); if (conn < 0) { eprintf("couldn't open '%s', err %u", argv[1], -conn); return -conn; diff --git a/src/user/app/netstack/fs.c b/src/user/app/netstack/fs.c index d8faadf..ad6c23c 100644 --- a/src/user/app/netstack/fs.c +++ b/src/user/app/netstack/fs.c @@ -144,7 +144,8 @@ static void fs_open(handle_t reqh, char *path, int flags) { } /* everything below ends up sending packets */ - if (flags & OPEN_RO) respond(NULL, -EACCES); + if (!OPEN_WRITEABLE(flags)) + respond(NULL, -EACCES); char *save; const char *verb, *proto, *port_s; diff --git a/src/user/app/netstack/netstack.c b/src/user/app/netstack/netstack.c index cc5247b..c0934fd 100644 --- a/src/user/app/netstack/netstack.c +++ b/src/user/app/netstack/netstack.c @@ -1,5 +1,6 @@ #include "proto.h" #include "util.h" +#include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdbool.h> #include <stddef.h> @@ -33,7 +34,7 @@ int main(int argc, char **argv) { eprintf("usage: netstack iface ip gateway"); return 1; } - state.raw_h = _syscall_open(argv[1], strlen(argv[1]), 0); + state.raw_h = _syscall_open(argv[1], strlen(argv[1]), OPEN_RW); if (state.raw_h < 0) { eprintf("couldn't open %s", argv[1]); return 1; diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c index bc7731c..a23e501 100644 --- a/src/user/app/shell/builtins.c +++ b/src/user/app/shell/builtins.c @@ -1,5 +1,6 @@ #include "builtins.h" #include "shell.h" +#include <camellia/flags.h> #include <camellia/path.h> #include <stdbool.h> #include <stdio.h> @@ -60,7 +61,7 @@ void cmd_getsize(int argc, char **argv) { } for (int i = 1; i < argc; i++) { - handle_t h = _syscall_open(argv[i], strlen(argv[i]), 0); + handle_t h = _syscall_open(argv[i], strlen(argv[i]), OPEN_READ); if (h < 0) { eprintf("error opening %s", argv[i]); continue; diff --git a/src/user/app/tests/kernel/misc.c b/src/user/app/tests/kernel/misc.c index c0bb6b3..9ee88dd 100644 --- a/src/user/app/tests/kernel/misc.c +++ b/src/user/app/tests/kernel/misc.c @@ -28,7 +28,7 @@ static void test_efault(void) { memcpy(str2, str, 16); - test((h = _syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE))); + test((h = _syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE)) >= 0); test(_syscall_write(h, str, 16, 0, 0) == 16); test(_syscall_write(h, str2, 16, 0, 0) == 16); diff --git a/src/user/app/tests/kernel/miscsyscall.c b/src/user/app/tests/kernel/miscsyscall.c index a2eed24..66899b1 100644 --- a/src/user/app/tests/kernel/miscsyscall.c +++ b/src/user/app/tests/kernel/miscsyscall.c @@ -270,6 +270,11 @@ static void test_sleep(void) { } } +static void test_badopen(void) { + test(_syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE) >= 0); + test(_syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE) == -EINVAL); +} + void r_k_miscsyscall(void) { run_test(test_await); run_test(test_pipe); @@ -277,4 +282,5 @@ void r_k_miscsyscall(void) { run_test(test_dup); run_test(test_execbuf); run_test(test_sleep); + run_test(test_badopen); } |