]> wimlib.net Git - wimlib/blob - include/wimlib/metadata.h
Don't unnecessarily rebuild exported metadata resources
[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
41 /* Retrieve the metadata of the image in @wim currently selected with
42  * select_wim_image().  */
43 static inline struct wim_image_metadata *
44 wim_get_current_image_metadata(WIMStruct *wim)
45 {
46         return wim->image_metadata[wim->current_image - 1];
47 }
48
49 /* Retrieve the root dentry of the image in @wim currently selected with
50  * select_wim_image().  */
51 static inline struct wim_dentry *
52 wim_get_current_root_dentry(WIMStruct *wim)
53 {
54         return wim_get_current_image_metadata(wim)->root_dentry;
55 }
56
57 /* Retrieve the security data of the image in @wim currently selected with
58  * select_wim_image().  */
59 static inline struct wim_security_data *
60 wim_get_current_security_data(WIMStruct *wim)
61 {
62         return wim_get_current_image_metadata(wim)->security_data;
63 }
64
65 /* Return true iff the specified image has been changed since being read from
66  * its backing file or has been created from scratch.  */
67 static inline bool
68 is_image_dirty(const struct wim_image_metadata *imd)
69 {
70         /* The only possible values here are BLOB_NONEXISTENT and BLOB_IN_WIM */
71         return imd->metadata_blob->blob_location == BLOB_NONEXISTENT;
72 }
73
74 /* Return true iff the specified image is unchanged since being read from the
75  * specified backing WIM file.  */
76 static inline bool
77 is_image_unchanged_from_wim(const struct wim_image_metadata *imd,
78                             const WIMStruct *wim)
79 {
80         return !is_image_dirty(imd) && imd->metadata_blob->rdesc->wim == wim;
81 }
82
83 /* Mark the metadata for the specified WIM image "dirty" following changes to
84  * the image's directory tree.  This records that the metadata no longer matches
85  * the version in the WIM file (if any).  */
86 static inline void
87 mark_image_dirty(struct wim_image_metadata *imd)
88 {
89         blob_release_location(imd->metadata_blob);
90 }
91
92 /* Iterate over each inode in a WIM image  */
93 #define image_for_each_inode(inode, imd) \
94         hlist_for_each_entry(inode, &(imd)->inode_list, i_hlist_node)
95
96 /* Iterate over each inode in a WIM image (safe against inode removal)  */
97 #define image_for_each_inode_safe(inode, tmp, imd) \
98         hlist_for_each_entry_safe(inode, tmp, &(imd)->inode_list, i_hlist_node)
99
100 /* Iterate over each blob in a WIM image that has not yet been hashed */
101 #define image_for_each_unhashed_blob(blob, imd) \
102         list_for_each_entry(blob, &(imd)->unhashed_blobs, unhashed_list)
103
104 /* Iterate over each blob in a WIM image that has not yet been hashed (safe
105  * against blob removal) */
106 #define image_for_each_unhashed_blob_safe(blob, tmp, imd) \
107         list_for_each_entry_safe(blob, tmp, &(imd)->unhashed_blobs, unhashed_list)
108
109 extern void
110 put_image_metadata(struct wim_image_metadata *imd, struct blob_table *table);
111
112 extern int
113 append_image_metadata(WIMStruct *wim, struct wim_image_metadata *imd);
114
115 extern struct wim_image_metadata *
116 new_image_metadata(void) _malloc_attribute;
117
118 #endif /* _WIMLIB_METADATA_H */