X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/8c6f505faaa66e18cdca108dca549d4ad806a077..aa67abb537f22db097db632d98212fa951bfeef0:/lunaix-os/includes/lunaix/fs.h diff --git a/lunaix-os/includes/lunaix/fs.h b/lunaix-os/includes/lunaix/fs.h index 4b28881..0240c96 100644 --- a/lunaix-os/includes/lunaix/fs.h +++ b/lunaix-os/includes/lunaix/fs.h @@ -6,24 +6,42 @@ #include #include #include +#include #include #include #include #include + #include +#include + #define VFS_NAME_MAXLEN 128 #define VFS_MAX_FD 32 -#define VFS_IFDIR 0x1 -#define VFS_IFFILE 0x2 -#define VFS_IFSEQDEV 0x4 -#define VFS_IFVOLDEV 0x8 -#define VFS_IFSYMLINK 0x16 +#define VFS_IFDIR F_DIR +#define VFS_IFFILE F_FILE +#define VFS_IFDEV (F_DEV | F_FILE) +#define VFS_IFSEQDEV (F_SEQDEV | F_FILE) +#define VFS_IFVOLDEV (F_VOLDEV | F_FILE) +#define VFS_IFSYMLINK (F_SYMLINK | F_FILE) +#define VFS_DEVFILE(type) ((type) & F_DEV) +#define VFS_DEVTYPE(type) ((type) & ((F_SEQDEV | F_VOLDEV) ^ F_DEV)) + +// Walk, mkdir if component encountered is non-exists. #define VFS_WALK_MKPARENT 0x1 + +// Walk, relative to current FS. #define VFS_WALK_FSRELATIVE 0x2 + +/* + Terminate the walk on the immediate parent, + name of child (last component) is returned through `component` +*/ #define VFS_WALK_PARENT 0x4 + +// Do not follow the symbolic link #define VFS_WALK_NOFOLLOW 0x8 #define VFS_HASHTABLE_BITS 10 @@ -37,6 +55,9 @@ #define TEST_FD(fd) (fd >= 0 && fd < VFS_MAX_FD) +#define EXPORT_FILE_SYSTEM(fs_id, init_fn) \ + export_ldga_el(fs, fs_id, ptr_t, init_fn) + #define VFS_VALID_CHAR(chr) \ (('A' <= (chr) && (chr) <= 'Z') || ('a' <= (chr) && (chr) <= 'z') || \ ('0' <= (chr) && (chr) <= '9') || (chr) == '.' || (chr) == '_' || \ @@ -77,6 +98,7 @@ extern struct v_dnode* vfs_sysroot; struct filesystem { + struct llist_header fs_flat; struct hlist_node fs_list; struct hstr fs_name; u32_t types; @@ -93,6 +115,7 @@ struct v_superblock struct filesystem* fs; struct hbucket* i_cache; void* data; + size_t blksize; struct { u32_t (*read_capacity)(struct v_superblock* vsb); @@ -122,8 +145,8 @@ struct v_file_ops // These additional operations allow underlying fs to use more specialized // and optimized code. - int (*write_page)(struct v_inode* inode, void* pg, size_t len, size_t fpos); - int (*read_page)(struct v_inode* inode, void* pg, size_t len, size_t fpos); + int (*write_page)(struct v_inode* inode, void* pg, size_t fpos); + int (*read_page)(struct v_inode* inode, void* pg, size_t fpos); int (*readdir)(struct v_file* file, struct dir_context* dctx); int (*seek)(struct v_inode* inode, size_t offset); // optional @@ -275,6 +298,12 @@ struct pcache_pg u32_t len; }; +static inline bool +check_itype_any(struct v_inode* inode, unsigned int type_mask) +{ + return !!(inode->itype & type_mask) || !type_mask; +} + void fsm_init(); @@ -475,6 +504,12 @@ default_file_write(struct v_inode* inode, size_t len, size_t fpos); +int +default_file_read_page(struct v_inode* inode, void* buffer, size_t fpos); + +int +default_file_write_page(struct v_inode* inode, void* buffer, size_t fpos); + int default_file_readdir(struct v_file* file, struct dir_context* dctx);