- if (fseeko(w->fp, WIM_HEADER_DISK_SIZE, SEEK_SET) != 0) {
- ERROR_WITH_ERRNO("Failed to seek to byte %u of WIM to check "
- "integrity", WIM_HEADER_DISK_SIZE);
- ret = WIMLIB_ERR_READ;
- goto out;
- }
- /* call verify_integrity(), which does the actual checking of the SHA1
- * message digests. */
- ret = verify_integrity(w->fp, bytes_to_check, chunk_size, p,
- show_progress, status);
-out:
- FREE(buf);
+/*
+ * write_integrity_table():
+ *
+ * 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, specify old_blob_table_end and old_table.
+ *
+ * On success, @wim->out_hdr.integrity_table_reshdr will be filled in with
+ * information about the integrity table that was written.
+ *
+ * @wim:
+ * WIMStruct for the WIM file. @wim->out_fd must be a seekable descriptor
+ * to the new WIM file, opened read-write, positioned at the location at
+ * which the integrity table is to be written.
+ *
+ * @new_blob_table_end:
+ * The offset of the byte directly following the blob table in the WIM
+ * being written.
+ *
+ * @old_blob_table_end:
+ * If nonzero, the offset of the byte directly following the old blob table
+ * in the WIM.
+ *
+ * @old_table
+ * Pointer to the old integrity table read into memory, or NULL if not
+ * specified.
+ */
+int
+write_integrity_table(WIMStruct *wim,
+ off_t new_blob_table_end,
+ off_t old_blob_table_end,
+ struct integrity_table *old_table)
+{
+ struct integrity_table *new_table;
+ int ret;
+ u32 new_table_size;
+
+ wimlib_assert(old_blob_table_end <= new_blob_table_end);
+
+ ret = calculate_integrity_table(&wim->out_fd, new_blob_table_end,
+ old_table, old_blob_table_end,
+ &new_table, wim->progfunc, wim->progctx);
+ if (ret)
+ return ret;
+
+ new_table_size = new_table->size;
+
+ new_table->size = cpu_to_le32(new_table->size);
+ new_table->num_entries = cpu_to_le32(new_table->num_entries);
+ new_table->chunk_size = cpu_to_le32(new_table->chunk_size);
+
+ ret = write_wim_resource_from_buffer(new_table,
+ new_table_size,
+ false,
+ &wim->out_fd,
+ WIMLIB_COMPRESSION_TYPE_NONE,
+ 0,
+ &wim->out_hdr.integrity_table_reshdr,
+ NULL,
+ 0);
+ FREE(new_table);