/* API function documented in wimlib.h */ WIMLIBAPI int wimlib_add_image_multisource(WIMStruct *wim, const struct wimlib_capture_source *sources, size_t num_sources, const tchar *name, const tchar *config_file, int add_flags) { int ret; struct wimlib_update_command *add_cmds; /* Make sure no reserved fields are set. */ for (size_t i = 0; i < num_sources; i++) if (sources[i].reserved != 0) return WIMLIB_ERR_INVALID_PARAM; /* Add the new image (initially empty). */ ret = wimlib_add_empty_image(wim, name, NULL); if (ret) return ret; /* Translate the "capture sources" into generic update commands. */ ret = WIMLIB_ERR_NOMEM; add_cmds = capture_sources_to_add_cmds(sources, num_sources, add_flags, config_file); if (!add_cmds) goto out_delete_image; /* Delegate the work to wimlib_update_image(). */ ret = wimlib_update_image(wim, wim->hdr.image_count, add_cmds, num_sources, 0); FREE(add_cmds); if (ret) goto out_delete_image; /* If requested, set this image as the WIM's bootable image. */ if (add_flags & WIMLIB_ADD_FLAG_BOOT) wim->hdr.boot_idx = wim->hdr.image_count; /* If requested, mark new image as WIMBoot-compatible. */ if (add_flags & WIMLIB_ADD_FLAG_WIMBOOT) wim_info_set_wimboot(wim->wim_info, wim->hdr.image_count, true); return 0; out_delete_image: /* Unsuccessful; rollback the WIM to its original state. */ /* wimlib_update_image() is now all-or-nothing, so no dentries remain * and there's no need to pass the lookup table here. */ put_image_metadata(wim->image_metadata[wim->hdr.image_count - 1], NULL); xml_delete_image(&wim->wim_info, wim->hdr.image_count); wim->hdr.image_count--; return ret; }
/* 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; /* Load the metadata for the image to be deleted. This is necessary * because streams 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 reference to the image metadata and decrement reference * counts on the streams referenced by files in the image. */ put_image_metadata(wim->image_metadata[image - 1], wim->lookup_table); /* 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->wim_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--; /* The image is no longer valid. */ wim->current_image = WIMLIB_NO_IMAGE; return 0; }