summaryrefslogtreecommitdiff
path: root/src/kernel/handle.h
blob: 4b066adacc7e4eef6dd4b28f28fecfa825549e03 (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
#pragma once
#include <kernel/types.h>
#include <stddef.h>

#define HANDLE_MAX 16

typedef int handle_t; // TODO duplicated in syscalls.h

enum handle_type {
	HANDLE_EMPTY,
	HANDLE_SPECIAL_TTY,
};

struct handle {
	enum handle_type type;
};


enum handleop { // describes the operations which can be done on handles
	HANDLEOP_MOUNT, // also closes the original handle
	HANDLEOP_OPEN,

	HANDLEOP_READ,
	HANDLEOP_WRITE,
	HANDLEOP_CLOSE,
};

struct handleop_args {
	enum handleop type;
	struct handle *handle;
	union {
		struct { // HANDLEOP_MOUNT
			struct mount *target;
		} mnt;
		struct { // HANDLEOP_OPEN
			struct handle *target;
			const char *path; // relative to the mount point
			size_t len;
		} open;
		struct { // HANDLEOP_READ, HANDLEOP_WRITE
			user_ptr ptr;
			size_t len;
		} rw;
	};
};

int handleop_dispatch(struct handleop_args args);