]> wimlib.net Git - wimlib/blob - include/wimlib/metadata.h
f9307a67859154d56b273f7c039673512b71832c
[wimlib] / include / wimlib / metadata.h
1 #ifndef _WIMLIB_METADATA_H
2 #define _WIMLIB_METADATA_H
3
4 #include "wimlib/blob_table.h"
5 #include "wimlib/list.h"
6 #include "wimlib/types.h"
7 #include "wimlib/wim.h"
8
9 /* Metadata for a WIM image  */
10 struct wim_image_metadata {
11
12         /* Number of WIMStruct's that are sharing this image metadata (from
13          * calls to wimlib_export_image().) */
14         unsigned long refcnt;
15
16         /* Pointer to the root dentry of the image. */
17         struct wim_dentry *root_dentry;
18
19         /* Pointer to the security data of the image. */
20         struct wim_security_data *security_data;
21
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;
29
30         /* Linked list of 'struct wim_inode's for this image. */
31         struct hlist_head inode_list;
32
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;
39
40         /* Are the filecount/bytecount stats (in the XML info) out of date for
41          * this image?  */
42         bool stats_outdated;
43 };
44
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)
49 {
50         return wim->image_metadata[wim->current_image - 1];
51 }
52
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)
57 {
58         return wim_get_current_image_metadata(wim)->root_dentry;
59 }
60
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)
65 {
66         return wim_get_current_image_metadata(wim)->security_data;
67 }
68
69 /* Return true iff the specified image has been changed since being read from
70  * its backing file or has been created from scratch.  */
71 static inline bool
72 is_image_dirty(const struct wim_image_metadata *imd)
73 {
74         /* The only possible values here are BLOB_NONEXISTENT and BLOB_IN_WIM */
75         return imd->metadata_blob->blob_location == BLOB_NONEXISTENT;
76 }
77
78 /* Return true iff the specified image is unchanged since being read from the
79  * specified backing WIM file.  */
80 static inline bool
81 is_image_unchanged_from_wim(const struct wim_image_metadata *imd,
82                             const WIMStruct *wim)
83 {
84         return !is_image_dirty(imd) && imd->metadata_blob->rdesc->wim == wim;
85 }
86
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.  */
90 static inline void
91 mark_image_dirty(struct wim_image_metadata *imd)
92 {
93         blob_release_location(imd->metadata_blob);
94         imd->stats_outdated = true;
95 }
96
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)
100
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)
104
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)
108
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)
113
114 extern void
115 put_image_metadata(struct wim_image_metadata *imd, struct blob_table *table);
116
117 extern int
118 append_image_metadata(WIMStruct *wim, struct wim_image_metadata *imd);
119
120 extern struct wim_image_metadata *
121 new_image_metadata(void) _malloc_attribute;
122
123 #endif /* _WIMLIB_METADATA_H */