- /* We shouldn't be allowing read over-runs in any part of the library.
- * */
- if (raw)
- wimlib_assert(offset + size <= lte->resource_entry.size);
- else
- wimlib_assert(offset + size <= lte->resource_entry.original_size);
-
- int ctype;
- int ret;
- FILE *fp;
- switch (lte->resource_location) {
- case RESOURCE_IN_WIM:
- /* The resource is in a WIM file, and its WIMStruct is given by
- * the lte->wim member. The resource may be either compressed
- * or uncompressed. */
- wimlib_assert(lte->wim);
- wimlib_assert(lte->wim->fp);
- ctype = wim_resource_compression_type(lte);
-
- /* XXX This check should be moved elsewhere */
- if (ctype == WIM_COMPRESSION_TYPE_NONE &&
- lte->resource_entry.original_size !=
- lte->resource_entry.size) {
- ERROR("WIM resource at offset %"PRIu64", size %"PRIu64
- "has an original size of %"PRIu64", but is "
- "uncompressed",
- lte->resource_entry.offset,
- lte->resource_entry.size,
- lte->resource_entry.original_size);
- return WIMLIB_ERR_INVALID_RESOURCE_SIZE;
- }
-
- if (raw || ctype == WIM_COMPRESSION_TYPE_NONE)
- return read_uncompressed_resource(lte->wim->fp,
- lte->resource_entry.offset + offset,
- size, buf);
- else
- return read_compressed_resource(lte->wim->fp,
- lte->resource_entry.size,
- lte->resource_entry.original_size,
- lte->resource_entry.offset,
- ctype, size, offset, buf);
- break;
- case RESOURCE_IN_STAGING_FILE:
- /* The WIM FUSE implementation needs to handle multiple open
- * file descriptors per lookup table entry so it does not
- * currently work with this function. */
- wimlib_assert(lte->staging_file_name);
- wimlib_assert(0);
- break;
- case RESOURCE_IN_FILE_ON_DISK:
- /* The resource is in some file on the external filesystem and
- * needs to be read uncompressed */
- wimlib_assert(lte->file_on_disk);
- /* Use existing file pointer if available; otherwise open one
- * temporarily */
- if (lte->file_on_disk_fp) {
- fp = lte->file_on_disk_fp;
- } else {
- fp = fopen(lte->file_on_disk, "rb");
- if (!fp) {
- ERROR_WITH_ERRNO("Failed to open the file "
- "`%s'", lte->file_on_disk);
- }
- }
- ret = read_uncompressed_resource(fp, offset, size, buf);
- if (fp != lte->file_on_disk_fp)
- fclose(fp);
- return ret;
- break;
- case RESOURCE_IN_ATTACHED_BUFFER:
- /* The resource is directly attached uncompressed in an
- * in-memory buffer. */
- wimlib_assert(lte->attached_buffer);
- memcpy(buf, lte->attached_buffer + offset, size);
- return 0;
- break;
- default:
- assert(0);