X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/1fe5f5eb5378a47bf0f3451762743c162e40faad..0fd474df7001837bde53da0e42e83081827c9641:/lunaix-os/includes/lunaix/fs/twifs.h diff --git a/lunaix-os/includes/lunaix/fs/twifs.h b/lunaix-os/includes/lunaix/fs/twifs.h index d77619e..733db19 100644 --- a/lunaix-os/includes/lunaix/fs/twifs.h +++ b/lunaix-os/includes/lunaix/fs/twifs.h @@ -6,26 +6,44 @@ #include #include +struct twifs_ops +{ + int (*write)(struct v_inode* inode, + void* buffer, + size_t len, + size_t fpos); + int (*read)(struct v_inode* inode, + void* buffer, + size_t len, + size_t fpos); +}; + struct twifs_node { struct hstr name; inode_t ino_id; void* data; u32_t itype; + int acl; + char name_val[VFS_NAME_MAXLEN]; struct llist_header children; struct llist_header siblings; - struct - { - int (*write)(struct v_inode* inode, - void* buffer, - size_t len, - size_t fpos); - int (*read)(struct v_inode* inode, - void* buffer, - size_t len, - size_t fpos); - } ops; + struct twifs_ops ops; +}; + +struct twifs_export +{ + char* name; + int acl; + struct twifs_ops ops; +}; + +struct twimap_export +{ + char* name; + int acl; + struct twimap_ops ops; }; #define twinode_getdata(inode, type) \ @@ -38,25 +56,78 @@ struct twifs_node #define EXPORT_TWIFS_PLUGIN(label, plg_init) \ export_ldga_el(twiplugin_inits, label, ptr_t, plg_init) -void -twifs_register_plugins(); +#define __twifs_export_base(name_, acl_) \ + .name=stringify(name_), .acl=(acl_) + +#define twifs_node_ro(name_, acl_) \ + struct twifs_export __twifs_exp_##name_ = \ + { __twifs_export_base(name_, acl_), \ + .ops = { .read = __twifs_read_##name_ }} + +#define twifs_node_rw(name_, acl_) \ + struct twifs_export __twifs_exp_##name_ = \ + { __twifs_export_base(name_, acl_), \ + .ops = { .read = __twifs_read_##name_, \ + .write = __twifs_write_##name_ }} + +#define twimap_value_export(name_, acl_) \ + struct twimap_export __twimap_exp_##name_ = \ + { __twifs_export_base(name_, acl_), \ + .ops = { .read = __twimap_read_##name_ }} + +#define twimap_list_export(name_, acl_) \ + struct twimap_export __twimap_exp_##name_ = \ + { __twifs_export_base(name_, acl_), \ + .ops = { .read = __twimap_read_##name_, \ + .go_next = __twimap_gonext_##name_, \ + .reset = __twimap_reset_##name_, }} + +#define twifs_export(parent, name_, data_) \ + twifs_basic_node_from(parent, &__twifs_exp_##name_, data_) + +#define twimap_export(parent, name_, data_) \ + twifs_mapped_node_from(parent, &__twimap_exp_##name_, data_) + +#define twifs_export_ro(parent, name_, acl_, data_) \ + ({ \ + twifs_node_ro(name_, acl_); \ + twifs_export(parent, name_, data_); \ + }) + +#define twimap_export_value(parent, name_, acl_, data_) \ + ({ \ + twimap_value_export(name_, acl_); \ + twimap_export(parent, name_, data_); \ + }) + +#define twimap_export_list(parent, name_, acl_, data_) \ + ({ \ + twimap_list_export(name_, acl_); \ + twimap_export(parent, name_, data_); \ + }) void -twifs_init(); +twifs_register_plugins(); struct twifs_node* twifs_file_node_vargs(struct twifs_node* parent, const char* fmt, va_list args); -struct twifs_node* -twifs_file_node(struct twifs_node* parent, const char* fmt, ...); - struct twifs_node* twifs_dir_node(struct twifs_node* parent, const char* fmt, ...); int twifs_rm_node(struct twifs_node* node); +struct twifs_node* +twifs_basic_node_from(struct twifs_node* parent, + struct twifs_export* exp_def, void* data); + +struct twifs_node* +twifs_mapped_node_from(struct twifs_node* parent, + struct twimap_export* exp_def, void* data); + struct twimap* -twifs_mapping(struct twifs_node* parent, void* data, const char* fmt, ...); +twifs_mapping(struct twifs_node* parent, + void* data, int acl, const char* fmt, ...); #endif /* __LUNAIX_TWIFS_H */