- wim_resource_compression_type(lte),
- <e->output_resource_entry);
- if (ret != 0)
- return ret;
- lte->out_refcnt = lte->refcnt;
- lte->part_number = w->hdr.part_number;
- return 0;
-}
-
-/*
- * Writes a dentry's resources, including the main file resource as well as all
- * alternate data streams, to the output file.
- *
- * @dentry: The dentry for the file.
- * @wim_p: A pointer to the WIMStruct containing @dentry.
- *
- * @return zero on success, nonzero on failure.
- */
-int write_dentry_resources(struct dentry *dentry, void *wim_p)
-{
- WIMStruct *w = wim_p;
- int ret = 0;
- struct lookup_table_entry *lte;
- int ctype = wimlib_get_compression_type(w);
-
- if (w->write_flags & WIMLIB_WRITE_FLAG_VERBOSE) {
- wimlib_assert(dentry->full_path_utf8);
- printf("Writing streams for `%s'\n", dentry->full_path_utf8);
- }
-
- for (unsigned i = 0; i <= dentry->num_ads; i++) {
- lte = dentry_stream_lte(dentry, i, w->lookup_table);
- if (lte && ++lte->out_refcnt == 1) {
- ret = write_wim_resource(lte, w->out_fp, ctype,
- <e->output_resource_entry);
- if (ret != 0)
- break;
- }
- }
- return ret;
-}
-
-/*
- * Reads the metadata metadata resource from the WIM file. The metadata
- * resource consists of the security data, followed by the directory entry for
- * the root directory, followed by all the other directory entries in the
- * filesystem. The subdir_offset field of each directory entry gives the start
- * of its child entries from the beginning of the metadata resource. An
- * end-of-directory is signaled by a directory entry of length '0', really of
- * length 8, because that's how long the 'length' field is.
- *
- * @fp: The FILE* for the input WIM file.
- * @wim_ctype: The compression type of the WIM file.
- * @imd: Pointer to the image metadata structure. Its `metadata_lte'
- * member specifies the lookup table entry for the metadata
- * resource. The rest of the image metadata entry will be filled
- * in by this function.
- *
- * @return: Zero on success, nonzero on failure.
- */
-int read_metadata_resource(FILE *fp, int wim_ctype, struct image_metadata *imd)
-{
- u8 *buf;
- int ctype;
- u32 dentry_offset;
- int ret;
- struct dentry *dentry;
- struct wim_security_data *sd;
- struct link_group_table *lgt;
- const struct lookup_table_entry *metadata_lte;
- const struct resource_entry *res_entry;
-
- metadata_lte = imd->metadata_lte;
- res_entry = &metadata_lte->resource_entry;
-
- DEBUG("Reading metadata resource: length = %"PRIu64", "
- "offset = %"PRIu64"",
- res_entry->original_size, res_entry->offset);
-
- if (res_entry->original_size < 8) {
- ERROR("Expected at least 8 bytes for the metadata resource");
- return WIMLIB_ERR_INVALID_RESOURCE_SIZE;
- }
-
- /* Allocate memory for the uncompressed metadata resource. */
- buf = MALLOC(res_entry->original_size);
-
- if (!buf) {
- ERROR("Failed to allocate %"PRIu64" bytes for uncompressed "
- "metadata resource", res_entry->original_size);
- return WIMLIB_ERR_NOMEM;