summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2021-09-04 17:45:42 +0200
committerdzwdz2021-09-04 17:45:42 +0200
commit400f218cdad6bceaed9843d4d44ab66593da591a (patch)
tree0271f9caaffd85c41008dac648458d129ef99e58
parent33b5bddebf6d38922c32c17aca481b9f031618b0 (diff)
nuke the old handle code
-rw-r--r--src/kernel/handle.c55
-rw-r--r--src/kernel/handle.h32
-rw-r--r--src/kernel/syscalls.c34
-rw-r--r--src/kernel/vfs/mount.c4
-rw-r--r--src/kernel/vfs/mount.h1
5 files changed, 7 insertions, 119 deletions
diff --git a/src/kernel/handle.c b/src/kernel/handle.c
deleted file mode 100644
index 6e25b74..0000000
--- a/src/kernel/handle.c
+++ /dev/null
@@ -1,55 +0,0 @@
-#include <kernel/handle.h>
-#include <kernel/mem.h>
-#include <kernel/panic.h>
-#include <kernel/proc.h>
-
-static int handleop_special_tty(struct handleop_args *args);
-
-int handleop_dispatch(struct handleop_args args) {
- switch(args.handle->type) {
- case HANDLE_EMPTY: {
- if (args.type == HANDLEOP_MOUNT) // mounting an empty handle is allowed
- return 0;
- return -1;
- }
- case HANDLE_SPECIAL_TTY:
- return handleop_special_tty(&args);
- default:
- panic();
- }
-}
-
-static int handleop_special_tty(struct handleop_args *args) {
- switch(args->type) {
- case HANDLEOP_MOUNT:
- return 0; // no special action needed
-
- case HANDLEOP_OPEN:
- /* don't allow anything after the mount point
- * this is a file, not a directory
- * for example: open("/tty") is allowed. open("/tty/smth") isn't */
- if (args->open.len == 0) {
- args->open.target->type = HANDLE_SPECIAL_TTY;
- return 0;
- }
- return -1;
-
- case HANDLEOP_READ:
- return -1; // input not implemented yet
-
- case HANDLEOP_WRITE: {
- struct virt_iter iter;
- virt_iter_new(&iter, args->rw.ptr, args->rw.len,
- process_current->pages, true, false);
- while (virt_iter_next(&iter))
- tty_write(iter.frag, iter.frag_len);
- return iter.prior;
- }
-
- case HANDLEOP_CLOSE:
- args->handle->type = HANDLE_EMPTY;
- return 0;
-
- default: panic();
- }
-}
diff --git a/src/kernel/handle.h b/src/kernel/handle.h
index 4b066ad..aae8937 100644
--- a/src/kernel/handle.h
+++ b/src/kernel/handle.h
@@ -8,40 +8,8 @@ typedef int handle_t; // TODO duplicated in syscalls.h
enum handle_type {
HANDLE_EMPTY,
- HANDLE_SPECIAL_TTY,
};
struct handle {
enum handle_type type;
};
-
-
-enum handleop { // describes the operations which can be done on handles
- HANDLEOP_MOUNT, // also closes the original handle
- HANDLEOP_OPEN,
-
- HANDLEOP_READ,
- HANDLEOP_WRITE,
- HANDLEOP_CLOSE,
-};
-
-struct handleop_args {
- enum handleop type;
- struct handle *handle;
- union {
- struct { // HANDLEOP_MOUNT
- struct mount *target;
- } mnt;
- struct { // HANDLEOP_OPEN
- struct handle *target;
- const char *path; // relative to the mount point
- size_t len;
- } open;
- struct { // HANDLEOP_READ, HANDLEOP_WRITE
- user_ptr ptr;
- size_t len;
- } rw;
- };
-};
-
-int handleop_dispatch(struct handleop_args args);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index a869af5..98df4f3 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -93,15 +93,7 @@ handle_t _syscall_fs_open(const user_ptr path, int len) {
mount = vfs_mount_resolve(process_current->mount, buffer, len);
if (!mount) return -1;
- res = handleop_dispatch((struct handleop_args){
- .type = HANDLEOP_OPEN,
- .handle = &mount->handle,
- .open = {
- .target = &process_current->handles[handle],
- .path = &buffer[mount->prefix_len],
- .len = len - mount->prefix_len,
- }
- });
+ res = -1; // TODO pass to filesystem
if (res < 0)
return res;
else
@@ -134,13 +126,8 @@ int _syscall_fd_mount(handle_t handle, const user_ptr path, int len) {
mount->prev = process_current->mount;
mount->prefix = path_buf;
mount->prefix_len = len;
- memcpy(&mount->handle, &process_current->handles[handle], sizeof(struct handle));
- res = handleop_dispatch((struct handleop_args){
- .type = HANDLEOP_MOUNT,
- .handle = &process_current->handles[handle],
- .mnt = {mount},
- });
+ res = -1; // TODO pass to filesystem
if (res < 0) goto fail;
process_current->mount = mount;
return 0;
@@ -152,28 +139,17 @@ fail:
int _syscall_fd_read(handle_t handle, user_ptr buf, int len) {
if (handle < 0 || handle >= HANDLE_MAX) return -1;
- return handleop_dispatch((struct handleop_args){
- .type = HANDLEOP_READ,
- .handle = &process_current->handles[handle],
- .rw = {buf, len}
- });
+ return -1;
}
int _syscall_fd_write(handle_t handle, user_ptr buf, int len) {
if (handle < 0 || handle >= HANDLE_MAX) return -1;
- return handleop_dispatch((struct handleop_args){
- .type = HANDLEOP_WRITE,
- .handle = &process_current->handles[handle],
- .rw = {buf, len}
- });
+ return -1;
}
int _syscall_fd_close(handle_t handle) {
if (handle < 0 || handle >= HANDLE_MAX) return -1;
- return handleop_dispatch((struct handleop_args){
- .type = HANDLEOP_CLOSE,
- .handle = &process_current->handles[handle],
- });
+ return -1;
}
int syscall_handler(int num, int a, int b, int c) {
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index d9d9d6d..9d66f0b 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -3,7 +3,7 @@
#include <kernel/vfs/mount.h>
struct vfs_mount *vfs_mount_seed(void) {
- struct vfs_mount *mount = kmalloc(sizeof(struct vfs_mount));
+ struct vfs_mount *mount = NULL; /*kmalloc(sizeof(struct vfs_mount));
*mount = (struct vfs_mount){
.prev = NULL,
.prefix = "/tty",
@@ -11,7 +11,7 @@ struct vfs_mount *vfs_mount_seed(void) {
.handle = {
.type = HANDLE_SPECIAL_TTY,
},
- };
+ };*/
return mount;
}
diff --git a/src/kernel/vfs/mount.h b/src/kernel/vfs/mount.h
index d70d30a..b7029cd 100644
--- a/src/kernel/vfs/mount.h
+++ b/src/kernel/vfs/mount.h
@@ -5,7 +5,6 @@ struct vfs_mount {
struct vfs_mount *prev;
char *prefix;
size_t prefix_len;
- struct handle handle;
};
// prepares init's filesystem view