+/* Return true iff the specified image has been changed since being read from
+ * its backing file or has been created from scratch. */
+static inline bool
+is_image_dirty(const struct wim_image_metadata *imd)
+{
+ /* The only possible values here are BLOB_NONEXISTENT and BLOB_IN_WIM */
+ return imd->metadata_blob->blob_location == BLOB_NONEXISTENT;
+}
+
+/* Return true iff the specified image is unchanged since being read from the
+ * specified backing WIM file. */
+static inline bool
+is_image_unchanged_from_wim(const struct wim_image_metadata *imd,
+ const WIMStruct *wim)
+{
+ return !is_image_dirty(imd) && imd->metadata_blob->rdesc->wim == wim;
+}
+
+/* Mark the metadata for the specified WIM image "dirty" following changes to
+ * the image's directory tree. This records that the metadata no longer matches
+ * the version in the WIM file (if any) and that its stats are out of date. */
+static inline void
+mark_image_dirty(struct wim_image_metadata *imd)
+{
+ blob_release_location(imd->metadata_blob);
+ imd->stats_outdated = true;
+}
+
+/* Return true iff the specified image is currently loaded into memory. */
+static inline bool
+is_image_loaded(const struct wim_image_metadata *imd)
+{
+ /* Check security_data rather than root_dentry, since root_dentry will
+ * be NULL for a completely empty image whereas security_data will still
+ * be non-NULL in that case. */
+ return imd->security_data != NULL;
+}
+
+/* Return true iff it is okay to unload the specified image. The image can be
+ * unloaded if no WIMStructs have it selected and it is not dirty. */
+static inline bool
+can_unload_image(const struct wim_image_metadata *imd)