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;
13 struct wim_lookup_table_entry;
14 struct wim_security_data;
16 /* Base size of a WIM dentry in the on-disk format, up to and including the file
17 * name length. This does not include the variable-length file name, short
18 * name, alternate data stream entries, and padding to 8-byte boundaries. */
19 #define WIM_DENTRY_DISK_SIZE 102
22 * In-memory structure for a WIM directory entry (dentry). There is a directory
23 * tree for each image in the WIM.
25 * Note that this is a directory entry and not an inode. Since NTFS allows hard
26 * links, it's possible for a NTFS inode to correspond to multiple WIM dentries.
27 * The hard link group ID field of the on-disk WIM dentry tells us the number of
28 * the NTFS inode that the dentry corresponds to (and this gets placed in
31 * Unfortunately, WIM files do not have an analogue to an inode; instead certain
32 * information, such as file attributes, the security descriptor, and file
33 * streams is replicated in each hard-linked dentry, even though this
34 * information really is associated with an inode. In-memory, we fix up this
35 * flaw by allocating a `struct wim_inode' for each dentry that contains some of
36 * this duplicated information, then combining the inodes for each hard link
39 * Confusingly, it's possible for stream information to be missing from a dentry
40 * in a hard link set, in which case the stream information needs to be gotten
41 * from one of the other dentries in the hard link set. In addition, it is
42 * possible for dentries to have inconsistent security IDs, file attributes, or
43 * file streams when they share the same hard link ID (don't even ask. I hope
44 * that Microsoft may have fixed this problem, since I've only noticed it in the
45 * 'install.wim' for Windows 7). For those dentries, we have to use the
46 * conflicting fields to split up the hard link groups. (See
47 * dentry_tree_fix_inodes() in inode_fixup.c.)
50 /* Pointer to the inode for this dentry. This will contain some
51 * information that was factored out of the on-disk WIM dentry as common
52 * to all dentries in a hard link group. */
53 struct wim_inode *d_inode;
55 /* Node for the parent's balanced binary search tree of child dentries
56 * sorted by case sensitive long name (root i_children). */
57 struct avl_tree_node d_index_node;
59 /* Node for the parent's balanced binary search tree of child dentries,
60 * sorted by case insensitive long name (root i_children_ci). */
61 struct avl_tree_node d_index_node_ci;
63 /* List of dentries in a directory that have different case sensitive
64 * long names but share the same case insensitive long name. */
65 struct list_head d_ci_conflict_list;
67 /* Length of UTF-16LE encoded short filename, in bytes, not including
68 * the terminating zero wide-character. */
69 u16 short_name_nbytes;
71 /* Length of UTF-16LE encoded "long" file name, in bytes, not including
72 * the terminating null character. */
75 /* Length of full path name encoded using "tchars", in bytes, not
76 * including the terminating null character. */
79 /* During extraction extractions, this flag will be set after the
80 * "skeleton" of the dentry has been extracted. */
81 u8 skeleton_extracted : 1;
83 /* When capturing from a NTFS volume using NTFS-3g, this flag is set on
84 * dentries that were created from a filename in the WIN32 or WIN32+DOS
85 * namespaces rather than the POSIX namespace. Otherwise this will
89 /* Temporary flag; always reset to 0 when done using. */
92 /* Set to 1 if this name was extracted as a link, so no streams need to
93 * be extracted to it. */
96 /* Temporary list field */
97 struct list_head tmp_list;
99 /* Links list of dentries being extracted */
100 struct list_head extraction_list;
102 /* Linked list node that places this dentry in the list of aliases for
103 * its inode (d_inode) */
104 struct list_head d_alias;
106 /* The parent of this directory entry. */
107 struct wim_dentry *parent;
109 /* 'length' and 'subdir_offset' are only used while reading and writing
110 * this dentry; see the corresponding field in
111 * `struct wim_dentry_on_disk' for explanation. */
115 /* Pointer to the UTF-16LE short filename (malloc()ed buffer), or NULL
116 * if this dentry has no short name. */
117 utf16lechar *short_name;
119 /* Pointer to the UTF-16LE filename (malloc()ed buffer), or NULL if this
120 * dentry has no filename. */
121 utf16lechar *file_name;
123 /* Full path to this dentry in the WIM, in platform-dependent tchars
124 * that can be printed without conversion. By default this field will
125 * be NULL and will only be calculated on-demand by the
126 * calculate_dentry_full_path() or dentry_full_path() functions. */
129 /* (Extraction only) Actual name to extract this dentry as, along with
130 * its length in tchars excluding the NULL terminator. This usually
131 * will be the same as file_name, with the character encoding converted
132 * if needed. But if file_name contains characters not accepted on the
133 * current platform, then this may be set slightly differently from
134 * file_name. This will be either NULL or a malloc()ed buffer that may
135 * alias file_name. */
136 tchar *extraction_name;
137 size_t extraction_name_nchars;
141 dentry_is_first_in_inode(const struct wim_dentry *dentry)
143 return inode_first_dentry(dentry->d_inode) == dentry;
147 dentry_out_total_length(const struct wim_dentry *dentry);
150 for_dentry_in_tree(struct wim_dentry *root,
151 int (*visitor)(struct wim_dentry*, void*),
155 for_dentry_in_tree_depth(struct wim_dentry *root,
156 int (*visitor)(struct wim_dentry*, void*),
159 /* Iterate through each @child dentry of the @dir directory inode,
160 * in sorted order (by case sensitive name). */
161 #define for_inode_child(child, dir) \
162 for (struct avl_tree_node *_tmp = \
163 avl_tree_first_in_order((dir)->i_children); \
165 (((child) = avl_tree_entry(_tmp, struct wim_dentry, \
166 d_index_node)), 1); \
167 _tmp = avl_tree_next_in_order(_tmp))
169 /* Iterate through each @child dentry of the @parent dentry,
170 * in sorted order (by case sensitive name). */
171 #define for_dentry_child(child, parent) \
172 for_inode_child((child), (parent)->d_inode)
174 /* Iterate through each @child dentry of the @dir directory inode,
175 * in postorder (safe for freeing the child dentries). */
176 #define for_inode_child_postorder(child, dir) \
177 for (struct avl_tree_node *_parent, *_tmp = \
178 avl_tree_first_in_postorder( \
179 (dir)->i_children); \
181 (((child) = avl_tree_entry(_tmp, struct wim_dentry, \
182 d_index_node)), 1) && \
183 ((_parent = avl_get_parent(_tmp)), 1); \
184 _tmp = avl_tree_next_in_postorder(_tmp, _parent))
186 /* Iterate through each @child dentry of the @parent dentry,
187 * in postorder (safe for freeing the child dentries). */
188 #define for_dentry_child_postorder(child, parent) \
189 for_inode_child_postorder((child), (parent)->d_inode)
191 /* Get any child dentry of the @dir directory inode. Requires
192 * inode_has_children(@dir) == true. */
193 #define inode_any_child(dir) \
194 avl_tree_entry((dir)->i_children, struct wim_dentry, d_index_node)
196 /* Get any child dentry of the @parent dentry. Requires
197 * dentry_has_children(@parent) == true. */
198 #define dentry_any_child(parent) \
199 inode_any_child((parent)->d_inode)
202 calculate_subdir_offsets(struct wim_dentry *root, u64 *subdir_offset_p);
205 dentry_set_name(struct wim_dentry *dentry, const tchar *new_name);
207 extern struct wim_dentry *
208 get_dentry(struct WIMStruct *wim, const tchar *path,
209 CASE_SENSITIVITY_TYPE case_type);
211 extern struct wim_dentry *
212 get_dentry_child_with_name(const struct wim_dentry *dentry,
214 CASE_SENSITIVITY_TYPE case_type);
216 extern struct wim_dentry *
217 get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry,
218 const utf16lechar *name,
220 CASE_SENSITIVITY_TYPE case_type);
222 extern struct wim_dentry *
223 get_parent_dentry(struct WIMStruct *wim, const tchar *path,
224 CASE_SENSITIVITY_TYPE case_type);
228 #define LOOKUP_FLAG_ADS_OK 0x00000001
229 #define LOOKUP_FLAG_DIRECTORY_OK 0x00000002
232 wim_pathname_to_stream(WIMStruct *wim,
235 struct wim_dentry **dentry_ret,
236 struct wim_lookup_table_entry **lte_ret,
237 u16 *stream_idx_ret);
241 calculate_dentry_full_path(struct wim_dentry *dentry);
244 calculate_dentry_tree_full_paths(struct wim_dentry *root);
247 dentry_full_path(struct wim_dentry *dentry);
250 new_dentry(const tchar *name, struct wim_dentry **dentry_ret);
253 new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret);
256 new_dentry_with_timeless_inode(const tchar *name, struct wim_dentry **dentry_ret);
259 dentry_tree_clear_inode_visited(struct wim_dentry *root);
262 new_filler_directory(const tchar *name, struct wim_dentry **dentry_ret);
265 free_dentry(struct wim_dentry *dentry);
268 put_dentry(struct wim_dentry *dentry);
271 free_dentry_tree(struct wim_dentry *root,
272 struct wim_lookup_table *lookup_table);
275 unlink_dentry(struct wim_dentry *dentry);
277 extern struct wim_dentry *
278 dentry_add_child(struct wim_dentry *parent, struct wim_dentry *child);
281 rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to,
282 CASE_SENSITIVITY_TYPE case_type);
286 read_dentry_tree(const u8 *buf, size_t buf_len,
287 u64 root_offset, struct wim_dentry **root_ret);
290 write_dentry_tree(struct wim_dentry *root, u8 *p);
293 dentry_is_root(const struct wim_dentry *dentry)
295 return dentry->parent == dentry;
299 dentry_is_directory(const struct wim_dentry *dentry)
301 return inode_is_directory(dentry->d_inode);
305 dentry_has_children(const struct wim_dentry *dentry)
307 return inode_has_children(dentry->d_inode);
311 dentry_has_short_name(const struct wim_dentry *dentry)
313 return dentry->short_name_nbytes != 0;
317 dentry_has_long_name(const struct wim_dentry *dentry)
319 return dentry->file_name_nbytes != 0;
323 dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list);
324 #endif /* _WIMLIB_DENTRY_H */