summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/arch/amd64/driver/fsroot.c4
-rw-r--r--src/kernel/arch/amd64/driver/pata.c5
-rw-r--r--src/kernel/arch/amd64/driver/ps2.c6
-rw-r--r--src/kernel/arch/amd64/driver/rtl8139.c4
-rw-r--r--src/kernel/arch/amd64/driver/serial.c6
-rw-r--r--src/kernel/arch/amd64/driver/util.c1
-rw-r--r--src/kernel/arch/amd64/driver/video.c4
-rw-r--r--src/kernel/proc.c1
-rw-r--r--src/kernel/syscalls.c1
-rw-r--r--src/kernel/vfs/mount.c9
-rw-r--r--src/kernel/vfs/mount.h2
-rw-r--r--src/kernel/vfs/request.c6
-rw-r--r--src/kernel/vfs/request.h15
13 files changed, 28 insertions, 36 deletions
diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c
index 2344205..6217e29 100644
--- a/src/kernel/arch/amd64/driver/fsroot.c
+++ b/src/kernel/arch/amd64/driver/fsroot.c
@@ -3,6 +3,7 @@
#include <kernel/arch/amd64/driver/fsroot.h>
#include <kernel/arch/amd64/driver/util.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <kernel/util.h>
#include <kernel/vfs/request.h>
#include <shared/mem.h>
@@ -34,5 +35,4 @@ static void accept(struct vfs_request *req) {
vfsreq_finish_short(req, handle(req));
}
-static struct vfs_backend backend = BACKEND_KERN(accept);
-void vfs_root_init(void) { vfs_mount_root_register("", &backend); }
+void vfs_root_init(void) { vfs_root_register("", accept); }
diff --git a/src/kernel/arch/amd64/driver/pata.c b/src/kernel/arch/amd64/driver/pata.c
index 1193add..b6ed05e 100644
--- a/src/kernel/arch/amd64/driver/pata.c
+++ b/src/kernel/arch/amd64/driver/pata.c
@@ -5,17 +5,16 @@
#include <kernel/arch/amd64/driver/util.h>
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <kernel/vfs/request.h>
#include <shared/mem.h>
static const int root_id = 100;
static void accept(struct vfs_request *req);
-static struct vfs_backend backend = BACKEND_KERN(accept);
-
void pata_init(void) {
ata_init();
- vfs_mount_root_register("/ata", &backend);
+ vfs_root_register("/ata", accept);
}
diff --git a/src/kernel/arch/amd64/driver/ps2.c b/src/kernel/arch/amd64/driver/ps2.c
index 9148c98..899f325 100644
--- a/src/kernel/arch/amd64/driver/ps2.c
+++ b/src/kernel/arch/amd64/driver/ps2.c
@@ -3,6 +3,7 @@
#include <kernel/arch/amd64/interrupts/irq.h>
#include <kernel/arch/amd64/port_io.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <kernel/ring.h>
#include <kernel/vfs/request.h>
#include <shared/mem.h>
@@ -19,7 +20,6 @@ static void accept(struct vfs_request *req);
static struct vfs_request *kb_queue = NULL;
static struct vfs_request *mouse_queue = NULL;
-static struct vfs_backend backend = BACKEND_KERN(accept);
static void wait_out(void) {
uint8_t status;
@@ -36,7 +36,7 @@ static void wait_in(void) {
}
void ps2_init(void) {
- vfs_mount_root_register("/ps2", &backend);
+ vfs_root_register("/ps2", accept);
uint8_t compaq, ack;
wait_out();
@@ -71,14 +71,12 @@ void ps2_irq(void) {
if (mouse_queue) {
accept(mouse_queue);
mouse_queue = mouse_queue->postqueue_next;
- vfs_backend_tryaccept(&backend);
}
} else {
ring_put1b((void*)&kb_backlog, port_in8(PS2));
if (kb_queue) {
accept(kb_queue);
kb_queue = kb_queue->postqueue_next;
- vfs_backend_tryaccept(&backend);
}
}
}
diff --git a/src/kernel/arch/amd64/driver/rtl8139.c b/src/kernel/arch/amd64/driver/rtl8139.c
index fd7717f..05a0f70 100644
--- a/src/kernel/arch/amd64/driver/rtl8139.c
+++ b/src/kernel/arch/amd64/driver/rtl8139.c
@@ -3,13 +3,13 @@
#include <kernel/arch/amd64/port_io.h>
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <kernel/vfs/request.h>
#include <stdbool.h>
#define WAIT -1000
static void accept(struct vfs_request *req);
-static struct vfs_backend backend = BACKEND_KERN(accept);
static struct vfs_request *blocked_on = NULL;
@@ -80,7 +80,7 @@ void rtl8139_init(uint32_t bdf) {
uint64_t mac = (((uint64_t)port_in32(iobase + MAC + 4) & 0xFFFF) << 32) + port_in32(iobase + MAC);
kprintf("rtl8139 mac %012x\n", mac);
- vfs_mount_root_register("/eth", &backend);
+ vfs_root_register("/eth", accept);
}
void rtl8139_irq(void) {
diff --git a/src/kernel/arch/amd64/driver/serial.c b/src/kernel/arch/amd64/driver/serial.c
index cf21b61..9ddb355 100644
--- a/src/kernel/arch/amd64/driver/serial.c
+++ b/src/kernel/arch/amd64/driver/serial.c
@@ -4,6 +4,7 @@
#include <kernel/mem/virt.h>
#include <kernel/ring.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <stdint.h>
static volatile uint8_t backlog_buf[64];
@@ -12,10 +13,8 @@ static volatile ring_t backlog = {(void*)backlog_buf, sizeof backlog_buf, 0, 0};
static const int COM1 = 0x3f8;
static void accept(struct vfs_request *req);
-
static struct vfs_request *blocked_on = NULL;
-static struct vfs_backend backend = BACKEND_KERN(accept);
-void serial_init(void) { vfs_mount_root_register("/com1", &backend); }
+void serial_init(void) { vfs_root_register("/com1", accept); }
static void serial_selftest(void) {
@@ -47,7 +46,6 @@ void serial_irq(void) {
if (blocked_on) {
accept(blocked_on);
blocked_on = blocked_on->postqueue_next;
- vfs_backend_tryaccept(&backend);
}
}
diff --git a/src/kernel/arch/amd64/driver/util.c b/src/kernel/arch/amd64/driver/util.c
index b03e582..11aecca 100644
--- a/src/kernel/arch/amd64/driver/util.c
+++ b/src/kernel/arch/amd64/driver/util.c
@@ -2,6 +2,7 @@
#include <kernel/arch/amd64/driver/util.h>
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <kernel/vfs/request.h>
int req_readcopy(struct vfs_request *req, const void *buf, size_t len) {
diff --git a/src/kernel/arch/amd64/driver/video.c b/src/kernel/arch/amd64/driver/video.c
index c1aabe1..945d5b4 100644
--- a/src/kernel/arch/amd64/driver/video.c
+++ b/src/kernel/arch/amd64/driver/video.c
@@ -4,6 +4,7 @@
#include <kernel/arch/amd64/driver/video.h>
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
#include <kernel/vfs/request.h>
#include <shared/mem.h>
#include <shared/printf.h>
@@ -64,10 +65,9 @@ static void accept(struct vfs_request *req) {
}
}
-static struct vfs_backend backend = BACKEND_KERN(accept);
void video_init(struct fb_info fb_) {
fb = fb_;
snprintf(namebuf, sizeof namebuf, "%ux%ux%u", fb.width, fb.height, fb.bpp);
namelen = strlen(namebuf);
- vfs_mount_root_register("/video", &backend);
+ vfs_root_register("/video", accept);
}
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index ed7180b..7b8e659 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -1,3 +1,4 @@
+#include <camellia/flags.h>
#include <camellia/errno.h>
#include <kernel/arch/generic.h>
#include <kernel/execbuf.h>
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 7b5d294..9f77679 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -62,7 +62,6 @@ long _syscall_fork(int flags, handle_t __user *fs_front) {
}
h->backend = kmalloc(sizeof *h->backend);
- h->backend->heap = true;
h->backend->is_user = true;
h->backend->potential_handlers = 1;
h->backend->refcount = 2; // child + handle
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index de2d708..aa73acb 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -9,8 +9,15 @@ struct vfs_mount *vfs_mount_seed(void) {
return mount_root;
}
-void vfs_mount_root_register(const char *path, struct vfs_backend *backend) {
+void vfs_root_register(const char *path, void (*accept)(struct vfs_request *)) {
+ struct vfs_backend *backend = kmalloc(sizeof *backend);
struct vfs_mount *mount = kmalloc(sizeof *mount);
+ *backend = (struct vfs_backend) {
+ .is_user = false,
+ .potential_handlers = 1,
+ .refcount = 1,
+ .kern.accept = accept,
+ };
*mount = (struct vfs_mount){
.prev = mount_root,
.prefix = path,
diff --git a/src/kernel/vfs/mount.h b/src/kernel/vfs/mount.h
index bcd3460..6efdaa7 100644
--- a/src/kernel/vfs/mount.h
+++ b/src/kernel/vfs/mount.h
@@ -21,4 +21,4 @@ struct vfs_mount *vfs_mount_resolve(
/** 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);
+void vfs_root_register(const char *path, void (*accept)(struct vfs_request *));
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 959b051..8559b23 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -7,6 +7,8 @@
#include <kernel/vfs/request.h>
#include <shared/mem.h>
+static void vfs_backend_user_accept(struct vfs_request *req);
+
void vfsreq_create(struct vfs_request req_) {
struct vfs_request *req;
if (req_.caller) {
@@ -90,7 +92,7 @@ void vfs_backend_tryaccept(struct vfs_backend *backend) {
}
}
-void vfs_backend_user_accept(struct vfs_request *req) {
+static void vfs_backend_user_accept(struct vfs_request *req) {
struct process *handler;
struct fs_wait_response res = {0};
struct virt_cpy_error cpyerr;
@@ -148,5 +150,5 @@ void vfs_backend_refdown(struct vfs_backend *b) {
if (--(b->refcount) > 0) return;
assert(!b->queue);
- if (b->heap) kfree(b);
+ kfree(b);
}
diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h
index 7c991f4..4e309b0 100644
--- a/src/kernel/vfs/request.h
+++ b/src/kernel/vfs/request.h
@@ -1,25 +1,21 @@
#pragma once
-#include <camellia/flags.h>
#include <camellia/types.h>
-#include <kernel/proc.h>
#include <stdbool.h>
#include <stddef.h>
// describes something which can act as an access function
struct vfs_backend {
- size_t refcount;
/* references:
* struct vfs_mount
* struct vfs_request
* struct process
* struct handle
*/
- bool heap;
+ size_t refcount;
size_t potential_handlers; // 0 - orphaned
struct vfs_request *queue;
bool is_user;
-
union {
struct {
struct process *handler;
@@ -71,14 +67,5 @@ static inline void vfsreq_finish_short(struct vfs_request *req, long ret) {
/** Try to accept an enqueued request */
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(accept) ((struct vfs_backend){\
- .is_user = false, \
- .heap = false, \
- .potential_handlers = 1, \
- .refcount = 1, \
- .kern.accept = accept})