]> wimlib.net Git - wimlib/blobdiff - src/integrity.c
w -> wim
[wimlib] / src / integrity.c
index 37ff7b7484fe1f7692a135304773aa00571ef977..fd656a4e272f1c908dffb522e91884a7da435500 100644 (file)
  * along with wimlib; if not, see http://www.gnu.org/licenses/.
  */
 
-#include "wimlib_internal.h"
-#include "buffer_io.h"
-#include "sha1.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "wimlib/assert.h"
+#include "wimlib/endianness.h"
+#include "wimlib/error.h"
+#include "wimlib/file_io.h"
+#include "wimlib/integrity.h"
+#include "wimlib/resource.h"
+#include "wimlib/sha1.h"
+#include "wimlib/wim.h"
 
 /* Size, in bytes, of each SHA1-summed chunk, when wimlib writes integrity
  * information. */
@@ -42,11 +51,11 @@ struct integrity_table {
        u32 size;
        u32 num_entries;
        u32 chunk_size;
-       u8  sha1sums[0][20];
-};
+       u8  sha1sums[][20];
+} _packed_attribute;
 
 static int
-calculate_chunk_sha1(filedes_t in_fd, size_t this_chunk_size,
+calculate_chunk_sha1(int in_fd, size_t this_chunk_size,
                     off_t offset, u8 sha1_md[])
 {
        u8 buf[BUFFER_SIZE];
@@ -100,7 +109,7 @@ calculate_chunk_sha1(filedes_t in_fd, size_t this_chunk_size,
  */
 static int
 read_integrity_table(const struct resource_entry *res_entry,
-                    filedes_t in_fd,
+                    int in_fd,
                     u64 num_checked_bytes,
                     struct integrity_table **table_ret)
 {
@@ -223,7 +232,7 @@ out:
  * Returns 0 on success; nonzero on failure.
  */
 static int
-calculate_integrity_table(filedes_t in_fd,
+calculate_integrity_table(int in_fd,
                          off_t new_check_end,
                          const struct integrity_table *old_table,
                          off_t old_check_end,
@@ -354,7 +363,7 @@ calculate_integrity_table(filedes_t in_fd,
  *                             to be checked.
  */
 int
-write_integrity_table(filedes_t fd,
+write_integrity_table(int fd,
                      struct resource_entry *integrity_res_entry,
                      off_t new_lookup_table_end,
                      off_t old_lookup_table_end,
@@ -441,7 +450,7 @@ out_free_old_table:
  *     -1 (WIM_INTEGRITY_NOT_OK) if the WIM failed the integrity check.
  */
 static int
-verify_integrity(filedes_t in_fd, const tchar *filename,
+verify_integrity(int in_fd, const tchar *filename,
                 const struct integrity_table *table,
                 u64 bytes_to_check,
                 wimlib_progress_func_t progress_func)
@@ -495,7 +504,7 @@ verify_integrity(filedes_t in_fd, const tchar *filename,
  * ~10 MiB chunks of the WIM match up with the values given in the integrity
  * table.
  *
- * @w:
+ * @wim:
  *     The WIM, opened for reading, and with the header already read.
  *
  * @progress_func
@@ -511,20 +520,20 @@ verify_integrity(filedes_t in_fd, const tchar *filename,
  *     information.
  */
 int
-check_wim_integrity(WIMStruct *w, wimlib_progress_func_t progress_func)
+check_wim_integrity(WIMStruct *wim, wimlib_progress_func_t progress_func)
 {
        int ret;
        u64 bytes_to_check;
        struct integrity_table *table;
        u64 end_lookup_table_offset;
 
-       if (w->hdr.integrity.offset == 0) {
+       if (wim->hdr.integrity.offset == 0) {
                DEBUG("No integrity information.");
                return WIM_INTEGRITY_NONEXISTENT;
        }
 
-       end_lookup_table_offset = w->hdr.lookup_table_res_entry.offset +
-                                 w->hdr.lookup_table_res_entry.size;
+       end_lookup_table_offset = wim->hdr.lookup_table_res_entry.offset +
+                                 wim->hdr.lookup_table_res_entry.size;
 
        if (end_lookup_table_offset < WIM_HEADER_DISK_SIZE) {
                ERROR("WIM lookup table ends before WIM header ends!");
@@ -533,11 +542,11 @@ check_wim_integrity(WIMStruct *w, wimlib_progress_func_t progress_func)
 
        bytes_to_check = end_lookup_table_offset - WIM_HEADER_DISK_SIZE;
 
-       ret = read_integrity_table(&w->hdr.integrity, w->in_fd,
+       ret = read_integrity_table(&wim->hdr.integrity, wim->in_fd,
                                   bytes_to_check, &table);
        if (ret)
                return ret;
-       ret = verify_integrity(w->in_fd, w->filename, table,
+       ret = verify_integrity(wim->in_fd, wim->filename, table,
                               bytes_to_check, progress_func);
        FREE(table);
        return ret;