#include <lunaix/ds/btrie.h>
#include <lunaix/ds/hashtable.h>
#include <lunaix/ds/hstr.h>
+#include <lunaix/ds/ldga.h>
#include <lunaix/ds/llist.h>
#include <lunaix/ds/lru.h>
#include <lunaix/ds/mutex.h>
-#include <lunaix/process.h>
#include <lunaix/status.h>
+
#include <stdatomic.h>
+#include <usr/lunaix/fstypes.h>
+
#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
#define FSTYPE_ROFS 0x1
-#define DO_STATUS(errno) SYSCALL_ESTATUS(__current->k_status = errno)
-#define DO_STATUS_OR_RETURN(errno) ({ errno < 0 ? DO_STATUS(errno) : errno; })
-
#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) == '_' || \
struct filesystem
{
+ struct llist_header fs_flat;
struct hlist_node fs_list;
struct hstr fs_name;
u32_t types;
struct device* dev;
struct v_dnode* root;
struct filesystem* fs;
- u32_t iobuf_size;
struct hbucket* i_cache;
void* data;
+ size_t blksize;
struct
{
u32_t (*read_capacity)(struct v_superblock* vsb);
// 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
struct pcache* pg_cache;
struct v_inode_ops* ops;
struct v_file_ops* default_fops;
+
+ void (*destruct)(struct v_inode* inode);
};
struct v_mount
void
vfs_ref_dnode(struct v_dnode* dnode);
+void
+vfs_ref_file(struct v_file* file);
+
void
vfs_unref_dnode(struct v_dnode* dnode);
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);