]> wimlib.net Git - wimlib/blobdiff - src/xml.c
Rework WIM writing code
[wimlib] / src / xml.c
index 76bc1713116fea98711a25f1bcecd7ebf12fbd42..f9e93fc36c1b6d6fedcdfc2ca3a4f192fb118384 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -1287,7 +1287,7 @@ out_cleanup_parser:
  * the offset of the XML data.
  */
 int write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
-                  u64 total_bytes)
+                  u64 total_bytes, struct resource_entry *out_res_entry)
 {
        xmlBuffer     *buf;
        xmlTextWriter *writer;
@@ -1297,11 +1297,16 @@ int write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
        size_t len;
        size_t utf16_len;
        size_t bytes_written;
+       off_t start_offset, end_offset;
 
        wimlib_assert(image == WIM_ALL_IMAGES ||
                        (wim_info != NULL && image >= 1 &&
                         image <= wim_info->num_images));
 
+       start_offset = ftello(out);
+       if (start_offset == -1)
+               return WIMLIB_ERR_WRITE;
+
        /* The contents of the <TOTALBYTES> element in the XML data, under the
         * <WIM> element not the <IMAGE> element, is (for non-spit WIMs) the
         * size of the WIM file excluding the XML data and integrity table,
@@ -1390,6 +1395,16 @@ int write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
 
        DEBUG("Cleaning up.");
 
+       end_offset = ftello(out);
+       if (end_offset == -1) {
+               ret = WIMLIB_ERR_WRITE;
+               goto out_free_utf16_str;
+       }
+
+       out_res_entry->offset        = start_offset;
+       out_res_entry->size          = end_offset - start_offset;
+       out_res_entry->original_size = end_offset - start_offset;
+       out_res_entry->flags         = WIM_RESHDR_FLAG_METADATA;
        ret = 0;
 out_free_utf16_str:
        FREE(utf16_str);