blob: 40a8e8746e07dbfef702bd055f9b07834c64475f [file] [log] [blame]
swissChili8efa4922021-03-02 16:34:49 -08001#pragma once
2
3#include "kint.h"
4
5struct fs_vtable;
6
7struct fs_node
8{
swissChilie5adca52021-06-16 21:00:31 -07009 /** file name */
10 char name[128];
11 /** identifier */
12 uint inode;
13 /** type of node */
14 uint flags;
15 /** permissions */
16 uint mask;
17 /** group id */
18 uint gid;
19 /** user id */
20 uint uid;
21 /** size in bytes */
22 size_t size;
23 /** reserved for driver */
24 uint dri_res;
swissChili8efa4922021-03-02 16:34:49 -080025
26 struct fs_vtable *vtable;
27
swissChilie5adca52021-06-16 21:00:31 -070028 /** used for mounts */
29 struct fs_node *mount;
swissChili8efa4922021-03-02 16:34:49 -080030};
31
32struct fs_dirent
33{
34 char name[128];
35 uint inode;
36};
37
swissChilie5adca52021-06-16 21:00:31 -070038typedef uint (*fs_read_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
39typedef uint (*fs_write_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
40typedef void (*fs_open_t)(struct fs_node *node);
41typedef void (*fs_close_t)(struct fs_node *node);
swissChili8efa4922021-03-02 16:34:49 -080042
swissChilie5adca52021-06-16 21:00:31 -070043typedef bool (*fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
44typedef struct fs_node *(*fs_finddir_t)(struct fs_node *node, char *name);
swissChili8efa4922021-03-02 16:34:49 -080045
46struct fs_vtable
47{
48 fs_read_t read;
49 fs_write_t write;
50 fs_open_t open;
51 fs_close_t close;
52 fs_readdir_t readdir;
53 fs_finddir_t finddir;
54};
55
56enum fs_flags
57{
58 FS_FILE = 1,
59 FS_DIRECTORY,
60 FS_CHARDEVICE,
61 FS_BLOCKDEVICE,
62 FS_PIPE,
63 FS_SYMLINK,
swissChilie5adca52021-06-16 21:00:31 -070064
65 FS_MOUNT = 8, /* Can be or'd with others */
swissChili8efa4922021-03-02 16:34:49 -080066};
67
swissChilif5448622021-03-08 20:17:36 -080068extern struct fs_node root, dev, initrd;
69
swissChili8efa4922021-03-02 16:34:49 -080070/* Not to be confused normal open, close, etc functions, these operate
swissChilif5448622021-03-08 20:17:36 -080071 * on the VFS directly
72 * read and write return the number of bytes written/read, */
swissChili8efa4922021-03-02 16:34:49 -080073
74uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
75uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
76void fs_open(struct fs_node *node);
77void fs_close(struct fs_node *node);
78
swissChilib7fe8992021-03-10 16:25:47 -080079bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
80struct fs_node *fs_finddir(struct fs_node *node, char *name);
swissChilif5448622021-03-08 20:17:36 -080081
82/* Returns the following error codes:
83 * 0: success
84 * 1: target is not a directory
85 * 2: target is already a mount point
86 * 3: source is not a directory */
87uint fs_mount(struct fs_node *target, struct fs_node *source);
swissChili6c0519e2021-03-07 19:40:23 -080088
89void init_vfs();