-static int
-move_lte_to_table(struct wim_lookup_table_entry *lte, void *combined_table)
-{
- hlist_del(<e->hash_list);
- lookup_table_insert((struct wim_lookup_table*)combined_table, lte);
- return 0;
-}
-
-static void
-lookup_table_join(struct wim_lookup_table *combined_table,
- struct wim_lookup_table *part_table)
-{
- for_lookup_table_entry(part_table, move_lte_to_table, combined_table);
- part_table->num_entries = 0;
-}
-
-/*
- * merge_lookup_tables() - Merge lookup tables from the parts of a split WIM.
- *
- * @w specifies the first part, while @additional_swms and @num_additional_swms
- * specify an array of pointers to the WIMStruct's for additional split WIM parts.
- *
- * The reason we join the lookup tables is so we only have to search one lookup
- * table to find the location of a resource in the entire WIM.
- */
-void
-merge_lookup_tables(WIMStruct *w,
- WIMStruct **additional_swms,
- unsigned num_additional_swms)
-{
- for (unsigned i = 0; i < num_additional_swms; i++)
- lookup_table_join(w->lookup_table, additional_swms[i]->lookup_table);
-}
-
-static int
-move_lte_to_orig_table(struct wim_lookup_table_entry *lte, void *_wim)
-{
- WIMStruct *wim = _wim;
- if (lte->wim != wim) {
- move_lte_to_table(lte, lte->wim->lookup_table);
- wim->lookup_table->num_entries--;
- }
- return 0;
-}
-
-/* Undo merge_lookup_tables(), given the first WIM part that contains the merged
- * lookup table. */
-void
-unmerge_lookup_table(WIMStruct *wim)
-{
- for_lookup_table_entry(wim->lookup_table, move_lte_to_orig_table, wim);
-}
-
-
-static int
-join_wims(WIMStruct **swms, unsigned num_swms,
- WIMStruct *joined_wim, int write_flags,
- wimlib_progress_func_t progress_func)
-{
- int ret;
- unsigned i;
- union wimlib_progress_info progress;
- u64 total_bytes = 0;
- u64 part_bytes;
- u64 swm_part_sizes[num_swms];
-
- /* Calculate total size of the streams in the split WIM parts. */
- for (i = 0; i < num_swms; i++) {
- part_bytes = lookup_table_total_stream_size(swms[i]->lookup_table);
- swm_part_sizes[i] = part_bytes;
- total_bytes += part_bytes;
- }
-
- if (progress_func) {
- progress.join.total_bytes = total_bytes;
- progress.join.total_parts = swms[0]->hdr.total_parts;
- progress.join.completed_bytes = 0;
- progress.join.completed_parts = 0;
- progress_func(WIMLIB_PROGRESS_MSG_JOIN_STREAMS, &progress);
- }
-
- /* Write the non-metadata resources from each SWM part */
- for (i = 0; i < num_swms; i++) {
- ret = reopen_wim(swms[i]);
- if (ret)
- return ret;
- swms[i]->out_fd = joined_wim->out_fd;
- swms[i]->hdr.part_number = 1;
-
- ret = for_lookup_table_entry_pos_sorted(swms[i]->lookup_table,
- copy_resource,
- swms[i]);
- swms[i]->out_fd = -1;
- if (i != 0)
- close_wim(swms[i]);
-
- if (ret)
- return ret;
-
- if (progress_func) {
- progress.join.completed_bytes += swm_part_sizes[i];
- progress.join.completed_parts++;
- progress_func(WIMLIB_PROGRESS_MSG_JOIN_STREAMS, &progress);
- }
- }
-
- /* Copy the metadata resources from the first SWM part */
- joined_wim->hdr.image_count = swms[0]->hdr.image_count;
- for (i = 0; i < joined_wim->hdr.image_count; i++) {
- ret = copy_resource(swms[0]->image_metadata[i]->metadata_lte,
- joined_wim);
- if (ret)
- return ret;
- }