-
- table = new_lookup_table(9001);
- if (!table)
- return WIMLIB_ERR_NOMEM;
- ret = lookup_table_join(table, w->lookup_table);
- if (ret != 0)
- goto out_free_table;
- for (i = 0; i < num_additional_swms; i++) {
- ret = lookup_table_join(table, additional_swms[i]->lookup_table);
- if (ret != 0)
- goto out_free_table;
- }
- *table_ret = table;
- return 0;
-out_free_table:
- free_lookup_table(table);
- return ret;
-}
-
-
-static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim,
- int write_flags)
-{
- uint i;
- int ret;
- FILE *out_fp = joined_wim->out_fp;
- u64 total_bytes = wim_info_get_total_bytes(swms[0]->wim_info);
-
- swms[0]->write_metadata = false;
- for (i = 0; i < num_swms; i++) {
- if (write_flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS) {
- off_t cur_offset = ftello(out_fp);
- printf("Writing resources from part %u of %u "
- "(%"PRIu64" of %"PRIu64" bytes, %.0f%% done)\n",
- i + 1, num_swms, cur_offset, total_bytes,
- (double)cur_offset / total_bytes * 100.0);
- }
- swms[i]->fp = fopen(swms[i]->filename, "rb");
- if (!swms[i]->fp) {
- ERROR_WITH_ERRNO("Failed to reopen `%s'",
- swms[i]->filename);
- return WIMLIB_ERR_OPEN;
- }
- swms[i]->out_fp = out_fp;
- swms[i]->hdr.part_number = 1;
- ret = for_lookup_table_entry(swms[i]->lookup_table,
- copy_resource, swms[i]);
- if (ret != 0)
- return ret;
- if (i != 0) {
- fclose(swms[i]->fp);
- swms[i]->fp = NULL;
- }
- }
- swms[0]->write_metadata = true;
- if (write_flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS)
- printf("Writing %d metadata resources\n",
- swms[0]->hdr.image_count);
-
- for (i = 0; i < swms[0]->hdr.image_count; i++) {
- ret = copy_resource(swms[0]->image_metadata[i].metadata_lte,
- swms[0]);
- if (ret != 0)
- return ret;
- }
-
- off_t lookup_table_offset = ftello(out_fp);
-
- if (write_flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS)
- printf("Writing lookup tables, XML data, and header\n");
- /* Now write the lookup table for the joined wim. Since the lookup
- * table has no header, we can just concatenate the lookup tables of all
- * the SWM parts. */
- for (i = 0; i < num_swms; i++) {
- ret = write_lookup_table(swms[i]->lookup_table, out_fp);
- if (ret != 0)
- return ret;
- }
- off_t xml_data_offset = ftello(out_fp);
-
- if (lookup_table_offset == -1 || xml_data_offset == -1) {
- ERROR_WITH_ERRNO("Failed to get file offset");
- return WIMLIB_ERR_WRITE;
- }
- swms[0]->hdr.lookup_table_res_entry.offset = lookup_table_offset;
- swms[0]->hdr.lookup_table_res_entry.size =
- xml_data_offset - lookup_table_offset;
-
-
- /* finish_write is called on the first swm, not the joined_wim, because
- * the first swm is the one that has the image metadata and XML data
- * attached to it. */
- swms[0]->hdr.flags &= ~WIM_HDR_FLAG_SPANNED;
- swms[0]->hdr.total_parts = 1;
- return finish_write(swms[0], WIM_ALL_IMAGES,
- write_flags | WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE);
-}
-
-
-WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms,
- const char *output_path, int flags)
-{
- int ret;
- int write_flags = 0;
- WIMStruct *joined_wim = NULL;
- WIMStruct *swms[num_swms];
-
- if (num_swms < 1)