]> wimlib.net Git - wimlib/commitdiff
Cache compression type in WIMStruct and wim_lookup_table_entry
authorEric Biggers <ebiggers3@gmail.com>
Thu, 23 May 2013 00:37:31 +0000 (19:37 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 23 May 2013 00:37:31 +0000 (19:37 -0500)
include/wimlib/lookup_table.h
include/wimlib/wim.h
src/join.c
src/lookup_table.c
src/metadata_resource.c
src/resource.c
src/swm.c
src/wim.c
src/write.c

index aad400deb2d556584cd3a2704729e13c2e00cb41..097750588454a733ad3167cc085b5e9dd2470eb4 100644 (file)
@@ -138,15 +138,21 @@ struct wim_lookup_table_entry {
        u16 resource_location : 5;
 
        /* 1 if this stream is a unique size (only set while writing streams). */
        u16 resource_location : 5;
 
        /* 1 if this stream is a unique size (only set while writing streams). */
-       u8 unique_size : 1;
+       u16 unique_size : 1;
 
        /* 1 if this stream has not had a SHA1 message digest calculated for it
         * yet */
 
        /* 1 if this stream has not had a SHA1 message digest calculated for it
         * yet */
-       u8 unhashed : 1;
+       u16 unhashed : 1;
 
 
-       u8 deferred : 1;
+       u16 deferred : 1;
 
 
-       u8 no_progress : 1;
+       u16 no_progress : 1;
+
+       /* If resource_location == RESOURCE_IN_WIM, this will be a cached value
+        * that specifies the compression type of this stream as one of
+        * WIMLIB_COMPRESSION_TYPE_*.  Otherwise this will be 0, which is the
+        * same as WIMLIB_COMPRESSION_TYPE_NONE.  */
+       u16 compression_type : 2;
 
        /* (On-disk field)
         * Number of times this lookup table entry is referenced by dentries.
 
        /* (On-disk field)
         * Number of times this lookup table entry is referenced by dentries.
@@ -268,8 +274,12 @@ wim_resource_compressed_size(const struct wim_lookup_table_entry *lte)
        return lte->resource_entry.size;
 }
 
        return lte->resource_entry.size;
 }
 
-extern int
-wim_resource_compression_type(const struct wim_lookup_table_entry *lte);
+static inline int
+wim_resource_compression_type(const struct wim_lookup_table_entry *lte)
+{
+       BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
+       return lte->compression_type;
+}
 
 static inline bool
 lte_filename_valid(const struct wim_lookup_table_entry *lte)
 
 static inline bool
 lte_filename_valid(const struct wim_lookup_table_entry *lte)
index a2d664eaf07d54e0f4decaca423fd3f719d1fc88..57adebde7522d7f780276865045215ccf3db700c 100644 (file)
@@ -55,6 +55,9 @@ struct WIMStruct {
        u8 refcnts_ok : 1;
 
        u8 wim_locked : 1;
        u8 refcnts_ok : 1;
 
        u8 wim_locked : 1;
+
+       /* One of WIMLIB_COMPRESSION_TYPE_*, cached from the header flags. */
+       u8 compression_type : 2;
 };
 
 extern void
 };
 
 extern void
