blob: 3bd135ee427061873a7ac304d49047a2ff6d25b5 [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
swissChili6c0519e2021-03-07 19:40:23 -080034// Dirent should be FREED BY CALLER
swissChili8efa4922021-03-02 16:34:49 -080035typedef struct fs_dirent *(* fs_readdir_t)(struct fs_node *node, uint index);
36typedef struct fs_node *(* fs_finddir_t)(struct fs_node *node, char *name);
37
38struct fs_vtable
39{
40 fs_read_t read;
41 fs_write_t write;
42 fs_open_t open;
43 fs_close_t close;
44 fs_readdir_t readdir;
45 fs_finddir_t finddir;
46};
47
48enum fs_flags
49{
50 FS_FILE = 1,
51 FS_DIRECTORY,
52 FS_CHARDEVICE,
53 FS_BLOCKDEVICE,
54 FS_PIPE,
55 FS_SYMLINK,
56
57 FS_MOUNT = 8, /* Can be or'd with others */
58};
59
60/* Not to be confused normal open, close, etc functions, these operate
61 * on the VFS directly */
62
63uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
64uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer);
65void fs_open(struct fs_node *node);
66void fs_close(struct fs_node *node);
67
68struct fs_dirent *fs_readdir(struct fs_node *node, uint index);
69struct fs_node *fs_finddir(struct fs_node *node, char *name);
swissChili6c0519e2021-03-07 19:40:23 -080070
71void init_vfs();