+ if (ret != 0) {
+ FREE(new_table);
+ } else {
+ printf("\rCalculating integrity checksums for WIM: "
+ "%"PRIu64" MiB of %"PRIu64" MiB (100%%) done\n",
+ new_check_bytes >> 20,
+ new_check_bytes >> 20);
+ fflush(stdout);
+ *integrity_table_ret = new_table;
+ }
+ return ret;
+}
+
+/*
+ * Writes a WIM integrity table (a list of SHA1 message digests of raw 10 MiB
+ * 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
+ * @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
+ * re-calculated.
+ *
+ * @fp:
+ * FILE * to the WIM file, opened read-write, positioned at the location at
+ * which the integrity table is to be written.
+ *
+ * @integrity_res_entry:
+ * Resource entry which will be set to point to the integrity table on
+ * success. In addition, if @old_lookup_table_end != 0, this initially
+ * must point to the resource entry for the old integrity table for the
+ * WIM.
+ *
+ * @new_lookup_table_end:
+ * The offset of the byte directly following the lookup table in the WIM
+ * being written.
+ *
+ * @old_lookup_table_end:
+ * If nonzero, the offset of the byte directly following the old lookup
+ * table in the WIM.
+ *
+ * @show_progress:
+ * True if progress information is to be shown while writing the integrity
+ * table.
+ *
+ * Returns:
+ * 0 on success, nonzero on failure. The possible error codes are:
+ * * WIMLIB_ERR_WRITE: Could not write the integrity table.
+ * * WIMLIB_ERR_READ: Could not read a chunk of data that needed
+ * to be checked.
+ */
+int write_integrity_table(FILE *fp,
+ struct resource_entry *integrity_res_entry,
+ off_t new_lookup_table_end,
+ off_t old_lookup_table_end,
+ bool show_progress)
+{
+ struct integrity_table *old_table;
+ struct integrity_table *new_table;
+ int ret;
+ off_t cur_offset;
+ u32 new_table_size;