aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs/vfs.h
blob: 41d80eb9e3412757744d87f334b00bb00321bf30 (plain) (blame)
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
#ifndef MELVIX_VFS_H
#define MELVIX_VFS_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#define MAX_NAME_LENGTH 128

enum node_type {
	FILE_NODE = 1,
	DIR_NODE,
	CHAR_DEV_NODE,
	BLOCK_DEV_NODE,
	PIPE_NODE,
	SYMLINK_NODE,
	MOUNTPOINT_NODE = 8
};

struct fs_node;
struct dir_entry;

typedef uint32_t (*read)(struct fs_node *, size_t, size_t, char *);
typedef uint32_t (*write)(struct fs_node *, size_t, size_t, char *);
typedef void (*open)(struct fs_node *);
typedef void (*close)(struct fs_node *);

typedef struct dir_entry *(*read_dir)(struct fs_node *, size_t);
typedef struct fs_node *(*find_dir)(struct fs_node *, char *);

struct fs_node {
	char name[MAX_NAME_LENGTH];
	uint32_t length;
	uint32_t inode;
	uint32_t permissions;
	uint32_t uid;
	uint32_t gid;
	enum node_type type;

	struct fs_node *node_ptr;

	void *impl;

	read read;
	write write;
	open open;
	close close;
	read_dir read_dir;
	find_dir find_dir;
};

struct dir_entry {
	char name[MAX_NAME_LENGTH];
	uint32_t inode;
};

struct fs_node *fs_root;

uint32_t read_fs_node(struct fs_node *node, size_t offset, size_t size, char *buf);
uint32_t write_fs_node(struct fs_node *node, size_t offset, size_t size, char *buf);
void open_fs_node(struct fs_node *node, bool read, bool write);
void close_fs_node(struct fs_node *node);
struct dir_entry *read_dir_node(struct fs_node *node, size_t index);
struct fs_node *find_dir_node(struct fs_node *node, char *name);

#endif