summaryrefslogtreecommitdiff
path: root/src/init/fs/misc.c
blob: a8d951744e661cc5c4832bcf3e98a2783fd1ba80 (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
#include <init/stdlib.h>
#include <shared/flags.h>
#include <shared/syscalls.h>

void fs_passthru(void) {
	struct fs_wait_response res;
	int buf_size = 64;
	char buf[      64];
	int ret;

	for (;;) {
		switch (_syscall_fs_wait(buf, buf_size, &res)) {
			case VFSOP_OPEN:
				ret = _syscall_open(buf, res.len);
				_syscall_fs_respond(NULL, ret);
				break;

			case VFSOP_READ:
				if (res.capacity > buf_size)
					res.capacity = buf_size; /* don't overflow the buffer */
				ret = _syscall_read(res.id, buf, res.capacity, res.offset);
				_syscall_fs_respond(buf, ret);
				break;

			// temporarily doesn't support writing
			// also TODO closing

			default:
				_syscall_fs_respond(NULL, -1);
				break;
		}
	}
}