-static int
-append_lookup_table_entry(struct wim_lookup_table_entry *lte, void *_list)
-{
- /* Lookup table entries with 'out_refcnt' == 0 correspond to streams not
- * written and not present in the resulting WIM file, and should not be
- * included in the lookup table.
- *
- * Lookup table entries marked as filtered (EXTERNAL_WIM) with
- * 'out_refcnt != 0' were referenced as part of the logical write but
- * correspond to streams that were not in fact written, and should not
- * be included in the lookup table.
- *
- * Lookup table entries marked as filtered (SAME_WIM) with 'out_refcnt
- * != 0' were referenced as part of the logical write but correspond to
- * streams that were not in fact written, but nevertheless were already
- * present in the WIM being overwritten in-place. These entries must be
- * included in the lookup table, and the resource information to write
- * needs to be copied from the resource information read originally.
- */
- if (lte->out_refcnt != 0 && !(lte->filtered & FILTERED_EXTERNAL_WIM)) {
- if (lte->filtered & FILTERED_SAME_WIM)
- wim_res_spec_to_hdr(lte->rspec, <e->out_reshdr);
- list_add_tail(<e->lookup_table_list, (struct list_head*)_list);
- }
- return 0;
-}
-
-int
-write_wim_lookup_table(WIMStruct *wim, int image, int write_flags,
- struct wim_reshdr *out_reshdr,
- struct list_head *stream_list_override)
-{
- int write_resource_flags;
- struct list_head _stream_list;
- struct list_head *stream_list;
-
- if (stream_list_override) {
- stream_list = stream_list_override;
- } else {
- stream_list = &_stream_list;
- INIT_LIST_HEAD(stream_list);
- }
-
- if (!(write_flags & WIMLIB_WRITE_FLAG_NO_METADATA)) {
- int start_image;
- int end_image;
-
- if (image == WIMLIB_ALL_IMAGES) {
- start_image = 1;
- end_image = wim->hdr.image_count;
- } else {
- start_image = image;
- end_image = image;
- }
-
- /* Push metadata resource lookup table entries onto the front of
- * the list in reverse order, so that they're written in order.
- */
- for (int i = end_image; i >= start_image; i--) {
- struct wim_lookup_table_entry *metadata_lte;
-
- metadata_lte = wim->image_metadata[i - 1]->metadata_lte;
- metadata_lte->out_refcnt = 1;
- metadata_lte->out_reshdr.flags |= WIM_RESHDR_FLAG_METADATA;
- list_add(&metadata_lte->lookup_table_list, stream_list);
- }
- }
-
- /* Append additional lookup table entries that need to be written, with
- * some special handling for streams that have been marked as filtered.
- */
- if (!stream_list_override) {
- for_lookup_table_entry(wim->lookup_table,
- append_lookup_table_entry, stream_list);
- }
-
- write_resource_flags = 0;
- if (write_flags & WIMLIB_WRITE_FLAG_PIPABLE)
- write_resource_flags |= WIMLIB_WRITE_RESOURCE_FLAG_PIPABLE;
- return write_wim_lookup_table_from_stream_list(stream_list,
- &wim->out_fd,
- wim->hdr.part_number,
- out_reshdr,
- write_resource_flags,
- &wim->lzx_context);
-}
-
-