]> wimlib.net Git - wimlib/blobdiff - src/integrity.c
Add kind-of-working LZMS decompression using cabinet.dll API
[wimlib] / src / integrity.c
index 1eeb671aa178e93c1eb1ea44a819bc2500e9d53f..8e1df18911f9d1d641e675cc95d2058f2fad17cd 100644 (file)
@@ -37,6 +37,7 @@
 #include "wimlib/resource.h"
 #include "wimlib/sha1.h"
 #include "wimlib/wim.h"
+#include "wimlib/write.h"
 
 /* Size, in bytes, of each SHA1-summed chunk, when wimlib writes integrity
  * information. */
@@ -87,9 +88,8 @@ calculate_chunk_sha1(struct filedes *in_fd, size_t this_chunk_size,
  * read_integrity_table: -  Reads the integrity table from a WIM file.
  *
  * @wim:
- *     WIMStruct for the WIM file; @wim->hdr.integrity specifies the location
- *     of the integrity table.  The integrity table must exist (i.e.
- *     res_entry->offset must not be 0).  @wim->in_fd is expected to be a
+ *     WIMStruct for the WIM file; @wim->hdr.integrity_table_reshdr specifies
+ *     the location of the integrity table.  @wim->in_fd is expected to be a
  *     seekable file descriptor to the WIM file opened for reading.
  *
  * @num_checked_bytes:
@@ -110,19 +110,19 @@ static int
 read_integrity_table(WIMStruct *wim, u64 num_checked_bytes,
                     struct integrity_table **table_ret)
 {
+       void *buf;
        struct integrity_table *table;
        int ret;
 
-       if (wim->hdr.integrity.size < 8)
+       if (wim->hdr.integrity_table_reshdr.uncompressed_size < 8)
                goto invalid;
 
-       DEBUG("Reading integrity table (offset %"PRIu64", "
-             "original_size %"PRIu64")",
-             wim->hdr.integrity.offset, wim->hdr.integrity.original_size);
+       DEBUG("Reading integrity table.");
 
-       ret = res_entry_to_data(&wim->hdr.integrity, wim, (void**)&table);
+       ret = wim_reshdr_to_data(&wim->hdr.integrity_table_reshdr, wim, &buf);
        if (ret)
                return ret;
+       table = buf;
 
        table->size        = le32_to_cpu(table->size);
        table->num_entries = le32_to_cpu(table->num_entries);
@@ -132,7 +132,7 @@ read_integrity_table(WIMStruct *wim, u64 num_checked_bytes,
              "table->chunk_size = %u",
              table->size, table->num_entries, table->chunk_size);
 
-       if (table->size != wim->hdr.integrity.original_size ||
+       if (table->size != wim->hdr.integrity_table_reshdr.uncompressed_size ||
            table->size != (u64)table->num_entries * SHA1_HASH_SIZE + 12 ||
            table->chunk_size == 0 ||
            table->num_entries != DIV_ROUND_UP(num_checked_bytes, table->chunk_size))
@@ -280,8 +280,8 @@ calculate_integrity_table(struct filedes *in_fd,
  * chunks of the file).
  *
  * This function can optionally re-use entries from an older integrity table.
- * To do this, make @integrity_res_entry point to the resource entry for the
- * older table (note: this is an input-output parameter), and set
+ * To do this, ensure that @wim->hdr.integrity_table_reshdr is the resource
+ * header for the older table (note: this is an input-output parameter), and set
  * @old_lookup_table_end to the offset of the byte directly following the last
  * byte checked by the old table.  If the old integrity table is invalid or
  * cannot be read, a warning is printed and the integrity information is
@@ -311,9 +311,7 @@ calculate_integrity_table(struct filedes *in_fd,
  *
  * Return values:
  *     WIMLIB_ERR_SUCCESS (0)
- *     WIMLIB_ERR_INVALID_INTEGRITY_TABLE
  *     WIMLIB_ERR_NOMEM
- *     WIMLIB_ERR_READ
  *     WIMLIB_ERR_UNEXPECTED_END_OF_FILE
  *     WIMLIB_ERR_WRITE
  */
@@ -326,16 +324,16 @@ write_integrity_table(WIMStruct *wim,
        struct integrity_table *old_table;
        struct integrity_table *new_table;
        int ret;
-       off_t cur_offset;
        u32 new_table_size;
 
-       wimlib_assert(old_lookup_table_end <= new_lookup_table_end);
+       DEBUG("Writing integrity table "
+             "(new_lookup_table_end=%"PRIu64", old_lookup_table_end=%"PRIu64")",
+             new_lookup_table_end, old_lookup_table_end);
 
-       cur_offset = wim->out_fd.offset;
+       wimlib_assert(old_lookup_table_end <= new_lookup_table_end);
 
-       if (wim->hdr.integrity.offset == 0 || old_lookup_table_end == 0) {
-               old_table = NULL;
-       } else {
+       old_table = NULL;
+       if (wim_has_integrity_table(wim) && old_lookup_table_end != 0) {
                ret = read_integrity_table(wim,
                                           old_lookup_table_end - WIM_HEADER_DISK_SIZE,
                                           &old_table);
@@ -365,12 +363,15 @@ write_integrity_table(WIMStruct *wim,
                                             0,
                                             &wim->out_fd,
                                             WIMLIB_COMPRESSION_TYPE_NONE,
-                                            &wim->hdr.integrity,
+                                            0,
+                                            &wim->hdr.integrity_table_reshdr,
                                             NULL,
-                                            0);
+                                            0,
+                                            &wim->lzx_context);
        FREE(new_table);
 out_free_old_table:
        FREE(old_table);
+       DEBUG("ret=%d", ret);
        return ret;
 }
 
@@ -478,13 +479,13 @@ check_wim_integrity(WIMStruct *wim, wimlib_progress_func_t progress_func)
        struct integrity_table *table;
        u64 end_lookup_table_offset;
 
-       if (wim->hdr.integrity.offset == 0) {
+       if (!wim_has_integrity_table(wim)) {
                DEBUG("No integrity information.");
                return WIM_INTEGRITY_NONEXISTENT;
        }
 
-       end_lookup_table_offset = wim->hdr.lookup_table_res_entry.offset +
-                                 wim->hdr.lookup_table_res_entry.size;
+       end_lookup_table_offset = wim->hdr.lookup_table_reshdr.offset_in_wim +
+                                 wim->hdr.lookup_table_reshdr.size_in_wim;
 
        if (end_lookup_table_offset < WIM_HEADER_DISK_SIZE) {
                ERROR("WIM lookup table ends before WIM header ends!");