#ifndef _WIMLIB_DENTRY_H
#define _WIMLIB_DENTRY_H
+#include "wimlib/avl_tree.h"
#include "wimlib/case.h"
#include "wimlib/compiler.h"
#include "wimlib/inode.h"
#include "wimlib/list.h"
-#include "wimlib/rbtree.h"
#include "wimlib/types.h"
struct wim_inode;
* to all dentries in a hard link group. */
struct wim_inode *d_inode;
- /* Node for the parent's red-black tree of child dentries, sorted by
- * case sensitive long name. */
- struct rb_node rb_node;
+ /* Node for the parent's balanced binary search tree of child dentries
+ * sorted by case sensitive long name (root i_children). */
+ struct avl_tree_node d_index_node;
- /* Node for the parent's red-black tree of child dentries, sorted by
- * case insensitive long name. */
- struct rb_node rb_node_case_insensitive;
+ /* Node for the parent's balanced binary search tree of child dentries,
+ * sorted by case insensitive long name (root i_children_ci). */
+ struct avl_tree_node d_index_node_ci;
/* List of dentries in a directory that have different case sensitive
- * long names but share the same case insensitive long name */
- struct list_head case_insensitive_conflict_list;
+ * long names but share the same case insensitive long name. */
+ struct list_head d_ci_conflict_list;
/* Length of UTF-16LE encoded short filename, in bytes, not including
* the terminating zero wide-character. */
* including the terminating null character. */
u32 full_path_nbytes;
- /* For extraction operations, this flag will be set on dentries in the
- * tree being extracted. Otherwise this will always be 0. */
- u8 in_extraction_tree : 1;
-
- /* For extraction operations, this flag will be set when a dentry in the
- * tree being extracted is not being extracted for some reason (file
- * type not supported by target filesystem, contains invalid characters,
- * or not in one of the multiple sub-trees being extracted). Otherwise
- * this will always be 0. */
- u8 extraction_skipped : 1;
-
/* During extraction extractions, this flag will be set after the
* "skeleton" of the dentry has been extracted. */
u8 skeleton_extracted : 1;
* always be 0. */
u8 is_win32_name : 1;
- /* When verifying the dentry tree after reading it into memory, this
- * flag will be set on all dentries in a hard link group that have a
- * nonempty DOS name except one. This is because it is supposed to be
- * illegal (on NTFS, at least) for a single inode to have multiple DOS
- * names. */
- u8 dos_name_invalid : 1;
-
+ /* Temporary flag; always reset to 0 when done using. */
u8 tmp_flag : 1;
- u8 was_hardlinked : 1;
+ /* Set to 1 if this name was extracted as a link, so no streams need to
+ * be extracted to it. */
+ u8 was_linked : 1;
- /* Temporary list field used to make lists of dentries in a few places.
- * */
+ /* Used by wimlib_update_image() */
+ u8 is_orphan : 1;
+
+ /* Temporary list field */
struct list_head tmp_list;
+ /* Links list of dentries being extracted */
+ struct list_head extraction_list;
+
/* Linked list node that places this dentry in the list of aliases for
* its inode (d_inode) */
struct list_head d_alias;
u64 length;
u64 subdir_offset;
- /* These correspond to the two unused fields in the on-disk WIM dentry;
- * we read them into memory so we can write them unchanged. These
- * fields are set to 0 on new dentries. */
- u64 d_unused_1;
- u64 d_unused_2;
-
/* Pointer to the UTF-16LE short filename (malloc()ed buffer), or NULL
* if this dentry has no short name. */
utf16lechar *short_name;
size_t extraction_name_nchars;
};
-#define rbnode_dentry(node) container_of(node, struct wim_dentry, rb_node)
-
static inline bool
dentry_is_first_in_inode(const struct wim_dentry *dentry)
{
int (*visitor)(struct wim_dentry*, void*),
void *args);
-extern int
-for_dentry_in_rbtree(struct rb_node *node,
- int (*visitor)(struct wim_dentry *, void *),
- void *arg);
-
-extern int
-for_dentry_child(const struct wim_dentry *dentry,
- int (*visitor)(struct wim_dentry *, void *),
- void *arg);
-
extern int
for_dentry_in_tree_depth(struct wim_dentry *root,
int (*visitor)(struct wim_dentry*, void*),
void *args);
+/* Iterate through each @child dentry of the @dir directory inode,
+ * in sorted order (by case sensitive name). */
+#define for_inode_child(child, dir) \
+ avl_tree_for_each_in_order((child), (dir)->i_children, \
+ struct wim_dentry, d_index_node)
+
+/* Iterate through each @child dentry of the @parent dentry,
+ * in sorted order (by case sensitive name). */
+#define for_dentry_child(child, parent) \
+ for_inode_child((child), (parent)->d_inode)
+
+/* Iterate through each @child dentry of the @dir directory inode,
+ * in postorder (safe for freeing the child dentries). */
+#define for_inode_child_postorder(child, dir) \
+ avl_tree_for_each_in_postorder((child), (dir)->i_children, \
+ struct wim_dentry, d_index_node)
+
+/* Iterate through each @child dentry of the @parent dentry,
+ * in postorder (safe for freeing the child dentries). */
+#define for_dentry_child_postorder(child, parent) \
+ for_inode_child_postorder((child), (parent)->d_inode)
+
+/* Get any child dentry of the @dir directory inode. Requires
+ * inode_has_children(@dir) == true. */
+#define inode_any_child(dir) \
+ avl_tree_entry((dir)->i_children, struct wim_dentry, d_index_node)
+
+/* Get any child dentry of the @parent dentry. Requires
+ * dentry_has_children(@parent) == true. */
+#define dentry_any_child(parent) \
+ inode_any_child((parent)->d_inode)
+
extern void
-calculate_subdir_offsets(struct wim_dentry *dentry, u64 *subdir_offset_p);
+calculate_subdir_offsets(struct wim_dentry *root, u64 *subdir_offset_p);
extern int
dentry_set_name(struct wim_dentry *dentry, const tchar *new_name);
+extern int
+dentry_set_name_utf16le(struct wim_dentry *dentry, const utf16lechar *new_name);
+
extern struct wim_dentry *
get_dentry(struct WIMStruct *wim, const tchar *path,
CASE_SENSITIVITY_TYPE case_type);
u16 *stream_idx_ret);
#endif
-extern int
-print_dentry(struct wim_dentry *dentry, void *lookup_table);
-
-extern int
-print_dentry_full_path(struct wim_dentry *entry, void *ignore);
-
extern int
calculate_dentry_full_path(struct wim_dentry *dentry);
unlink_dentry(struct wim_dentry *dentry);
extern struct wim_dentry *
-dentry_add_child(struct wim_dentry * restrict parent,
- struct wim_dentry * restrict child);
+dentry_add_child(struct wim_dentry *parent, struct wim_dentry *child);
+
+struct update_command_journal;
extern int
rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to,
- CASE_SENSITIVITY_TYPE case_type);
+ CASE_SENSITIVITY_TYPE case_type,
+ struct update_command_journal *j);
extern int
u64 root_offset, struct wim_dentry **root_ret);
extern u8 *
-write_dentry_tree(const struct wim_dentry * restrict tree,
- u8 * restrict p);
+write_dentry_tree(struct wim_dentry *root, u8 *p);
static inline bool
dentry_is_root(const struct wim_dentry *dentry)