+ /* If the WIM resource is in an external file, open a FILE * to it so we
+ * don't have to open a temporary one in read_wim_resource() for each
+ * chunk. */
+ if (lte->resource_location == RESOURCE_IN_FILE_ON_DISK
+ && !lte->file_on_disk_fp)
+ {
+ wimlib_assert(lte->file_on_disk);
+ lte->file_on_disk_fp = fopen(lte->file_on_disk, "rb");
+ if (!lte->file_on_disk_fp) {
+ ERROR_WITH_ERRNO("Failed to open the file `%s' for "
+ "reading", lte->file_on_disk);
+ ret = WIMLIB_ERR_OPEN;
+ goto out;
+ }
+ }
+#ifdef WITH_NTFS_3G
+ else if (lte->resource_location == RESOURCE_IN_NTFS_VOLUME
+ && !lte->attr)
+ {
+ struct ntfs_location *loc = lte->ntfs_loc;
+ wimlib_assert(loc);
+ ni = ntfs_pathname_to_inode(*loc->ntfs_vol_p, NULL, loc->path_utf8);
+ if (!ni) {
+ ERROR_WITH_ERRNO("Failed to open inode `%s' in NTFS "
+ "volume", loc->path_utf8);
+ ret = WIMLIB_ERR_NTFS_3G;
+ goto out;
+ }
+ lte->attr = ntfs_attr_open(ni,
+ loc->is_reparse_point ? AT_REPARSE_POINT : AT_DATA,
+ (ntfschar*)loc->stream_name_utf16,
+ loc->stream_name_utf16_num_chars);
+ if (!lte->attr) {
+ ERROR_WITH_ERRNO("Failed to open attribute of `%s' in "
+ "NTFS volume", loc->path_utf8);
+ ret = WIMLIB_ERR_NTFS_3G;
+ goto out_fclose;
+ }
+ }
+#endif
+
+ /* If we aren't doing a raw copy, we will compute the SHA1 message
+ * digest of the resource as we read it, and verify it's the same as the
+ * hash given in the lookup table entry once we've finished reading the
+ * resource. */
+ SHA_CTX ctx;
+ if (!raw)
+ sha1_init(&ctx);
+
+ /* While there are still bytes remaining in the WIM resource, read a
+ * chunk of the resource, update SHA1, then write that chunk using the
+ * desired compression type. */
+ do {