summaryrefslogtreecommitdiff
path: root/src/kernel/vfs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/vfs')
-rw-r--r--src/kernel/vfs/mount.c25
-rw-r--r--src/kernel/vfs/mount.h1
-rw-r--r--src/kernel/vfs/root.c42
3 files changed, 23 insertions, 45 deletions
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index 232e702..178cc54 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -4,7 +4,9 @@
#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>
struct vfs_mount *vfs_mount_seed(void) {
struct vfs_mount *mount = kmalloc(sizeof *mount);
@@ -19,7 +21,7 @@ struct vfs_mount *vfs_mount_seed(void) {
.prefix = NULL,
.prefix_len = 0,
.backend = backend,
- .refs = 1, // never to be freed
+ .refs = 1,
};
// what a mess.
@@ -39,7 +41,23 @@ struct vfs_mount *vfs_mount_seed(void) {
.refs = 1,
};
- return ps2;
+ // 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;
}
struct vfs_mount *vfs_mount_resolve(
@@ -71,7 +89,8 @@ void vfs_mount_remref(struct vfs_mount *mnt) {
struct vfs_mount *prev = mnt->prev;
if (mnt->backend)
vfs_backend_refdown(mnt->backend);
- kfree(mnt->prefix);
+ if (mnt->prefix_owned)
+ kfree(mnt->prefix);
kfree(mnt);
if (prev) vfs_mount_remref(prev);
diff --git a/src/kernel/vfs/mount.h b/src/kernel/vfs/mount.h
index 96a2d7b..4aa08d4 100644
--- a/src/kernel/vfs/mount.h
+++ b/src/kernel/vfs/mount.h
@@ -6,6 +6,7 @@ struct vfs_mount {
struct vfs_mount *prev;
char *prefix;
size_t prefix_len;
+ bool prefix_owned;
struct vfs_backend *backend;
size_t refs; /* counts all references, atm from:
* - struct vfs_mount
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c
index 0c58d86..c1b16fa 100644
--- a/src/kernel/vfs/root.c
+++ b/src/kernel/vfs/root.c
@@ -1,6 +1,4 @@
#include <kernel/arch/i386/ata.h>
-#include <kernel/arch/i386/driver/ps2.h>
-#include <kernel/arch/i386/driver/serial.h>
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
@@ -14,7 +12,6 @@
enum {
HANDLE_ROOT,
HANDLE_VGA,
- HANDLE_COM1,
HANDLE_ATA_ROOT,
HANDLE_ATA,
_SKIP = HANDLE_ATA + 4,
@@ -52,25 +49,12 @@ static void wait_callback(struct process *proc) {
vfs_root_accept(proc->waits4irq.req);
}
-static bool wait_setup(struct vfs_request *req, bool *ready, bool (*ready_fn)()) {
- if (!ready_fn()) {
- *ready = false;
- process_transition(req->caller, PS_WAITS4IRQ);
- req->caller->waits4irq.req = req;
- req->caller->waits4irq.ready = ready_fn;
- req->caller->waits4irq.callback = wait_callback;
- return true;
- }
- return false;
-}
-
static int handle(struct vfs_request *req, bool *ready) {
assert(req->caller);
switch (req->type) {
case VFSOP_OPEN:
if (exacteq(req, "/")) return HANDLE_ROOT;
if (exacteq(req, "/vga")) return HANDLE_VGA;
- if (exacteq(req, "/com1")) return HANDLE_COM1;
if (exacteq(req, "/ata/")) return HANDLE_ATA_ROOT;
if (exacteq(req, "/ata/0"))
@@ -104,13 +88,6 @@ static int handle(struct vfs_request *req, bool *ready) {
vga + req->offset, req->output.len);
return req->output.len;
}
- case HANDLE_COM1: {
- if (wait_setup(req, ready, serial_ready)) return -1;
- char buf[16];
- size_t len = serial_read(buf, min(req->output.len, sizeof buf));
- virt_cpy_to(req->caller->pages, req->output.buf, buf, len);
- return len;
- }
case HANDLE_ATA_ROOT: {
// TODO offset
char list[8] = {};
@@ -147,14 +124,6 @@ static int handle(struct vfs_request *req, bool *ready) {
req->input.buf, req->input.len);
return req->input.len;
}
- case HANDLE_COM1: {
- struct virt_iter iter;
- virt_iter_new(&iter, req->input.buf, req->input.len,
- req->caller->pages, true, false);
- while (virt_iter_next(&iter))
- serial_write(iter.frag, iter.frag_len);
- return iter.prior;
- }
default: return -1;
}
@@ -167,17 +136,6 @@ static int handle(struct vfs_request *req, bool *ready) {
int vfs_root_accept(struct vfs_request *req) {
if (req->caller) {
- /* this introduces a difference between the root vfs and emulated ones:
- *
- * the root vfs has to immediately discard requests from dead processes.
- * so, if 16 processes queue up for an IRQ, and the middle 14 quit, only
- * 2 IRQs will be processed
- *
- * but if they do that in an emulated root vfs, all 16 IRQs will be processed
- *
- * to fix this, i need to make it so callerless requests can also wait
- * for IRQs.
- */
bool ready = true;
int ret = handle(req, &ready);
if (ready) {