summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2022-06-29 21:52:15 +0200
committerdzwdz2022-06-29 21:52:15 +0200
commitbf4cbc830d78774ac00d9501c45e8b84d0ae9ae7 (patch)
treef302f92badf74dade9e724e37f85d1ee2dd99833 /src/kernel
parent43de6a4d8ead1e609828ef34ad1957d34c94ee6a (diff)
kernel/vfs: add the OPEN_CREATE flag
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/arch/i386/driver/fsroot.c2
-rw-r--r--src/kernel/arch/i386/driver/ps2.c5
-rw-r--r--src/kernel/arch/i386/driver/serial.c5
-rw-r--r--src/kernel/syscalls.c5
-rw-r--r--src/kernel/vfs/request.c1
-rw-r--r--src/kernel/vfs/request.h1
6 files changed, 13 insertions, 6 deletions
diff --git a/src/kernel/arch/i386/driver/fsroot.c b/src/kernel/arch/i386/driver/fsroot.c
index e6e53cd..4207541 100644
--- a/src/kernel/arch/i386/driver/fsroot.c
+++ b/src/kernel/arch/i386/driver/fsroot.c
@@ -47,6 +47,8 @@ static int handle(struct vfs_request *req) {
assert(req->caller);
switch (req->type) {
case VFSOP_OPEN:
+ if (req->flags & OPEN_CREATE) return -1;
+
if (exacteq(req, "/")) return HANDLE_ROOT;
if (exacteq(req, "/vga")) return HANDLE_VGA;
diff --git a/src/kernel/arch/i386/driver/ps2.c b/src/kernel/arch/i386/driver/ps2.c
index b7e82eb..e1e97c0 100644
--- a/src/kernel/arch/i386/driver/ps2.c
+++ b/src/kernel/arch/i386/driver/ps2.c
@@ -31,10 +31,11 @@ static void accept(struct vfs_request *req) {
// when you fix something here go also fix it in the COM1 driver
static uint8_t buf[32]; // pretty damn stupid
int ret;
+ bool valid;
switch (req->type) {
case VFSOP_OPEN:
- ret = req->input.len == 0 ? 0 : -1;
- vfsreq_finish(req, 0);
+ valid = req->input.len == 0 && !(req->flags & OPEN_CREATE);
+ vfsreq_finish(req, valid ? 0 : -1);
break;
case VFSOP_READ:
if (ring_size((void*)&backlog) == 0) {
diff --git a/src/kernel/arch/i386/driver/serial.c b/src/kernel/arch/i386/driver/serial.c
index cda016c..b776d0c 100644
--- a/src/kernel/arch/i386/driver/serial.c
+++ b/src/kernel/arch/i386/driver/serial.c
@@ -69,10 +69,11 @@ void serial_write(const char *buf, size_t len) {
static void accept(struct vfs_request *req) {
static char buf[32];
int ret;
+ bool valid;
switch (req->type) {
case VFSOP_OPEN:
- ret = req->input.len == 0 ? 0 : -1;
- vfsreq_finish(req, 0);
+ valid = req->input.len == 0 && !(req->flags & OPEN_CREATE);
+ vfsreq_finish(req, valid ? 0 : -1);
break;
case VFSOP_READ:
if (ring_size((void*)&backlog) == 0) {
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 0d18af8..7040f6b 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -79,7 +79,7 @@ int _syscall_fork(int flags, handle_t __user *fs_front) {
SYSCALL_RETURN(1);
}
-handle_t _syscall_open(const char __user *path, int len) {
+handle_t _syscall_open(const char __user *path, int len, int flags) {
struct vfs_mount *mount;
char *path_buf = NULL;
@@ -114,6 +114,7 @@ handle_t _syscall_open(const char __user *path, int len) {
},
.caller = process_current,
.backend = mount->backend,
+ .flags = flags,
});
return -1; // dummy
fail:
@@ -300,7 +301,7 @@ int _syscall(int num, int a, int b, int c, int d) {
_syscall_fork(a, (userptr_t)b);
break;
case _SYSCALL_OPEN:
- _syscall_open((userptr_t)a, b);
+ _syscall_open((userptr_t)a, b, c);
break;
case _SYSCALL_MOUNT:
_syscall_mount(a, (userptr_t)b, c);
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 30c0e77..4ee5986 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -113,6 +113,7 @@ void vfs_backend_user_accept(struct vfs_request *req) {
res.capacity = req->output.len;
res.id = req->id;
res.offset = req->offset;
+ res.flags = req->flags;
res.op = req->type;
if (!virt_cpy_to(handler->pages,
diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h
index e034bc6..cad0981 100644
--- a/src/kernel/vfs/request.h
+++ b/src/kernel/vfs/request.h
@@ -49,6 +49,7 @@ struct vfs_request {
int id; // handle.file.id
int offset;
+ int flags;
struct process *caller;
struct vfs_backend *backend;