- ret = read_uncompressed_resource(fp, offset, size, buf);
- if (fp != lte->file_on_disk_fp)
- fclose(fp);
- break;
-#ifdef __WIN32__
- case RESOURCE_WIN32:
- wimlib_assert(lte->file_on_disk_fp != NULL);
- ret = win32_read_file(lte->file_on_disk, lte->file_on_disk_fp,
- offset, size, buf);
- break;
-#endif
- case RESOURCE_IN_ATTACHED_BUFFER:
- /* The resource is directly attached uncompressed in an
- * in-memory buffer. */
- wimlib_assert(lte->attached_buffer != NULL);
- memcpy(buf, lte->attached_buffer + offset, size);
- break;
-#ifdef WITH_NTFS_3G
- case RESOURCE_IN_NTFS_VOLUME:
- wimlib_assert(lte->ntfs_loc != NULL);
- wimlib_assert(lte->attr != NULL);
- if (lte->ntfs_loc->is_reparse_point)
- offset += 8;
- if (ntfs_attr_pread(lte->attr, offset, size, buf) != size) {
- ERROR_WITH_ERRNO("Error reading NTFS attribute "
- "at `%s'",
- lte->ntfs_loc->path_utf8);
- ret = WIMLIB_ERR_NTFS_3G;
+ ret = 0;
+ }
+ goto out_release_fp;
+read_error:
+ ERROR_WITH_ERRNO("Error reading data from WIM");
+ ret = WIMLIB_ERR_READ;
+out_release_fp:
+ if (flags & WIMLIB_RESOURCE_FLAG_THREADSAFE_READ)
+ ret |= wim_release_fp(wim, wim_fp);
+out:
+ if (ret) {
+ if (errno == 0)
+ errno = EIO;
+ }
+ return ret;
+}
+
+
+int
+read_partial_wim_resource_into_buf(const struct wim_lookup_table_entry *lte,
+ size_t size, u64 offset, void *buf,
+ bool threadsafe)
+{
+ return read_partial_wim_resource(lte, size, NULL, buf,
+ threadsafe ? WIMLIB_RESOURCE_FLAG_THREADSAFE_READ : 0,
+ offset);
+}
+
+static int
+read_wim_resource_prefix(const struct wim_lookup_table_entry *lte,
+ u64 size,
+ consume_data_callback_t cb,
+ void *ctx_or_buf,
+ int flags)
+{
+ return read_partial_wim_resource(lte, size, cb, ctx_or_buf, flags, 0);
+}
+
+
+static int
+read_file_on_disk_prefix(const struct wim_lookup_table_entry *lte,
+ u64 size,
+ consume_data_callback_t cb,
+ void *ctx_or_buf,
+ int _ignored_flags)
+{
+ const tchar *filename = lte->file_on_disk;
+ int ret;
+ int fd;
+ size_t bytes_read;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ ERROR_WITH_ERRNO("Can't open \"%"TS"\"", filename);
+ return WIMLIB_ERR_OPEN;
+ }
+ if (cb) {
+ /* Send data to callback function */
+ u8 buf[min(WIM_CHUNK_SIZE, size)];
+ size_t bytes_to_read;
+ while (size) {
+ bytes_to_read = min(WIM_CHUNK_SIZE, size);
+ bytes_read = full_read(fd, buf, bytes_to_read);
+ if (bytes_read != bytes_to_read)
+ goto read_error;
+ ret = cb(buf, bytes_read, ctx_or_buf);
+ if (ret)
+ goto out_close;
+ size -= bytes_read;