+ if (cur_rspec == NULL ||
+ !(reshdr.flags & WIM_RESHDR_FLAG_CONCAT))
+ {
+ /* Starting new run of stream entries that all share the
+ * same WIM resource (streams concatenated together); or
+ * simply a single normal entry by itself. */
+
+ if (cur_rspec != NULL) {
+ ret = validate_resource(cur_rspec);
+ if (ret)
+ goto out_free_cur_entry;
+ }
+
+ cur_rspec = MALLOC(sizeof(struct wim_resource_spec));
+ if (cur_rspec == NULL) {
+ ERROR("Not enough memory to read lookup table!");
+ ret = WIMLIB_ERR_NOMEM;
+ goto out_free_cur_entry;
+ }
+ wim_res_hdr_to_spec(&reshdr, wim, cur_rspec);
+ if (reshdr.flags & WIM_RESHDR_FLAG_CONCAT) {
+ cur_rspec->size_in_wim = 0;
+ cur_rspec->uncompressed_size = 0;
+ }
+ } else if (is_zero_hash(cur_entry->hash)) {
+ /* Found the resource specification for the run. */
+ cur_rspec->offset_in_wim = reshdr.offset_in_wim;
+ cur_rspec->size_in_wim = reshdr.size_in_wim;
+ cur_rspec->flags = reshdr.flags;
+ DEBUG("Full run is %"PRIu64" compressed bytes "
+ "at file offset %"PRIu64" (flags 0x%02x)",
+ cur_rspec->size_in_wim,
+ cur_rspec->offset_in_wim,
+ cur_rspec->flags);
+ free_lookup_table_entry(cur_entry);
+ continue;
+ }
+
+ if (reshdr.flags & WIM_RESHDR_FLAG_CONCAT) {
+ /* Continuing the run with another stream. */
+ DEBUG("Continuing concat run with stream: "
+ "%"PRIu64" uncompressed bytes @ resource offset %"PRIu64")",
+ reshdr.size_in_wim, reshdr.offset_in_wim);
+ cur_rspec->uncompressed_size += reshdr.size_in_wim;
+ }
+
+ lte_bind_wim_resource_spec(cur_entry, cur_rspec);
+ if (reshdr.flags & WIM_RESHDR_FLAG_CONCAT) {
+ /* In concatenation runs, the offset field is used for
+ * in-resource offset, not the in-WIM offset, and the
+ * size field is used for the uncompressed size, not the
+ * compressed size. */
+ cur_entry->offset_in_res = reshdr.offset_in_wim;
+ cur_entry->size = reshdr.size_in_wim;
+ cur_entry->flags = reshdr.flags;
+ } else {
+ cur_entry->offset_in_res = 0;
+ cur_entry->size = reshdr.uncompressed_size;
+ cur_entry->flags = reshdr.flags;
+ cur_rspec = NULL;
+ }
+