blob: e7cf8d93886a4105b0c125dc0bbc1ebec0d6cfb3 [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{
swissChilicaa24782021-07-19 14:29:58 -070034 // EXT2 supports up to 256 byte file names, so we will do the same
35 char name[256];
swissChili8efa4922021-03-02 16:34:49 -080036 uint inode;
37};
38
swissChilie5adca52021-06-16 21:00:31 -070039typedef uint (*fs_read_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
40typedef uint (*fs_write_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
41typedef void (*fs_open_t)(struct fs_node *node);
42typedef void (*fs_close_t)(struct fs_node *node);
swissChili8efa4922021-03-02 16:34:49 -080043
swissChilie5adca52021-06-16 21:00:31 -070044typedef bool (*fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
45typedef struct fs_node *(*fs_finddir_t)(struct fs_node *node, char *name);
swissChili8efa4922021-03-02 16:34:49 -080046
47struct fs_vtable
48{
49 fs_read_t read;
50 fs_write_t write;
51 fs_open_t open;
52 fs_close_t close;
53 fs_readdir_t readdir;
54 fs_finddir_t finddir;
55};
56
57enum fs_flags
58{
59 FS_FILE = 1,
60 FS_DIRECTORY,
61 FS_CHARDEVICE,
62 FS_BLOCKDEVICE,
63 FS_PIPE,
64 FS_SYMLINK,
swissChilie5adca52021-06-16 21:00:31 -070065
66 FS_MOUNT = 8, /* Can be or'd with others */
swissChili8efa4922021-03-02 16:34:49 -080067};
68
swissChilif5448622021-03-08 20:17:36 -080069extern struct fs_node root, dev, initrd;
70
swissChili8efa4922021-03-02 16:34:49 -080071/* Not to be confused normal open, close, etc functions, these operate
swissChilif5448622021-03-08 20:17:36 -080072 * on the VFS directly
73 * read and write return the number of bytes written/read, */
swissChili8efa4922021-03-02 16:34:49 -080074
75uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
76uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
77void fs_open(struct fs_node *node);
78void fs_close(struct fs_node *node);
79
swissChilib7fe8992021-03-10 16:25:47 -080080bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
81struct fs_node *fs_finddir(struct fs_node *node, char *name);
swissChilif5448622021-03-08 20:17:36 -080082
83/* Returns the following error codes:
84 * 0: success
85 * 1: target is not a directory
86 * 2: target is already a mount point
87 * 3: source is not a directory */
88uint fs_mount(struct fs_node *target, struct fs_node *source);
swissChili6c0519e2021-03-07 19:40:23 -080089
90void init_vfs();