+ const struct wim_image_metadata *imd = wim->image_metadata[image - 1];
+ xmlNode *image_node = wim->xml_info->images[image - 1];
+ const struct wim_inode *inode;
+ u64 dir_count = 0;
+ u64 file_count = 0;
+ u64 total_bytes = 0;
+ u64 hard_link_bytes = 0;
+ u64 size;
+ xmlNode *dircount_node;
+ xmlNode *filecount_node;
+ xmlNode *totalbytes_node;
+ xmlNode *hardlinkbytes_node;
+ xmlNode *lastmodificationtime_node;
+
+ image_for_each_inode(inode, imd) {
+ if (inode_is_directory(inode))
+ dir_count += inode->i_nlink;
+ else
+ file_count += inode->i_nlink;
+ size = inode_sum_stream_sizes(inode, wim->blob_table);
+ total_bytes += size * inode->i_nlink;
+ hard_link_bytes += size * (inode->i_nlink - 1);
+ }
+
+ dircount_node = new_element_with_u64(NULL, "DIRCOUNT", dir_count);
+ filecount_node = new_element_with_u64(NULL, "FILECOUNT", file_count);
+ totalbytes_node = new_element_with_u64(NULL, "TOTALBYTES", total_bytes);
+ hardlinkbytes_node = new_element_with_u64(NULL, "HARDLINKBYTES",
+ hard_link_bytes);
+ lastmodificationtime_node =
+ new_element_with_timestamp(NULL, "LASTMODIFICATIONTIME",
+ now_as_wim_timestamp());
+
+ if (unlikely(!dircount_node || !filecount_node || !totalbytes_node ||
+ !hardlinkbytes_node || !lastmodificationtime_node)) {
+ xmlFreeNode(dircount_node);
+ xmlFreeNode(filecount_node);
+ xmlFreeNode(totalbytes_node);
+ xmlFreeNode(hardlinkbytes_node);
+ xmlFreeNode(lastmodificationtime_node);
+ return WIMLIB_ERR_NOMEM;
+ }
+
+ node_replace_child_element(image_node, dircount_node);
+ node_replace_child_element(image_node, filecount_node);
+ node_replace_child_element(image_node, totalbytes_node);
+ node_replace_child_element(image_node, hardlinkbytes_node);
+ node_replace_child_element(image_node, lastmodificationtime_node);
+ return 0;
+}