summaryrefslogtreecommitdiff
path: root/src/init/main.c
blob: 06e59a2e8a4e3b51cece482b535193a98e1a580e (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
#include <init/types.h>
#include <shared/syscalls.h>
#include <stdint.h>

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

__attribute__((section("text")))
int tty_fd;

void fs_test(void);

int main(void) {
	tty_fd = _syscall_open("/tty", sizeof("/tty") - 1);
	if (tty_fd < 0)
		_syscall_exit(argify("couldn't open tty"));
	log(" opened /tty ");

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

void fs_test(void) {
	static char buf[64] __attribute__((section("text")));
	int len = 64;
	handle_t front, back, file;
	front = _syscall_fs_create(&back);

	if (_syscall_fork()) {
		// child: is the fs server
		log("fs_wait started. ");
		_syscall_fs_wait(back, buf, &len);
		log("fs_wait returned. ");
		_syscall_write(tty_fd, buf, len);
	} else {
		// parent: accesses the fs
		_syscall_mount(front, argify("/mnt"));
		log("requesting file. ");
		file = _syscall_open(argify("/mnt/test"));
	}
}