+ offset += lte->resource_entry.offset;
+ if (cb) {
+ /* Send data to callback function */
+ u8 buf[min(WIM_CHUNK_SIZE, size)];
+ while (size) {
+ size_t bytes_to_read = min(WIM_CHUNK_SIZE, size);
+ size_t bytes_read = full_pread(in_fd, buf,
+ bytes_to_read, offset);
+ if (bytes_read != bytes_to_read)
+ goto read_error;
+ ret = cb(buf, bytes_read, ctx_or_buf);
+ if (ret)
+ goto out;
+ size -= bytes_read;
+ offset += bytes_read;
+ }
+ } else {
+ /* Send data directly to a buffer */
+ if (full_pread(in_fd, ctx_or_buf, size, offset) != size)
+ goto read_error;
+ }
+ ret = 0;
+ }
+ goto out;
+read_error:
+ ERROR_WITH_ERRNO("Error reading data from WIM");
+ ret = WIMLIB_ERR_READ;
+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)
+{
+ return read_partial_wim_resource(lte, size, NULL, buf, 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);
+}
+
+
+#ifndef __WIN32__
+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;
+ }
+ } else {
+ /* Send data directly to a buffer */
+ bytes_read = full_read(fd, ctx_or_buf, size);
+ if (bytes_read != size)
+ goto read_error;