- res_entry = <e->output_resource_entry;
- lte->out_refcnt++;
- if (memcmp(hash, lte->hash, WIM_HASH_SIZE) != 0) {
- lookup_table_unlink(w->lookup_table, lte);
- memcpy(lte->hash, hash, WIM_HASH_SIZE);
- lookup_table_insert(w->lookup_table, lte);
- }
- res_entry->original_size = metadata_original_size;
- res_entry->offset = metadata_offset;
- res_entry->size = metadata_compressed_size;
- res_entry->flags = WIM_RESHDR_FLAG_METADATA;
- if (metadata_ctype != WIM_COMPRESSION_TYPE_NONE)
- res_entry->flags |= WIM_RESHDR_FLAG_COMPRESSED;
- return 0;
-}
-
-/*
- * Writes a file resource to the output file.
- *
- * @dentry: The dentry for the file resource.
- * @wim_p: A pointer to the WIMStruct. The fields of interest to this
- * function are the input and output file streams and the lookup
- * table.
- *
- * @return zero on success, nonzero on failure.
- */
-int write_file_resource(struct dentry *dentry, void *wim_p)
-{
- WIMStruct *w;
- FILE *out_fp;
- FILE *in_fp;
- struct lookup_table_entry *lte;
- int in_wim_ctype;
- int out_wim_ctype;
- struct resource_entry *output_res_entry;
- u64 len;
- int ret;
-
- w = wim_p;
- out_fp = w->out_fp;
-
- /* Directories don't need file resources. */
- if (dentry_is_directory(dentry))
- return 0;
-
- /* Get the lookup entry for the file resource. */
- lte = wim_lookup_resource(w, dentry);
- if (!lte)
- return 0;
-
- /* No need to write file resources twice. (This indicates file
- * resources that are part of a hard link set.) */
- if (++lte->out_refcnt != 1)
- return 0;
-
- out_wim_ctype = wimlib_get_compression_type(w);
- output_res_entry = <e->output_resource_entry;
-
- /* do not write empty resources */
- if (lte->resource_entry.original_size == 0)
- return 0;
-
- /* Figure out if we can read the resource from the WIM file, or
- * if we have to read it from the filesystem outside. */
- if (lte->file_on_disk) {
-
- /* Read from disk (uncompressed) */
-
- len = lte->resource_entry.original_size;
-
- in_fp = fopen(lte->file_on_disk, "rb");
- if (!in_fp) {
- ERROR_WITH_ERRNO("Failed to open the file `%s'",
- lte->file_on_disk);
- return WIMLIB_ERR_OPEN;
- }
-
- if (w->verbose)
- puts(lte->file_on_disk);
-
- ret = transfer_file_resource(in_fp, len, len, 0,
- WIM_COMPRESSION_TYPE_NONE, out_fp,
- out_wim_ctype, output_res_entry);
- fclose(in_fp);
- } else {
-
- /* Read from input WIM (possibly compressed) */