- if (lte == NULL) {
- tputc(T('\n'), out);
- return;
- }
-
-
- tprintf(T("Uncompressed size = %"PRIu64" bytes\n"),
- lte->size);
- if (lte->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
- tprintf(T("Offset = %"PRIu64" bytes\n"),
- lte->offset_in_res);
-
- tprintf(T("Raw uncompressed size = %"PRIu64" bytes\n"),
- lte->rspec->uncompressed_size);
-
- tprintf(T("Raw compressed size = %"PRIu64" bytes\n"),
- lte->rspec->size_in_wim);
-
- tprintf(T("Raw offset = %"PRIu64" bytes\n"),
- lte->rspec->offset_in_wim);
- } else if (lte->resource_location == RESOURCE_IN_WIM) {
- tprintf(T("Compressed size = %"PRIu64" bytes\n"),
- lte->rspec->size_in_wim);
-
- tprintf(T("Offset = %"PRIu64" bytes\n"),
- lte->rspec->offset_in_wim);
- }
-
- tfprintf(out, T("Reference Count = %u\n"), lte->refcnt);
-
- if (lte->unhashed) {
- tfprintf(out, T("(Unhashed: inode %p, stream_id = %u)\n"),
- lte->back_inode, lte->back_stream_id);
- } else {
- tfprintf(out, T("Hash = 0x"));
- print_hash(lte->hash, out);
- tputc(T('\n'), out);
- }
-
- tfprintf(out, T("Flags = "));
- u8 flags = lte->flags;
- if (flags & WIM_RESHDR_FLAG_COMPRESSED)
- tfputs(T("WIM_RESHDR_FLAG_COMPRESSED, "), out);
- if (flags & WIM_RESHDR_FLAG_FREE)
- tfputs(T("WIM_RESHDR_FLAG_FREE, "), out);
- if (flags & WIM_RESHDR_FLAG_METADATA)
- tfputs(T("WIM_RESHDR_FLAG_METADATA, "), out);
- if (flags & WIM_RESHDR_FLAG_SPANNED)
- tfputs(T("WIM_RESHDR_FLAG_SPANNED, "), out);
- if (flags & WIM_RESHDR_FLAG_PACKED_STREAMS)
- tfputs(T("WIM_RESHDR_FLAG_PACKED_STREAMS, "), out);
- tputc(T('\n'), out);
- switch (lte->resource_location) {
- case RESOURCE_IN_WIM:
- if (lte->rspec->wim->filename) {
- tfprintf(out, T("WIM file = `%"TS"'\n"),
- lte->rspec->wim->filename);
- }
- break;
-#ifdef __WIN32__
- case RESOURCE_WIN32_ENCRYPTED:
-#endif
- case RESOURCE_IN_FILE_ON_DISK:
- tfprintf(out, T("File on Disk = `%"TS"'\n"),
- lte->file_on_disk);
- break;
-#ifdef WITH_FUSE
- case RESOURCE_IN_STAGING_FILE:
- tfprintf(out, T("Staging File = `%"TS"'\n"),
- lte->staging_file_name);
- break;
-#endif
- default:
- break;
- }
- tputc(T('\n'), out);
-}
-
-void
-lte_to_wimlib_resource_entry(const struct wim_lookup_table_entry *lte,
- struct wimlib_resource_entry *wentry)
-{
- memset(wentry, 0, sizeof(*wentry));
-
- wentry->uncompressed_size = lte->size;
- if (lte->resource_location == RESOURCE_IN_WIM) {
- wentry->part_number = lte->rspec->wim->hdr.part_number;
- if (lte->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
- wentry->compressed_size = 0;
- wentry->offset = lte->offset_in_res;
- } else {
- wentry->compressed_size = lte->rspec->size_in_wim;
- wentry->offset = lte->rspec->offset_in_wim;
- }
- wentry->raw_resource_offset_in_wim = lte->rspec->offset_in_wim;
- wentry->raw_resource_uncompressed_size = lte->rspec->uncompressed_size;
- wentry->raw_resource_compressed_size = lte->rspec->size_in_wim;
- }
- copy_hash(wentry->sha1_hash, lte->hash);
- wentry->reference_count = lte->refcnt;
- wentry->is_compressed = (lte->flags & WIM_RESHDR_FLAG_COMPRESSED) != 0;
- wentry->is_metadata = (lte->flags & WIM_RESHDR_FLAG_METADATA) != 0;
- wentry->is_free = (lte->flags & WIM_RESHDR_FLAG_FREE) != 0;
- wentry->is_spanned = (lte->flags & WIM_RESHDR_FLAG_SPANNED) != 0;
- wentry->is_packed_streams = (lte->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) != 0;
-}
-
-struct iterate_lte_context {
- wimlib_iterate_lookup_table_callback_t cb;
- void *user_ctx;
-};
-
-static int
-do_iterate_lte(struct wim_lookup_table_entry *lte, void *_ctx)
-{
- struct iterate_lte_context *ctx = _ctx;
- struct wimlib_resource_entry entry;
-
- lte_to_wimlib_resource_entry(lte, &entry);
- return (*ctx->cb)(&entry, ctx->user_ctx);
-}
-
-/* API function documented in wimlib.h */
-WIMLIBAPI int
-wimlib_iterate_lookup_table(WIMStruct *wim, int flags,
- wimlib_iterate_lookup_table_callback_t cb,
- void *user_ctx)
-{
- struct iterate_lte_context ctx = {
- .cb = cb,
- .user_ctx = user_ctx,
- };
- if (wim->hdr.part_number == 1) {
- int ret;
- for (int i = 0; i < wim->hdr.image_count; i++) {
- ret = do_iterate_lte(wim->image_metadata[i]->metadata_lte,
- &ctx);
- if (ret)
- return ret;
- }
- }
- return for_lookup_table_entry(wim->lookup_table, do_iterate_lte, &ctx);
-}
-
-/* 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
-wim_pathname_to_stream(WIMStruct *wim,
- 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(wim, path);
- if (p)
- *p = T(':');
- if (!dentry)
- return -errno;
-
- inode = dentry->d_inode;
-
- if (!inode->i_resolved)
- if (inode_resolve_ltes(inode, wim->lookup_table, false))
- return -EIO;
-
- 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;
- }