+ /* Make sure there is no data after the XML data, except
+ * possibily an integrity table. If this were the case, then
+ * this data would be overwritten. */
+ old_xml_begin = wim->hdr.xml_data_reshdr.offset_in_wim;
+ old_xml_end = old_xml_begin + wim->hdr.xml_data_reshdr.size_in_wim;
+ old_blob_table_end = wim->hdr.blob_table_reshdr.offset_in_wim +
+ wim->hdr.blob_table_reshdr.size_in_wim;
+ if (wim_has_integrity_table(wim) &&
+ wim->hdr.integrity_table_reshdr.offset_in_wim < old_xml_end) {
+ WARNING("Didn't expect the integrity table to be "
+ "before the XML data");
+ ret = WIMLIB_ERR_RESOURCE_ORDER;
+ goto out;
+ }
+
+ if (old_blob_table_end > old_xml_begin) {
+ WARNING("Didn't expect the blob table to be after "
+ "the XML data");
+ ret = WIMLIB_ERR_RESOURCE_ORDER;
+ goto out;
+ }
+ /* Set @old_wim_end, which indicates the point beyond which we
+ * don't allow any file and metadata resources to appear without
+ * returning WIMLIB_ERR_RESOURCE_ORDER (due to the fact that we
+ * would otherwise overwrite these resources). */
+ if (!wim->image_deletion_occurred && !any_images_modified(wim)) {
+ /* If no images have been modified and no images have
+ * been deleted, a new blob table does not need to be
+ * written. We shall write the new XML data and
+ * optional integrity table immediately after the blob
+ * table. Note that this may overwrite an existing
+ * integrity table. */
+ old_wim_end = old_blob_table_end;
+ write_flags |= WIMLIB_WRITE_FLAG_NO_NEW_BLOBS;
+ } else if (wim_has_integrity_table(wim)) {
+ /* Old WIM has an integrity table; begin writing new
+ * blobs after it. */
+ old_wim_end = wim->hdr.integrity_table_reshdr.offset_in_wim +
+ wim->hdr.integrity_table_reshdr.size_in_wim;
+ } else {
+ /* No existing integrity table; begin writing new blobs
+ * after the old XML data. */
+ old_wim_end = old_xml_end;
+ }