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/status.h>
13 #define VFS_NAME_MAXLEN 128
17 #define VFS_IFFILE 0x2
18 #define VFS_IFSEQDEV 0x4
19 #define VFS_IFVOLDEV 0x8
20 #define VFS_IFSYMLINK 0x16
22 #define VFS_WALK_MKPARENT 0x1
23 #define VFS_WALK_FSRELATIVE 0x2
24 #define VFS_WALK_PARENT 0x4
25 #define VFS_WALK_NOFOLLOW 0x4
27 #define FSTYPE_ROFS 0x1
29 #define VFS_VALID_CHAR(chr) \
30 ('A' <= (chr) && (chr) <= 'Z' || 'a' <= (chr) && (chr) <= 'z' || \
31 '0' <= (chr) && (chr) <= '9' || (chr) == '.' || (chr) == '_' || \
34 extern struct hstr vfs_ddot;
35 extern struct hstr vfs_dot;
42 struct hlist_node fs_list;
45 int (*mount)(struct v_superblock* vsb, struct v_dnode* mount_point);
46 int (*unmount)(struct v_superblock* vsb);
51 struct llist_header sb_list;
55 struct filesystem* fs;
59 uint32_t (*read_capacity)(struct v_superblock* vsb);
60 uint32_t (*read_usage)(struct v_superblock* vsb);
68 void (*read_complete_callback)(struct dir_context* dctx,
76 int (*write)(struct v_file* file, void* buffer, size_t len, size_t fpos);
77 int (*read)(struct v_file* file, void* buffer, size_t len, size_t fpos);
78 int (*readdir)(struct v_file* file, struct dir_context* dctx);
79 int (*seek)(struct v_file* file, size_t offset);
80 int (*rename)(struct v_file* file, char* new_name);
81 int (*close)(struct v_file* file);
82 int (*sync)(struct v_file* file);
87 struct v_inode* inode;
88 struct v_dnode* dnode;
89 struct llist_header* f_list;
92 void* data; // 允许底层FS绑定他的一些专有数据
93 struct v_file_ops ops;
113 struct pcache* pg_cache;
114 void* data; // 允许底层FS绑定他的一些专有数据
117 int (*create)(struct v_inode* this);
118 int (*open)(struct v_inode* this, struct v_file* file);
119 int (*sync)(struct v_inode* this);
120 int (*mkdir)(struct v_inode* this, struct v_dnode* dnode);
121 int (*rmdir)(struct v_inode* this);
122 int (*unlink)(struct v_inode* this);
123 int (*link)(struct v_inode* this, struct v_dnode* new_name);
124 int (*read_symlink)(struct v_inode* this, const char** path_out);
125 int (*symlink)(struct v_inode* this, const char* target);
126 int (*dir_lookup)(struct v_inode* this, struct v_dnode* dnode);
128 struct v_file_ops default_fops;
134 struct v_inode* inode;
135 struct v_dnode* parent;
136 struct hlist_node hash_list;
137 struct llist_header children;
138 struct llist_header siblings;
139 struct v_superblock* super_block;
142 void (*destruct)(struct v_dnode* dnode);
148 struct v_fd* fds[VFS_MAX_FD];
153 struct llist_header pg_list;
154 struct llist_header dirty_list;
163 struct llist_header pages;
164 struct llist_header dirty;
169 /* --- file system manager --- */
174 fsm_register(struct filesystem* fs);
177 fsm_get(const char* fs_name);
183 vfs_dcache_lookup(struct v_dnode* parent, struct hstr* str);
186 vfs_dcache_add(struct v_dnode* parent, struct v_dnode* dnode);
189 vfs_walk(struct v_dnode* start,
191 struct v_dnode** dentry,
192 struct hstr* component,
196 vfs_mount(const char* target, const char* fs_name, bdev_t device);
199 vfs_unmount(const char* target);
202 vfs_mount_at(const char* fs_name, bdev_t device, struct v_dnode* mnt_point);
205 vfs_unmount_at(struct v_dnode* mnt_point);
208 vfs_mkdir(const char* path, struct v_dnode** dentry);
211 vfs_open(struct v_dnode* dnode, struct v_file** file);
214 vfs_close(struct v_file* file);
217 vfs_fsync(struct v_file* file);
223 vfs_sb_free(struct v_superblock* sb);
229 vfs_d_free(struct v_dnode* dnode);
235 vfs_i_free(struct v_inode* inode);
238 vfs_dup_fd(struct v_fd* old, struct v_fd** new);
241 pcache_init(struct pcache* pcache);
244 pcache_release_page(struct pcache* pcache, struct pcache_pg* page);
247 pcache_new_page(struct pcache* pcache, uint32_t index);
250 pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg);
253 pcache_get_page(struct pcache* pcache,
256 struct pcache_pg** page);
259 pcache_write(struct v_file* file, void* data, uint32_t len, uint32_t fpos);
262 pcache_read(struct v_file* file, void* data, uint32_t len, uint32_t fpos);
265 pcache_release(struct pcache* pcache);
268 pcache_commit(struct v_file* file, struct pcache_pg* page);
271 pcache_invalidate(struct v_file* file, struct pcache_pg* page);
274 pcache_commit_all(struct v_file* file);
275 #endif /* __LUNAIX_VFS_H */