4 #include <hal/ahci/hba.h>
5 #include <lunaix/block.h>
6 #include <lunaix/ds/btrie.h>
7 #include <lunaix/ds/hashtable.h>
8 #include <lunaix/ds/hstr.h>
9 #include <lunaix/ds/llist.h>
10 #include <lunaix/status.h>
12 #define VFS_NAME_MAXLEN 128
15 #define VFS_INODE_TYPE_DIR 0x1
16 #define VFS_INODE_TYPE_FILE 0x2
17 #define VFS_INODE_TYPE_DEVICE 0x4
18 #define VFS_INODE_TYPE_SYMLINK 0x8
20 #define VFS_WALK_MKPARENT 0x1
21 #define VFS_WALK_FSRELATIVE 0x2
22 #define VFS_WALK_PARENT 0x4
23 #define VFS_WALK_NOFOLLOW 0x4
25 #define FSTYPE_ROFS 0x1
27 #define VFS_VALID_CHAR(chr) \
28 ('A' <= (chr) && (chr) <= 'Z' || 'a' <= (chr) && (chr) <= 'z' || \
29 '0' <= (chr) && (chr) <= '9' || (chr) == '.' || (chr) == '_' || \
32 extern struct hstr vfs_ddot;
33 extern struct hstr vfs_dot;
40 struct hlist_node fs_list;
43 int (*mount)(struct v_superblock* vsb, struct v_dnode* mount_point);
44 int (*unmount)(struct v_superblock* vsb);
49 struct llist_header sb_list;
53 struct filesystem* fs;
57 uint32_t (*read_capacity)(struct v_superblock* vsb);
58 uint32_t (*read_usage)(struct v_superblock* vsb);
66 void (*read_complete_callback)(struct dir_context* dctx,
74 int (*write)(struct v_file* file, void* buffer, size_t len, size_t fpos);
75 int (*read)(struct v_file* file, void* buffer, size_t len, size_t fpos);
76 int (*readdir)(struct v_file* file, struct dir_context* dctx);
77 int (*seek)(struct v_file* file, size_t offset);
78 int (*rename)(struct v_file* file, char* new_name);
79 int (*close)(struct v_file* file);
80 int (*sync)(struct v_file* file);
85 struct v_inode* inode;
86 struct v_dnode* dnode;
87 struct llist_header* f_list;
90 void* data; // 允许底层FS绑定他的一些专有数据
91 struct v_file_ops ops;
110 struct pcache* pg_cache;
111 void* data; // 允许底层FS绑定他的一些专有数据
114 int (*create)(struct v_inode* this);
115 int (*open)(struct v_inode* this, struct v_file* file);
116 int (*sync)(struct v_inode* this);
117 int (*mkdir)(struct v_inode* this, struct v_dnode* dnode);
118 int (*rmdir)(struct v_inode* this);
119 int (*unlink)(struct v_inode* this);
120 int (*link)(struct v_inode* this, struct v_dnode* new_name);
121 int (*read_symlink)(struct v_inode* this, const char** path_out);
122 int (*symlink)(struct v_inode* this, const char* target);
123 int (*dir_lookup)(struct v_inode* this, struct v_dnode* dnode);
130 struct v_inode* inode;
131 struct v_dnode* parent;
132 struct hlist_node hash_list;
133 struct llist_header children;
134 struct llist_header siblings;
135 struct v_superblock* super_block;
138 void (*destruct)(struct v_dnode* dnode);
144 struct v_fd* fds[VFS_MAX_FD];
149 struct llist_header pg_list;
150 struct llist_header dirty_list;
159 struct llist_header pages;
160 struct llist_header dirty;
165 /* --- file system manager --- */
170 fsm_register(struct filesystem* fs);
173 fsm_get(const char* fs_name);
179 vfs_dcache_lookup(struct v_dnode* parent, struct hstr* str);
182 vfs_dcache_add(struct v_dnode* parent, struct v_dnode* dnode);
185 vfs_walk(struct v_dnode* start,
187 struct v_dnode** dentry,
188 struct hstr* component,
192 vfs_mount(const char* target, const char* fs_name, bdev_t device);
195 vfs_unmount(const char* target);
198 vfs_mount_at(const char* fs_name, bdev_t device, struct v_dnode* mnt_point);
201 vfs_unmount_at(struct v_dnode* mnt_point);
204 vfs_mkdir(const char* path, struct v_dnode** dentry);
207 vfs_open(struct v_dnode* dnode, struct v_file** file);
210 vfs_close(struct v_file* file);
213 vfs_fsync(struct v_file* file);
219 vfs_sb_free(struct v_superblock* sb);
225 vfs_d_free(struct v_dnode* dnode);
231 vfs_i_free(struct v_inode* inode);
234 pcache_init(struct pcache* pcache);
237 pcache_release_page(struct pcache* pcache, struct pcache_pg* page);
240 pcache_new_page(struct pcache* pcache, uint32_t index);
243 pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg);
246 pcache_get_page(struct pcache* pcache,
249 struct pcache_pg** page);
252 pcache_write(struct v_file* file, void* data, uint32_t len);
255 pcache_read(struct v_file* file, void* data, uint32_t len);
258 pcache_release(struct pcache* pcache);
261 pcache_commit(struct v_file* file, struct pcache_pg* page);
264 pcache_invalidate(struct v_file* file, struct pcache_pg* page);
267 pcache_commit_all(struct v_file* file);
268 #endif /* __LUNAIX_VFS_H */