summaryrefslogtreecommitdiff
path: root/src/kernel/vfs/request.h
blob: b4624fa9c178e48bca22a27936a9a9a87050135e (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
65
66
67
68
69
70
71
#pragma once
#include <kernel/proc.h>
#include <shared/flags.h>
#include <shared/types.h>
#include <stdbool.h>
#include <stddef.h>

// describes something which can act as an access function
struct vfs_backend {
	size_t refcount;
	/* references:
	 *   struct vfs_mount
	 *   struct vfs_request
	 *   struct process
	 *   struct handle
	 */

	size_t potential_handlers; // 0 - orphaned
	struct vfs_request *queue;
	bool is_user;

	union {
		struct {
			struct process *handler;
		} user;
		struct {
			bool (*ready)(struct vfs_backend *);

			// return value might be passed to caller
			// TODO make return void
			int (*accept)(struct vfs_request *);
		} kern;
	};
};

// describes an in-process vfs call
struct vfs_request {
	enum vfs_operation type;
	struct {
		bool kern; // if false: use .buf ; if true: use .buf_kern
		union {
			char __user *buf;
			char *buf_kern;
		};
		size_t len;
	} input;
	struct {
		char __user *buf;
		size_t len;
	} output;

	int id; // handle.file.id
	int offset;

	struct process *caller;
	struct vfs_backend *backend;

	struct vfs_request *queue_next;
};

/** Assigns the vfs_request to the caller, and dispatches the call */
int vfsreq_create(struct vfs_request);
int vfsreq_finish(struct vfs_request *, int ret);

/** Try to accept an enqueued request
 * @return same as _syscall_fs_wait, passed to it. except on calls to kern backend, where it returns the result of the fs op - also gets directly passed to caller. it's a mess */
// TODO fix the return value mess
int vfs_backend_tryaccept(struct vfs_backend *);
int vfs_backend_user_accept(struct vfs_request *req);

void vfs_backend_refdown(struct vfs_backend *);