]> wimlib.net Git - wimlib/blobdiff - include/wimlib/resource.h
Consistently use the name "solid resource"
[wimlib] / include / wimlib / resource.h
index 3b863f4654d66d1146c6070e42cd79810ddc1c1b..5572f523819b2b844025c6c562fccae967241153 100644 (file)
@@ -2,25 +2,25 @@
 #define _WIMLIB_RESOURCE_H
 
 #include "wimlib/callback.h"
-#include "wimlib/file_io.h"
 #include "wimlib/list.h"
 #include "wimlib/sha1.h"
 #include "wimlib/types.h"
 
+struct filedes;
 struct wim_lookup_table_entry;
 struct wim_image_metadata;
 
-/* Specification of a resource in a WIM file.
+/*
+ * Specification of a resource in a WIM file.
  *
- * If a `struct wim_lookup_table_entry' lte has
- * (lte->resource_location == RESOURCE_IN_WIM), then lte->wim_res_spec points to
- * an instance of this structure.
+ * If a `struct wim_lookup_table_entry' lte has (lte->resource_location ==
+ * RESOURCE_IN_WIM), then lte->rspec points to an instance of this structure.
  *
- * Normally, there is a one-to-one correspondence between WIM lookup table
- * entries ("streams", each of which may be the contents of a file, for example)
- * and WIM resources.  However, WIM resources with the
- * WIM_RESHDR_FLAG_PACKED_STREAMS flag set may actually contain multiple streams
- * compressed together.  */
+ * Normally, there is a one-to-one correspondence between lookup table entries
+ * ("streams", each of which may be the contents of a file, for example) and
+ * resources.  However, a resource with the WIM_RESHDR_FLAG_SOLID flag set is a
+ * "solid" resource that may contain multiple streams compressed together.
+ */
 struct wim_resource_spec {
        /* The WIM containing this resource.  @wim->in_fd is expected to be a
         * file descriptor to the underlying WIM file, opened for reading.  */
@@ -52,6 +52,13 @@ struct wim_resource_spec {
 
        /* Temporary flag.  */
        u32 raw_copy_ok : 1;
+
+       /* Compression type of this resource.  */
+       u32 compression_type : 22;
+
+       /* Compression chunk size of this resource.  Irrelevant if the resource
+        * is uncompressed.  */
+       u32 chunk_size;
 };
 
 /* On-disk version of a WIM resource header.  */
@@ -90,32 +97,30 @@ struct wim_reshdr {
  * or XML data for the WIM.  */
 #define WIM_RESHDR_FLAG_METADATA        0x02
 
-/* The resource is compressed using the WIM's default compression type and uses
- * the regular chunk table format.  */
+/* The resource is a non-solid resource compressed using the WIM's default
+ * compression type.  */
 #define WIM_RESHDR_FLAG_COMPRESSED     0x04
 
 /* Unknown meaning; may be intended to indicate a partial stream.  Currently
  * ignored by wimlib.  */
 #define WIM_RESHDR_FLAG_SPANNED         0x08
 
-/* The resource is packed in a special format that may contain multiple
- * underlying streams, or this resource entry represents a stream packed into
- * one such resource.  When resources have this flag set, the WIM version number
- * should be WIM_VERSION_PACKED_STREAMS.  */
-#define WIM_RESHDR_FLAG_PACKED_STREAMS 0x10
+/* The resource is a solid compressed resource which may contain multiple
+ * streams.  This flag is only allowed if the WIM version number is
+ * WIM_VERSION_SOLID.  */
+#define WIM_RESHDR_FLAG_SOLID          0x10
 
 /* Magic number in the 'uncompressed_size' field of the resource header that
- * identifies the main entry for a pack.  */
-#define WIM_PACK_MAGIC_NUMBER          0x100000000ULL
+ * identifies the main entry for a solid resource.  */
+#define SOLID_RESOURCE_MAGIC_NUMBER    0x100000000ULL
 
-/* Returns true if the specified WIM resource is compressed, using either the
- * original chunk table layout or the alternate layout for resources that may
- * contain multiple packed streams.  */
+/* Returns true if the specified WIM resource is compressed (may be either solid
+ * or non-solid)  */
 static inline bool
 resource_is_compressed(const struct wim_resource_spec *rspec)
 {
        return (rspec->flags & (WIM_RESHDR_FLAG_COMPRESSED |
-                               WIM_RESHDR_FLAG_PACKED_STREAMS));
+                               WIM_RESHDR_FLAG_SOLID));
 }
 
 static inline void
