1 #ifndef _WIMLIB_DENTRY_H
2 #define _WIMLIB_DENTRY_H
4 #include "wimlib/avl_tree.h"
5 #include "wimlib/case.h"
6 #include "wimlib/compiler.h"
7 #include "wimlib/inode.h"
8 #include "wimlib/list.h"
9 #include "wimlib/types.h"
12 struct wim_lookup_table;
14 /* Base size of a WIM dentry in the on-disk format, up to and including the file
15 * name length. This does not include the variable-length file name, short
16 * name, alternate data stream entries, and padding to 8-byte boundaries. */
17 #define WIM_DENTRY_DISK_SIZE 102
20 * In-memory structure for a WIM directory entry (dentry). There is a directory
21 * tree for each image in the WIM.
23 * Note that this is a directory entry and not an inode. Since NTFS allows hard
24 * links, it's possible for an NTFS inode to correspond to multiple WIM dentries.
25 * The hard link group ID field of the on-disk WIM dentry tells us the number of
26 * the NTFS inode that the dentry corresponds to (and this gets placed in
29 * Unfortunately, WIM files do not have an analogue to an inode; instead certain
30 * information, such as file attributes, the security descriptor, and file
31 * streams is replicated in each hard-linked dentry, even though this
32 * information really is associated with an inode. In-memory, we fix up this
33 * flaw by allocating a `struct wim_inode' for each dentry that contains some of
34 * this duplicated information, then combining the inodes for each hard link
37 * Confusingly, it's possible for stream information to be missing from a dentry
38 * in a hard link set, in which case the stream information needs to be gotten
39 * from one of the other dentries in the hard link set. In addition, it is
40 * possible for dentries to have inconsistent security IDs, file attributes, or
41 * file streams when they share the same hard link ID (don't even ask. I hope
42 * that Microsoft may have fixed this problem, since I've only noticed it in the
43 * 'install.wim' for Windows 7). For those dentries, we have to use the
44 * conflicting fields to split up the hard link groups. (See
45 * dentry_tree_fix_inodes() in inode_fixup.c.)
48 /* Pointer to the inode for this dentry. This will contain some
49 * information that was factored out of the on-disk WIM dentry as common
50 * to all dentries in a hard link group. */
51 struct wim_inode *d_inode;
53 /* Node for the parent's balanced binary search tree of child dentries
54 * sorted by case sensitive long name (root i_children). */
55 struct avl_tree_node d_index_node;
57 /* Node for the parent's balanced binary search tree of child dentries,
58 * sorted by case insensitive long name (root i_children_ci). */
59 struct avl_tree_node d_index_node_ci;
61 /* List of dentries in a directory that have different case sensitive
62 * long names but share the same case insensitive long name. */
63 struct list_head d_ci_conflict_list;
65 /* The parent of this directory entry. (The root is its own parent.) */
66 struct wim_dentry *d_parent;
68 /* Linked list node that places this dentry in the list of aliases for
69 * its inode (d_inode) */
70 struct list_head d_alias;
72 /* Pointer to the UTF-16LE short filename (malloc()ed buffer), or NULL
73 * if this dentry has no short name. */
74 utf16lechar *short_name;
76 /* Pointer to the UTF-16LE filename (malloc()ed buffer), or NULL if this
77 * dentry has no filename. */
78 utf16lechar *file_name;
80 /* Length of UTF-16LE encoded short filename, in bytes, not including
81 * the terminating zero wide-character. */
82 u16 short_name_nbytes;
84 /* Length of UTF-16LE encoded "long" file name, in bytes, not including
85 * the terminating null character. */
88 /* When capturing from an NTFS volume using NTFS-3g, this flag is set on
89 * dentries that were created from a filename in the WIN32 or WIN32+DOS
90 * namespaces rather than the POSIX namespace. Otherwise this will
94 /* Temporary flag; always reset to 0 when done using. */
97 /* Used by wimlib_update_image() */
101 /* 'subdir_offset' is only used while reading and writing this
102 * dentry. See the corresponding field in `struct
103 * wim_dentry_on_disk' for explanation. */
106 /* Temporary list field */
107 struct list_head tmp_list;
110 /* Full path to this dentry in the WIM, in platform-dependent tchars
111 * that can be printed without conversion. By default this field will
112 * be NULL and will only be calculated on-demand by the
113 * calculate_dentry_full_path() or dentry_full_path() functions. */
116 /* (Extraction only) Actual name to extract this dentry as. This may be
117 * either in 'tchars' or in 'utf16lechars', depending on what encoding
118 * the extraction backend needs. This may alias 'file_name'. If it
119 * doesn't, it is an allocated buffer which must be freed. */
120 void *d_extraction_name;
122 /* (Extraction only) Number of characters in d_extraction_name. */
123 size_t d_extraction_name_nchars;
125 /* (Extraction only) Linked list node that connects all dentries being
126 * extracted as part of the current extraction operation. */
127 struct list_head d_extraction_list_node;
129 /* (Extraction only) Linked list node that connects all dentries being
130 * extracted as aliases of the same inode as part of the current
131 * extraction operation. */
132 struct list_head d_extraction_alias_node;
136 dentry_is_first_in_inode(const struct wim_dentry *dentry)
138 return inode_first_dentry(dentry->d_inode) == dentry;
142 will_extract_dentry(const struct wim_dentry *dentry)
144 return dentry->d_extraction_list_node.next != NULL;
148 dentry_out_total_length(const struct wim_dentry *dentry);
151 for_dentry_in_tree(struct wim_dentry *root,
152 int (*visitor)(struct wim_dentry*, void*),
155 /* Iterate through each @child dentry of the @dir directory inode,
156 * in sorted order (by case sensitive name). */
157 #define for_inode_child(child, dir) \
158 avl_tree_for_each_in_order((child), (dir)->i_children, \
159 struct wim_dentry, d_index_node)
161 /* Iterate through each @child dentry of the @parent dentry,
162 * in sorted order (by case sensitive name). */
163 #define for_dentry_child(child, parent) \
164 for_inode_child((child), (parent)->d_inode)
166 /* Iterate through each @child dentry of the @dir directory inode,
167 * in postorder (safe for freeing the child dentries). */
168 #define for_inode_child_postorder(child, dir) \
169 avl_tree_for_each_in_postorder((child), (dir)->i_children, \
170 struct wim_dentry, d_index_node)
172 /* Iterate through each @child dentry of the @parent dentry,
173 * in postorder (safe for freeing the child dentries). */
174 #define for_dentry_child_postorder(child, parent) \
175 for_inode_child_postorder((child), (parent)->d_inode)
177 /* Get any child dentry of the @dir directory inode. Requires
178 * inode_has_children(@dir) == true. */
179 #define inode_any_child(dir) \
180 avl_tree_entry((dir)->i_children, struct wim_dentry, d_index_node)
182 /* Get any child dentry of the @parent dentry. Requires
183 * dentry_has_children(@parent) == true. */
184 #define dentry_any_child(parent) \
185 inode_any_child((parent)->d_inode)
188 calculate_subdir_offsets(struct wim_dentry *root, u64 *subdir_offset_p);
191 dentry_set_name(struct wim_dentry *dentry, const tchar *new_name);
194 dentry_set_name_utf16le(struct wim_dentry *dentry, const utf16lechar *new_name,
195 size_t new_name_nbytes);
197 extern struct wim_dentry *
198 get_dentry(struct WIMStruct *wim, const tchar *path,
199 CASE_SENSITIVITY_TYPE case_type);
201 extern struct wim_dentry *
202 get_dentry_child_with_name(const struct wim_dentry *dentry,
204 CASE_SENSITIVITY_TYPE case_type);
206 extern struct wim_dentry *
207 get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry,
208 const utf16lechar *name,
210 CASE_SENSITIVITY_TYPE case_type);
212 extern struct wim_dentry *
213 get_parent_dentry(struct WIMStruct *wim, const tchar *path,
214 CASE_SENSITIVITY_TYPE case_type);
217 calculate_dentry_full_path(struct wim_dentry *dentry);
220 dentry_full_path(struct wim_dentry *dentry);
223 new_dentry(const tchar *name, struct wim_dentry **dentry_ret);
226 new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret);
229 new_dentry_with_timeless_inode(const tchar *name, struct wim_dentry **dentry_ret);
232 dentry_tree_clear_inode_visited(struct wim_dentry *root);
235 new_filler_directory(struct wim_dentry **dentry_ret);
238 free_dentry(struct wim_dentry *dentry);
241 free_dentry_tree(struct wim_dentry *root,
242 struct wim_lookup_table *lookup_table);
245 unlink_dentry(struct wim_dentry *dentry);
247 extern struct wim_dentry *
248 dentry_add_child(struct wim_dentry *parent, struct wim_dentry *child);
250 struct update_command_journal;
253 rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to,
254 CASE_SENSITIVITY_TYPE case_type,
255 struct update_command_journal *j);
259 read_dentry_tree(const u8 *buf, size_t buf_len,
260 u64 root_offset, struct wim_dentry **root_ret);
263 write_dentry_tree(struct wim_dentry *root, u8 *p);
266 dentry_is_root(const struct wim_dentry *dentry)
268 return dentry->d_parent == dentry;
272 dentry_is_directory(const struct wim_dentry *dentry)
274 return inode_is_directory(dentry->d_inode);
278 dentry_has_children(const struct wim_dentry *dentry)
280 return inode_has_children(dentry->d_inode);
284 dentry_has_short_name(const struct wim_dentry *dentry)
286 return dentry->short_name_nbytes != 0;
290 dentry_has_long_name(const struct wim_dentry *dentry)
292 return dentry->file_name_nbytes != 0;
294 #endif /* _WIMLIB_DENTRY_H */