+ int ret;
+
+ if (offset < fd->offset) {
+ ERROR("Can't seek backwards in pipe "
+ "(offset %"PRIu64" => %"PRIu64").\n"
+ " Make sure the WIM was captured as "
+ "pipable.",
+ fd->offset, offset);
+ errno = ESPIPE;
+ return WIMLIB_ERR_RESOURCE_ORDER;
+ }
+ while (fd->offset != offset) {
+ size_t bytes_to_read = min(offset - fd->offset, BUFFER_SIZE);
+ u8 dummy[bytes_to_read];
+
+ ret = full_read(fd, dummy, bytes_to_read);
+ if (ret)
+ return ret;
+ }
+ return full_read(fd, buf, count);
+}
+
+/* Wrapper around pread() that keep retrying until all requested bytes have been
+ * read or until end-of file has occurred. This also transparently handle
+ * reading from pipe files, but the caller needs to be sure the requested offset
+ * is greater than or equal to the current offset, or else
+ * WIMLIB_ERR_RESOURCE_ORDER will be returned.
+ *
+ * Return values:
+ * WIMLIB_ERR_SUCCESS (0)
+ * WIMLIB_ERR_READ (errno set)
+ * WIMLIB_ERR_UNEXPECTED_END_OF_FILE (errno set to 0)
+ * WIMLIB_ERR_RESOURCE_ORDER (errno set to ESPIPE)
+ * */
+int
+full_pread(struct filedes *fd, void *buf, size_t count, off_t offset)
+{
+ ssize_t bytes_read;