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"
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, extra 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
25 * dentries. The hard link group ID field of the on-disk WIM dentry tells us
26 * the number of the NTFS inode that the dentry corresponds to (and this gets
27 * placed in d_inode->i_ino).
29 * Unfortunately, WIM files do not have an analogue to an inode; instead certain
30 * information, such as file attributes, the security descriptor, and streams is
31 * replicated in each hard-linked dentry, even though this information really is
32 * associated with an inode. In-memory, we fix up this flaw by allocating a
33 * `struct wim_inode' for each dentry that contains some of this duplicated
34 * information, then combining the inodes for each hard link group together.
35 * (See dentry_tree_fix_inodes().)
38 /* Pointer to the inode for this dentry. This will contain some
39 * information that was factored out of the on-disk WIM dentry as common
40 * to all dentries in a hard link group. */
41 struct wim_inode *d_inode;
43 /* Node for the parent's balanced binary search tree of child dentries
44 * sorted by case sensitive long name (root i_children). */
45 struct avl_tree_node d_index_node;
47 /* Node for the parent's balanced binary search tree of child dentries,
48 * sorted by case insensitive long name (root i_children_ci). */
49 struct avl_tree_node d_index_node_ci;
51 /* List of dentries in a directory that have different case sensitive
52 * long names but share the same case insensitive long name. */
53 struct list_head d_ci_conflict_list;
55 /* The parent of this directory entry. (The root is its own parent.) */
56 struct wim_dentry *d_parent;
58 /* Linked list node that places this dentry in the list of aliases for
59 * its inode (d_inode) */
60 struct hlist_node d_alias_node;
62 /* Pointer to the UTF-16LE filename (malloc()ed buffer), or NULL if this
63 * dentry has no filename. */
66 /* Pointer to the UTF-16LE short filename (malloc()ed buffer), or NULL
67 * if this dentry has no short name. */
68 utf16lechar *d_short_name;
70 /* Length of 'd_name' in bytes, excluding the terminating null */
73 /* Length of 'd_short_name' in bytes, excluding the terminating null */
74 u16 d_short_name_nbytes;
76 /* (Extraction only) Length of 'd_extraction_name' in _characters_,
77 * excluding the terminating null */
78 u16 d_extraction_name_nchars;
80 /* When capturing from an NTFS volume using NTFS-3g, this flag is set on
81 * dentries that were created from a filename in the WIN32 or WIN32+DOS
82 * namespaces rather than the POSIX namespace. Otherwise this will
84 u16 d_is_win32_name : 1;
86 /* Temporary flag; always reset to 0 when done using. */
89 /* Used by wimlib_update_image() */
93 /* The subdir offset is only used while reading and writing this
94 * dentry. See the corresponding field in `struct
95 * wim_dentry_on_disk' for explanation. */
98 /* Temporary list field */
99 struct list_head d_tmp_list;
102 /* Full path to this dentry in the WIM, in platform-dependent tchars
103 * that can be printed without conversion. By default this field will
104 * be NULL and will only be calculated on-demand by the
105 * calculate_dentry_full_path() or dentry_full_path() functions. */
108 /* (Extraction only) Actual name to extract this dentry as. This may be
109 * either in 'tchars' or in 'utf16lechars', depending on what encoding
110 * the extraction backend needs. This may alias 'd_name'. If it
111 * doesn't, it is an allocated buffer which must be freed. */
112 void *d_extraction_name;
114 /* (Extraction only) Linked list node that connects all dentries being
115 * extracted as part of the current extraction operation. */
116 struct list_head d_extraction_list_node;
118 /* (Extraction only) Pointer to the next alias of this dentry's inode
119 * that needs to be extracted as part of the current extraction
120 * operation, or NULL if this is the last alias. */
121 struct wim_dentry *d_next_extraction_alias;
125 will_extract_dentry(const struct wim_dentry *dentry)
127 return dentry->d_extraction_list_node.next != NULL;
131 dentry_out_total_length(const struct wim_dentry *dentry);
134 for_dentry_in_tree(struct wim_dentry *root,
135 int (*visitor)(struct wim_dentry *, void *), void *args);
137 /* Iterate through each @child dentry of the @dir directory inode,
138 * in sorted order by case sensitive name. */
139 #define for_inode_child(child, dir) \
140 avl_tree_for_each_in_order((child), (dir)->i_children, \
141 struct wim_dentry, d_index_node)
143 /* Iterate through each @child dentry of the @parent dentry,
144 * in sorted order by case sensitive name. */
145 #define for_dentry_child(child, parent) \
146 for_inode_child((child), (parent)->d_inode)
148 /* Iterate through each @child dentry of the @dir directory inode,
149 * in sorted order by case insensitive name. */
150 #define for_inode_child_case_insensitive(child, dir) \
151 avl_tree_for_each_in_order((child), (dir)->i_children_ci, \
152 struct wim_dentry, d_index_node_ci)
154 /* Iterate through each @child dentry of the @parent dentry,
155 * in sorted order by case insensitive name. */
156 #define for_dentry_child_case_insensitive(child, parent) \
157 for_inode_child_case_insensitive((child), (parent)->d_inode)
159 /* Iterate through each @child dentry of the @dir directory inode,
160 * in postorder (safe for freeing the child dentries). */
161 #define for_inode_child_postorder(child, dir) \
162 avl_tree_for_each_in_postorder((child), (dir)->i_children, \
163 struct wim_dentry, d_index_node)
165 /* Iterate through each @child dentry of the @parent dentry,
166 * in postorder (safe for freeing the child dentries). */
167 #define for_dentry_child_postorder(child, parent) \
168 for_inode_child_postorder((child), (parent)->d_inode)
170 /* Get any child dentry of the @dir directory inode. Requires
171 * inode_has_children(@dir) == true. */
172 #define inode_any_child(dir) \
173 avl_tree_entry((dir)->i_children, struct wim_dentry, d_index_node)
175 /* Get any child dentry of the @parent dentry. Requires
176 * dentry_has_children(@parent) == true. */
177 #define dentry_any_child(parent) \
178 inode_any_child((parent)->d_inode)
181 calculate_subdir_offsets(struct wim_dentry *root, u64 *subdir_offset_p);
184 dentry_set_name(struct wim_dentry *dentry, const tchar *name);
187 dentry_set_name_utf16le(struct wim_dentry *dentry, const utf16lechar *name,
190 extern struct wim_dentry *
191 get_dentry(WIMStruct *wim, const tchar *path, CASE_SENSITIVITY_TYPE case_type);
193 extern struct wim_dentry *
194 get_dentry_child_with_name(const struct wim_dentry *dentry, const tchar *name,
195 CASE_SENSITIVITY_TYPE case_type);
197 extern struct wim_dentry *
198 get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry,
199 const utf16lechar *name,
201 CASE_SENSITIVITY_TYPE case_type);
203 extern struct wim_dentry *
204 get_parent_dentry(WIMStruct *wim, const tchar *path,
205 CASE_SENSITIVITY_TYPE case_type);
208 calculate_dentry_full_path(struct wim_dentry *dentry);
211 dentry_full_path(struct wim_dentry *dentry);
214 new_dentry_with_new_inode(const tchar *name, bool set_timestamps,
215 struct wim_dentry **dentry_ret);
218 new_dentry_with_existing_inode(const tchar *name, struct wim_inode *inode,
219 struct wim_dentry **dentry_ret);
222 new_filler_directory(struct wim_dentry **dentry_ret);
225 free_dentry(struct wim_dentry *dentry);
228 free_dentry_tree(struct wim_dentry *root, struct blob_table *blob_table);
231 unlink_dentry(struct wim_dentry *dentry);
233 extern struct wim_dentry *
234 dentry_add_child(struct wim_dentry *parent, struct wim_dentry *child);
236 struct update_command_journal;
239 rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to,
240 CASE_SENSITIVITY_TYPE case_type,
241 struct update_command_journal *j);
245 read_dentry_tree(const u8 *buf, size_t buf_len,
246 u64 root_offset, struct wim_dentry **root_ret);
249 write_dentry_tree(struct wim_dentry *root, u8 *p);
252 dentry_is_root(const struct wim_dentry *dentry)
254 return dentry->d_parent == dentry;
258 dentry_is_directory(const struct wim_dentry *dentry)
260 return inode_is_directory(dentry->d_inode);
264 dentry_has_children(const struct wim_dentry *dentry)
266 return inode_has_children(dentry->d_inode);
270 dentry_has_long_name(const struct wim_dentry *dentry)
272 return dentry->d_name_nbytes != 0;
276 dentry_has_short_name(const struct wim_dentry *dentry)
278 return dentry->d_short_name_nbytes != 0;
281 #endif /* _WIMLIB_DENTRY_H */