-static int
-do_print_lookup_table_entry(struct wim_lookup_table_entry *lte, void *fp)
-{
- print_lookup_table_entry(lte, (FILE*)fp);
- return 0;
-}
-
-/*
- * Prints the lookup table of a WIM file.
- */
-WIMLIBAPI void
-wimlib_print_lookup_table(WIMStruct *wim)
-{
- for (int i = 0; i < wim->hdr.image_count; i++)
- print_lookup_table_entry(wim->image_metadata[i]->metadata_lte, stdout);
- for_lookup_table_entry(wim->lookup_table,
- do_print_lookup_table_entry,
- stdout);
-}
-
-/* Given a SHA1 message digest, return the corresponding entry in the WIM's
- * lookup table, or NULL if there is none. */
-struct wim_lookup_table_entry *
-__lookup_resource(const struct wim_lookup_table *table, const u8 hash[])
-{
- size_t i;
- struct wim_lookup_table_entry *lte;
- struct hlist_node *pos;
-
- wimlib_assert(table != NULL);
- wimlib_assert(hash != NULL);
-
- i = *(size_t*)hash % table->capacity;
- hlist_for_each_entry(lte, pos, &table->array[i], hash_list)
- if (hashes_equal(hash, lte->hash))
- return lte;
- return NULL;
-}
-
-#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 tchar *path,
- int lookup_flags,
- struct wim_dentry **dentry_ret,
- struct wim_lookup_table_entry **lte_ret,
- u16 *stream_idx_ret)
-{
- struct wim_dentry *dentry;
- struct wim_lookup_table_entry *lte;
- u16 stream_idx;
- const tchar *stream_name = NULL;
- struct wim_inode *inode;
- tchar *p = NULL;
-
- if (lookup_flags & LOOKUP_FLAG_ADS_OK) {
- stream_name = path_stream_name(path);
- if (stream_name) {
- p = (tchar*)stream_name - 1;
- *p = T('\0');
- }
- }
-
- dentry = get_dentry(w, path);
- if (p)
- *p = T(':');
- if (!dentry)
- return -errno;
-
- inode = dentry->d_inode;
-
- wimlib_assert(inode->i_resolved);
-
- if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK)
- && inode_is_directory(inode))
- return -EISDIR;
-
- if (stream_name) {
- struct wim_ads_entry *ads_entry;
- u16 ads_idx;
- ads_entry = inode_get_ads_entry(inode, stream_name,
- &ads_idx);
- if (ads_entry) {
- stream_idx = ads_idx + 1;
- lte = ads_entry->lte;
- goto out;
- } else {
- return -ENOENT;
- }
- } else {
- lte = inode->i_lte;
- stream_idx = 0;
- }
-out:
- if (dentry_ret)
- *dentry_ret = dentry;
- if (lte_ret)
- *lte_ret = lte;
- if (stream_idx_ret)
- *stream_idx_ret = stream_idx;
- return 0;
-}
-#endif
-
-/*
- * XXX Probably should store the compression type directly in the lookup table
- * entry
- */
-int
-wim_resource_compression_type(const struct wim_lookup_table_entry *lte)
-{
- if (!(lte->resource_entry.flags & WIM_RESHDR_FLAG_COMPRESSED)
- || lte->resource_location != RESOURCE_IN_WIM)
- return WIMLIB_COMPRESSION_TYPE_NONE;
- return wimlib_get_compression_type(lte->wim);
-}
-
-/* Resolve an inode's lookup table entries
- *
- * This replaces the SHA1 hash fields (which are used to lookup an entry in the
- * lookup table) with pointers directly to the lookup table entries. A circular
- * linked list of streams sharing the same lookup table entry is created.
- *
- * This function always succeeds; unresolved lookup table entries are given a
- * NULL pointer.
- */
-int
-inode_resolve_ltes(struct wim_inode *inode, struct wim_lookup_table *table)
-{
- int ret;
- const u8 *hash;
-
- if (!inode->i_resolved) {
- struct wim_lookup_table_entry *lte, *ads_lte;
-
- /* Resolve the default file stream */
- lte = NULL;
- hash = inode->i_hash;
- if (!is_zero_hash(hash)) {
- lte = __lookup_resource(table, hash);
- if (unlikely(!lte))
- goto resource_not_found;
- }
-
- /* Resolve the alternate data streams */
- struct wim_lookup_table_entry *ads_ltes[inode->i_num_ads];
- for (u16 i = 0; i < inode->i_num_ads; i++) {
- struct wim_ads_entry *cur_entry;
-
- ads_lte = NULL;
- cur_entry = &inode->i_ads_entries[i];
- hash = cur_entry->hash;
- if (!is_zero_hash(hash)) {
- ads_lte = __lookup_resource(table, hash);
- if (unlikely(!ads_lte))
- goto resource_not_found;
- }
- ads_ltes[i] = ads_lte;
- }
- inode->i_lte = lte;
- for (u16 i = 0; i < inode->i_num_ads; i++)
- inode->i_ads_entries[i].lte = ads_ltes[i];
- inode->i_resolved = 1;
- }
- return 0;
-resource_not_found:
- if (wimlib_print_errors) {
- ERROR("\"%"TS"\": resource not found", inode_first_full_path(inode));
- tfprintf(stderr, T(" SHA-1 message digest of missing resource:\n "));
- print_hash(hash, stderr);
- tputc(T('\n'), stderr);
- }
- return WIMLIB_ERR_RESOURCE_NOT_FOUND;
-}
-