+
+int
+twifs_rm_node(struct twifs_node* node)
+{
+ if ((node->itype & VFS_IFDIR) && !llist_empty(&node->children)) {
+ return ENOTEMPTY;
+ }
+ llist_delete(&node->siblings);
+ cake_release(twi_pile, node);
+ return 0;
+}
+
+struct twifs_node*
+twifs_file_node(struct twifs_node* parent,
+ const char* name,
+ int name_len,
+ uint32_t itype)
+{
+ struct twifs_node* twi_node =
+ __twifs_new_node(parent, name, name_len, VFS_IFFILE | itype);
+
+ return twi_node;
+}
+
+struct twifs_node*
+twifs_dir_node(struct twifs_node* parent,
+ const char* name,
+ int name_len,
+ uint32_t itype)
+{
+ struct hstr hname = HSTR(name, name_len);
+ hstr_rehash(&hname, HSTR_FULL_HASH);
+ struct twifs_node* node = __twifs_get_node(parent, &hname);
+ if (node) {
+ return node;
+ }
+
+ struct twifs_node* twi_node =
+ __twifs_new_node(parent, name, name_len, VFS_IFDIR | itype);
+
+ return twi_node;
+}
+
+struct twifs_node*
+twifs_toplevel_node(const char* name, int name_len, uint32_t itype)
+{
+ return twifs_dir_node(fs_root, name, name_len, itype);
+}
+
+void
+twifs_init()
+{
+ twi_pile = cake_new_pile("twifs_node", sizeof(struct twifs_node), 1, 0);
+
+ struct filesystem* twifs = vzalloc(sizeof(struct filesystem));
+ twifs->fs_name = HSTR("twifs", 5);
+ twifs->mount = __twifs_mount;
+ twifs->types = FSTYPE_ROFS;
+ twifs->fs_id = 0;
+
+ fsm_register(twifs);
+
+ fs_root = twifs_dir_node(NULL, NULL, 0, 0);
+}
+
+const struct v_file_ops twifs_file_ops = { .close = default_file_close,
+ .read = __twifs_fread,
+ .write = __twifs_fwrite,
+ .readdir = __twifs_iterate_dir };
+
+const struct v_inode_ops twifs_inode_ops = { .dir_lookup = __twifs_dirlookup,
+ .mkdir = default_inode_mkdir,
+ .rmdir = default_inode_rmdir,
+ .open = __twifs_openfile };
\ No newline at end of file