+ /* Set image count and boot index correctly for single image writes */
+ if (image != WIMLIB_ALL_IMAGES) {
+ hdr.image_count = 1;
+ if (hdr.boot_idx == image)
+ hdr.boot_idx = 1;
+ else
+ hdr.boot_idx = 0;
+ }
+
+ /* In the WIM header, there is room for the resource entry for a
+ * metadata resource labeled as the "boot metadata". This entry should
+ * be zeroed out if there is no bootable image (boot_idx 0). Otherwise,
+ * it should be a copy of the resource entry for the image that is
+ * marked as bootable. This is not well documented... */
+ if (hdr.boot_idx == 0) {
+ memset(&hdr.boot_metadata_res_entry, 0,
+ sizeof(struct resource_entry));
+ } else {
+ memcpy(&hdr.boot_metadata_res_entry,
+ &w->image_metadata[
+ hdr.boot_idx - 1]->metadata_lte->output_resource_entry,
+ sizeof(struct resource_entry));
+ }
+