]> wimlib.net Git - wimlib/blobdiff - include/wimlib/resource.h
mount_image.c: add fallback definitions of RENAME_* constants
[wimlib] / include / wimlib / resource.h
index 2fea2f579048759ce3d9b5c9784603b316694ce8..8924b80716232b0e7489fd6ea8d9f7273954323f 100644 (file)
@@ -72,7 +72,7 @@ struct wim_reshdr_disk {
 
        /* Uncompressed size of the resource, in bytes.  */
        le64 uncompressed_size;
-} _packed_attribute;
+} __attribute__((packed));
 
 /* In-memory version of a WIM resource header (`struct wim_reshdr_disk').  */
 struct wim_reshdr {
@@ -119,20 +119,20 @@ zero_reshdr(struct wim_reshdr *reshdr)
        memset(reshdr, 0, sizeof(struct wim_reshdr));
 }
 
-extern void
+void
 wim_reshdr_to_desc(const struct wim_reshdr *reshdr, WIMStruct *wim,
                   struct wim_resource_descriptor *rdesc);
 
-extern void
+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
+void
 get_wim_reshdr(const struct wim_reshdr_disk *disk_reshdr,
               struct wim_reshdr *reshdr);
 
-extern void
+void
 put_wim_reshdr(const struct wim_reshdr *reshdr,
               struct wim_reshdr_disk *disk_reshdr);
 
@@ -158,7 +158,7 @@ struct alt_chunk_table_header_disk {
 
        /* This header is directly followed by a table of compressed sizes of
         * the chunks (4 bytes per entry).  */
-} _packed_attribute;
+} __attribute__((packed));
 
 static inline unsigned int
 get_chunk_entry_size(u64 res_size, bool is_alt)
@@ -171,27 +171,46 @@ get_chunk_entry_size(u64 res_size, bool is_alt)
 
 /* Functions to read blobs  */
 
-extern int
+int
 read_partial_wim_blob_into_buf(const struct blob_descriptor *blob,
                               u64 offset, size_t size, void *buf);
 
-extern int
+int
 read_blob_into_buf(const struct blob_descriptor *blob, void *buf);
 
-extern int
+int
 read_blob_into_alloc_buf(const struct blob_descriptor *blob, void **buf_ret);
 
-extern int
+int
 wim_reshdr_to_data(const struct wim_reshdr *reshdr, WIMStruct *wim,
                   void **buf_ret);
 
-extern int
+int
 wim_reshdr_to_hash(const struct wim_reshdr *reshdr, WIMStruct *wim,
                   u8 hash[SHA1_HASH_SIZE]);
 
-extern int
+int
 skip_wim_resource(const struct wim_resource_descriptor *rdesc);
 
+/*
+ * Callback function for reading chunks.  Called whenever the next chunk of
+ * uncompressed data is available, passing 'ctx' as the last argument. 'size' is
+ * guaranteed to be nonzero.  Must return 0 on success, or a positive wimlib
+ * error code on failure.
+ */
+struct consume_chunk_callback {
+       int (*func)(const void *chunk, size_t size, void *ctx);
+       void *ctx;
+};
+
+/* Pass a chunk of data to the specified consume_chunk callback */
+static inline int
+consume_chunk(const struct consume_chunk_callback *cb,
+             const void *chunk, size_t size)
+{
+       return (*cb->func)(chunk, size, cb->ctx);
+}
+
 /* Callback functions for reading blobs  */
 struct read_blob_callbacks {
 
@@ -205,7 +224,8 @@ struct read_blob_callbacks {
        /* Called when the next chunk of uncompressed data is available.  'size'
         * is guaranteed to be nonzero.  Must return 0 on success, or a positive
         * wimlib error code on failure.  */
-       int (*consume_chunk)(const void *chunk, size_t size, void *ctx);
+       int (*continue_blob)(const struct blob_descriptor *blob, u64 offset,
+                            const void *chunk, size_t size, void *ctx);
 
        /* Called when a blob has been successfully read (status=0), or when
         * begin_blob() was successfully called but an error occurred before the
@@ -228,14 +248,15 @@ call_begin_blob(struct blob_descriptor *blob,
        return (*cbs->begin_blob)(blob, cbs->ctx);
 }
 
-/* Call cbs->consume_chunk() if present.  */
+/* Call cbs->continue_blob() if present.  */
 static inline int
-call_consume_chunk(const void *chunk, size_t size,
+call_continue_blob(const struct blob_descriptor *blob, u64 offset,
+                  const void *chunk, size_t size,
                   const struct read_blob_callbacks *cbs)
 {
-       if (!cbs->consume_chunk)
+       if (!cbs->continue_blob)
                return 0;
-       return (*cbs->consume_chunk)(chunk, size, cbs->ctx);
+       return (*cbs->continue_blob)(blob, offset, chunk, size, cbs->ctx);
 }
 
 /* Call cbs->end_blob() if present.  */
@@ -252,37 +273,39 @@ call_end_blob(struct blob_descriptor *blob, int status,
 #define VERIFY_BLOB_HASHES             0x1
 #define COMPUTE_MISSING_BLOB_HASHES    0x2
 #define BLOB_LIST_ALREADY_SORTED       0x4
+#define RECOVER_DATA                   0x8
 
-extern int
+int
 read_blob_list(struct list_head *blob_list, size_t list_head_offset,
               const struct read_blob_callbacks *cbs, int flags);
 
-extern int
+int
 read_blob_with_cbs(struct blob_descriptor *blob,
-                  const struct read_blob_callbacks *cbs);
+                  const struct read_blob_callbacks *cbs, bool recover_data);
 
-extern int
+int
 read_blob_with_sha1(struct blob_descriptor *blob,
-                   const struct read_blob_callbacks *cbs);
+                   const struct read_blob_callbacks *cbs, bool recover_data);
 
-extern int
+int
 extract_blob_prefix_to_fd(struct blob_descriptor *blob, u64 size,
                          struct filedes *fd);
 
-extern int
-extract_blob_to_fd(struct blob_descriptor *blob, struct filedes *fd);
+int
+extract_blob_to_fd(struct blob_descriptor *blob, struct filedes *fd,
+                  bool recover_data);
 
 /* Miscellaneous blob functions.  */
 
-extern int
+int
 sha1_blob(struct blob_descriptor *blob);
 
 /* Functions to read/write metadata resources.  */
 
-extern int
+int
 read_metadata_resource(struct wim_image_metadata *imd);
 
-extern int
+int
 write_metadata_resource(WIMStruct *wim, int image, int write_resource_flags);
 
 /* Definitions specific to pipable WIM resources.  */
@@ -298,12 +321,12 @@ struct pwm_blob_hdr {
        u8 hash[SHA1_HASH_SIZE];        /* +16  */
        le32 flags;                     /* +36  */
                                        /* +40  */
-} _packed_attribute;
+} __attribute__((packed));
 
 /* Header that precedes each chunk of a compressed resource in a pipable WIM.
  */
 struct pwm_chunk_hdr {
        le32 compressed_size;
-} _packed_attribute;
+} __attribute__((packed));
 
 #endif /* _WIMLIB_RESOURCE_H */