summaryrefslogtreecommitdiff
path: root/src/kernel/vfs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/vfs')
-rw-r--r--src/kernel/vfs/mount.c68
-rw-r--r--src/kernel/vfs/mount.h4
-rw-r--r--src/kernel/vfs/request.c2
-rw-r--r--src/kernel/vfs/request.h9
-rw-r--r--src/kernel/vfs/root.c7
-rw-r--r--src/kernel/vfs/root.h5
6 files changed, 34 insertions, 61 deletions
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index 178cc54..77cc14b 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -1,63 +1,13 @@
#include <kernel/mem/alloc.h>
#include <kernel/panic.h>
#include <kernel/vfs/mount.h>
-#include <kernel/vfs/root.h>
#include <shared/mem.h>
// TODO not the place where this should be done
-#include <kernel/arch/i386/driver/ps2.h>
-#include <kernel/arch/i386/driver/serial.h>
+static struct vfs_mount *mount_root = NULL;
struct vfs_mount *vfs_mount_seed(void) {
- struct vfs_mount *mount = kmalloc(sizeof *mount);
- struct vfs_backend *backend = kmalloc(sizeof *backend);
- backend->is_user = false;
- backend->potential_handlers = 1;
- backend->refcount = 1;
- backend->kern.ready = vfs_root_ready;
- backend->kern.accept = vfs_root_accept;
- *mount = (struct vfs_mount){
- .prev = NULL,
- .prefix = NULL,
- .prefix_len = 0,
- .backend = backend,
- .refs = 1,
- };
-
- // what a mess.
- // TODO register funcs
- struct vfs_mount *ps2 = kmalloc(sizeof *ps2);
- backend = kmalloc(sizeof *backend);
- backend->is_user = false;
- backend->potential_handlers = 1;
- backend->refcount = 1;
- backend->kern.ready = vfs_ps2_ready;
- backend->kern.accept = vfs_ps2_accept;
- *ps2 = (struct vfs_mount){
- .prev = mount,
- .prefix = "/ps2",
- .prefix_len = 4,
- .backend = backend,
- .refs = 1,
- };
-
- // oh god oh fuck
- struct vfs_mount *com = kmalloc(sizeof *com);
- backend = kmalloc(sizeof *backend);
- backend->is_user = false;
- backend->potential_handlers = 1;
- backend->refcount = 1;
- backend->kern.ready = vfs_com1_ready;
- backend->kern.accept = vfs_com1_accept;
- *com = (struct vfs_mount){
- .prev = ps2,
- .prefix = "/com1",
- .prefix_len = 5,
- .backend = backend,
- .refs = 1,
- };
-
- return com;
+ return mount_root;
}
struct vfs_mount *vfs_mount_resolve(
@@ -90,8 +40,20 @@ void vfs_mount_remref(struct vfs_mount *mnt) {
if (mnt->backend)
vfs_backend_refdown(mnt->backend);
if (mnt->prefix_owned)
- kfree(mnt->prefix);
+ kfree((void*)mnt->prefix);
kfree(mnt);
if (prev) vfs_mount_remref(prev);
}
+
+void vfs_mount_root_register(const char *path, struct vfs_backend *backend) {
+ struct vfs_mount *mount = kmalloc(sizeof *mount);
+ *mount = (struct vfs_mount){
+ .prev = mount_root,
+ .prefix = path,
+ .prefix_len = strlen(path),
+ .backend = backend,
+ .refs = 1,
+ };
+ mount_root = mount;
+}
diff --git a/src/kernel/vfs/mount.h b/src/kernel/vfs/mount.h
index 4aa08d4..bcd3460 100644
--- a/src/kernel/vfs/mount.h
+++ b/src/kernel/vfs/mount.h
@@ -4,7 +4,7 @@
struct vfs_mount {
struct vfs_mount *prev;
- char *prefix;
+ const char *prefix;
size_t prefix_len;
bool prefix_owned;
struct vfs_backend *backend;
@@ -20,3 +20,5 @@ struct vfs_mount *vfs_mount_resolve(
struct vfs_mount *top, const char *path, size_t path_len);
/** Decrements the reference count, potentially freeing the mount. */
void vfs_mount_remref(struct vfs_mount *mnt);
+
+void vfs_mount_root_register(const char *path, struct vfs_backend *backend);
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 3e7c9f0..0c3084d 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -134,5 +134,5 @@ void vfs_backend_refdown(struct vfs_backend *b) {
if (--(b->refcount) > 0) return;
assert(!b->queue);
- kfree(b);
+ if (b->heap) kfree(b);
}
diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h
index 9dc6088..e034bc6 100644
--- a/src/kernel/vfs/request.h
+++ b/src/kernel/vfs/request.h
@@ -14,6 +14,7 @@ struct vfs_backend {
* struct process
* struct handle
*/
+ bool heap;
size_t potential_handlers; // 0 - orphaned
struct vfs_request *queue;
@@ -64,3 +65,11 @@ void vfs_backend_tryaccept(struct vfs_backend *);
void vfs_backend_user_accept(struct vfs_request *req);
void vfs_backend_refdown(struct vfs_backend *);
+
+
+#define BACKEND_KERN(ready, accept) ((struct vfs_backend){\
+ .is_user = false, \
+ .heap = false, \
+ .potential_handlers = 1, \
+ .refcount = 1, \
+ .kern = {ready, accept}})
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c
index 989c77e..8ba2043 100644
--- a/src/kernel/vfs/root.c
+++ b/src/kernel/vfs/root.c
@@ -130,7 +130,7 @@ static int handle(struct vfs_request *req, bool *ready) {
}
}
-void vfs_root_accept(struct vfs_request *req) {
+static void accept(struct vfs_request *req) {
if (req->caller) {
bool ready = true;
int ret = handle(req, &ready);
@@ -142,6 +142,9 @@ void vfs_root_accept(struct vfs_request *req) {
}
}
-bool vfs_root_ready(struct vfs_backend *self) {
+static bool is_ready(struct vfs_backend *self) {
return true;
}
+
+static struct vfs_backend backend = BACKEND_KERN(is_ready, accept);
+void vfs_root_init(void) { vfs_mount_root_register("", &backend); }
diff --git a/src/kernel/vfs/root.h b/src/kernel/vfs/root.h
index 3db958d..dd72202 100644
--- a/src/kernel/vfs/root.h
+++ b/src/kernel/vfs/root.h
@@ -1,5 +1,2 @@
#pragma once
-#include <kernel/vfs/request.h>
-
-void vfs_root_accept(struct vfs_request *);
-bool vfs_root_ready(struct vfs_backend *);
+void vfs_root_init(void);