-/*
- * Unlinks and frees a dentry tree.
- *
- * @root: The root of the tree.
- * @lookup_table: The lookup table for dentries. If non-NULL, the
- * reference counts in the lookup table for the lookup
- * table entries corresponding to the dentries will be
- * decremented.
- */
-void
-free_dentry_tree(struct wim_dentry *root, struct wim_lookup_table *lookup_table)
-{
- for_dentry_in_tree_depth(root, do_free_dentry, lookup_table);
-}
-
-#ifdef __WIN32__
-
-/* Insert a dentry into the case insensitive index for a directory.
- *
- * This is a red-black tree, but when multiple dentries share the same
- * case-insensitive name, only one is inserted into the tree itself; the rest
- * are connected in a list.
- */
-static struct wim_dentry *
-dentry_add_child_case_insensitive(struct wim_dentry *parent,
- struct wim_dentry *child)
-{
- struct rb_root *root;
- struct rb_node **new;
- struct rb_node *rb_parent;
-
- root = &parent->d_inode->i_children_case_insensitive;
- new = &root->rb_node;
- rb_parent = NULL;
- while (*new) {
- struct wim_dentry *this = container_of(*new, struct wim_dentry,
- rb_node_case_insensitive);
- int result = dentry_compare_names_case_insensitive(child, this);
-
- rb_parent = *new;
-
- if (result < 0)
- new = &((*new)->rb_left);
- else if (result > 0)
- new = &((*new)->rb_right);
- else
- return this;
- }
- rb_link_node(&child->rb_node_case_insensitive, rb_parent, new);
- rb_insert_color(&child->rb_node_case_insensitive, root);
- return NULL;
-}
-#endif
-
-/*
- * Links a dentry into the directory tree.
- *
- * @parent: The dentry that will be the parent of @child.
- * @child: The dentry to link.
- *
- * Returns NULL if successful. If @parent already contains a dentry with the
- * same case-sensitive name as @child, the pointer to this duplicate dentry is
- * returned.
- */
-struct wim_dentry *
-dentry_add_child(struct wim_dentry * restrict parent,
- struct wim_dentry * restrict child)
-{
- struct rb_root *root;
- struct rb_node **new;
- struct rb_node *rb_parent;
-
- wimlib_assert(dentry_is_directory(parent));
- wimlib_assert(parent != child);
-
- /* Case sensitive child dentry index */
- root = &parent->d_inode->i_children;
- new = &root->rb_node;
- rb_parent = NULL;
- while (*new) {
- struct wim_dentry *this = rbnode_dentry(*new);
- int result = dentry_compare_names_case_sensitive(child, this);
-
- rb_parent = *new;
-
- if (result < 0)
- new = &((*new)->rb_left);
- else if (result > 0)
- new = &((*new)->rb_right);
- else
- return this;
- }
- child->parent = parent;
- rb_link_node(&child->rb_node, rb_parent, new);
- rb_insert_color(&child->rb_node, root);
-
-#ifdef __WIN32__
- {
- struct wim_dentry *existing;
- existing = dentry_add_child_case_insensitive(parent, child);
- if (existing) {
- list_add(&child->case_insensitive_conflict_list,
- &existing->case_insensitive_conflict_list);
- child->rb_node_case_insensitive.__rb_parent_color = 0;
- } else {
- INIT_LIST_HEAD(&child->case_insensitive_conflict_list);
- }
- }
-#endif
- return NULL;
-}
-
-/* Unlink a WIM dentry from the directory entry tree. */
-void
-unlink_dentry(struct wim_dentry *dentry)
-{
- struct wim_dentry *parent = dentry->parent;
-
- if (parent == dentry)
- return;
- rb_erase(&dentry->rb_node, &parent->d_inode->i_children);
-#ifdef __WIN32__
- if (dentry->rb_node_case_insensitive.__rb_parent_color) {
- /* This dentry was in the case-insensitive red-black tree. */
- rb_erase(&dentry->rb_node_case_insensitive,
- &parent->d_inode->i_children_case_insensitive);
- if (!list_empty(&dentry->case_insensitive_conflict_list)) {
- /* Make a different case-insensitively-the-same dentry
- * be the "representative" in the red-black tree. */
- struct list_head *next;
- struct wim_dentry *other;
- struct wim_dentry *existing;
-
- next = dentry->case_insensitive_conflict_list.next;
- other = list_entry(next, struct wim_dentry, case_insensitive_conflict_list);
- existing = dentry_add_child_case_insensitive(parent, other);
- wimlib_assert(existing == NULL);
- }
- }
- list_del(&dentry->case_insensitive_conflict_list);
-#endif