blob: 1da0d6e11a1f2c6f72599ecd76a3bb2a15306a08 [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{
9 char name[128]; /* file name */
10 uint inode; /* identifier */
11 uint flags; /* type of node */
12 uint mask; /* permissions */
13 uint gid; /* group id */
14 uint uid; /* user id */
15 size_t size; /* size in bytes */
16 uint dri_res; /* reserved for driver */
17
18 struct fs_vtable *vtable;
19
20 struct fs_node *mount; /* used for mounts */
21};
22
23struct fs_dirent
24{
25 char name[128];
26 uint inode;
27};
28
29typedef uint (* fs_read_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
30typedef uint (* fs_write_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
31typedef void (* fs_open_t)(struct fs_node *node);
32typedef void (* fs_close_t)(struct fs_node *node);
33
swissChilib7fe8992021-03-10 16:25:47 -080034typedef bool (* fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
35typedef struct fs_node *(* fs_finddir_t)(struct fs_node *node, char *name);
swissChili8efa4922021-03-02 16:34:49 -080036
37struct fs_vtable
38{
39 fs_read_t read;
40 fs_write_t write;
41 fs_open_t open;
42 fs_close_t close;
43 fs_readdir_t readdir;
44 fs_finddir_t finddir;
45};
46
47enum fs_flags
48{
49 FS_FILE = 1,
50 FS_DIRECTORY,
51 FS_CHARDEVICE,
52 FS_BLOCKDEVICE,
53 FS_PIPE,
54 FS_SYMLINK,
55
56 FS_MOUNT = 8, /* Can be or'd with others */
57};
58
swissChilif5448622021-03-08 20:17:36 -080059extern struct fs_node root, dev, initrd;
60
swissChili8efa4922021-03-02 16:34:49 -080061/* Not to be confused normal open, close, etc functions, these operate
swissChilif5448622021-03-08 20:17:36 -080062 * on the VFS directly
63 * read and write return the number of bytes written/read, */
swissChili8efa4922021-03-02 16:34:49 -080064
65uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
66uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
67void fs_open(struct fs_node *node);
68void fs_close(struct fs_node *node);
69
swissChilib7fe8992021-03-10 16:25:47 -080070bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
71struct fs_node *fs_finddir(struct fs_node *node, char *name);
swissChilif5448622021-03-08 20:17:36 -080072
73/* Returns the following error codes:
74 * 0: success
75 * 1: target is not a directory
76 * 2: target is already a mount point
77 * 3: source is not a directory */
78uint fs_mount(struct fs_node *target, struct fs_node *source);
swissChili6c0519e2021-03-07 19:40:23 -080079
80void init_vfs();