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 0ccccfb..9dfca8d 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 5cfbd45..2fea2f5 100644 (file)
@@ -124,6 +124,11 @@ 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 aa73cc0..b3eb63f 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 efce477..5fcf524 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 74c9bb8..a4cc6c1 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,