]> wimlib.net Git - wimlib/blobdiff - src/xml.c
Initial imagex_update functionality
[wimlib] / src / xml.c
index 72eca4b378b80d8a4320eee177e30d9ae92da536..a6e745aaf3f09405975077dc880f720b977331ff 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -78,6 +78,7 @@ struct image_info {
        tchar *display_name;
        tchar *display_description;
        tchar *flags;
+       struct wim_lookup_table *lookup_table; /* temporary field */
 };
 
 struct xml_string_spec {
@@ -1078,7 +1079,7 @@ calculate_dentry_statistics(struct wim_dentry *dentry, void *arg)
         * link bytes", and this size is multiplied by the link count (NOT one
         * less than the link count).
         */
-       lte = inode_unnamed_lte_resolved(inode);
+       lte = inode_unnamed_lte(inode, info->lookup_table);
        if (lte) {
                info->total_bytes += wim_resource_size(lte);
                if (!dentry_is_first_in_inode(dentry))
@@ -1088,7 +1089,7 @@ calculate_dentry_statistics(struct wim_dentry *dentry, void *arg)
        if (inode->i_nlink >= 2 && dentry_is_first_in_inode(dentry)) {
                for (unsigned i = 0; i < inode->i_num_ads; i++) {
                        if (inode->i_ads_entries[i].stream_name_nbytes) {
-                               lte = inode_stream_lte_resolved(inode, i + 1);
+                               lte = inode_stream_lte(inode, i + 1, info->lookup_table);
                                if (lte) {
                                        info->hard_link_bytes += inode->i_nlink *
                                                                 wim_resource_size(lte);
@@ -1119,6 +1120,7 @@ xml_update_image_info(WIMStruct *w, int image)
        image_info->dir_count       = 0;
        image_info->total_bytes     = 0;
        image_info->hard_link_bytes = 0;
+       image_info->lookup_table = w->lookup_table;
 
        for_dentry_in_tree(w->image_metadata[image - 1]->root_dentry,
                           calculate_dentry_statistics,
@@ -1236,7 +1238,8 @@ libxml_global_cleanup()
  * Reads the XML data from a WIM file.
  */
 int
-read_xml_data(FILE *fp, const struct resource_entry *res_entry,
+read_xml_data(int in_fd,
+             const struct resource_entry *res_entry,
              struct wim_info **info_ret)
 {
        utf16lechar *xml_data;
@@ -1265,10 +1268,13 @@ read_xml_data(FILE *fp, const struct resource_entry *res_entry,
                goto out;
        }
 
-       ret = read_uncompressed_resource(fp, res_entry->offset,
-                                        res_entry->size, xml_data);
-       if (ret)
+       if (full_pread(in_fd, xml_data,
+                      res_entry->size, res_entry->offset) != res_entry->size)
+       {
+               ERROR_WITH_ERRNO("Error reading XML data");
+               ret = WIMLIB_ERR_READ;
                goto out_free_xml_data;
+       }
 
        /* Null-terminate just in case */
        ((u8*)xml_data)[res_entry->size] = 0;
@@ -1324,7 +1330,7 @@ out:
  * the offset of the XML data.
  */
 int
-write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
+write_xml_data(const struct wim_info *wim_info, int image, int out_fd,
               u64 total_bytes, struct resource_entry *out_res_entry)
 {
        xmlCharEncodingHandler *encoding_handler;
@@ -1338,7 +1344,7 @@ write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
                        (wim_info != NULL && image >= 1 &&
                         image <= wim_info->num_images));
 
-       start_offset = ftello(out);
+       start_offset = filedes_offset(out_fd);
        if (start_offset == -1)
                return WIMLIB_ERR_WRITE;
 
@@ -1347,7 +1353,8 @@ write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
 
        /* 2 bytes endianness marker for UTF-16LE.  This is _required_ for WIM
         * XML data. */
-       if ((putc(0xff, out)) == EOF || (putc(0xfe, out) == EOF)) {
+       static u8 bom[2] = {0xff, 0xfe};
+       if (full_write(out_fd, bom, 2) != 2) {
                ERROR_WITH_ERRNO("Error writing XML data");
                return WIMLIB_ERR_WRITE;
        }
@@ -1373,7 +1380,7 @@ write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
                goto out;
        }
 
-       out_buffer = xmlOutputBufferCreateFile(out, encoding_handler);
+       out_buffer = xmlOutputBufferCreateFd(out_fd, encoding_handler);
        if (!out_buffer) {
                ERROR("Failed to allocate xmlOutputBuffer");
                ret = WIMLIB_ERR_NOMEM;
@@ -1423,12 +1430,7 @@ write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
 
        DEBUG("Ended XML document");
 
-       /* Call xmlFreeTextWriter() before ftello() because the former will
-        * flush the file stream. */
-       xmlFreeTextWriter(writer);
-       writer = NULL;
-
-       end_offset = ftello(out);
+       end_offset = filedes_offset(out_fd);
        if (end_offset == -1) {
                ret = WIMLIB_ERR_WRITE;
        } else {
@@ -1499,10 +1501,15 @@ wimlib_extract_xml_data(WIMStruct *w, FILE *fp)
        if (!buf)
                return WIMLIB_ERR_NOMEM;
 
-       ret = read_uncompressed_resource(w->fp, w->hdr.xml_res_entry.offset,
-                                        size, buf);
-       if (ret)
+       if (full_pread(w->in_fd,
+                      buf,
+                      w->hdr.xml_res_entry.size,
+                      w->hdr.xml_res_entry.offset) != w->hdr.xml_res_entry.size)
+       {
+               ERROR_WITH_ERRNO("Error reading XML data");
+               ret = WIMLIB_ERR_READ;
                goto out_free_buf;
+       }
 
        if (fwrite(buf, 1, size, fp) != size) {
                ERROR_WITH_ERRNO("Failed to extract XML data");