X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwim.c;h=bf6ebbf0cbe494ca9ba1077fc9628c45fd83f649;hb=2254a0fc3f1d7af1151ee83f3458f44339b5028b;hp=5ebf94ca4e3518fa6bd25d5668e24e49d4ccb46a;hpb=761a138b6419c30f6213af46186f678600750404;p=wimlib diff --git a/src/wim.c b/src/wim.c index 5ebf94ca..bf6ebbf0 100644 --- a/src/wim.c +++ b/src/wim.c @@ -70,6 +70,7 @@ new_wim_struct(void) if (wim) { wim->in_fd.fd = -1; wim->out_fd.fd = -1; + INIT_LIST_HEAD(&wim->subwims); } return wim; } @@ -167,9 +168,11 @@ select_wim_image(WIMStruct *wim, int image) return WIMLIB_ERR_INVALID_IMAGE; } - if (wim->hdr.part_number != 1) { - ERROR("Cannot select an image from a non-first part of a split WIM"); - return WIMLIB_ERR_SPLIT_UNSUPPORTED; + if (!wim_has_metadata(wim)) { + ERROR("\"%"TS"\" does not contain metadata resources!", wim->filename); + if (wim->hdr.part_number != 1) + ERROR("Specify the first part of the split WIM instead."); + return WIMLIB_ERR_METADATA_NOT_FOUND; } /* If a valid image is currently selected, it can be freed if it is not @@ -278,12 +281,6 @@ wimlib_print_available_images(const WIMStruct *wim, int image) WIMLIBAPI int wimlib_print_metadata(WIMStruct *wim, int image) { - if (wim->hdr.part_number != 1) { - ERROR("Cannot show the metadata from part %hu of a %hu-part split WIM!", - wim->hdr.part_number, wim->hdr.total_parts); - ERROR("Select the first part of the split WIM to see the metadata."); - return WIMLIB_ERR_SPLIT_UNSUPPORTED; - } return for_image(wim, image, image_print_metadata); } @@ -336,8 +333,10 @@ wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int whic if (ret) return ret; - if (which & WIMLIB_CHANGE_GUID) + if (which & WIMLIB_CHANGE_GUID) { memcpy(wim->hdr.guid, info->guid, WIM_GID_LEN); + wim->guid_set_explicitly = 1; + } if (which & WIMLIB_CHANGE_BOOT_INDEX) { if (info->boot_index > wim->hdr.image_count) { @@ -421,7 +420,7 @@ begin_read(WIMStruct *wim, const void *wim_filename_or_fd, * intervening time... * * Warning: in Windows native builds, realpath() calls the - * replacement function in win32.c. + * replacement function in win32_replacements.c. */ wim->filename = realpath(wimfile, NULL); if (!wim->filename) { @@ -449,11 +448,9 @@ begin_read(WIMStruct *wim, const void *wim_filename_or_fd, return ret; } - if (wim->hdr.total_parts != 1 && !(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK)) { - ERROR("\"%"TS"\": This WIM is part %u of a %u-part WIM", - wimfile, wim->hdr.part_number, wim->hdr.total_parts); - return WIMLIB_ERR_SPLIT_UNSUPPORTED; - } + if ((open_flags & WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT) && + (wim->hdr.total_parts != 1)) + return WIMLIB_ERR_IS_SPLIT_WIM; DEBUG("According to header, WIM contains %u images", wim->hdr.image_count); @@ -683,6 +680,9 @@ int wim_checksum_unhashed_streams(WIMStruct *wim) { int ret; + + if (!wim_has_metadata(wim)) + return 0; for (int i = 0; i < wim->hdr.image_count; i++) { struct wim_lookup_table_entry *lte, *tmp; struct wim_image_metadata *imd = wim->image_metadata[i]; @@ -715,7 +715,7 @@ can_modify_wim(WIMStruct *wim) } } if (wim->hdr.total_parts != 1) { - ERROR("Cannot modify \"%"TS"\": is part of a spanned set", + ERROR("Cannot modify \"%"TS"\": is part of a split WIM", wim->filename); return WIMLIB_ERR_WIM_IS_READONLY; } @@ -755,15 +755,28 @@ can_delete_from_wim(WIMStruct *wim) WIMLIBAPI void wimlib_free(WIMStruct *wim) { - DEBUG("Freeing WIMStruct"); - if (!wim) return; + + DEBUG("Freeing WIMStruct (filename=\"%"TS"\", image_count=%u)", + wim->filename, wim->hdr.image_count); + + while (!list_empty(&wim->subwims)) { + WIMStruct *subwim; + + subwim = list_entry(wim->subwims.next, WIMStruct, subwim_node); + list_del(&subwim->subwim_node); + DEBUG("Freeing subwim."); + wimlib_free(subwim); + } + if (filedes_valid(&wim->in_fd)) filedes_close(&wim->in_fd); if (filedes_valid(&wim->out_fd)) filedes_close(&wim->out_fd); + wimlib_lzx_free_context(wim->lzx_context); + free_lookup_table(wim->lookup_table); FREE(wim->filename); @@ -774,7 +787,6 @@ wimlib_free(WIMStruct *wim) FREE(wim->image_metadata); } FREE(wim); - DEBUG("Freed WIMStruct"); } static bool