- ret = read_lookup_table(w->fp, w->hdr.lookup_table_res_entry.offset,
- w->hdr.lookup_table_res_entry.size,
- &w->lookup_table);
-
- if (ret != 0)
- goto done;
-
- 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\n",
- w->hdr.image_count);
- goto done;
- }
- w->current_image = 0;
-
- DEBUG("Looking for metadata resources in the lookup table.\n");
-
- /* 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 && w->hdr.part_number == 1)
- goto done;
-
- /* 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!\n",
- w->current_image, w->hdr.image_count);
- ret = WIMLIB_ERR_IMAGE_COUNT;
- goto done;
- }
-
-
- /* 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 may be
- * 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;