4 #include <hal/ahci/hba.h>
5 #include <lunaix/block.h>
6 #include <lunaix/clock.h>
7 #include <lunaix/ds/btrie.h>
8 #include <lunaix/ds/hashtable.h>
9 #include <lunaix/ds/hstr.h>
10 #include <lunaix/ds/llist.h>
11 #include <lunaix/ds/lru.h>
12 #include <lunaix/status.h>
14 #define VFS_NAME_MAXLEN 128
18 #define VFS_IFFILE 0x2
19 #define VFS_IFSEQDEV 0x4
20 #define VFS_IFVOLDEV 0x8
21 #define VFS_IFSYMLINK 0x16
23 #define VFS_WALK_MKPARENT 0x1
24 #define VFS_WALK_FSRELATIVE 0x2
25 #define VFS_WALK_PARENT 0x4
26 #define VFS_WALK_NOFOLLOW 0x4
28 #define FSTYPE_ROFS 0x1
30 #define VFS_VALID_CHAR(chr) \
31 (('A' <= (chr) && (chr) <= 'Z') || ('a' <= (chr) && (chr) <= 'z') || \
32 ('0' <= (chr) && (chr) <= '9') || (chr) == '.' || (chr) == '_' || \
35 extern struct hstr vfs_ddot;
36 extern struct hstr vfs_dot;
47 struct hlist_node fs_list;
50 int (*mount)(struct v_superblock* vsb, struct v_dnode* mount_point);
51 int (*unmount)(struct v_superblock* vsb);
56 struct llist_header sb_list;
60 struct filesystem* fs;
64 uint32_t (*read_capacity)(struct v_superblock* vsb);
65 uint32_t (*read_usage)(struct v_superblock* vsb);
73 void (*read_complete_callback)(struct dir_context* dctx,
81 int (*write)(struct v_inode* inode, void* buffer, size_t len, size_t fpos);
82 int (*read)(struct v_inode* inode, void* buffer, size_t len, size_t fpos);
83 int (*readdir)(struct v_inode* inode, struct dir_context* dctx);
84 int (*seek)(struct v_inode* inode, size_t offset);
85 int (*rename)(struct v_inode* inode, char* new_name);
86 int (*close)(struct v_file* file);
87 int (*sync)(struct v_inode* inode);
92 struct v_inode* inode;
93 struct v_dnode* dnode;
94 struct llist_header* f_list;
97 struct v_file_ops ops;
117 struct pcache* pg_cache;
118 void* data; // 允许底层FS绑定他的一些专有数据
121 int (*create)(struct v_inode* this);
122 int (*open)(struct v_inode* this, struct v_file* file);
123 int (*sync)(struct v_inode* this);
124 int (*mkdir)(struct v_inode* this, struct v_dnode* dnode);
125 int (*rmdir)(struct v_inode* this);
126 int (*unlink)(struct v_inode* this);
127 int (*link)(struct v_inode* this, struct v_dnode* new_name);
128 int (*read_symlink)(struct v_inode* this, const char** path_out);
129 int (*symlink)(struct v_inode* this, const char* target);
130 int (*dir_lookup)(struct v_inode* this, struct v_dnode* dnode);
132 struct v_file_ops default_fops;
138 struct v_inode* inode;
139 struct v_dnode* parent;
140 struct hlist_node hash_list;
141 struct llist_header children;
142 struct llist_header siblings;
143 struct v_superblock* super_block;
147 void (*destruct)(struct v_dnode* dnode);
153 struct v_fd* fds[VFS_MAX_FD];
158 struct llist_header pg_list;
159 struct llist_header dirty_list;
168 struct v_inode* master;
170 struct llist_header pages;
171 struct llist_header dirty;
176 /* --- file system manager --- */
181 fsm_register(struct filesystem* fs);
184 fsm_get(const char* fs_name);
190 vfs_dcache_lookup(struct v_dnode* parent, struct hstr* str);
193 vfs_dcache_add(struct v_dnode* parent, struct v_dnode* dnode);
196 vfs_walk(struct v_dnode* start,
198 struct v_dnode** dentry,
199 struct hstr* component,
203 vfs_mount(const char* target, const char* fs_name, bdev_t device);
206 vfs_unmount(const char* target);
209 vfs_mount_at(const char* fs_name, bdev_t device, struct v_dnode* mnt_point);
212 vfs_unmount_at(struct v_dnode* mnt_point);
215 vfs_mkdir(const char* path, struct v_dnode** dentry);
218 vfs_open(struct v_dnode* dnode, struct v_file** file);
221 vfs_close(struct v_file* file);
224 vfs_fsync(struct v_file* file);
230 vfs_sb_free(struct v_superblock* sb);
236 vfs_d_free(struct v_dnode* dnode);
242 vfs_i_free(struct v_inode* inode);
245 vfs_dup_fd(struct v_fd* old, struct v_fd** new);
248 pcache_init(struct pcache* pcache);
251 pcache_release_page(struct pcache* pcache, struct pcache_pg* page);
254 pcache_new_page(struct pcache* pcache, uint32_t index);
257 pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg);
260 pcache_get_page(struct pcache* pcache,
263 struct pcache_pg** page);
266 pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos);
269 pcache_read(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos);
272 pcache_release(struct pcache* pcache);
275 pcache_commit(struct v_inode* inode, struct pcache_pg* page);
278 pcache_commit_all(struct v_inode* inode);
281 pcache_invalidate(struct pcache* pcache, struct pcache_pg* page);
282 #endif /* __LUNAIX_VFS_H */