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>
10 #define VFS_NAME_MAXLEN 128
13 #define VFS_INODE_TYPE_DIR 0x1
14 #define VFS_INODE_TYPE_FILE 0x2
15 #define VFS_INODE_TYPE_DEVICE 0x4
17 #define VFS_ETOOLONG -1
19 #define VFS_EBADMNT -3
21 #define VFS_EENDOFDIR -5
22 #define VFS_ENOTFOUND -6
27 #define VFS_WALK_MKPARENT 0x1
28 #define VFS_WALK_FSRELATIVE 0x2
29 #define VFS_WALK_MKDIR 0x4
31 #define VFS_IOBUF_FDIRTY 0x1
33 #define VFS_VALID_CHAR(chr) \
34 ('A' <= (chr) && (chr) <= 'Z' || 'a' <= (chr) && (chr) <= 'z' || \
35 '0' <= (chr) && (chr) <= '9' || (chr) == '.' || (chr) == '_' || \
42 struct hlist_node fs_list;
44 int (*mount)(struct v_superblock* vsb, struct v_dnode* mount_point);
45 int (*unmount)(struct v_superblock* vsb);
50 struct llist_header sb_list;
54 struct filesystem* fs;
58 uint32_t (*read_capacity)(struct v_superblock* vsb);
59 uint32_t (*read_usage)(struct v_superblock* vsb);
67 void (*read_complete_callback)(struct dir_context* dctx,
74 int (*write)(struct v_file* file, void* buffer, size_t len);
75 int (*read)(struct v_file* file, void* buffer, size_t len);
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 llist_header* f_list;
88 void* data; // 允许底层FS绑定他的一些专有数据
89 struct v_file_ops ops;
106 void* data; // 允许底层FS绑定他的一些专有数据
109 int (*open)(struct v_inode* inode, struct v_file* file);
110 int (*sync)(struct v_inode* inode);
111 int (*mkdir)(struct v_inode* inode, struct v_dnode* dnode);
112 int (*dir_lookup)(struct v_inode* inode, struct v_dnode* dnode);
119 struct v_inode* inode;
120 struct v_dnode* parent;
121 struct hlist_node hash_list;
122 struct llist_header children;
123 struct llist_header siblings;
124 struct v_superblock* super_block;
127 void (*destruct)(struct v_dnode* dnode);
133 struct v_fd* fds[VFS_MAX_FD];
136 /* --- file system manager --- */
141 fsm_register(struct filesystem* fs);
144 fsm_get(const char* fs_name);
147 vfs_dcache_lookup(struct v_dnode* parent, struct hstr* str);
150 vfs_dcache_add(struct v_dnode* parent, struct v_dnode* dnode);
153 vfs_walk(struct v_dnode* start,
155 struct v_dnode** dentry,
159 vfs_mount(const char* fs_name, bdev_t device, struct v_dnode* mnt_point);
162 vfs_unmount(struct v_dnode* mnt_point);
165 vfs_mkdir(const char* parent_path,
166 const char* component,
167 struct v_dnode** dentry);
170 vfs_open(struct v_dnode* dnode, struct v_file** file);
173 vfs_close(struct v_file* file);
176 vfs_fsync(struct v_file* file);
182 vfs_sb_free(struct v_superblock* sb);
188 vfs_d_free(struct v_dnode* dnode);
194 vfs_i_free(struct v_inode* inode);
195 #endif /* __LUNAIX_VFS_H */