fix dependency check logic cause config always disabled
[lunaix-os.git] / lunaix-os / includes / lunaix / fs / twifs.h
1 #ifndef __LUNAIX_TWIFS_H
2 #define __LUNAIX_TWIFS_H
3
4 #include <lunaix/ds/ldga.h>
5 #include <lunaix/fs.h>
6 #include <lunaix/fs/twimap.h>
7 #include <lunaix/spike.h>
8
9 struct twifs_ops
10 {
11     int (*write)(struct v_inode* inode,
12                     void* buffer,
13                     size_t len,
14                     size_t fpos);
15     int (*read)(struct v_inode* inode,
16                 void* buffer,
17                 size_t len,
18                 size_t fpos);
19 };
20
21 struct twifs_node
22 {
23     struct hstr name;
24     inode_t ino_id;
25     void* data;
26     u32_t itype;
27     int acl;
28
29     char name_val[VFS_NAME_MAXLEN];
30     struct llist_header children;
31     struct llist_header siblings;
32     struct twifs_ops ops;
33 };
34
35 struct twifs_export
36 {
37     char* name;
38     int acl;
39     struct twifs_ops ops;
40 };
41
42 struct twimap_export
43 {
44     char* name;
45     int acl;
46     struct twimap_ops ops;
47 };
48
49 #define twinode_getdata(inode, type)                                           \
50     ({                                                                         \
51         struct twifs_node* twinode = (struct twifs_node*)(inode)->data;        \
52         assert(twinode);                                                       \
53         (type) twinode->data;                                                  \
54     })
55
56 #define EXPORT_TWIFS_PLUGIN(label, plg_init)                                   \
57     export_ldga_el(twiplugin_inits, label, ptr_t, plg_init)
58
59 #define __twifs_export_base(name_, acl_) \
60             .name=stringify(name_), .acl=(acl_)
61
62 #define twifs_node_ro(name_, acl_)                        \
63         struct twifs_export __twifs_exp_##name_ =           \
64             { __twifs_export_base(name_, acl_),             \
65                 .ops = { .read =  __twifs_read_##name_ }}
66
67 #define twifs_node_rw(name_, acl_)                        \
68         struct twifs_export __twifs_exp_##name_ =           \
69             { __twifs_export_base(name_, acl_),             \
70                 .ops = { .read =  __twifs_read_##name_,         \
71                          .write =  __twifs_write_##name_ }}
72
73 #define twimap_value_export(name_, acl_)                    \
74         struct twimap_export __twimap_exp_##name_ =          \
75             { __twifs_export_base(name_, acl_),             \
76                 .ops = { .read =  __twimap_read_##name_ }}
77
78 #define twimap_list_export(name_, acl_)                     \
79         struct twimap_export __twimap_exp_##name_ =          \
80             { __twifs_export_base(name_, acl_),             \
81                 .ops = { .read =  __twimap_read_##name_,         \
82                          .go_next =  __twimap_gonext_##name_,   \
83                          .reset =  __twimap_reset_##name_, }}
84
85 #define twifs_export(parent, name_, data_)      \
86         twifs_basic_node_from(parent, &__twifs_exp_##name_, data_)
87
88 #define twimap_export(parent, name_, data_)      \
89         twifs_mapped_node_from(parent, &__twimap_exp_##name_, data_)
90
91 #define twifs_export_ro(parent, name_, acl_, data_)                     \
92         ({                                                              \
93             twifs_node_ro(name_, acl_);                                 \
94             twifs_export(parent, name_, data_);                        \
95         })
96
97 #define twimap_export_value(parent, name_, acl_, data_)                 \
98         ({                                                              \
99             twimap_value_export(name_, acl_);                           \
100             twimap_export(parent, name_, data_);                        \
101         })
102
103 #define twimap_export_list(parent, name_, acl_, data_)                  \
104         ({                                                              \
105             twimap_list_export(name_, acl_);                            \
106             twimap_export(parent, name_, data_);                        \
107         })
108
109 void
110 twifs_register_plugins();
111
112 struct twifs_node*
113 twifs_file_node_vargs(struct twifs_node* parent, const char* fmt, va_list args);
114
115 struct twifs_node*
116 twifs_dir_node(struct twifs_node* parent, const char* fmt, ...);
117
118 int
119 twifs_rm_node(struct twifs_node* node);
120
121 struct twifs_node*
122 twifs_basic_node_from(struct twifs_node* parent, 
123                         struct twifs_export* exp_def, void* data);
124
125 struct twifs_node*
126 twifs_mapped_node_from(struct twifs_node* parent, 
127                         struct twimap_export* exp_def, void* data);
128
129 struct twimap*
130 twifs_mapping(struct twifs_node* parent, 
131                 void* data, int acl, const char* fmt, ...);
132
133 #endif /* __LUNAIX_TWIFS_H */