From b82856cb22783df0e19990eb68d3694753f52220 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 30 May 2015 15:48:12 -0500 Subject: [PATCH 1/1] New helper: wim_reshdr_to_desc_and_blob() --- include/wimlib/blob_table.h | 12 ------------ include/wimlib/resource.h | 5 +++++ src/blob_table.c | 4 +--- src/extract.c | 12 +++++------- src/resource.c | 21 +++++++++++++++++---- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/wimlib/blob_table.h b/include/wimlib/blob_table.h index 0ccccfbb..9dfca8dc 100644 --- a/include/wimlib/blob_table.h +++ b/include/wimlib/blob_table.h @@ -376,18 +376,6 @@ blob_set_is_located_in_wim_resource(struct blob_descriptor *blob, blob->offset_in_res = offset_in_res; } -/* - * Declare that the specified blob is located in the specified non-solid WIM - * resource. In this case, the blob data is the entire uncompressed resource. - */ -static inline void -blob_set_is_located_in_nonsolid_wim_resource(struct blob_descriptor *blob, - struct wim_resource_descriptor *rdesc) -{ - blob_set_is_located_in_wim_resource(blob, rdesc, 0); - blob->size = rdesc->uncompressed_size; -} - static inline void blob_unset_is_located_in_wim_resource(struct blob_descriptor *blob) { diff --git a/include/wimlib/resource.h b/include/wimlib/resource.h index 5cfbd45c..2fea2f57 100644 --- a/include/wimlib/resource.h +++ b/include/wimlib/resource.h @@ -123,6 +123,11 @@ extern void wim_reshdr_to_desc(const struct wim_reshdr *reshdr, WIMStruct *wim, struct wim_resource_descriptor *rdesc); +extern void +wim_reshdr_to_desc_and_blob(const struct wim_reshdr *reshdr, WIMStruct *wim, + struct wim_resource_descriptor *rdesc, + struct blob_descriptor *blob); + extern void get_wim_reshdr(const struct wim_reshdr_disk *disk_reshdr, struct wim_reshdr *reshdr); diff --git a/src/blob_table.c b/src/blob_table.c index aa73cc01..b3eb63fc 100644 --- a/src/blob_table.c +++ b/src/blob_table.c @@ -969,9 +969,7 @@ read_blob_table(WIMStruct *wim) if (!rdesc) goto oom; - wim_reshdr_to_desc(&reshdr, wim, rdesc); - - blob_set_is_located_in_nonsolid_wim_resource(cur_blob, rdesc); + wim_reshdr_to_desc_and_blob(&reshdr, wim, rdesc, cur_blob); } /* cur_blob is now a blob bound to a resource. */ diff --git a/src/extract.c b/src/extract.c index efce477e..5fcf5248 100644 --- a/src/extract.c +++ b/src/extract.c @@ -233,19 +233,18 @@ read_blobs_from_pipe(struct apply_ctx *ctx, const struct read_blob_callbacks *cb if (ret) return ret; - wim_reshdr_to_desc(&reshdr, ctx->wim, &rdesc); - - if (!(rdesc.flags & WIM_RESHDR_FLAG_METADATA) + if (!(reshdr.flags & WIM_RESHDR_FLAG_METADATA) && (blob = lookup_blob(ctx->wim->blob_table, hash)) && (blob->out_refcnt)) { - blob_set_is_located_in_nonsolid_wim_resource(blob, &rdesc); + wim_reshdr_to_desc_and_blob(&reshdr, ctx->wim, &rdesc, blob); ret = read_blob_with_sha1(blob, cbs); blob_unset_is_located_in_wim_resource(blob); if (ret) return ret; ctx->num_blobs_remaining--; } else { + wim_reshdr_to_desc(&reshdr, ctx->wim, &rdesc); ret = skip_wim_resource(&rdesc); if (ret) return ret; @@ -1958,9 +1957,8 @@ wimlib_extract_image_from_pipe_with_progress(int pipe_fd, metadata_rdesc = MALLOC(sizeof(struct wim_resource_descriptor)); if (!metadata_rdesc) goto out_wimlib_free; - wim_reshdr_to_desc(&reshdr, pwm, metadata_rdesc); - blob_set_is_located_in_nonsolid_wim_resource(imd->metadata_blob, - metadata_rdesc); + wim_reshdr_to_desc_and_blob(&reshdr, pwm, metadata_rdesc, + imd->metadata_blob); if (i == image) { /* Metadata resource is for the image being extracted. diff --git a/src/resource.c b/src/resource.c index 74c9bb8b..a4cc6c12 100644 --- a/src/resource.c +++ b/src/resource.c @@ -808,8 +808,7 @@ wim_reshdr_to_data(const struct wim_reshdr *reshdr, WIMStruct *wim, struct wim_resource_descriptor rdesc; struct blob_descriptor blob; - wim_reshdr_to_desc(reshdr, wim, &rdesc); - blob_set_is_located_in_nonsolid_wim_resource(&blob, &rdesc); + wim_reshdr_to_desc_and_blob(reshdr, wim, &rdesc, &blob); return read_blob_into_alloc_buf(&blob, buf_ret); } @@ -824,8 +823,7 @@ wim_reshdr_to_hash(const struct wim_reshdr *reshdr, WIMStruct *wim, struct blob_descriptor blob; int ret; - wim_reshdr_to_desc(reshdr, wim, &rdesc); - blob_set_is_located_in_nonsolid_wim_resource(&blob, &rdesc); + wim_reshdr_to_desc_and_blob(reshdr, wim, &rdesc, &blob); blob.unhashed = 1; ret = sha1_blob(&blob); @@ -1267,6 +1265,21 @@ wim_reshdr_to_desc(const struct wim_reshdr *reshdr, WIMStruct *wim, } } +/* + * Convert the short WIM resource header @reshdr to a stand-alone WIM resource + * descriptor @rdesc, then set @blob to consist of that entire resource. This + * should only be used for non-solid resources! + */ +void +wim_reshdr_to_desc_and_blob(const struct wim_reshdr *reshdr, WIMStruct *wim, + struct wim_resource_descriptor *rdesc, + struct blob_descriptor *blob) +{ + wim_reshdr_to_desc(reshdr, wim, rdesc); + blob->size = rdesc->uncompressed_size; + blob_set_is_located_in_wim_resource(blob, rdesc, 0); +} + /* Import a WIM resource header from the on-disk format. */ void get_wim_reshdr(const struct wim_reshdr_disk *disk_reshdr, -- 2.43.0