blob: d9f36a6f640d0d70740fca0e2b7049e88b8c6f54 [file] [log] [blame]
swissChili8efa4922021-03-02 16:34:49 -08001#pragma once
2
3#include "kint.h"
4
5struct fs_vtable;
6
swissChili480f1762021-07-26 22:17:34 -07007#define FS_MAX_NAME_LEN 128
8
swissChili8efa4922021-03-02 16:34:49 -08009struct fs_node
10{
swissChili480f1762021-07-26 22:17:34 -070011 /** length of file name */
12 uint name_len;
swissChilie5adca52021-06-16 21:00:31 -070013 /** file name */
14 char name[128];
15 /** identifier */
16 uint inode;
17 /** type of node */
18 uint flags;
19 /** permissions */
20 uint mask;
21 /** group id */
22 uint gid;
23 /** user id */
24 uint uid;
25 /** size in bytes */
26 size_t size;
27 /** reserved for driver */
swissChili480f1762021-07-26 22:17:34 -070028 union
29 {
30 uint dri_res_i;
31 void *dri_res_p;
32 };
swissChili8efa4922021-03-02 16:34:49 -080033
34 struct fs_vtable *vtable;
35
swissChilie5adca52021-06-16 21:00:31 -070036 /** used for mounts */
37 struct fs_node *mount;
swissChili8efa4922021-03-02 16:34:49 -080038};
39
40struct fs_dirent
41{
swissChilicaa24782021-07-19 14:29:58 -070042 // EXT2 supports up to 256 byte file names, so we will do the same
43 char name[256];
swissChili480f1762021-07-26 22:17:34 -070044 uint name_len;
swissChili8efa4922021-03-02 16:34:49 -080045 uint inode;
46};
47
swissChilie5adca52021-06-16 21:00:31 -070048typedef uint (*fs_read_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
49typedef uint (*fs_write_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
50typedef void (*fs_open_t)(struct fs_node *node);
51typedef void (*fs_close_t)(struct fs_node *node);
swissChili8efa4922021-03-02 16:34:49 -080052
swissChilie5adca52021-06-16 21:00:31 -070053typedef bool (*fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
swissChili480f1762021-07-26 22:17:34 -070054typedef struct fs_node *(*fs_finddir_t)(struct fs_node *node, char *name, uint name_len);
swissChili8efa4922021-03-02 16:34:49 -080055
56struct fs_vtable
57{
58 fs_read_t read;
59 fs_write_t write;
60 fs_open_t open;
61 fs_close_t close;
62 fs_readdir_t readdir;
63 fs_finddir_t finddir;
64};
65
66enum fs_flags
67{
68 FS_FILE = 1,
69 FS_DIRECTORY,
70 FS_CHARDEVICE,
71 FS_BLOCKDEVICE,
72 FS_PIPE,
73 FS_SYMLINK,
swissChilie5adca52021-06-16 21:00:31 -070074
75 FS_MOUNT = 8, /* Can be or'd with others */
swissChili8efa4922021-03-02 16:34:49 -080076};
77
swissChilif5448622021-03-08 20:17:36 -080078extern struct fs_node root, dev, initrd;
79
swissChili8efa4922021-03-02 16:34:49 -080080/* Not to be confused normal open, close, etc functions, these operate
swissChilif5448622021-03-08 20:17:36 -080081 * on the VFS directly
82 * read and write return the number of bytes written/read, */
swissChili8efa4922021-03-02 16:34:49 -080083
84uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
85uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
86void fs_open(struct fs_node *node);
87void fs_close(struct fs_node *node);
88
swissChilib7fe8992021-03-10 16:25:47 -080089bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
swissChili480f1762021-07-26 22:17:34 -070090struct fs_node *fs_finddir(struct fs_node *node, char *name, uint name_len);
swissChilif5448622021-03-08 20:17:36 -080091
92/* Returns the following error codes:
93 * 0: success
94 * 1: target is not a directory
95 * 2: target is already a mount point
96 * 3: source is not a directory */
97uint fs_mount(struct fs_node *target, struct fs_node *source);
swissChili6c0519e2021-03-07 19:40:23 -080098
99void init_vfs();