1 #ifndef _WIMLIB_INODE_H
2 #define _WIMLIB_INODE_H
4 #include "wimlib/assert.h"
5 #include "wimlib/list.h"
6 #include "wimlib/sha1.h"
7 #include "wimlib/types.h"
10 struct blob_descriptor;
13 struct wim_security_data;
16 /* Valid values for the 'stream_type' field of a 'struct wim_inode_stream' */
17 enum wim_inode_stream_type {
19 /* Data stream, may be unnamed (usual case) or named */
22 /* Reparse point stream. This is the same as the data of the on-disk
23 * reparse point attribute, except that the first 8 bytes of the on-disk
24 * attribute are omitted. The omitted bytes contain the reparse tag
25 * (which is instead stored in the on-disk WIM dentry), the reparse data
26 * size (which is redundant with the stream size), and a reserved field
27 * that is always zero. */
28 STREAM_TYPE_REPARSE_POINT,
30 /* Encrypted data in the "EFSRPC raw data format" specified by [MS-EFSR]
31 * section 2.2.3. This contains metadata for the Encrypting File System
32 * as well as the encrypted data of all the file's data streams. */
33 STREAM_TYPE_EFSRPC_RAW_DATA,
35 /* Stream type could not be determined */
39 extern const utf16lechar NO_STREAM_NAME[1];
42 * 'struct wim_inode_stream' describes a "stream", which associates a blob of
43 * data with an inode. Each stream has a type and optionally a name.
45 * The most frequently seen kind of stream is the "unnamed data stream"
46 * (stream_type == STREAM_TYPE_DATA && stream_name == NO_STREAM_NAME), which is
47 * the "default file contents". Many inodes just have an unnamed data stream
48 * and no other streams. However, files on NTFS filesystems may have
49 * additional, "named" data streams, and this is supported by the WIM format.
51 * A "reparse point" is an inode with reparse data set. The reparse data is
52 * stored in a stream of type STREAM_TYPE_REPARSE_POINT. There should be only
53 * one such stream, and it should be unnamed. However, it is possible for an
54 * inode to have both a reparse point stream and an unnamed data stream, and
55 * even named data streams as well.
57 struct wim_inode_stream {
59 /* The name of the stream or NO_STREAM_NAME. */
60 utf16lechar *stream_name;
63 * If 'stream_resolved' = 0, then 'stream_hash' is the SHA-1 message
64 * digest of the uncompressed data of this stream, or all zeroes if this
67 * If 'stream_resolved' = 1, then 'stream_blob' is a pointer directly to
68 * a descriptor for this stream's blob, or NULL if this stream is empty.
71 u8 _stream_hash[SHA1_HASH_SIZE];
72 struct blob_descriptor *_stream_blob;
75 /* 'stream_resolved' determines whether 'stream_hash' or 'stream_blob'
76 * is valid as described above. */
77 u32 stream_resolved : 1;
79 /* A unique identifier for this stream within the context of its inode.
80 * This stays constant even if the streams array is reallocated. */
83 /* The type of this stream as one of the STREAM_TYPE_* values */
88 * WIM inode - a "file" in an image which may be accessible via multiple paths
90 * Note: in WIM files there is no true on-disk analogue of an inode; there are
91 * only directory entries, and some fields are duplicated among all links to a
92 * file. However, wimlib uses inode structures internally to simplify handling
98 * The collection of streams for this inode. 'i_streams' points to
99 * either 'i_embedded_streams' or an allocated array.
101 struct wim_inode_stream *i_streams;
102 struct wim_inode_stream i_embedded_streams[1];
103 unsigned i_num_streams;
105 /* Windows file attribute flags (FILE_ATTRIBUTE_*). */
108 /* Root of a balanced binary search tree storing the child directory
109 * entries of this inode, if any. Keyed by wim_dentry->file_name, case
110 * sensitively. If this inode is not a directory or if it has no
111 * children then this will be an empty tree (NULL). */
112 struct avl_tree_node *i_children;
114 /* Root of a balanced binary search tree storing the child directory
115 * entries of this inode, if any. Keyed by wim_dentry->file_name, case
116 * insensitively. If this inode is not a directory or if it has no
117 * children then this will be an empty tree (NULL). */
118 struct avl_tree_node *i_children_ci;
120 /* List of dentries that are aliases for this inode. There will be
121 * i_nlink dentries in this list. */
122 struct list_head i_dentry;
124 /* Field to place this inode into a list. While reading a WIM image or
125 * adding files to a WIM image this is owned by the inode table;
126 * otherwise this links the inodes for the WIM image. */
127 struct hlist_node i_hlist;
129 /* Number of dentries that are aliases for this inode. */
132 /* Flag used to mark this inode as visited; this is used when visiting
133 * all the inodes in a dentry tree exactly once. It will be 0 by
134 * default and must be cleared following the tree traversal, even in
139 u8 i_can_externally_back : 1;
141 /* If not NULL, a pointer to the extra data that was read from the
142 * dentry. This should be a series of tagged items, each of which
143 * represents a bit of extra metadata, such as the file's object ID.
144 * See tagged_items.c for more information. */
147 /* Size of @i_extra buffer in bytes. If 0, there is no extra data. */
150 /* Creation time, last access time, and last write time for this inode,
151 * in 100-nanosecond intervals since 12:00 a.m UTC January 1, 1601.
152 * They should correspond to the times gotten by calling GetFileTime()
155 u64 i_last_access_time;
156 u64 i_last_write_time;
158 /* Corresponds to 'security_id' in `struct wim_dentry_on_disk': The
159 * index of this inode's security descriptor in the WIM image's table of
160 * security descriptors, or -1. Note: when a WIM image is loaded,
161 * wimlib sets out-of-bounds indices and values less than -1 in this
162 * field to -1. So the extraction code need not do an upper bound check
163 * after checking for -1 (or equivalently < 0). */
164 int32_t i_security_id;
166 /* Identity of a reparse point. See
167 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa365503(v=vs.85).aspx
168 * for what a reparse point is. */
171 /* Unused/unknown fields that we just read into memory so we can
172 * re-write them unchanged. */
176 /* Corresponds to not_rpfixed in `struct wim_dentry_on_disk': Set to 0
177 * if reparse point fixups have been done. Otherwise set to 1. Note:
178 * this actually may reflect the SYMBOLIC_LINK_RELATIVE flag.
182 /* Inode number; corresponds to hard_link_group_id in the `struct
183 * wim_dentry_on_disk'. */
187 /* Device number, used only during image capture, so we can
188 * identify hard linked files by the combination of inode number
189 * and device number (rather than just inode number, which could
190 * be ambigious if the captured tree spans a mountpoint). Set
194 /* Fields used only during extraction */
196 /* List of aliases of this dentry that are being
197 * extracted in the current extraction operation. This
198 * will be a (possibly nonproper) subset of the dentries
199 * in the i_dentry list. This list will be constructed
200 * regardless of whether the extraction backend supports
201 * hard links or not. */
202 struct list_head i_extraction_aliases;
205 /* In NTFS-3g extraction mode, this is set to the Master
206 * File Table (MFT) number of the NTFS file that was
207 * created for this inode. */
212 /* Used during WIM writing with
213 * WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES: the number
214 * of streams this inode has that have not yet been fully read.
216 u32 num_remaining_streams;
220 /* Used only during image mount: Table of file
221 * descriptors that have been opened to this inode.
222 * This table is freed when the last file descriptor is
224 struct wimfs_fd **i_fds;
226 /* Lower bound on the index of the next available entry
234 u16 i_num_opened_fds;
235 u16 i_num_allocated_fds;
238 /* Next stream ID to be assigned */
239 u32 i_next_stream_id;
243 * Reparse tags documented at
244 * http://msdn.microsoft.com/en-us/library/dd541667(v=prot.10).aspx
246 #define WIM_IO_REPARSE_TAG_RESERVED_ZERO 0x00000000
247 #define WIM_IO_REPARSE_TAG_RESERVED_ONE 0x00000001
248 #define WIM_IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
249 #define WIM_IO_REPARSE_TAG_HSM 0xC0000004
250 #define WIM_IO_REPARSE_TAG_HSM2 0x80000006
251 #define WIM_IO_REPARSE_TAG_DRIVER_EXTENDER 0x80000005
252 #define WIM_IO_REPARSE_TAG_SIS 0x80000007
253 #define WIM_IO_REPARSE_TAG_DFS 0x8000000A
254 #define WIM_IO_REPARSE_TAG_DFSR 0x80000012
255 #define WIM_IO_REPARSE_TAG_FILTER_MANAGER 0x8000000B
256 #define WIM_IO_REPARSE_TAG_SYMLINK 0xA000000C
258 #define FILE_ATTRIBUTE_READONLY 0x00000001
259 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
260 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
261 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
262 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
263 #define FILE_ATTRIBUTE_DEVICE 0x00000040
264 #define FILE_ATTRIBUTE_NORMAL 0x00000080
265 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
266 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
267 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
268 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
269 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
270 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
271 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
272 #define FILE_ATTRIBUTE_VIRTUAL 0x00010000
274 extern struct wim_inode *
275 new_inode(struct wim_dentry *dentry, bool set_timestamps);
277 /* Iterate through each alias of the specified inode. */
278 #define inode_for_each_dentry(dentry, inode) \
279 list_for_each_entry((dentry), &(inode)->i_dentry, d_alias)
281 /* Return an alias of the specified inode. */
282 #define inode_first_dentry(inode) \
283 container_of(inode->i_dentry.next, struct wim_dentry, d_alias)
285 /* Return the full path of an alias of the specified inode, or NULL if a full
286 * path could not be determined. */
287 #define inode_first_full_path(inode) \
288 dentry_full_path(inode_first_dentry(inode))
291 d_associate(struct wim_dentry *dentry, struct wim_inode *inode);
294 d_disassociate(struct wim_dentry *dentry);
298 inode_dec_num_opened_fds(struct wim_inode *inode);
301 /* Is the inode a directory?
302 * This doesn't count directories with reparse data.
303 * wimlib only allows inodes of this type to have children.
306 inode_is_directory(const struct wim_inode *inode)
308 return (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
309 FILE_ATTRIBUTE_REPARSE_POINT))
310 == FILE_ATTRIBUTE_DIRECTORY;
313 /* Is the inode a symbolic link?
314 * This returns true iff the inode is a reparse point that is either a "real"
315 * symbolic link or a junction point. */
317 inode_is_symlink(const struct wim_inode *inode)
319 return (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
320 && (inode->i_reparse_tag == WIM_IO_REPARSE_TAG_SYMLINK ||
321 inode->i_reparse_tag == WIM_IO_REPARSE_TAG_MOUNT_POINT);
324 /* Does the inode have children? Currently (based on read_dentry_tree() as well
325 * as the various build-dentry-tree implementations), this can only return true
326 * for inodes for which inode_is_directory() returns true. */
328 inode_has_children(const struct wim_inode *inode)
330 return inode->i_children != NULL;
333 extern struct wim_inode_stream *
334 inode_get_stream(const struct wim_inode *inode, int stream_type,
335 const utf16lechar *stream_name);
337 extern struct wim_inode_stream *
338 inode_get_unnamed_stream(const struct wim_inode *inode, int stream_type);
340 static inline struct wim_inode_stream *
341 inode_get_unnamed_data_stream(const struct wim_inode *inode)
343 return inode_get_unnamed_stream(inode, STREAM_TYPE_DATA);
346 extern struct wim_inode_stream *
347 inode_add_stream(struct wim_inode *inode, int stream_type,
348 const utf16lechar *stream_name, struct blob_descriptor *blob);
351 inode_replace_stream_blob(struct wim_inode *inode,
352 struct wim_inode_stream *strm,
353 struct blob_descriptor *new_blob,
354 struct blob_table *blob_table);
357 inode_replace_stream_data(struct wim_inode *inode,
358 struct wim_inode_stream *strm,
359 const void *data, size_t size,
360 struct blob_table *blob_table);
363 inode_add_stream_with_data(struct wim_inode *inode, int stream_type,
364 const utf16lechar *stream_name,
365 const void *data, size_t size,
366 struct blob_table *blob_table);
369 inode_remove_stream(struct wim_inode *inode, struct wim_inode_stream *strm,
370 struct blob_table *blob_table);
372 static inline struct blob_descriptor *
373 stream_blob_resolved(const struct wim_inode_stream *strm)
375 wimlib_assert(strm->stream_resolved);
376 return strm->_stream_blob;
380 stream_is_named(const struct wim_inode_stream *strm)
382 return strm->stream_name != NO_STREAM_NAME;
386 stream_is_unnamed_data_stream(const struct wim_inode_stream *strm)
388 return strm->stream_type == STREAM_TYPE_DATA && !stream_is_named(strm);
392 stream_is_named_data_stream(const struct wim_inode_stream *strm)
394 return strm->stream_type == STREAM_TYPE_DATA && stream_is_named(strm);
398 inode_has_named_data_stream(const struct wim_inode *inode);
401 inode_resolve_streams(struct wim_inode *inode,
402 struct blob_table *table, bool force);
405 blob_not_found_error(const struct wim_inode *inode, const u8 *hash);
407 extern struct blob_descriptor *
408 stream_blob(const struct wim_inode_stream *strm, const struct blob_table *table);
410 extern struct blob_descriptor *
411 inode_get_blob_for_unnamed_data_stream(const struct wim_inode *inode,
412 const struct blob_table *blob_table);
414 extern struct blob_descriptor *
415 inode_get_blob_for_unnamed_data_stream_resolved(const struct wim_inode *inode);
418 stream_hash(const struct wim_inode_stream *strm);
421 inode_get_hash_of_unnamed_data_stream(const struct wim_inode *inode);
424 inode_ref_blobs(struct wim_inode *inode);
427 inode_unref_blobs(struct wim_inode *inode, struct blob_table *blob_table);
431 dentry_tree_fix_inodes(struct wim_dentry *root, struct hlist_head *inode_list);
433 #endif /* _WIMLIB_INODE_H */