@@ -146,8 +151,8 @@ void
 put_wim_reshdr(const struct wim_reshdr *reshdr,
               struct wim_reshdr_disk *disk_reshdr);
 
-/* Alternate chunk table format for resources with
- * WIM_RESHDR_FLAG_PACKED_STREAMS set.  */
+/* Alternate chunk table format for resources with WIM_RESHDR_FLAG_SOLID set.
+ */
 struct alt_chunk_table_header_disk {
        /* Uncompressed size of the resource in bytes.  */
        le64 res_usize;
@@ -159,8 +164,8 @@ struct alt_chunk_table_header_disk {
 
        /* Compression format used for compressed chunks:
         * 0 = None
-        * 1 = LZX
-        * 2 = XPRESS
+        * 1 = XPRESS
+        * 2 = LZX
         * 3 = LZMS
         *
         * This overrides the compression type specified by the WIM header.  */
@@ -170,6 +175,15 @@ struct alt_chunk_table_header_disk {
         * the chunks (4 bytes per entry).  */
 } _packed_attribute;
 
+static inline unsigned int
+get_chunk_entry_size(u64 res_size, bool is_alt)
+{
+       if (res_size <= UINT32_MAX || is_alt)
+               return 4;
+       else
+               return 8;
+}
+
 /* Functions to read streams  */
 
 extern int
@@ -187,6 +201,10 @@ extern int
 wim_reshdr_to_data(const struct wim_reshdr *reshdr,
                   WIMStruct *wim, void **buf_ret);
 
+extern int
+wim_reshdr_to_hash(const struct wim_reshdr *reshdr, WIMStruct *wim,
+                  u8 hash[SHA1_HASH_SIZE]);
+
 extern int
 skip_wim_stream(struct wim_lookup_table_entry *lte);
 
@@ -196,11 +214,6 @@ skip_wim_stream(struct wim_lookup_table_entry *lte);
  * @lte:
  *     Stream that is about to be read.
  *
- * @is_partial_res:
- *     Set to true if the stream is just one of several being read from a
- *     single pack and therefore would be extra expensive to read
- *     independently.
- *
  * @ctx:
  *     User-provided context.
  *
@@ -210,7 +223,6 @@ skip_wim_stream(struct wim_lookup_table_entry *lte);
  * (without calling @consume_chunk or @end_stream).
  */
 typedef int (*read_stream_list_begin_stream_t)(struct wim_lookup_table_entry *lte,
-                                              bool is_partial_res,
                                               void *ctx);
 
 #define BEGIN_STREAM_STATUS_SKIP_STREAM        -1
@@ -284,9 +296,6 @@ extern int
 extract_full_stream_to_fd(struct wim_lookup_table_entry *lte,
                          struct filedes *fd);
 
-extern int
-extract_chunk_to_fd(const void *chunk, size_t size, void *_fd_p);
-
 /* Miscellaneous stream functions.  */
 
 extern int
@@ -295,8 +304,7 @@ sha1_stream(struct wim_lookup_table_entry *lte);
 /* Functions to read/write metadata resources.  */
 
 extern int
-read_metadata_resource(WIMStruct *wim,
-                      struct wim_image_metadata *image_metadata);
+read_metadata_resource(struct wim_image_metadata *imd);
 
 extern int
 write_metadata_resource(WIMStruct *wim, int image, int write_resource_flags);