swissChili | 8efa492 | 2021-03-02 16:34:49 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "kint.h" |
| 4 | |
| 5 | struct fs_vtable; |
| 6 | |
| 7 | struct 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 | |
| 23 | struct fs_dirent |
| 24 | { |
| 25 | char name[128]; |
| 26 | uint inode; |
| 27 | }; |
| 28 | |
| 29 | typedef uint (* fs_read_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer); |
| 30 | typedef uint (* fs_write_t)(struct fs_node *node, size_t offset, size_t size, uchar *buffer); |
| 31 | typedef void (* fs_open_t)(struct fs_node *node); |
| 32 | typedef void (* fs_close_t)(struct fs_node *node); |
| 33 | |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 34 | typedef bool (* fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent); |
| 35 | typedef struct fs_node *(* fs_finddir_t)(struct fs_node *node, char *name); |
swissChili | 8efa492 | 2021-03-02 16:34:49 -0800 | [diff] [blame] | 36 | |
| 37 | struct 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 | |
| 47 | enum 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 | |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 59 | extern struct fs_node root, dev, initrd; |
| 60 | |
swissChili | 8efa492 | 2021-03-02 16:34:49 -0800 | [diff] [blame] | 61 | /* Not to be confused normal open, close, etc functions, these operate |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 62 | * on the VFS directly |
| 63 | * read and write return the number of bytes written/read, */ |
swissChili | 8efa492 | 2021-03-02 16:34:49 -0800 | [diff] [blame] | 64 | |
| 65 | uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer); |
| 66 | uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer); |
| 67 | void fs_open(struct fs_node *node); |
| 68 | void fs_close(struct fs_node *node); |
| 69 | |
swissChili | b7fe899 | 2021-03-10 16:25:47 -0800 | [diff] [blame] | 70 | bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out); |
| 71 | struct fs_node *fs_finddir(struct fs_node *node, char *name); |
swissChili | f544862 | 2021-03-08 20:17:36 -0800 | [diff] [blame] | 72 | |
| 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 */ |
| 78 | uint fs_mount(struct fs_node *target, struct fs_node *source); |
swissChili | 6c0519e | 2021-03-07 19:40:23 -0800 | [diff] [blame] | 79 | |
| 80 | void init_vfs(); |