+ DEBUG("ret=%d", ret);
+ return ret;
+
+out_write_error:
+ ERROR("Error writing XML data");
+ ret = WIMLIB_ERR_WRITE;
+ goto out_free_text_writer;
+}
+
+/* Writes the XML data to a WIM file. */
+int
+write_wim_xml_data(WIMStruct *wim, int image, u64 total_bytes,
+ struct resource_entry *out_res_entry,
+ int write_resource_flags)
+{
+ int ret;
+ u8 *xml_data;
+ size_t xml_len;
+
+ DEBUG("Writing WIM XML data (image=%d, offset=%"PRIu64")",
+ image, total_bytes, wim->out_fd.offset);
+
+ ret = prepare_wim_xml_data(wim, image, total_bytes,
+ &xml_data, &xml_len);
+ if (ret)
+ return ret;
+
+ /* Write the XML data uncompressed. Although wimlib can handle
+ * compressed XML data, MS software cannot. */
+ ret = write_wim_resource_from_buffer(xml_data,
+ xml_len,
+ WIM_RESHDR_FLAG_METADATA,
+ &wim->out_fd,
+ WIMLIB_COMPRESSION_TYPE_NONE,
+ 0,
+ out_res_entry,
+ NULL,
+ write_resource_flags,
+ &wim->lzx_context);
+ FREE(xml_data);
+ DEBUG("ret=%d");