From: Eric Biggers Date: Thu, 2 Apr 2015 04:43:54 +0000 (-0500) Subject: Improve helper functions for setting blob locations X-Git-Tag: v1.8.1~53 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=3abe6501c7ebb20a0ead1cd69ebd93cbe6b917e1;hp=6f535b981a9192e1e2a38b3a8aaa8cd8124d8e96 Improve helper functions for setting blob locations --- diff --git a/include/wimlib/blob_table.h b/include/wimlib/blob_table.h index e273de25..c86fac0d 100644 --- a/include/wimlib/blob_table.h +++ b/include/wimlib/blob_table.h @@ -345,13 +345,31 @@ blob_extraction_targets(struct blob_descriptor *blob) return blob->blob_extraction_targets; } +/* + * Declare that the specified blob is located in the specified WIM resource at + * the specified offset. The caller is expected to set blob->size if required. + */ static inline void blob_set_is_located_in_wim_resource(struct blob_descriptor *blob, - struct wim_resource_descriptor *rdesc) + struct wim_resource_descriptor *rdesc, + u64 offset_in_res) { blob->blob_location = BLOB_IN_WIM; blob->rdesc = rdesc; list_add_tail(&blob->rdesc_node, &rdesc->blob_list); + 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 @@ -361,6 +379,15 @@ blob_unset_is_located_in_wim_resource(struct blob_descriptor *blob) blob->blob_location = BLOB_NONEXISTENT; } +static inline void +blob_set_is_located_in_attached_buffer(struct blob_descriptor *blob, + void *buffer, size_t size) +{ + blob->blob_location = BLOB_IN_ATTACHED_BUFFER; + blob->attached_buffer = buffer; + blob->size = size; +} + extern struct blob_descriptor * new_blob_from_data_buffer(const void *buffer, size_t size, struct blob_table *blob_table); diff --git a/src/blob_table.c b/src/blob_table.c index c94635f1..cf25d005 100644 --- a/src/blob_table.c +++ b/src/blob_table.c @@ -740,8 +740,7 @@ assign_blob_to_solid_resource(const struct wim_reshdr *reshdr, blob->size = reshdr->size_in_wim; for (size_t i = 0; i < num_rdescs; i++) { if (offset + blob->size <= rdescs[i]->uncompressed_size) { - blob->offset_in_res = offset; - blob_set_is_located_in_wim_resource(blob, rdescs[i]); + blob_set_is_located_in_wim_resource(blob, rdescs[i], offset); return 0; } offset -= rdescs[i]->uncompressed_size; @@ -1011,10 +1010,7 @@ read_blob_table(WIMStruct *wim) wim_res_hdr_to_desc(&reshdr, wim, rdesc); - cur_blob->offset_in_res = 0; - cur_blob->size = reshdr.uncompressed_size; - - blob_set_is_located_in_wim_resource(cur_blob, rdesc); + blob_set_is_located_in_nonsolid_wim_resource(cur_blob, rdesc); } /* cur_blob is now a blob bound to a resource. */ @@ -1275,9 +1271,7 @@ new_blob_from_data_buffer(const void *buffer, size_t size, free_blob_descriptor(blob); return NULL; } - blob->blob_location = BLOB_IN_ATTACHED_BUFFER; - blob->attached_buffer = buffer_copy; - blob->size = size; + blob_set_is_located_in_attached_buffer(blob, buffer_copy, size); copy_hash(blob->hash, hash); blob_table_insert(blob_table, blob); } diff --git a/src/extract.c b/src/extract.c index 56ec644a..5945a4d8 100644 --- a/src/extract.c +++ b/src/extract.c @@ -181,9 +181,7 @@ read_pwm_blob_header(WIMStruct *pwm, struct blob_descriptor *blob, reshdr.offset_in_wim = pwm->in_fd.offset; reshdr.uncompressed_size = le64_to_cpu(buf.blob_hdr.uncompressed_size); wim_res_hdr_to_desc(&reshdr, pwm, rdesc); - blob_set_is_located_in_wim_resource(blob, rdesc); - blob->size = rdesc->uncompressed_size; - blob->offset_in_res = 0; + blob_set_is_located_in_nonsolid_wim_resource(blob, rdesc); blob->is_metadata = (rdesc->flags & WIM_RESHDR_FLAG_METADATA) != 0; return 0; @@ -234,11 +232,8 @@ read_blobs_from_pipe(struct apply_ctx *ctx, && (needed_blob = lookup_blob(blob_table, found_blob->hash)) && (needed_blob->out_refcnt)) { - needed_blob->offset_in_res = found_blob->offset_in_res; - needed_blob->size = found_blob->size; - blob_unset_is_located_in_wim_resource(found_blob); - blob_set_is_located_in_wim_resource(needed_blob, rdesc); + blob_set_is_located_in_nonsolid_wim_resource(needed_blob, rdesc); ret = (*cbs->begin_blob)(needed_blob, cbs->begin_blob_ctx); diff --git a/src/resource.c b/src/resource.c index 11e09d67..a49507f3 100644 --- a/src/resource.c +++ b/src/resource.c @@ -912,10 +912,7 @@ wim_reshdr_to_data(const struct wim_reshdr *reshdr, WIMStruct *wim, void **buf_r struct blob_descriptor blob; wim_res_hdr_to_desc(reshdr, wim, &rdesc); - blob_set_is_located_in_wim_resource(&blob, &rdesc); - - blob.size = rdesc.uncompressed_size; - blob.offset_in_res = 0; + blob_set_is_located_in_nonsolid_wim_resource(&blob, &rdesc); return read_full_blob_into_alloc_buf(&blob, buf_ret); } @@ -929,10 +926,7 @@ wim_reshdr_to_hash(const struct wim_reshdr *reshdr, WIMStruct *wim, int ret; wim_res_hdr_to_desc(reshdr, wim, &rdesc); - blob_set_is_located_in_wim_resource(&blob, &rdesc); - - blob.size = rdesc.uncompressed_size; - blob.offset_in_res = 0; + blob_set_is_located_in_nonsolid_wim_resource(&blob, &rdesc); blob.unhashed = 1; ret = sha1_blob(&blob); diff --git a/src/unix_apply.c b/src/unix_apply.c index a0b62519..e6bd2321 100644 --- a/src/unix_apply.c +++ b/src/unix_apply.c @@ -503,9 +503,8 @@ unix_create_symlink(const struct wim_inode *inode, const char *path, int ret; struct blob_descriptor blob_override; - blob_override.blob_location = BLOB_IN_ATTACHED_BUFFER; - blob_override.attached_buffer = (void *)rpdata; - blob_override.size = rpdatalen; + blob_set_is_located_in_attached_buffer(&blob_override, + (void *)rpdata, rpdatalen); ret = wim_inode_readlink(inode, link_target, sizeof(link_target) - 1, &blob_override); diff --git a/src/write.c b/src/write.c index 75a6fcf2..6be215e3 100644 --- a/src/write.c +++ b/src/write.c @@ -1788,9 +1788,7 @@ write_wim_resource_from_buffer(const void *buf, int ret; struct blob_descriptor blob; - blob.blob_location = BLOB_IN_ATTACHED_BUFFER; - blob.attached_buffer = (void*)buf; - blob.size = buf_size; + blob_set_is_located_in_attached_buffer(&blob, (void *)buf, buf_size); sha1_buffer(buf, buf_size, blob.hash); blob.unhashed = 0; blob.is_metadata = is_metadata;