2ee5390b65cfe240e787fcfc53d22dbee5714797
[lunaix-os.git] / lunaix-os / includes / lunaix / fs / twifs.h
1 #ifndef __LUNAIX_TWIFS_H
2 #define __LUNAIX_TWIFS_H
3
4 #include <lunaix/fs.h>
5 #include <lunaix/fs/twimap.h>
6 #include <lunaix/spike.h>
7
8 struct twifs_node
9 {
10     struct hstr name;
11     inode_t ino_id;
12     void* data;
13     u32_t itype;
14     char name_val[VFS_NAME_MAXLEN];
15     struct llist_header children;
16     struct llist_header siblings;
17     struct
18     {
19         int (*write)(struct v_inode* inode,
20                      void* buffer,
21                      size_t len,
22                      size_t fpos);
23         int (*read)(struct v_inode* inode,
24                     void* buffer,
25                     size_t len,
26                     size_t fpos);
27     } ops;
28 };
29
30 #define twinode_getdata(inode, type)                                           \
31     ({                                                                         \
32         struct twifs_node* twinode = (struct twifs_node*)(inode)->data;        \
33         assert(twinode);                                                       \
34         (type) twinode->data;                                                  \
35     })
36
37 void
38 twifs_init();
39
40 struct twifs_node*
41 twifs_file_node_vargs(struct twifs_node* parent, const char* fmt, va_list args);
42
43 struct twifs_node*
44 twifs_file_node(struct twifs_node* parent, const char* fmt, ...);
45
46 struct twifs_node*
47 twifs_dir_node(struct twifs_node* parent, const char* fmt, ...);
48
49 int
50 twifs_rm_node(struct twifs_node* node);
51
52 struct twimap*
53 twifs_mapping(struct twifs_node* parent, void* data, const char* fmt, ...);
54
55 #endif /* __LUNAIX_TWIFS_H */