X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fjoin.c;h=222c9a9a8e81411405d08f25be93c847018dc45c;hp=3710eec85ec72ec02fee1bae2d857cf328fd79b2;hb=5cdd60306facd14cc9dcc24471386451294ca73c;hpb=35dd893208119869db6a90b1d1663f9aea88a3f7 diff --git a/src/join.c b/src/join.c index 3710eec8..222c9a9a 100644 --- a/src/join.c +++ b/src/join.c @@ -31,7 +31,7 @@ static int copy_lte_to_table(struct lookup_table_entry *lte, void *table) { struct lookup_table_entry *copy; - copy = new_lookup_table_entry(); + copy = MALLOC(sizeof(struct lookup_table_entry)); if (!copy) return WIMLIB_ERR_NOMEM; memcpy(copy, lte, sizeof(struct lookup_table_entry)); @@ -53,6 +53,23 @@ static int cmp_swms_by_part_number(const void *swm1, const void *swm2) return (int)partno_1 - (int)partno_2; } +/* + * Sanity checks to make sure a set of WIMs correctly correspond to a spanned + * set. + * + * @w: + * Part 1 of the set. + * + * @additional_swms: + * All parts of the set other than part 1. + * + * @num_additional_swms: + * Number of WIMStructs in @additional_swms. Or, the total number of parts + * in the set minus 1. + * + * @return: + * 0 on success; WIMLIB_ERR_SPLIT_INVALID if the set is not valid. + */ int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms, unsigned num_additional_swms) { @@ -63,8 +80,8 @@ int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms, if (total_parts != num_additional_swms + 1) { ERROR("`%s' says there are %u parts in the spanned set, " "but %s%u part%s provided", - w->filename, w->hdr.total_parts, - (num_additional_swms + 1 < w->hdr.total_parts) ? "only " : "", + w->filename, total_parts, + (num_additional_swms + 1 < total_parts) ? "only " : "", num_additional_swms + 1, (num_additional_swms) ? "s were" : " was"); return WIMLIB_ERR_SPLIT_INVALID; @@ -77,7 +94,7 @@ int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms, for (unsigned i = 0; i < num_additional_swms; i++) { if (additional_swms[i]->hdr.total_parts != total_parts) { ERROR("WIM `%s' says there are %u parts in the spanned set, " - "but %u parts were provided", + "but %u parts were provided", additional_swms[i]->filename, additional_swms[i]->hdr.total_parts, total_parts); @@ -108,7 +125,7 @@ int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms, } if (swm->hdr.part_number == 1) { ERROR("WIMs `%s' and `%s' both are marked as the " - "first WIM in the spanned set", + "first WIM in the spanned set", w->filename, swm->filename); return WIMLIB_ERR_SPLIT_INVALID; } @@ -137,6 +154,21 @@ int verify_swm_set(WIMStruct *w, WIMStruct **additional_swms, return 0; } +/* + * Joins 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 points to the WIMStruct's for additional split WIM parts. + * + * On success, 0 is returned on a pointer to the joined lookup table is returned + * in @table_ret. + * + * 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 split WIM. + * - Each lookup table entry will have a pointer to its split WIM part (and + * a part number field, although we don't really use it). + */ int new_joined_lookup_table(WIMStruct *w, WIMStruct **additional_swms, unsigned num_additional_swms, @@ -191,7 +223,7 @@ static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim, } swms[i]->out_fp = out_fp; swms[i]->hdr.part_number = 1; - ret = for_lookup_table_entry(swms[i]->lookup_table, + ret = for_lookup_table_entry(swms[i]->lookup_table, copy_resource, swms[i]); if (ret != 0) return ret; @@ -202,11 +234,11 @@ static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim, } swms[0]->write_metadata = true; if (write_flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS) - printf("Writing %d metadata resources\n", + 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, + ret = copy_resource(swms[0]->image_metadata[i].metadata_lte, swms[0]); if (ret != 0) return ret; @@ -220,7 +252,9 @@ static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim, * 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); + ret = for_lookup_table_entry(swms[i]->lookup_table, + write_lookup_table_entry, + out_fp); if (ret != 0) return ret; } @@ -231,8 +265,12 @@ static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim, return WIMLIB_ERR_WRITE; } swms[0]->hdr.lookup_table_res_entry.offset = lookup_table_offset; - swms[0]->hdr.lookup_table_res_entry.size = + swms[0]->hdr.lookup_table_res_entry.size = xml_data_offset - lookup_table_offset; + swms[0]->hdr.lookup_table_res_entry.original_size = + xml_data_offset - lookup_table_offset; + swms[0]->hdr.lookup_table_res_entry.flags = + WIM_RESHDR_FLAG_METADATA; /* finish_write is called on the first swm, not the joined_wim, because @@ -240,30 +278,26 @@ static int join_wims(WIMStruct **swms, uint num_swms, WIMStruct *joined_wim, * 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, 0); + 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, +WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms, const char *output_path, int flags) { - int i; int ret; - int part_idx; int write_flags = 0; WIMStruct *joined_wim = NULL; WIMStruct *swms[num_swms]; - int ctype; - u8 *guid; - if (num_swms < 1) return WIMLIB_ERR_INVALID_PARAM; ZERO_ARRAY(swms); - for (i = 0; i < num_swms; i++) { - ret = wimlib_open_wim(swm_names[i], + for (unsigned i = 0; i < num_swms; i++) { + ret = wimlib_open_wim(swm_names[i], flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &swms[i]); if (ret != 0) goto out; @@ -296,14 +330,13 @@ WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms, goto out; ret = join_wims(swms, num_swms, joined_wim, write_flags); out: - for (i = 0; i < num_swms; i++) { - /* out_fp is the same in all the swms and joined_wim; only close - * it one time, when freeing joined_wim. */ - if (swms[i]) { - swms[i]->out_fp = NULL; - wimlib_free(swms[i]); - } + /* out_fp is the same in all the swms and joined_wim. And it was + * already closed in the call to finish_write(). */ + for (unsigned i = 0; i < num_swms; i++) { + swms[i]->out_fp = NULL; + wimlib_free(swms[i]); } + joined_wim->out_fp = NULL; wimlib_free(joined_wim); return ret; }