1 #ifndef _WIMLIB_METADATA_H
2 #define _WIMLIB_METADATA_H
4 #include "wimlib/blob_table.h"
5 #include "wimlib/list.h"
6 #include "wimlib/types.h"
7 #include "wimlib/wim.h"
9 /* Metadata for a WIM image */
10 struct wim_image_metadata {
12 /* Number of WIMStruct's that are sharing this image metadata (from
13 * calls to wimlib_export_image().) */
16 /* Pointer to the root dentry of the image. */
17 struct wim_dentry *root_dentry;
19 /* Pointer to the security data of the image. */
20 struct wim_security_data *security_data;
22 /* Pointer to the blob descriptor for this image's metadata resource.
23 * If this image metadata is sourced from a WIM file (as opposed to
24 * being created from scratch) and hasn't been modified from the version
25 * in that WIM file, then this blob descriptor's data corresponds to the
26 * WIM backing source. Otherwise, this blob descriptor is a dummy entry
27 * with blob_location==BLOB_NONEXISTENT. */
28 struct blob_descriptor *metadata_blob;
30 /* Linked list of 'struct wim_inode's for this image. */
31 struct hlist_head inode_list;
33 /* Linked list of 'struct blob_descriptor's for blobs that are
34 * referenced by this image's dentry tree, but have not had their SHA-1
35 * message digests calculated yet and therefore have not been inserted
36 * into the WIMStruct's blob table. This list is appended to when files
37 * are scanned for inclusion in this WIM image. */
38 struct list_head unhashed_blobs;
40 /* Are the filecount/bytecount stats (in the XML info) out of date for
45 /* Retrieve the metadata of the image in @wim currently selected with
46 * select_wim_image(). */
47 static inline struct wim_image_metadata *
48 wim_get_current_image_metadata(WIMStruct *wim)
50 return wim->image_metadata[wim->current_image - 1];
53 /* Retrieve the root dentry of the image in @wim currently selected with
54 * select_wim_image(). */
55 static inline struct wim_dentry *
56 wim_get_current_root_dentry(WIMStruct *wim)
58 return wim_get_current_image_metadata(wim)->root_dentry;
61 /* Retrieve the security data of the image in @wim currently selected with
62 * select_wim_image(). */
63 static inline struct wim_security_data *
64 wim_get_current_security_data(WIMStruct *wim)
66 return wim_get_current_image_metadata(wim)->security_data;
69 /* Return true iff the specified image has been changed since being read from
70 * its backing file or has been created from scratch. */
72 is_image_dirty(const struct wim_image_metadata *imd)
74 /* The only possible values here are BLOB_NONEXISTENT and BLOB_IN_WIM */
75 return imd->metadata_blob->blob_location == BLOB_NONEXISTENT;
78 /* Return true iff the specified image is unchanged since being read from the
79 * specified backing WIM file. */
81 is_image_unchanged_from_wim(const struct wim_image_metadata *imd,
84 return !is_image_dirty(imd) && imd->metadata_blob->rdesc->wim == wim;
87 /* Mark the metadata for the specified WIM image "dirty" following changes to
88 * the image's directory tree. This records that the metadata no longer matches
89 * the version in the WIM file (if any) and that its stats are out of date. */
91 mark_image_dirty(struct wim_image_metadata *imd)
93 blob_release_location(imd->metadata_blob);
94 imd->stats_outdated = true;
97 /* Iterate over each inode in a WIM image */
98 #define image_for_each_inode(inode, imd) \
99 hlist_for_each_entry(inode, &(imd)->inode_list, i_hlist_node)
101 /* Iterate over each inode in a WIM image (safe against inode removal) */
102 #define image_for_each_inode_safe(inode, tmp, imd) \
103 hlist_for_each_entry_safe(inode, tmp, &(imd)->inode_list, i_hlist_node)
105 /* Iterate over each blob in a WIM image that has not yet been hashed */
106 #define image_for_each_unhashed_blob(blob, imd) \
107 list_for_each_entry(blob, &(imd)->unhashed_blobs, unhashed_list)
109 /* Iterate over each blob in a WIM image that has not yet been hashed (safe
110 * against blob removal) */
111 #define image_for_each_unhashed_blob_safe(blob, tmp, imd) \
112 list_for_each_entry_safe(blob, tmp, &(imd)->unhashed_blobs, unhashed_list)
115 put_image_metadata(struct wim_image_metadata *imd, struct blob_table *table);
118 append_image_metadata(WIMStruct *wim, struct wim_image_metadata *imd);
120 extern struct wim_image_metadata *
121 new_image_metadata(void) _malloc_attribute;
123 #endif /* _WIMLIB_METADATA_H */