]> wimlib.net Git - wimlib/blobdiff - src/resource.c
Make win32.h includable on non-Windows
[wimlib] / src / resource.c
index f3e1349b7e6b943d42da039be63df3f1d9caebcb..134821971a6b3b20e4b6d79f520be219ab6c1dbc 100644 (file)
 #include "wimlib/endianness.h"
 #include "wimlib/error.h"
 #include "wimlib/file_io.h"
+#include "wimlib/ntfs_3g.h"
 #include "wimlib/resource.h"
 #include "wimlib/sha1.h"
 #include "wimlib/wim.h"
-
-#ifdef __WIN32__
-/* for read_winnt_stream_prefix(), read_win32_encrypted_file_prefix() */
-#  include "wimlib/win32.h"
-#endif
-
-#ifdef WITH_NTFS_3G
-/* for read_ntfs_attribute_prefix() */
-#  include "wimlib/ntfs_3g.h"
-#endif
-
+#include "wimlib/win32.h"
 
 /*
  *                         Compressed WIM resources
@@ -769,8 +760,6 @@ read_file_on_disk_prefix(const struct blob_descriptor *blob, u64 size,
        int raw_fd;
        struct filedes fd;
 
-       wimlib_assert(size <= blob->size);
-
        DEBUG("Reading %"PRIu64" bytes from \"%"TS"\"", size, blob->file_on_disk);
 
        raw_fd = topen(blob->file_on_disk, O_BINARY | O_RDONLY);
@@ -793,8 +782,6 @@ read_staging_file_prefix(const struct blob_descriptor *blob, u64 size,
        struct filedes fd;
        int ret;
 
-       wimlib_assert(size <= blob->size);
-
        DEBUG("Reading %"PRIu64" bytes from staging file \"%s\"",
              size, blob->staging_file_name);
 
@@ -818,7 +805,6 @@ static int
 read_buffer_prefix(const struct blob_descriptor *blob,
                   u64 size, consume_data_callback_t cb, void *cb_ctx)
 {
-       wimlib_assert(size <= blob->size);
        return (*cb)(blob->attached_buffer, size, cb_ctx);
 }
 
@@ -863,6 +849,7 @@ read_blob_prefix(const struct blob_descriptor *blob, u64 size,
        };
        wimlib_assert(blob->blob_location < ARRAY_LEN(handlers)
                      && handlers[blob->blob_location] != NULL);
+       wimlib_assert(size <= blob->size);
        return handlers[blob->blob_location](blob, size, cb, cb_ctx);
 }
 
@@ -909,25 +896,12 @@ int
 wim_reshdr_to_data(const struct wim_reshdr *reshdr, WIMStruct *wim, void **buf_ret)
 {
        struct wim_resource_descriptor rdesc;
-       struct blob_descriptor *blob;
-       int ret;
+       struct blob_descriptor blob;
 
        wim_res_hdr_to_desc(reshdr, wim, &rdesc);
+       blob_set_is_located_in_nonsolid_wim_resource(&blob, &rdesc);
 
-       blob = new_blob_descriptor();
-       if (!blob)
-               return WIMLIB_ERR_NOMEM;
-
-       blob_set_is_located_in_wim_resource(blob, &rdesc);
-       blob->flags = rdesc.flags;
-       blob->size = rdesc.uncompressed_size;
-       blob->offset_in_res = 0;
-
-       ret = read_full_blob_into_alloc_buf(blob, buf_ret);
-
-       blob_unset_is_located_in_wim_resource(blob);
-       free_blob_descriptor(blob);
-       return ret;
+       return read_full_blob_into_alloc_buf(&blob, buf_ret);
 }
 
 int
@@ -935,27 +909,18 @@ wim_reshdr_to_hash(const struct wim_reshdr *reshdr, WIMStruct *wim,
                   u8 hash[SHA1_HASH_SIZE])
 {
        struct wim_resource_descriptor rdesc;
+       struct blob_descriptor blob;
        int ret;
-       struct blob_descriptor *blob;
 
        wim_res_hdr_to_desc(reshdr, wim, &rdesc);
+       blob_set_is_located_in_nonsolid_wim_resource(&blob, &rdesc);
+       blob.unhashed = 1;
 
-       blob = new_blob_descriptor();
-       if (blob == NULL)
-               return WIMLIB_ERR_NOMEM;
-
-       blob_set_is_located_in_wim_resource(blob, &rdesc);
-       blob->flags = rdesc.flags;
-       blob->size = rdesc.uncompressed_size;
-       blob->offset_in_res = 0;
-       blob->unhashed = 1;
-
-       ret = sha1_blob(blob);
-
-       blob_unset_is_located_in_wim_resource(blob);
-       copy_hash(hash, blob->hash);
-       free_blob_descriptor(blob);
-       return ret;
+       ret = sha1_blob(&blob);
+       if (ret)
+               return ret;
+       copy_hash(hash, blob.hash);
+       return 0;
 }
 
 struct blobifier_context {
@@ -1107,7 +1072,7 @@ hasher_end_blob(struct blob_descriptor *blob, int status, void *_ctx)
                                        tchar actual_hashstr[SHA1_HASH_SIZE * 2 + 1];
                                        sprint_hash(blob->hash, expected_hashstr);
                                        sprint_hash(hash, actual_hashstr);
-                                       ERROR("The blob is corrupted!\n"
+                                       ERROR("The data is corrupted!\n"
                                              "        (Expected SHA-1=%"TS",\n"
                                              "              got SHA-1=%"TS")",
                                              expected_hashstr, actual_hashstr);
@@ -1282,9 +1247,9 @@ read_blobs_in_solid_resource(struct blob_descriptor *first_blob,
  */
 int
 read_blob_list(struct list_head *blob_list,
-                size_t list_head_offset,
-                const struct read_blob_list_callbacks *cbs,
-                int flags)
+              size_t list_head_offset,
+              const struct read_blob_list_callbacks *cbs,
+              int flags)
 {
        int ret;
        struct list_head *cur, *next;
@@ -1323,10 +1288,9 @@ read_blob_list(struct list_head *blob_list,
        {
                blob = (struct blob_descriptor*)((u8*)cur - list_head_offset);
 
-               if (blob->flags & WIM_RESHDR_FLAG_SOLID &&
+               if (blob->blob_location == BLOB_IN_WIM &&
                    blob->size != blob->rdesc->uncompressed_size)
                {
-
                        struct blob_descriptor *blob_next, *blob_last;
                        struct list_head *next2;
                        u64 blob_count;