]> wimlib.net Git - wimlib/commitdiff
New helper: wim_reshdr_to_desc_and_blob()
authorEric Biggers <ebiggers3@gmail.com>
Sat, 30 May 2015 20:48:12 +0000 (15:48 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 5 Jun 2015 03:05:37 +0000 (22:05 -0500)
include/wimlib/blob_table.h
include/wimlib/resource.h
src/blob_table.c
src/extract.c
src/resource.c

index 0ccccfbbbbb0f876e4172016d7e2fc60d864834e..9dfca8dcc7171bfc8a81447a3375b8b2c66c3a73 100644 (file)
@@ -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)
 {
index 5cfbd45cb966d99b2375c3e546b8f95434a3c1b4..2fea2f579048759ce3d9b5c9784603b316694ce8 100644 (file)
@@ -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);
index aa73cc01d766135c47e7ecb50f1ebd194b19a096..b3eb63fcad750d17ea7dbe471a543748738a1043 100644 (file)
@@ -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.  */
index efce477e0a122cd076799ea0cb7ad3af67f79eed..5fcf52480ee2ca9cd95712c0edb905da843ba642 100644 (file)
@@ -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.
index 74c9bb8b9a9570aa52110139e73cc9a0907982bb..a4cc6c1291c669da3715f51d5132f6dfb03f6349 100644 (file)
@@ -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,