4 #include <hal/ahci/hba.h>
5 #include <lunaix/block.h>
6 #include <lunaix/ds/hashtable.h>
7 #include <lunaix/ds/hstr.h>
8 #include <lunaix/ds/llist.h>
9 #include <lunaix/status.h>
11 #define VFS_NAME_MAXLEN 128
14 #define VFS_INODE_TYPE_DIR 0x1
15 #define VFS_INODE_TYPE_FILE 0x2
16 #define VFS_INODE_TYPE_DEVICE 0x4
19 #define VFS_EBADMNT -3
21 #define VFS_EENDOFDIR -5
26 #define VFS_WALK_MKPARENT 0x1
27 #define VFS_WALK_FSRELATIVE 0x2
28 #define VFS_WALK_PARENT 0x4
30 #define VFS_IOBUF_FDIRTY 0x1
32 #define FSTYPE_ROFS 0x1
34 #define VFS_VALID_CHAR(chr) \
35 ('A' <= (chr) && (chr) <= 'Z' || 'a' <= (chr) && (chr) <= 'z' || \
36 '0' <= (chr) && (chr) <= '9' || (chr) == '.' || (chr) == '_' || \
39 extern struct hstr vfs_ddot;
40 extern struct hstr vfs_dot;
46 struct hlist_node fs_list;
49 int (*mount)(struct v_superblock* vsb, struct v_dnode* mount_point);
50 int (*unmount)(struct v_superblock* vsb);
55 struct llist_header sb_list;
59 struct filesystem* fs;
63 uint32_t (*read_capacity)(struct v_superblock* vsb);
64 uint32_t (*read_usage)(struct v_superblock* vsb);
72 void (*read_complete_callback)(struct dir_context* dctx,
80 int (*write)(struct v_file* file, void* buffer, size_t len);
81 int (*read)(struct v_file* file, void* buffer, size_t len);
82 int (*readdir)(struct v_file* file, struct dir_context* dctx);
83 int (*seek)(struct v_file* file, size_t offset);
84 int (*rename)(struct v_file* file, char* new_name);
85 int (*close)(struct v_file* file);
86 int (*sync)(struct v_file* file);
91 struct v_inode* inode;
92 struct llist_header* f_list;
94 void* data; // 允许底层FS绑定他的一些专有数据
95 struct v_file_ops ops;
113 void* data; // 允许底层FS绑定他的一些专有数据
116 int (*create)(struct v_inode* inode, struct v_file* file);
117 int (*open)(struct v_inode* inode, struct v_file* file);
118 int (*sync)(struct v_inode* inode);
119 int (*mkdir)(struct v_inode* inode, struct v_dnode* dnode);
120 int (*dir_lookup)(struct v_inode* inode, struct v_dnode* dnode);
127 struct v_inode* inode;
128 struct v_dnode* parent;
129 struct hlist_node hash_list;
130 struct llist_header children;
131 struct llist_header siblings;
132 struct v_superblock* super_block;
135 void (*destruct)(struct v_dnode* dnode);
141 struct v_fd* fds[VFS_MAX_FD];
144 /* --- file system manager --- */
149 fsm_register(struct filesystem* fs);
152 fsm_get(const char* fs_name);
158 vfs_dcache_lookup(struct v_dnode* parent, struct hstr* str);
161 vfs_dcache_add(struct v_dnode* parent, struct v_dnode* dnode);
164 vfs_walk(struct v_dnode* start,
166 struct v_dnode** dentry,
167 struct hstr* component,
171 vfs_mount(const char* target, const char* fs_name, bdev_t device);
174 vfs_unmount(const char* target);
177 vfs_mount_at(const char* fs_name, bdev_t device, struct v_dnode* mnt_point);
180 vfs_unmount_at(struct v_dnode* mnt_point);
183 vfs_mkdir(const char* path, struct v_dnode** dentry);
186 vfs_open(struct v_dnode* dnode, struct v_file** file);
189 vfs_close(struct v_file* file);
192 vfs_fsync(struct v_file* file);
198 vfs_sb_free(struct v_superblock* sb);
204 vfs_d_free(struct v_dnode* dnode);
210 vfs_i_free(struct v_inode* inode);
211 #endif /* __LUNAIX_VFS_H */