- w->image_metadata = CALLOC(w->hdr.image_count,
- sizeof(struct image_metadata));
-
- if (!w->image_metadata) {
- ERROR("Failed to allocate memory for %u metadata structures",
- w->hdr.image_count);
- return WIMLIB_ERR_NOMEM;
- }
- w->current_image = 0;
-
- DEBUG("Looking for metadata resources in the lookup table.");
-
- /* Find the images in the WIM by searching the lookup table. */
- ret = for_lookup_table_entry(w->lookup_table,
- append_metadata_resource_entry, w);
-
- if (ret != 0)
- return ret;
-
- /* Make sure all the expected images were found. (We already have
- * returned false if *extra* images were found) */
- if (w->current_image != w->hdr.image_count && w->hdr.part_number == 1) {
- ERROR("Only found %u images in WIM, but expected %u",
- w->current_image, w->hdr.image_count);
- return WIMLIB_ERR_IMAGE_COUNT;
- }
-
-
- /* Sort images by the position of their metadata resources. I'm
- * assuming that is what determines the other of the images in the WIM
- * file, rather than their order in the lookup table, which is random
- * because of hashing. */
- qsort(w->image_metadata, w->current_image,
- sizeof(struct image_metadata), sort_image_metadata_by_position);
-
- w->current_image = WIM_NO_IMAGE;
-
- /* Read the XML data. */
- ret = read_xml_data(w->fp, &w->hdr.xml_res_entry,