index 3500654168671247318c0f866f18e0967d5aebf0..2c459d30aa1d4826a80835cf3ee16021d823eabe 100644 (file)
@@ -158,8 +158,7 @@ wimlib_join(const tchar * const *swm_names,
        if (ret)
                goto out_free_wims;
 
        if (ret)
                goto out_free_wims;
 
-       ret = wimlib_create_new_wim(wimlib_get_compression_type(swms[0]),
-                                   &joined_wim);
+       ret = wimlib_create_new_wim(swms[0]->compression_type, &joined_wim);
        if (ret)
                goto out_free_wims;
 
        if (ret)
                goto out_free_wims;
 
index c1bd00d33e3e25caf0bf31dd81f3eeebe51702b2..ba832453e6750517aba7b98014426329db594ba5 100644 (file)
@@ -447,6 +447,11 @@ read_lookup_table(WIMStruct *w)
                cur_entry->refcnt = le32_to_cpu(disk_entry->refcnt);
                copy_hash(cur_entry->hash, disk_entry->hash);
 
                cur_entry->refcnt = le32_to_cpu(disk_entry->refcnt);
                copy_hash(cur_entry->hash, disk_entry->hash);
 
+               if (cur_entry->resource_entry.flags & WIM_RESHDR_FLAG_COMPRESSED)
+                       cur_entry->compression_type = w->compression_type;
+               else
+                       BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
+
                if (cur_entry->part_number != w->hdr.part_number) {
                        WARNING("A lookup table entry in part %hu of the WIM "
                                "points to part %hu (ignoring it)",
                if (cur_entry->part_number != w->hdr.part_number) {
                        WARNING("A lookup table entry in part %hu of the WIM "
                                "points to part %hu (ignoring it)",
@@ -872,19 +877,6 @@ out:
 }
 #endif
 
 }
 #endif
 
-/*
- * XXX Probably should store the compression type directly in the lookup table
- * entry
- */
-int
-wim_resource_compression_type(const struct wim_lookup_table_entry *lte)
-{
-       if (!(lte->resource_entry.flags & WIM_RESHDR_FLAG_COMPRESSED)
-           || lte->resource_location != RESOURCE_IN_WIM)
-               return WIMLIB_COMPRESSION_TYPE_NONE;
-       return wimlib_get_compression_type(lte->wim);
-}
-
 /* Resolve an inode's lookup table entries
  *
  * This replaces the SHA1 hash fields (which are used to lookup an entry in the
 /* Resolve an inode's lookup table entries
  *
  * This replaces the SHA1 hash fields (which are used to lookup an entry in the
index 5f392e52dbc15123f65c58c9ae3b657938b4b9bd..d23b6b0731020e4d75b014749183142f0ad79250 100644 (file)
@@ -311,7 +311,7 @@ write_metadata_resource(WIMStruct *w)
         * is updated. */
        ret = write_wim_resource_from_buffer(buf, metadata_original_size,
                                             w->out_fd,
         * is updated. */
        ret = write_wim_resource_from_buffer(buf, metadata_original_size,
                                             w->out_fd,
-                                            wimlib_get_compression_type(w),
+                                            w->compression_type,
                                             &lte->output_resource_entry,
                                             lte->hash);
        /* Note that although the SHA1 message digest of the metadata resource
                                             &lte->output_resource_entry,
                                             lte->hash);
        /* Note that although the SHA1 message digest of the metadata resource
index f37b8958300e6cd024a8882f559ed0d043781926..84d4441bb26add7738f25cee44b3af044e97e145 100644 (file)
@@ -460,7 +460,7 @@ read_partial_wim_resource(const struct wim_lookup_table_entry *lte,
                                               lte->resource_entry.size,
                                               lte->resource_entry.original_size,
                                               lte->resource_entry.offset,
                                               lte->resource_entry.size,
                                               lte->resource_entry.original_size,
                                               lte->resource_entry.offset,
-                                              wimlib_get_compression_type(wim),
+                                              wim->compression_type,
                                               size,
                                               offset,
                                               cb,
                                               size,
                                               offset,
                                               cb,
index 58e594f879eaa2cbb57354830133e68d4338ed45..19452db1cf34904899c8fa67385566e7295210a6 100644 (file)
--- a/src/swm.c
+++ b/src/swm.c
@@ -137,7 +137,7 @@ verify_swm_set(WIMStruct *w, WIMStruct **additional_swms,
 
        /* keep track of ctype and guid just to make sure they are the same for
         * all the WIMs. */
 
        /* keep track of ctype and guid just to make sure they are the same for
         * all the WIMs. */
-       ctype = wimlib_get_compression_type(w);
+       ctype = w->compression_type;
        guid = w->hdr.guid;
 
        {
        guid = w->hdr.guid;
 
        {
@@ -151,7 +151,7 @@ verify_swm_set(WIMStruct *w, WIMStruct **additional_swms,
 
                        WIMStruct *swm = additional_swms[i];
 
 
                        WIMStruct *swm = additional_swms[i];
 
-                       if (wimlib_get_compression_type(swm) != ctype) {
+                       if (swm->compression_type != ctype) {
                                ERROR("The split WIMs do not all have the same "
                                      "compression type");
                                return WIMLIB_ERR_SPLIT_INVALID;
                                ERROR("The split WIMs do not all have the same "
                                      "compression type");
                                return WIMLIB_ERR_SPLIT_INVALID;
index a745c0a2558a42f2eaddefaaa5f63f724ed32a3e..cfe100d69b516fcb0633c1ad784496b9c2f39880 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -115,22 +115,6 @@ for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *))
        return 0;
 }
 
        return 0;
 }
 
-/* Returns the compression type given in the flags of a WIM header. */
-static int
-wim_hdr_flags_compression_type(int wim_hdr_flags)
-{
-       if (wim_hdr_flags & WIM_HDR_FLAG_COMPRESSION) {
-               if (wim_hdr_flags & WIM_HDR_FLAG_COMPRESS_LZX)
-                       return WIMLIB_COMPRESSION_TYPE_LZX;
-               else if (wim_hdr_flags & WIM_HDR_FLAG_COMPRESS_XPRESS)
-                       return WIMLIB_COMPRESSION_TYPE_XPRESS;
-               else
-                       return WIMLIB_COMPRESSION_TYPE_INVALID;
-       } else {
-               return WIMLIB_COMPRESSION_TYPE_NONE;
-       }
-}
-
 /*
  * Creates a WIMStruct for a new WIM file.
  */
 /*
  * Creates a WIMStruct for a new WIM file.
  */
@@ -160,6 +144,7 @@ wimlib_create_new_wim(int ctype, WIMStruct **w_ret)
        }
        w->lookup_table = table;
        w->refcnts_ok = 1;
        }
        w->lookup_table = table;
        w->refcnts_ok = 1;
+       w->compression_type = ctype;
        *w_ret = w;
        return 0;
 out_free:
        *w_ret = w;
        return 0;
 out_free:
@@ -227,7 +212,7 @@ select_wim_image(WIMStruct *w, int image)
 WIMLIBAPI int
 wimlib_get_compression_type(const WIMStruct *w)
 {
 WIMLIBAPI int
 wimlib_get_compression_type(const WIMStruct *w)
 {
-       return wim_hdr_flags_compression_type(w->hdr.flags);
+       return w->compression_type;
 }
 
 WIMLIBAPI const tchar *
 }
 
 WIMLIBAPI const tchar *
@@ -293,7 +278,7 @@ wimlib_print_wim_information(const WIMStruct *w)
        tputchar(T('\n'));
        tprintf(T("Image Count:    %d\n"), hdr->image_count);
        tprintf(T("Compression:    %"TS"\n"),
        tputchar(T('\n'));
        tprintf(T("Image Count:    %d\n"), hdr->image_count);
        tprintf(T("Compression:    %"TS"\n"),
-               wimlib_get_compression_type_string(wimlib_get_compression_type(w)));
+               wimlib_get_compression_type_string(w->compression_type));
        tprintf(T("Part Number:    %d/%d\n"), hdr->part_number, hdr->total_parts);
        tprintf(T("Boot Index:     %d\n"), hdr->boot_idx);
        tprintf(T("Size:           %"PRIu64" bytes\n"),
        tprintf(T("Part Number:    %d/%d\n"), hdr->part_number, hdr->total_parts);
        tprintf(T("Boot Index:     %d\n"), hdr->boot_idx);
        tprintf(T("Size:           %"PRIu64" bytes\n"),
@@ -496,10 +481,25 @@ begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags,
                w->hdr.boot_idx = 0;
        }
 
                w->hdr.boot_idx = 0;
        }
 
-       if (wimlib_get_compression_type(w) == WIMLIB_COMPRESSION_TYPE_INVALID) {
-               ERROR("Invalid compression type (WIM header flags = 0x%x)",
-                     w->hdr.flags);
-               return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
+       /* Check and cache the compression type */
+       if (w->hdr.flags & WIM_HDR_FLAG_COMPRESSION) {
+               if (w->hdr.flags & WIM_HDR_FLAG_COMPRESS_LZX) {
+                       if (w->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
+                               ERROR("Multiple compression flags are set in \"%"TS"\"",
+                                     in_wim_path);
+                               return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
+                       }
+                       w->compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
+               } else if (w->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
+                       w->compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
+               } else {
+                       ERROR("The compression flag is set on \"%"TS"\", but "
+                             "neither the XPRESS nor LZX flag is set",
+                             in_wim_path);
+                       return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
+               }
+       } else {
+               BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
        }
 
        if (open_flags & WIMLIB_OPEN_FLAG_CHECK_INTEGRITY) {
        }
 
        if (open_flags & WIMLIB_OPEN_FLAG_CHECK_INTEGRITY) {
index 3b2aa18e0477b405288403ebed0b337c7aafa799..54257e046f2effae9916681cfe4f60ff3be427a5 100644 (file)
@@ -377,7 +377,7 @@ write_wim_resource(struct wim_lookup_table_entry *lte,
        if (!(flags & WIMLIB_RESOURCE_FLAG_RECOMPRESS) &&
            lte->resource_location == RESOURCE_IN_WIM &&
            out_ctype != WIMLIB_COMPRESSION_TYPE_NONE &&
        if (!(flags & WIMLIB_RESOURCE_FLAG_RECOMPRESS) &&
            lte->resource_location == RESOURCE_IN_WIM &&
            out_ctype != WIMLIB_COMPRESSION_TYPE_NONE &&
-           wimlib_get_compression_type(lte->wim) == out_ctype)
+           lte->wim->compression_type == out_ctype)
        {
                flags |= WIMLIB_RESOURCE_FLAG_RAW;
                write_ctx.doing_sha = false;
        {
                flags |= WIMLIB_RESOURCE_FLAG_RAW;
                write_ctx.doing_sha = false;
@@ -1207,7 +1207,7 @@ main_thread_process_next_stream(struct wim_lookup_table_entry *lte, void *_ctx)
            ctx->out_ctype == WIMLIB_COMPRESSION_TYPE_NONE ||
            (lte->resource_location == RESOURCE_IN_WIM &&
             !(ctx->write_resource_flags & WIMLIB_RESOURCE_FLAG_RECOMPRESS) &&
            ctx->out_ctype == WIMLIB_COMPRESSION_TYPE_NONE ||
            (lte->resource_location == RESOURCE_IN_WIM &&
             !(ctx->write_resource_flags & WIMLIB_RESOURCE_FLAG_RECOMPRESS) &&
-            wimlib_get_compression_type(lte->wim) == ctx->out_ctype))
+            lte->wim->compression_type == ctx->out_ctype))
        {
                /* Stream is too small or isn't being compressed.  Process it by
                 * the main thread when we have a chance.  We can't necessarily
        {
                /* Stream is too small or isn't being compressed.  Process it by
                 * the main thread when we have a chance.  We can't necessarily
@@ -1713,7 +1713,7 @@ write_wim_streams(WIMStruct *wim, int image, int write_flags,
        return write_stream_list(&stream_list,
                                 wim->lookup_table,
                                 wim->out_fd,
        return write_stream_list(&stream_list,
                                 wim->lookup_table,
                                 wim->out_fd,
-                                wimlib_get_compression_type(wim),
+                                wim->compression_type,
                                 write_flags,
                                 num_threads,
                                 progress_func);
                                 write_flags,
                                 num_threads,
                                 progress_func);
@@ -2133,7 +2133,7 @@ overwrite_wim_inplace(WIMStruct *w, int write_flags,
        ret = write_stream_list(&stream_list,
                                w->lookup_table,
                                w->out_fd,
        ret = write_stream_list(&stream_list,
                                w->lookup_table,
                                w->out_fd,
-                               wimlib_get_compression_type(w),
+                               w->compression_type,
                                write_flags,
                                num_threads,
                                progress_func);
                                write_flags,
                                num_threads,
                                progress_func);