+ /* Zero 'out_refcnt' in all lookup table entries in the destination WIM;
+ * this tracks the number of references found from the source WIM
+ * image(s). */
+ for_lookup_table_entry(dest_wim->lookup_table, lte_zero_out_refcnt,
+ NULL);
+
+ /* Save the original count of images in the destination WIM and the boot
+ * index (used if rollback necessary). */
+ orig_dest_image_count = dest_wim->hdr.image_count;
+ orig_dest_boot_idx = dest_wim->hdr.boot_idx;
+
+ /* Export each requested image. */
+ for (image = start_image; image <= end_image; image++) {
+ const tchar *next_dest_name, *next_dest_description;
+ struct wim_image_metadata *src_imd;
+ struct wim_inode *inode;
+
+ DEBUG("Exporting image %d from \"%"TS"\"",
+ image, src_wim->filename);
+
+ /* Determine destination image name and description. */
+
+ if (export_flags & WIMLIB_EXPORT_FLAG_NO_NAMES) {
+ next_dest_name = T("");
+ } else if (dest_name) {
+ next_dest_name = dest_name;
+ } else {
+ next_dest_name = wimlib_get_image_name(src_wim,
+ image);
+ }
+
+ DEBUG("Using name \"%"TS"\"", next_dest_name);
+
+ if (export_flags & WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS) {
+ next_dest_description = T("");
+ } else if (dest_description) {
+ next_dest_description = dest_description;
+ } else {
+ next_dest_description = wimlib_get_image_description(
+ src_wim, image);
+ }
+
+ DEBUG("Using description \"%"TS"\"", next_dest_description);
+
+ /* Check for name conflict. */
+ if (wimlib_image_name_in_use(dest_wim, next_dest_name)) {
+ ERROR("There is already an image named \"%"TS"\" "
+ "in the destination WIM", next_dest_name);
+ ret = WIMLIB_ERR_IMAGE_NAME_COLLISION;
+ goto out_rollback;
+ }
+
+ /* Load metadata for source image into memory. */
+ ret = select_wim_image(src_wim, image);