- int out_wim_ctype = wimlib_get_compression_type(w);
- struct resource_entry *output_res_entry = <e->output_resource_entry;
- u64 len;
- FILE *in_fp;
- FILE *out_fp = w->out_fp;
- int ret = 0;
-
- /* Figure out if we can read the resource from the WIM file, or
- * if we have to read it from the filesystem outside, or if it's a
- * symbolic link with the data already in memory pointed to by a field
- * of the lookup table entry. */
- if (lte->is_symlink) {
- off_t offset = ftello(w->out_fp);
- u64 new_size;
-
- if (offset == -1) {
- ERROR_WITH_ERRNO("Could not get position in output "
- "file");
- return WIMLIB_ERR_WRITE;
- }
-
- wimlib_assert(lte->symlink_buf);
-
- len = lte->resource_entry.original_size;
-
- ret = recompress_resource(NULL, lte->symlink_buf, len, len, 0,
- 0, out_fp, out_wim_ctype, &new_size);
- output_res_entry->size = new_size;
- output_res_entry->original_size = len;
- output_res_entry->offset = offset;
- output_res_entry->flags = (out_wim_ctype == WIM_COMPRESSION_TYPE_NONE)
- ? 0 : WIM_RESHDR_FLAG_COMPRESSED;
- } else 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;
- }
-
- 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 {
- int in_wim_ctype;
-
- /* Read from input WIM (possibly compressed) */
-
- /* It may be a different WIM file, in the case of
- * exporting images from one WIM file to another */
- if (lte->other_wim_fp) {
- /* Different WIM file. */
- in_fp = lte->other_wim_fp;
- in_wim_ctype = lte->other_wim_ctype;
- } else {
- /* Same WIM file. */
- in_fp = w->fp;
- in_wim_ctype = out_wim_ctype;
- }
- int input_res_ctype = resource_compression_type(
- in_wim_ctype,
- lte->resource_entry.flags);
-
- ret = transfer_file_resource(in_fp,
- lte->resource_entry.size,
- lte->resource_entry.original_size,
- lte->resource_entry.offset,
- input_res_ctype,
- out_fp,
- out_wim_ctype,
- output_res_entry);
- }
- return ret;
-}
-
-/*
- * Writes a dentry's resources 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, and the alternate data streams.
- *
- * @return zero on success, nonzero on failure.
- */
-int write_dentry_resources(struct dentry *dentry, void *wim_p)
-{
- WIMStruct *w = wim_p;
- int ret;
-
- /* Directories don't need file resources. */
- if (dentry_is_directory(dentry))
- return 0;
-
- ret = write_file_resource(w, dentry->hash);