-#define WIM_FILE_ATTRIBUTE_READONLY 0x1
-#define WIM_FILE_ATTRIBUTE_HIDDEN 0x2
-#define WIM_FILE_ATTRIBUTE_SYSTEM 0x4
-#define WIM_FILE_ATTRIBUTE_DIRECTORY 0x10
-#define WIM_FILE_ATTRIBUTE_ARCHIVE 0x20
-#define WIM_FILE_ATTRIBUTE_DEVICE 0x40
-#define WIM_FILE_ATTRIBUTE_NORMAL 0x80
-#define WIM_FILE_ATTRIBUTE_TEMPORARY 0x100
-#define WIM_FILE_ATTRIBUTE_SPARSE_FILE 0x200
-#define WIM_FILE_ATTRIBUTE_REPARSE_POINT 0x400
-#define WIM_FILE_ATTRIBUTE_COMPRESSED 0x800
-#define WIM_FILE_ATTRIBUTE_OFFLINE 0x1000
-#define WIM_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
-#define WIM_FILE_ATTRIBUTE_ENCRYPTED 0x4000
-#define WIM_FILE_ATTRIBUTE_VIRTUAL 0x10000
-
-extern void stbuf_to_dentry(const struct stat *stbuf, struct dentry *dentry);
-
-extern void dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf,
- const struct lookup_table *table);
-
-extern int for_dentry_in_tree(struct dentry *root,
- int (*visitor)(struct dentry*, void*),
+#define rbnode_dentry(node) container_of(node, struct dentry, rb_node)
+
+/*
+ * WIM inode.
+ *
+ * As mentioned above, in the WIM file that is no on-disk analogue of a real
+ * inode, as most of these fields are duplicated in the dentries.
+ */
+struct inode {
+ /* Timestamps for the inode. The timestamps are the number of
+ * 100-nanosecond intervals that have elapsed since 12:00 A.M., January
+ * 1st, 1601, UTC. This is the same format used in NTFS inodes. */
+ u64 creation_time;
+ u64 last_access_time;
+ u64 last_write_time;
+
+ /* The file attributes associated with this inode. This is a bitwise OR
+ * of the FILE_ATTRIBUTE_* flags. */
+ u32 attributes;
+
+ /* The index of the security descriptor in the WIM image's table of
+ * security descriptors that contains this file's security information.
+ * If -1, no security information exists for this file. */
+ int32_t security_id;
+
+ /* %true iff the inode's lookup table entries has been resolved (i.e.
+ * the @lte field is valid, but the @hash field is not valid)
+ *
+ * (This is not an on-disk field.) */
+ u8 resolved : 1;
+
+ /* %true iff verify_inode() has run on this dentry. */
+ u8 verified : 1;
+
+ /* Number of alternate data streams associated with this inode */
+ u16 num_ads;
+
+ /* A hash of the file's contents, or a pointer to the lookup table entry
+ * for this dentry if the lookup table entries have been resolved.
+ *
+ * More specifically, this is for the un-named default file stream, as
+ * opposed to the alternate (named) file streams, which may have their
+ * own lookup table entries. */
+ union {
+ u8 hash[SHA1_HASH_SIZE];
+ struct lookup_table_entry *lte;
+ };
+
+ /* Identity of a reparse point. See
+ * http://msdn.microsoft.com/en-us/library/windows/desktop/aa365503(v=vs.85).aspx
+ * for what a reparse point is. */
+ u32 reparse_tag;
+
+ /* Number of dentries that reference this inode */
+ u32 link_count;
+
+ /* Alternate data stream entries. */
+ struct ads_entry *ads_entries;
+
+ /* Inode number */
+ u64 ino;
+
+ /* List of dentries that reference this inode (there should be
+ * link_count of them) */
+ struct list_head dentry_list;
+ struct hlist_node hlist;
+ char *extracted_file;
+
+ /* Root of a red-black tree storing the children of this inode (if
+ * non-empty, implies the inode is a directory, although that is also
+ * noted in the @attributes field.) */
+ struct rb_root children;
+
+#ifdef WITH_FUSE
+ /* wimfs file descriptors table for the inode */
+ u16 num_opened_fds;
+ u16 num_allocated_fds;
+ struct wimlib_fd **fds;
+
+ /* Next alternate data stream ID to be assigned */
+ u32 next_stream_id;
+
+ /* This mutex protects the inode's file descriptors table during
+ * read-only mounts. Read-write mounts are still restricted to 1
+ * thread. */
+ pthread_mutex_t i_mutex;
+#endif
+};
+
+#define inode_for_each_dentry(dentry, inode) \
+ list_for_each_entry((dentry), &(inode)->dentry_list, inode_dentry_list)
+
+#define inode_add_dentry(dentry, inode) \
+ ({ \
+ wimlib_assert((inode)->dentry_list.next != NULL); \
+ list_add(&(dentry)->inode_dentry_list, &(inode)->dentry_list); \
+ })
+
+static inline bool dentry_is_extracted(const struct dentry *dentry)
+{
+ return dentry->is_extracted;
+}
+
+static inline bool dentry_is_first_in_inode(const struct dentry *dentry)
+{
+ return container_of(dentry->d_inode->dentry_list.next,
+ struct dentry,
+ inode_dentry_list) == dentry;
+}
+
+extern u64 dentry_correct_total_length(const struct dentry *dentry);
+
+extern int inode_to_stbuf(const struct inode *inode,
+ struct lookup_table_entry *lte, struct stat *stbuf);
+
+extern int for_dentry_in_tree(struct dentry *root,
+ int (*visitor)(struct dentry*, void*),