+/* Internal method for single-image deletion. This doesn't set the
+ * image_deletion_occurred' flag on the WIMStruct. */
+int
+delete_wim_image(WIMStruct *wim, int image)
+{
+ int ret;
+ struct wim_image_metadata *imd;
+
+ /* Load the metadata for the image to be deleted. This is necessary
+ * because blobs referenced by files in the image need to have their
+ * reference counts decremented. */
+ ret = select_wim_image(wim, image);
+ if (ret)
+ return ret;
+
+ /* Release the files and decrement the reference counts of the blobs
+ * they reference. */
+ imd = wim->image_metadata[image - 1];
+ free_dentry_tree(imd->root_dentry, wim->blob_table);
+ imd->root_dentry = NULL;
+
+ /* Deselect the image and release its metadata. */
+ deselect_current_wim_image(wim);
+ put_image_metadata(imd);
+
+ /* Remove the empty slot from the image metadata array. */
+ memmove(&wim->image_metadata[image - 1], &wim->image_metadata[image],
+ (wim->hdr.image_count - image) *
+ sizeof(wim->image_metadata[0]));
+
+ /* Decrement the image count. */
+ wim->hdr.image_count--;
+
+ /* Remove the image from the XML information. */
+ xml_delete_image(wim->xml_info, image);
+
+ /* Fix the boot index. */
+ if (wim->hdr.boot_idx == image)
+ wim->hdr.boot_idx = 0;
+ else if (wim->hdr.boot_idx > image)
+ wim->hdr.boot_idx--;
+
+ return 0;
+}
+