summaryrefslogtreecommitdiff
path: root/src/init/main.c
blob: f31da025fa4d38c9187302b0ee649589dc101629 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <init/types.h>
#include <shared/flags.h>
#include <shared/syscalls.h>
#include <stdint.h>

#define argify(str) str, sizeof(str) - 1
#define log(str) _syscall_write(tty_fd, argify(str))

extern char _bss_start; // provided by the linker
extern char _bss_end;

int tty_fd;

void fs_test(void);
void fs_server(handle_t back);

__attribute__((section(".text.startup")))
int main(void) {
	// allocate bss
	_syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT);

	tty_fd = _syscall_open("/tty", sizeof("/tty") - 1);
	if (tty_fd < 0)
		_syscall_exit(argify("couldn't open tty"));

	fs_test();
	_syscall_exit(argify("my job here is done."));
}

void fs_test(void) {
	handle_t front, back, file;
	front = _syscall_fs_create(&back);

	if (_syscall_fork()) {
		// child: is the fs server
		fs_server(back);
		return;
	}

	// parent: accesses the fs
	_syscall_mount(front, argify("/mnt"));
	log("requesting file. ");
	file = _syscall_open(argify("/mnt/tty"));
	log("open returned. ");
}

void fs_server(handle_t back) {
	static char buf[64];
	int len;
	for (;;) {
		len = 64;
		switch (_syscall_fs_wait(back, buf, &len)) {
			case VFSOP_OPEN:
				_syscall_write(tty_fd, buf, len);
				log(" was opened. ");
				_syscall_fs_respond(0, NULL, 0); // doesn't check the path yet
				break;
			default:
				log("fuck");
				break;
		}
	}

}