-#ifdef WITH_FUSE
-/*
- * Finds the dentry, lookup table entry, and stream index for a WIM file stream,
- * given a path name.
- *
- * This is only for pre-resolved inodes.
- */
-int lookup_resource(WIMStruct *w, const char *path,
- int lookup_flags,
- struct dentry **dentry_ret,
- struct lookup_table_entry **lte_ret,
- u16 *stream_idx_ret)
-{
- struct dentry *dentry;
- struct lookup_table_entry *lte;
- u16 stream_idx;
- const char *stream_name = NULL;
- struct inode *inode;
- char *p = NULL;
-
- if (lookup_flags & LOOKUP_FLAG_ADS_OK) {
- stream_name = path_stream_name(path);
- if (stream_name) {
- p = (char*)stream_name - 1;
- *p = '\0';
+ DEBUG("reshdr: size_in_wim=%"PRIu64", "
+ "uncompressed_size=%"PRIu64", "
+ "offset_in_wim=%"PRIu64", "
+ "flags=0x%02x",
+ reshdr.size_in_wim, reshdr.uncompressed_size,
+ reshdr.offset_in_wim, reshdr.flags);
+
+ if (wim->hdr.wim_version == WIM_VERSION_DEFAULT)
+ reshdr.flags &= ~WIM_RESHDR_FLAG_PACKED_STREAMS;
+
+ cur_entry = new_lookup_table_entry();
+ if (cur_entry == NULL) {
+ ERROR("Not enough memory to read lookup table!");
+ ret = WIMLIB_ERR_NOMEM;
+ goto err;
+ }
+
+ part_number = le16_to_cpu(disk_entry->part_number);
+ cur_entry->refcnt = le32_to_cpu(disk_entry->refcnt);
+ copy_hash(cur_entry->hash, disk_entry->hash);
+
+ if (part_number != wim->hdr.part_number) {
+ WARNING("A lookup table entry in part %hu of the WIM "
+ "points to part %hu (ignoring it)",
+ wim->hdr.part_number, part_number);
+ free_lookup_table_entry(cur_entry);
+ continue;
+ }
+
+ if (!(reshdr.flags & (WIM_RESHDR_FLAG_PACKED_STREAMS |
+ WIM_RESHDR_FLAG_COMPRESSED))) {
+ if (reshdr.uncompressed_size != reshdr.size_in_wim) {
+ ERROR("Invalid resource entry!");
+ ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
+ goto err;
+ }
+ }
+
+ back_to_back_pack = false;
+ if (!(reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) ||
+ cur_rspec == NULL ||
+ (back_to_back_pack =
+ ((reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) &&
+ reshdr.uncompressed_size == WIM_PACK_MAGIC_NUMBER &&
+ cur_rspec != NULL &&
+ cur_rspec->size_in_wim != 0)))
+ {
+ /* Starting new run of streams that share the same WIM
+ * resource. */
+ struct wim_lookup_table_entry *prev_entry = NULL;
+
+ if (back_to_back_pack &&
+ !list_empty(&cur_rspec->stream_list))
+ {
+ prev_entry = list_entry(cur_rspec->stream_list.prev,
+ struct wim_lookup_table_entry,
+ rspec_node);
+ lte_unbind_wim_resource_spec(prev_entry);
+ }
+ if (cur_rspec != NULL) {
+ ret = validate_resource(cur_rspec);
+ if (ret)
+ goto err;
+ }
+
+ /* Allocate the resource specification and initialize it
+ * with values from the current stream entry. */
+ cur_rspec = MALLOC(sizeof(*cur_rspec));
+ if (cur_rspec == NULL) {
+ ERROR("Not enough memory to read lookup table!");
+ ret = WIMLIB_ERR_NOMEM;
+ goto err;
+ }
+ wim_res_hdr_to_spec(&reshdr, wim, cur_rspec);
+
+ /* If this is a packed run, the current stream entry may
+ * specify a stream within the resource, and not the
+ * resource itself. Zero possibly irrelevant data until
+ * it is read for certain. (Note that the computation
+ * of 'back_to_back_pack' tests if 'size_in_wim' is
+ * nonzero to see if the resource info has been read;
+ * hence we need to set it to 0 here.) */
+ if (reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
+ cur_rspec->size_in_wim = 0;
+ cur_rspec->uncompressed_size = 0;
+ cur_rspec->offset_in_wim = 0;
+ }
+
+ if (prev_entry)
+ lte_bind_wim_resource_spec(prev_entry, cur_rspec);