summaryrefslogtreecommitdiff
path: root/src/kernel/vfs/root.c
blob: 0f11a5b2107c3c55fdaebe1214056df733180446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <kernel/mem.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/types.h>
#include <kernel/util.h>
#include <kernel/vfs/root.h>

int vfs_root_handler(struct vfs_op_request *req) {
	switch (req->op.type) {
		case VFSOP_OPEN:
			if (req->op.open.path_len == 4
					&& !memcmp(req->op.open.path, "/tty", 4)) {
				return 0;
			}
			return -1;
		case VFSOP_WRITE:
			switch (req->op.rw.id) {
				// every id corresponds to a special file type
				// this is a shit way to do this but :shrug:
				case 0: { // tty
					struct virt_iter iter;
					virt_iter_new(&iter, req->op.rw.buf, req->op.rw.buf_len,
							req->caller->pages, true, false);
					while (virt_iter_next(&iter))
						tty_write(iter.frag, iter.frag_len);
					return iter.prior;
				}
				default: panic();
			}
		default: panic();
	}
}