4 * Lookup table, implemented as a hash table, that maps SHA1 message digests to
5 * data streams; plus code to read and write the corresponding on-disk data.
9 * Copyright (C) 2012, 2013 Eric Biggers
11 * This file is part of wimlib, a library for working with WIM files.
13 * wimlib is free software; you can redistribute it and/or modify it under the
14 * terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 3 of the License, or (at your option)
18 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
19 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 * A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with wimlib; if not, see http://www.gnu.org/licenses/.
31 #include "wimlib/endianness.h"
32 #include "wimlib/error.h"
33 #include "wimlib/file_io.h"
34 #include "wimlib/glob.h"
35 #include "wimlib/lookup_table.h"
36 #include "wimlib/metadata.h"
37 #include "wimlib/paths.h"
38 #include "wimlib/resource.h"
39 #include "wimlib/util.h"
40 #include "wimlib/write.h"
45 # include <unistd.h> /* for unlink() */
48 struct wim_lookup_table *
49 new_lookup_table(size_t capacity)
51 struct wim_lookup_table *table;
52 struct hlist_head *array;
54 table = CALLOC(1, sizeof(struct wim_lookup_table));
56 array = CALLOC(capacity, sizeof(array[0]));
58 table->num_entries = 0;
59 table->capacity = capacity;
64 ERROR("Failed to allocate memory for lookup table "
65 "with capacity %zu", capacity);
71 struct wim_lookup_table_entry *
72 new_lookup_table_entry(void)
74 struct wim_lookup_table_entry *lte;
76 lte = CALLOC(1, sizeof(struct wim_lookup_table_entry));
78 ERROR("Out of memory (tried to allocate %zu bytes for "
79 "lookup table entry)",
80 sizeof(struct wim_lookup_table_entry));
84 BUILD_BUG_ON(RESOURCE_NONEXISTENT != 0);
88 struct wim_lookup_table_entry *
89 clone_lookup_table_entry(const struct wim_lookup_table_entry *old)
91 struct wim_lookup_table_entry *new;
93 new = memdup(old, sizeof(struct wim_lookup_table_entry));
97 new->extracted_file = NULL;
98 switch (new->resource_location) {
100 list_add(&new->rspec_node, &new->rspec->stream_list);
103 case RESOURCE_IN_FILE_ON_DISK:
105 case RESOURCE_WIN32_ENCRYPTED:
108 case RESOURCE_IN_STAGING_FILE:
109 BUILD_BUG_ON((void*)&old->file_on_disk !=
110 (void*)&old->staging_file_name);
112 new->file_on_disk = TSTRDUP(old->file_on_disk);
113 if (new->file_on_disk == NULL)
116 case RESOURCE_IN_ATTACHED_BUFFER:
117 new->attached_buffer = memdup(old->attached_buffer, old->size);
118 if (new->attached_buffer == NULL)
122 case RESOURCE_IN_NTFS_VOLUME:
124 struct ntfs_location *loc;
125 loc = memdup(old->ntfs_loc, sizeof(struct ntfs_location));
129 loc->stream_name = NULL;
131 loc->path = STRDUP(old->ntfs_loc->path);
132 if (loc->path == NULL)
134 if (loc->stream_name_nchars != 0) {
135 loc->stream_name = memdup(old->ntfs_loc->stream_name,
136 loc->stream_name_nchars * 2);
137 if (loc->stream_name == NULL)
148 free_lookup_table_entry(new);
153 free_lookup_table_entry(struct wim_lookup_table_entry *lte)
156 switch (lte->resource_location) {
157 case RESOURCE_IN_WIM:
158 list_del(<e->rspec_node);
159 if (list_empty(<e->rspec->stream_list))
162 case RESOURCE_IN_FILE_ON_DISK:
164 case RESOURCE_WIN32_ENCRYPTED:
167 case RESOURCE_IN_STAGING_FILE:
168 BUILD_BUG_ON((void*)<e->file_on_disk !=
169 (void*)<e->staging_file_name);
171 case RESOURCE_IN_ATTACHED_BUFFER:
172 BUILD_BUG_ON((void*)<e->file_on_disk !=
173 (void*)<e->attached_buffer);
174 FREE(lte->file_on_disk);
177 case RESOURCE_IN_NTFS_VOLUME:
179 FREE(lte->ntfs_loc->path);
180 FREE(lte->ntfs_loc->stream_name);
193 do_free_lookup_table_entry(struct wim_lookup_table_entry *entry, void *ignore)
195 free_lookup_table_entry(entry);
201 free_lookup_table(struct wim_lookup_table *table)
203 DEBUG("Freeing lookup table.");
206 for_lookup_table_entry(table,
207 do_free_lookup_table_entry,
216 lookup_table_insert_raw(struct wim_lookup_table *table,
217 struct wim_lookup_table_entry *lte)
219 size_t i = lte->hash_short % table->capacity;
221 hlist_add_head(<e->hash_list, &table->array[i]);
225 enlarge_lookup_table(struct wim_lookup_table *table)
227 size_t old_capacity, new_capacity;
228 struct hlist_head *old_array, *new_array;
229 struct wim_lookup_table_entry *lte;
230 struct hlist_node *cur, *tmp;
233 old_capacity = table->capacity;
234 new_capacity = old_capacity * 2;
235 new_array = CALLOC(new_capacity, sizeof(struct hlist_head));
236 if (new_array == NULL)
238 old_array = table->array;
239 table->array = new_array;
240 table->capacity = new_capacity;
242 for (i = 0; i < old_capacity; i++) {
243 hlist_for_each_entry_safe(lte, cur, tmp, &old_array[i], hash_list) {
244 hlist_del(<e->hash_list);
245 lookup_table_insert_raw(table, lte);
253 * Inserts an entry into the lookup table.
255 * @table: A pointer to the lookup table.
256 * @lte: A pointer to the entry to insert.
259 lookup_table_insert(struct wim_lookup_table *table,
260 struct wim_lookup_table_entry *lte)
262 lookup_table_insert_raw(table, lte);
263 if (++table->num_entries > table->capacity)
264 enlarge_lookup_table(table);
268 finalize_lte(struct wim_lookup_table_entry *lte)
271 if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
272 unlink(lte->staging_file_name);
273 list_del(<e->unhashed_list);
276 free_lookup_table_entry(lte);
279 /* Decrements the reference count for the lookup table entry @lte. If its
280 * reference count reaches 0, it is unlinked from the lookup table. If,
281 * furthermore, the entry has no opened file descriptors associated with it, the
284 lte_decrement_refcnt(struct wim_lookup_table_entry *lte,
285 struct wim_lookup_table *table)
287 wimlib_assert(lte != NULL);
288 wimlib_assert(lte->refcnt != 0);
289 if (--lte->refcnt == 0) {
291 list_del(<e->unhashed_list);
293 lookup_table_unlink(table, lte);
295 if (lte->num_opened_fds == 0)
303 lte_decrement_num_opened_fds(struct wim_lookup_table_entry *lte)
305 if (lte->num_opened_fds != 0)
306 if (--lte->num_opened_fds == 0 && lte->refcnt == 0)
311 /* Calls a function on all the entries in the WIM lookup table. Stop early and
312 * return nonzero if any call to the function returns nonzero. */
314 for_lookup_table_entry(struct wim_lookup_table *table,
315 int (*visitor)(struct wim_lookup_table_entry *, void *),
318 struct wim_lookup_table_entry *lte;
319 struct hlist_node *pos, *tmp;
322 for (size_t i = 0; i < table->capacity; i++) {
323 hlist_for_each_entry_safe(lte, pos, tmp, &table->array[i],
326 ret = visitor(lte, arg);
334 /* qsort() callback that sorts streams (represented by `struct
335 * wim_lookup_table_entry's) into an order optimized for reading.
337 * Sorting is done primarily by resource location, then secondarily by a
338 * per-resource location order. For example, resources in WIM files are sorted
339 * primarily by part number, then secondarily by offset, as to implement optimal
340 * reading of either a standalone or split WIM. */
342 cmp_streams_by_sequential_order(const void *p1, const void *p2)
344 const struct wim_lookup_table_entry *lte1, *lte2;
346 WIMStruct *wim1, *wim2;
348 lte1 = *(const struct wim_lookup_table_entry**)p1;
349 lte2 = *(const struct wim_lookup_table_entry**)p2;
351 v = (int)lte1->resource_location - (int)lte2->resource_location;
353 /* Different resource locations? */
357 switch (lte1->resource_location) {
358 case RESOURCE_IN_WIM:
359 wim1 = lte1->rspec->wim;
360 wim2 = lte2->rspec->wim;
362 /* Different (possibly split) WIMs? */
364 v = memcmp(wim1->hdr.guid, wim2->hdr.guid, WIM_GID_LEN);
369 /* Different part numbers in the same WIM? */
370 v = (int)wim1->hdr.part_number - (int)wim2->hdr.part_number;
374 if (lte1->rspec->offset_in_wim != lte2->rspec->offset_in_wim)
375 return cmp_u64(lte1->rspec->offset_in_wim,
376 lte2->rspec->offset_in_wim);
378 return cmp_u64(lte1->offset_in_res, lte2->offset_in_res);
380 case RESOURCE_IN_FILE_ON_DISK:
382 case RESOURCE_IN_STAGING_FILE:
385 case RESOURCE_WIN32_ENCRYPTED:
387 /* Compare files by path: just a heuristic that will place files
388 * in the same directory next to each other. */
389 return tstrcmp(lte1->file_on_disk, lte2->file_on_disk);
391 case RESOURCE_IN_NTFS_VOLUME:
392 return tstrcmp(lte1->ntfs_loc->path, lte2->ntfs_loc->path);
395 /* No additional sorting order defined for this resource
396 * location (e.g. RESOURCE_IN_ATTACHED_BUFFER); simply compare
397 * everything equal to each other. */
403 sort_stream_list(struct list_head *stream_list,
404 size_t list_head_offset,
405 int (*compar)(const void *, const void*))
407 struct list_head *cur;
408 struct wim_lookup_table_entry **array;
411 size_t num_streams = 0;
413 list_for_each(cur, stream_list)
416 if (num_streams <= 1)
419 array_size = num_streams * sizeof(array[0]);
420 array = MALLOC(array_size);
422 return WIMLIB_ERR_NOMEM;
424 cur = stream_list->next;
425 for (i = 0; i < num_streams; i++) {
426 array[i] = (struct wim_lookup_table_entry*)((u8*)cur -
431 qsort(array, num_streams, sizeof(array[0]), compar);
433 INIT_LIST_HEAD(stream_list);
434 for (i = 0; i < num_streams; i++) {
435 list_add_tail((struct list_head*)
436 ((u8*)array[i] + list_head_offset),
443 /* Sort the specified list of streams in an order optimized for reading. */
445 sort_stream_list_by_sequential_order(struct list_head *stream_list,
446 size_t list_head_offset)
448 return sort_stream_list(stream_list, list_head_offset,
449 cmp_streams_by_sequential_order);
454 add_lte_to_array(struct wim_lookup_table_entry *lte,
457 struct wim_lookup_table_entry ***pp = _pp;
462 /* Iterate through the lookup table entries, but first sort them by stream
463 * offset in the WIM. Caution: this is intended to be used when the stream
464 * offset field has actually been set. */
466 for_lookup_table_entry_pos_sorted(struct wim_lookup_table *table,
467 int (*visitor)(struct wim_lookup_table_entry *,
471 struct wim_lookup_table_entry **lte_array, **p;
472 size_t num_streams = table->num_entries;
475 lte_array = MALLOC(num_streams * sizeof(lte_array[0]));
477 return WIMLIB_ERR_NOMEM;
479 for_lookup_table_entry(table, add_lte_to_array, &p);
481 wimlib_assert(p == lte_array + num_streams);
483 qsort(lte_array, num_streams, sizeof(lte_array[0]),
484 cmp_streams_by_sequential_order);
486 for (size_t i = 0; i < num_streams; i++) {
487 ret = visitor(lte_array[i], arg);
495 /* On-disk format of a WIM lookup table entry (stream entry). */
496 struct wim_lookup_table_entry_disk {
497 /* Size, offset, and flags of the stream. */
498 struct wim_reshdr_disk reshdr;
500 /* Which part of the split WIM this stream is in; indexed from 1. */
503 /* Reference count of this stream over all WIM images. */
506 /* SHA1 message digest of the uncompressed data of this stream, or
507 * optionally all zeroes if this stream is of zero length. */
508 u8 hash[SHA1_HASH_SIZE];
511 #define WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE 50
513 /* Validate the size and location of a WIM resource. */
515 validate_resource(const struct wim_resource_spec *rspec)
517 struct wim_lookup_table_entry *lte;
520 /* Verify that calculating the offset of the end of the resource doesn't
522 if (rspec->offset_in_wim + rspec->size_in_wim < rspec->size_in_wim)
525 /* Verify that each stream in the resource has a valid offset and size,
526 * and that no streams overlap, and that the streams were added in order
527 * of increasing offset. */
529 list_for_each_entry(lte, &rspec->stream_list, rspec_node) {
530 if (lte->offset_in_res + lte->size < lte->size ||
531 lte->offset_in_res + lte->size > rspec->uncompressed_size ||
532 lte->offset_in_res < cur_offset)
535 cur_offset = lte->offset_in_res + lte->size;
541 ERROR("Invalid resource entry!");
542 return WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
546 * Reads the lookup table from a WIM file. Each entry specifies a stream that
547 * the WIM file contains, along with its location and SHA1 message digest.
549 * Saves lookup table entries for non-metadata streams in a hash table, and
550 * saves the metadata entry for each image in a special per-image location (the
551 * image_metadata array).
554 * WIMLIB_ERR_SUCCESS (0)
555 * WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY
556 * WIMLIB_ERR_RESOURCE_NOT_FOUND
558 * Or an error code caused by failure to read the lookup table into memory.
561 read_wim_lookup_table(WIMStruct *wim)
566 struct wim_lookup_table *table;
567 struct wim_lookup_table_entry *cur_entry, *duplicate_entry;
568 struct wim_resource_spec *cur_rspec;
570 bool back_to_back_pack;
572 DEBUG("Reading lookup table.");
574 /* Sanity check: lookup table entries are 50 bytes each. */
575 BUILD_BUG_ON(sizeof(struct wim_lookup_table_entry_disk) !=
576 WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE);
578 /* Calculate number of entries in the lookup table. */
579 num_entries = wim->hdr.lookup_table_reshdr.uncompressed_size /
580 sizeof(struct wim_lookup_table_entry_disk);
582 /* Read the lookup table into a buffer. */
583 ret = wim_reshdr_to_data(&wim->hdr.lookup_table_reshdr, wim, &buf);
587 /* Allocate a hash table to map SHA1 message digests into stream
588 * specifications. This is the in-memory "lookup table". */
589 table = new_lookup_table(num_entries * 2 + 1);
591 ERROR("Not enough memory to read lookup table.");
592 ret = WIMLIB_ERR_NOMEM;
596 /* Allocate and initalize stream entries from the raw lookup table
598 wim->current_image = 0;
600 for (i = 0; i < num_entries; i++) {
601 const struct wim_lookup_table_entry_disk *disk_entry =
602 &((const struct wim_lookup_table_entry_disk*)buf)[i];
604 struct wim_reshdr reshdr;
606 get_wim_reshdr(&disk_entry->reshdr, &reshdr);
608 DEBUG("reshdr: size_in_wim=%"PRIu64", "
609 "uncompressed_size=%"PRIu64", "
610 "offset_in_wim=%"PRIu64", "
612 reshdr.size_in_wim, reshdr.uncompressed_size,
613 reshdr.offset_in_wim, reshdr.flags);
615 if (wim->hdr.wim_version == WIM_VERSION_DEFAULT)
616 reshdr.flags &= ~WIM_RESHDR_FLAG_PACKED_STREAMS;
618 cur_entry = new_lookup_table_entry();
619 if (cur_entry == NULL) {
620 ERROR("Not enough memory to read lookup table!");
621 ret = WIMLIB_ERR_NOMEM;
625 part_number = le16_to_cpu(disk_entry->part_number);
626 cur_entry->refcnt = le32_to_cpu(disk_entry->refcnt);
627 copy_hash(cur_entry->hash, disk_entry->hash);
629 if (part_number != wim->hdr.part_number) {
630 WARNING("A lookup table entry in part %hu of the WIM "
631 "points to part %hu (ignoring it)",
632 wim->hdr.part_number, part_number);
633 free_lookup_table_entry(cur_entry);
637 if (!(reshdr.flags & (WIM_RESHDR_FLAG_PACKED_STREAMS |
638 WIM_RESHDR_FLAG_COMPRESSED))) {
639 if (reshdr.uncompressed_size != reshdr.size_in_wim) {
640 ERROR("Invalid resource entry!");
641 ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
646 back_to_back_pack = false;
647 if (!(reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) ||
650 ((reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) &&
651 reshdr.uncompressed_size == WIM_PACK_MAGIC_NUMBER &&
653 cur_rspec->size_in_wim != 0)))
655 /* Starting new run of streams that share the same WIM
657 struct wim_lookup_table_entry *prev_entry = NULL;
659 if (back_to_back_pack &&
660 !list_empty(&cur_rspec->stream_list))
662 prev_entry = list_entry(cur_rspec->stream_list.prev,
663 struct wim_lookup_table_entry,
665 lte_unbind_wim_resource_spec(prev_entry);
667 if (cur_rspec != NULL) {
668 ret = validate_resource(cur_rspec);
673 /* Allocate the resource specification and initialize it
674 * with values from the current stream entry. */
675 cur_rspec = MALLOC(sizeof(*cur_rspec));
676 if (cur_rspec == NULL) {
677 ERROR("Not enough memory to read lookup table!");
678 ret = WIMLIB_ERR_NOMEM;
681 wim_res_hdr_to_spec(&reshdr, wim, cur_rspec);
683 /* If this is a packed run, the current stream entry may
684 * specify a stream within the resource, and not the
685 * resource itself. Zero possibly irrelevant data until
686 * it is read for certain. */
687 if (reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
688 cur_rspec->size_in_wim = 0;
689 cur_rspec->uncompressed_size = 0;
690 cur_rspec->offset_in_wim = 0;
694 lte_bind_wim_resource_spec(prev_entry, cur_rspec);
697 if ((reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) &&
698 reshdr.uncompressed_size == WIM_PACK_MAGIC_NUMBER)
700 /* Found the specification for the packed resource.
701 * Transfer the values to the `struct
702 * wim_resource_spec', and discard the current stream
703 * since this lookup table entry did not, in fact,
704 * correspond to a "stream".
707 /* Uncompressed size of the resource pack is actually
708 * stored in the header of the resource itself. */
709 struct alt_chunk_table_header_disk hdr;
711 ret = full_pread(&wim->in_fd, &hdr,
712 sizeof(hdr), reshdr.offset_in_wim);
716 cur_rspec->uncompressed_size = le64_to_cpu(hdr.res_usize);
717 cur_rspec->offset_in_wim = reshdr.offset_in_wim;
718 cur_rspec->size_in_wim = reshdr.size_in_wim;
719 cur_rspec->flags = reshdr.flags;
720 DEBUG("Full pack is %"PRIu64" compressed bytes "
721 "at file offset %"PRIu64" (flags 0x%02x)",
722 cur_rspec->size_in_wim,
723 cur_rspec->offset_in_wim,
725 free_lookup_table_entry(cur_entry);
729 if (is_zero_hash(cur_entry->hash)) {
730 free_lookup_table_entry(cur_entry);
734 if (reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
735 /* Continuing the pack with another stream. */
736 DEBUG("Continuing pack with stream: "
737 "%"PRIu64" uncompressed bytes @ "
738 "resource offset %"PRIu64")",
739 reshdr.size_in_wim, reshdr.offset_in_wim);
742 lte_bind_wim_resource_spec(cur_entry, cur_rspec);
743 if (reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
744 /* In packed runs, the offset field is used for
745 * in-resource offset, not the in-WIM offset, and the
746 * size field is used for the uncompressed size, not the
747 * compressed size. */
748 cur_entry->offset_in_res = reshdr.offset_in_wim;
749 cur_entry->size = reshdr.size_in_wim;
750 cur_entry->flags = reshdr.flags;
752 /* Normal case: The stream corresponds one-to-one with
753 * the resource entry. */
754 cur_entry->offset_in_res = 0;
755 cur_entry->size = reshdr.uncompressed_size;
756 cur_entry->flags = reshdr.flags;
760 if (cur_entry->flags & WIM_RESHDR_FLAG_METADATA) {
761 /* Lookup table entry for a metadata resource */
763 /* Metadata entries with no references must be ignored;
764 * see for example the WinPE WIMs from the WAIK v2.1.
766 if (cur_entry->refcnt == 0) {
767 free_lookup_table_entry(cur_entry);
771 if (cur_entry->refcnt != 1) {
772 if (wimlib_print_errors) {
773 ERROR("Found metadata resource with refcnt != 1:");
774 print_lookup_table_entry(cur_entry, stderr);
776 ret = WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY;
780 if (wim->hdr.part_number != 1) {
781 WARNING("Ignoring metadata resource found in a "
782 "non-first part of the split WIM");
783 free_lookup_table_entry(cur_entry);
786 if (wim->current_image == wim->hdr.image_count) {
787 WARNING("The WIM header says there are %u images "
788 "in the WIM, but we found more metadata "
789 "resources than this (ignoring the extra)",
790 wim->hdr.image_count);
791 free_lookup_table_entry(cur_entry);
795 /* Notice very carefully: We are assigning the metadata
796 * resources in the exact order mirrored by their lookup
797 * table entries on disk, which is the behavior of
798 * Microsoft's software. In particular, this overrides
799 * the actual locations of the metadata resources
800 * themselves in the WIM file as well as any information
801 * written in the XML data. */
802 DEBUG("Found metadata resource for image %u at "
804 wim->current_image + 1,
805 cur_entry->rspec->offset_in_wim);
807 wim->current_image++]->metadata_lte = cur_entry;
811 /* Lookup table entry for a stream that is not a metadata
813 duplicate_entry = lookup_resource(table, cur_entry->hash);
814 if (duplicate_entry) {
815 if (wimlib_print_errors) {
816 WARNING("The WIM lookup table contains two entries with the "
817 "same SHA1 message digest!");
818 WARNING("The first entry is:");
819 print_lookup_table_entry(duplicate_entry, stderr);
820 WARNING("The second entry is:");
821 print_lookup_table_entry(cur_entry, stderr);
823 free_lookup_table_entry(cur_entry);
827 /* Finally, insert the stream into the lookup table, keyed by
828 * its SHA1 message digest. */
829 lookup_table_insert(table, cur_entry);
833 /* Validate the last resource. */
834 if (cur_rspec != NULL) {
835 ret = validate_resource(cur_rspec);
840 if (wim->hdr.part_number == 1 && wim->current_image != wim->hdr.image_count) {
841 WARNING("The header of \"%"TS"\" says there are %u images in\n"
842 " the WIM, but we only found %d metadata resources! Acting as if\n"
843 " the header specified only %d images instead.",
844 wim->filename, wim->hdr.image_count,
845 wim->current_image, wim->current_image);
846 for (int i = wim->current_image; i < wim->hdr.image_count; i++)
847 put_image_metadata(wim->image_metadata[i], NULL);
848 wim->hdr.image_count = wim->current_image;
850 DEBUG("Done reading lookup table.");
851 wim->lookup_table = table;
856 if (cur_rspec && list_empty(&cur_rspec->stream_list))
858 free_lookup_table_entry(cur_entry);
859 free_lookup_table(table);
863 wim->current_image = 0;
868 put_wim_lookup_table_entry(struct wim_lookup_table_entry_disk *disk_entry,
869 const struct wim_reshdr *out_reshdr,
870 u16 part_number, u32 refcnt, const u8 *hash)
872 put_wim_reshdr(out_reshdr, &disk_entry->reshdr);
873 disk_entry->part_number = cpu_to_le16(part_number);
874 disk_entry->refcnt = cpu_to_le32(refcnt);
875 copy_hash(disk_entry->hash, hash);
879 write_wim_lookup_table_from_stream_list(struct list_head *stream_list,
880 struct filedes *out_fd,
882 struct wim_reshdr *out_reshdr,
883 int write_resource_flags)
886 struct wim_lookup_table_entry *lte;
887 struct wim_lookup_table_entry_disk *table_buf;
888 struct wim_lookup_table_entry_disk *table_buf_ptr;
890 u64 prev_res_offset_in_wim = ~0ULL;
893 list_for_each_entry(lte, stream_list, lookup_table_list) {
894 table_size += sizeof(struct wim_lookup_table_entry_disk);
896 if (lte->out_reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS &&
897 lte->out_res_offset_in_wim != prev_res_offset_in_wim)
899 table_size += sizeof(struct wim_lookup_table_entry_disk);
900 prev_res_offset_in_wim = lte->out_res_offset_in_wim;
904 DEBUG("Writing WIM lookup table (size=%zu, offset=%"PRIu64")",
905 table_size, out_fd->offset);
907 table_buf = MALLOC(table_size);
908 if (table_buf == NULL) {
909 ERROR("Failed to allocate %zu bytes for temporary lookup table",
911 return WIMLIB_ERR_NOMEM;
913 table_buf_ptr = table_buf;
915 prev_res_offset_in_wim = ~0ULL;
916 list_for_each_entry(lte, stream_list, lookup_table_list) {
918 put_wim_lookup_table_entry(table_buf_ptr++,
923 if (lte->out_reshdr.flags & WIM_RESHDR_FLAG_PACKED_STREAMS &&
924 lte->out_res_offset_in_wim != prev_res_offset_in_wim)
926 /* Put the main resource entry for the pack. */
928 struct wim_reshdr reshdr;
930 reshdr.offset_in_wim = lte->out_res_offset_in_wim;
931 reshdr.size_in_wim = lte->out_res_size_in_wim;
932 reshdr.uncompressed_size = WIM_PACK_MAGIC_NUMBER;
933 reshdr.flags = WIM_RESHDR_FLAG_PACKED_STREAMS;
935 DEBUG("Putting main entry for pack: "
936 "size_in_wim=%"PRIu64", "
937 "offset_in_wim=%"PRIu64", "
938 "uncompressed_size=%"PRIu64,
940 reshdr.offset_in_wim,
941 reshdr.uncompressed_size);
943 put_wim_lookup_table_entry(table_buf_ptr++,
947 prev_res_offset_in_wim = lte->out_res_offset_in_wim;
951 wimlib_assert((u8*)table_buf_ptr - (u8*)table_buf == table_size);
953 /* Write the lookup table uncompressed. Although wimlib can handle a
954 * compressed lookup table, MS software cannot. */
955 ret = write_wim_resource_from_buffer(table_buf,
957 WIM_RESHDR_FLAG_METADATA,
959 WIMLIB_COMPRESSION_TYPE_NONE,
963 write_resource_flags);
965 DEBUG("ret=%d", ret);
970 lte_zero_real_refcnt(struct wim_lookup_table_entry *lte, void *_ignore)
972 lte->real_refcnt = 0;
977 lte_zero_out_refcnt(struct wim_lookup_table_entry *lte, void *_ignore)
984 lte_free_extracted_file(struct wim_lookup_table_entry *lte, void *_ignore)
986 if (lte->extracted_file != NULL) {
987 FREE(lte->extracted_file);
988 lte->extracted_file = NULL;
994 print_lookup_table_entry(const struct wim_lookup_table_entry *lte, FILE *out)
1002 tprintf(T("Uncompressed size = %"PRIu64" bytes\n"),
1004 if (lte->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
1005 tprintf(T("Offset = %"PRIu64" bytes\n"),
1006 lte->offset_in_res);
1008 tprintf(T("Raw uncompressed size = %"PRIu64" bytes\n"),
1009 lte->rspec->uncompressed_size);
1011 tprintf(T("Raw compressed size = %"PRIu64" bytes\n"),
1012 lte->rspec->size_in_wim);
1014 tprintf(T("Raw offset = %"PRIu64" bytes\n"),
1015 lte->rspec->offset_in_wim);
1016 } else if (lte->resource_location == RESOURCE_IN_WIM) {
1017 tprintf(T("Compressed size = %"PRIu64" bytes\n"),
1018 lte->rspec->size_in_wim);
1020 tprintf(T("Offset = %"PRIu64" bytes\n"),
1021 lte->rspec->offset_in_wim);
1024 tfprintf(out, T("Reference Count = %u\n"), lte->refcnt);
1026 if (lte->unhashed) {
1027 tfprintf(out, T("(Unhashed: inode %p, stream_id = %u)\n"),
1028 lte->back_inode, lte->back_stream_id);
1030 tfprintf(out, T("Hash = 0x"));
1031 print_hash(lte->hash, out);
1032 tputc(T('\n'), out);
1035 tfprintf(out, T("Flags = "));
1036 u8 flags = lte->flags;
1037 if (flags & WIM_RESHDR_FLAG_COMPRESSED)
1038 tfputs(T("WIM_RESHDR_FLAG_COMPRESSED, "), out);
1039 if (flags & WIM_RESHDR_FLAG_FREE)
1040 tfputs(T("WIM_RESHDR_FLAG_FREE, "), out);
1041 if (flags & WIM_RESHDR_FLAG_METADATA)
1042 tfputs(T("WIM_RESHDR_FLAG_METADATA, "), out);
1043 if (flags & WIM_RESHDR_FLAG_SPANNED)
1044 tfputs(T("WIM_RESHDR_FLAG_SPANNED, "), out);
1045 if (flags & WIM_RESHDR_FLAG_PACKED_STREAMS)
1046 tfputs(T("WIM_RESHDR_FLAG_PACKED_STREAMS, "), out);
1047 tputc(T('\n'), out);
1048 switch (lte->resource_location) {
1049 case RESOURCE_IN_WIM:
1050 if (lte->rspec->wim->filename) {
1051 tfprintf(out, T("WIM file = `%"TS"'\n"),
1052 lte->rspec->wim->filename);
1056 case RESOURCE_WIN32_ENCRYPTED:
1058 case RESOURCE_IN_FILE_ON_DISK:
1059 tfprintf(out, T("File on Disk = `%"TS"'\n"),
1063 case RESOURCE_IN_STAGING_FILE:
1064 tfprintf(out, T("Staging File = `%"TS"'\n"),
1065 lte->staging_file_name);
1071 tputc(T('\n'), out);
1075 lte_to_wimlib_resource_entry(const struct wim_lookup_table_entry *lte,
1076 struct wimlib_resource_entry *wentry)
1078 memset(wentry, 0, sizeof(*wentry));
1080 wentry->uncompressed_size = lte->size;
1081 if (lte->resource_location == RESOURCE_IN_WIM) {
1082 wentry->part_number = lte->rspec->wim->hdr.part_number;
1083 if (lte->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) {
1084 wentry->compressed_size = 0;
1085 wentry->offset = lte->offset_in_res;
1087 wentry->compressed_size = lte->rspec->size_in_wim;
1088 wentry->offset = lte->rspec->offset_in_wim;
1090 wentry->raw_resource_offset_in_wim = lte->rspec->offset_in_wim;
1091 /*wentry->raw_resource_uncompressed_size = lte->rspec->uncompressed_size;*/
1092 wentry->raw_resource_compressed_size = lte->rspec->size_in_wim;
1094 copy_hash(wentry->sha1_hash, lte->hash);
1095 wentry->reference_count = lte->refcnt;
1096 wentry->is_compressed = (lte->flags & WIM_RESHDR_FLAG_COMPRESSED) != 0;
1097 wentry->is_metadata = (lte->flags & WIM_RESHDR_FLAG_METADATA) != 0;
1098 wentry->is_free = (lte->flags & WIM_RESHDR_FLAG_FREE) != 0;
1099 wentry->is_spanned = (lte->flags & WIM_RESHDR_FLAG_SPANNED) != 0;
1100 wentry->packed = (lte->flags & WIM_RESHDR_FLAG_PACKED_STREAMS) != 0;
1103 struct iterate_lte_context {
1104 wimlib_iterate_lookup_table_callback_t cb;
1109 do_iterate_lte(struct wim_lookup_table_entry *lte, void *_ctx)
1111 struct iterate_lte_context *ctx = _ctx;
1112 struct wimlib_resource_entry entry;
1114 lte_to_wimlib_resource_entry(lte, &entry);
1115 return (*ctx->cb)(&entry, ctx->user_ctx);
1118 /* API function documented in wimlib.h */
1120 wimlib_iterate_lookup_table(WIMStruct *wim, int flags,
1121 wimlib_iterate_lookup_table_callback_t cb,
1124 struct iterate_lte_context ctx = {
1126 .user_ctx = user_ctx,
1128 if (wim->hdr.part_number == 1) {
1130 for (int i = 0; i < wim->hdr.image_count; i++) {
1131 ret = do_iterate_lte(wim->image_metadata[i]->metadata_lte,
1137 return for_lookup_table_entry(wim->lookup_table, do_iterate_lte, &ctx);
1140 /* Given a SHA1 message digest, return the corresponding entry in the WIM's
1141 * lookup table, or NULL if there is none. */
1142 struct wim_lookup_table_entry *
1143 lookup_resource(const struct wim_lookup_table *table, const u8 hash[])
1146 struct wim_lookup_table_entry *lte;
1147 struct hlist_node *pos;
1149 wimlib_assert(table != NULL);
1150 wimlib_assert(hash != NULL);
1152 i = *(size_t*)hash % table->capacity;
1153 hlist_for_each_entry(lte, pos, &table->array[i], hash_list)
1154 if (hashes_equal(hash, lte->hash))
1161 * Finds the dentry, lookup table entry, and stream index for a WIM file stream,
1162 * given a path name.
1164 * This is only for pre-resolved inodes.
1167 wim_pathname_to_stream(WIMStruct *wim,
1170 struct wim_dentry **dentry_ret,
1171 struct wim_lookup_table_entry **lte_ret,
1172 u16 *stream_idx_ret)
1174 struct wim_dentry *dentry;
1175 struct wim_lookup_table_entry *lte;
1177 const tchar *stream_name = NULL;
1178 struct wim_inode *inode;
1181 if (lookup_flags & LOOKUP_FLAG_ADS_OK) {
1182 stream_name = path_stream_name(path);
1184 p = (tchar*)stream_name - 1;
1189 dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
1195 inode = dentry->d_inode;
1197 if (!inode->i_resolved)
1198 if (inode_resolve_ltes(inode, wim->lookup_table, false))
1201 if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK)
1202 && inode_is_directory(inode))
1206 struct wim_ads_entry *ads_entry;
1208 ads_entry = inode_get_ads_entry(inode, stream_name,
1211 stream_idx = ads_idx + 1;
1212 lte = ads_entry->lte;
1218 lte = inode_unnamed_stream_resolved(inode, &stream_idx);
1222 *dentry_ret = dentry;
1226 *stream_idx_ret = stream_idx;
1232 resource_not_found_error(const struct wim_inode *inode, const u8 *hash)
1234 if (wimlib_print_errors) {
1235 ERROR("\"%"TS"\": resource not found", inode_first_full_path(inode));
1236 tfprintf(stderr, T(" SHA-1 message digest of missing resource:\n "));
1237 print_hash(hash, stderr);
1238 tputc(T('\n'), stderr);
1240 return WIMLIB_ERR_RESOURCE_NOT_FOUND;
1244 * Resolve an inode's lookup table entries.
1246 * This replaces the SHA1 hash fields (which are used to lookup an entry in the
1247 * lookup table) with pointers directly to the lookup table entries.
1249 * If @force is %false:
1250 * If any needed SHA1 message digests are not found in the lookup table,
1251 * WIMLIB_ERR_RESOURCE_NOT_FOUND is returned and the inode is left
1253 * If @force is %true:
1254 * If any needed SHA1 message digests are not found in the lookup table,
1255 * new entries are allocated and inserted into the lookup table.
1258 inode_resolve_ltes(struct wim_inode *inode, struct wim_lookup_table *table,
1263 if (!inode->i_resolved) {
1264 struct wim_lookup_table_entry *lte, *ads_lte;
1266 /* Resolve the default file stream */
1268 hash = inode->i_hash;
1269 if (!is_zero_hash(hash)) {
1270 lte = lookup_resource(table, hash);
1273 lte = new_lookup_table_entry();
1275 return WIMLIB_ERR_NOMEM;
1276 copy_hash(lte->hash, hash);
1277 lookup_table_insert(table, lte);
1279 goto resource_not_found;
1284 /* Resolve the alternate data streams */
1285 struct wim_lookup_table_entry *ads_ltes[inode->i_num_ads];
1286 for (u16 i = 0; i < inode->i_num_ads; i++) {
1287 struct wim_ads_entry *cur_entry;
1290 cur_entry = &inode->i_ads_entries[i];
1291 hash = cur_entry->hash;
1292 if (!is_zero_hash(hash)) {
1293 ads_lte = lookup_resource(table, hash);
1296 ads_lte = new_lookup_table_entry();
1298 return WIMLIB_ERR_NOMEM;
1299 copy_hash(ads_lte->hash, hash);
1300 lookup_table_insert(table, ads_lte);
1302 goto resource_not_found;
1306 ads_ltes[i] = ads_lte;
1309 for (u16 i = 0; i < inode->i_num_ads; i++)
1310 inode->i_ads_entries[i].lte = ads_ltes[i];
1311 inode->i_resolved = 1;
1316 return resource_not_found_error(inode, hash);
1320 inode_unresolve_ltes(struct wim_inode *inode)
1322 if (inode->i_resolved) {
1324 copy_hash(inode->i_hash, inode->i_lte->hash);
1326 zero_out_hash(inode->i_hash);
1328 for (u16 i = 0; i < inode->i_num_ads; i++) {
1329 if (inode->i_ads_entries[i].lte)
1330 copy_hash(inode->i_ads_entries[i].hash,
1331 inode->i_ads_entries[i].lte->hash);
1333 zero_out_hash(inode->i_ads_entries[i].hash);
1335 inode->i_resolved = 0;
1340 * Returns the lookup table entry for stream @stream_idx of the inode, where
1341 * stream_idx = 0 means the default un-named file stream, and stream_idx >= 1
1342 * corresponds to an alternate data stream.
1344 * This works for both resolved and un-resolved inodes.
1346 struct wim_lookup_table_entry *
1347 inode_stream_lte(const struct wim_inode *inode, unsigned stream_idx,
1348 const struct wim_lookup_table *table)
1350 if (inode->i_resolved)
1351 return inode_stream_lte_resolved(inode, stream_idx);
1353 return inode_stream_lte_unresolved(inode, stream_idx, table);
1356 struct wim_lookup_table_entry *
1357 inode_unnamed_stream_resolved(const struct wim_inode *inode, u16 *stream_idx_ret)
1359 wimlib_assert(inode->i_resolved);
1360 for (unsigned i = 0; i <= inode->i_num_ads; i++) {
1361 if (inode_stream_name_nbytes(inode, i) == 0 &&
1362 !is_zero_hash(inode_stream_hash_resolved(inode, i)))
1364 *stream_idx_ret = i;
1365 return inode_stream_lte_resolved(inode, i);
1368 *stream_idx_ret = 0;
1372 struct wim_lookup_table_entry *
1373 inode_unnamed_lte_resolved(const struct wim_inode *inode)
1376 return inode_unnamed_stream_resolved(inode, &stream_idx);
1379 struct wim_lookup_table_entry *
1380 inode_unnamed_lte_unresolved(const struct wim_inode *inode,
1381 const struct wim_lookup_table *table)
1383 wimlib_assert(!inode->i_resolved);
1384 for (unsigned i = 0; i <= inode->i_num_ads; i++) {
1385 if (inode_stream_name_nbytes(inode, i) == 0 &&
1386 !is_zero_hash(inode_stream_hash_unresolved(inode, i)))
1388 return inode_stream_lte_unresolved(inode, i, table);
1394 /* Return the lookup table entry for the unnamed data stream of an inode, or
1395 * NULL if there is none.
1397 * You'd think this would be easier than it actually is, since the unnamed data
1398 * stream should be the one referenced from the inode itself. Alas, if there
1399 * are named data streams, Microsoft's "imagex.exe" program will put the unnamed
1400 * data stream in one of the alternate data streams instead of inside the WIM
1401 * dentry itself. So we need to check the alternate data streams too.
1403 * Also, note that a dentry may appear to have more than one unnamed stream, but
1404 * if the SHA1 message digest is all 0's then the corresponding stream does not
1405 * really "count" (this is the case for the inode's own file stream when the
1406 * file stream that should be there is actually in one of the alternate stream
1407 * entries.). This is despite the fact that we may need to extract such a
1408 * missing entry as an empty file or empty named data stream.
1410 struct wim_lookup_table_entry *
1411 inode_unnamed_lte(const struct wim_inode *inode,
1412 const struct wim_lookup_table *table)
1414 if (inode->i_resolved)
1415 return inode_unnamed_lte_resolved(inode);
1417 return inode_unnamed_lte_unresolved(inode, table);
1420 /* Returns the SHA1 message digest of the unnamed data stream of a WIM inode, or
1421 * 'zero_hash' if the unnamed data stream is missing has all zeroes in its SHA1
1422 * message digest field. */
1424 inode_unnamed_stream_hash(const struct wim_inode *inode)
1428 for (unsigned i = 0; i <= inode->i_num_ads; i++) {
1429 if (inode_stream_name_nbytes(inode, i) == 0) {
1430 hash = inode_stream_hash(inode, i);
1431 if (!is_zero_hash(hash))
1438 struct wim_lookup_table_entry **
1439 retrieve_lte_pointer(struct wim_lookup_table_entry *lte)
1441 wimlib_assert(lte->unhashed);
1442 struct wim_inode *inode = lte->back_inode;
1443 u32 stream_id = lte->back_stream_id;
1445 return &inode->i_lte;
1447 for (u16 i = 0; i < inode->i_num_ads; i++)
1448 if (inode->i_ads_entries[i].stream_id == stream_id)
1449 return &inode->i_ads_entries[i].lte;
1454 /* Calculate the SHA1 message digest of a stream and move it from the list of
1455 * unhashed streams to the stream lookup table, possibly joining it with an
1456 * existing lookup table entry for an identical stream.
1458 * @lte: An unhashed lookup table entry.
1459 * @lookup_table: Lookup table for the WIM.
1460 * @lte_ret: On success, write a pointer to the resulting lookup table
1461 * entry to this location. This will be the same as @lte
1462 * if it was inserted into the lookup table, or different if
1463 * a duplicate stream was found.
1465 * Returns 0 on success; nonzero if there is an error reading the stream.
1468 hash_unhashed_stream(struct wim_lookup_table_entry *lte,
1469 struct wim_lookup_table *lookup_table,
1470 struct wim_lookup_table_entry **lte_ret)
1473 struct wim_lookup_table_entry *duplicate_lte;
1474 struct wim_lookup_table_entry **back_ptr;
1476 wimlib_assert(lte->unhashed);
1478 /* back_ptr must be saved because @back_inode and @back_stream_id are in
1479 * union with the SHA1 message digest and will no longer be valid once
1480 * the SHA1 has been calculated. */
1481 back_ptr = retrieve_lte_pointer(lte);
1483 ret = sha1_stream(lte);
1487 /* Look for a duplicate stream */
1488 duplicate_lte = lookup_resource(lookup_table, lte->hash);
1489 list_del(<e->unhashed_list);
1490 if (duplicate_lte) {
1491 /* We have a duplicate stream. Transfer the reference counts
1492 * from this stream to the duplicate and update the reference to
1493 * this stream (in an inode or ads_entry) to point to the
1494 * duplicate. The caller is responsible for freeing @lte if
1496 wimlib_assert(!(duplicate_lte->unhashed));
1497 wimlib_assert(duplicate_lte->size == lte->size);
1498 duplicate_lte->refcnt += lte->refcnt;
1500 *back_ptr = duplicate_lte;
1501 lte = duplicate_lte;
1503 /* No duplicate stream, so we need to insert this stream into
1504 * the lookup table and treat it as a hashed stream. */
1505 lookup_table_insert(lookup_table, lte);
1513 lte_clone_if_new(struct wim_lookup_table_entry *lte, void *_lookup_table)
1515 struct wim_lookup_table *lookup_table = _lookup_table;
1517 if (lookup_resource(lookup_table, lte->hash))
1518 return 0; /* Resource already present. */
1520 lte = clone_lookup_table_entry(lte);
1522 return WIMLIB_ERR_NOMEM;
1523 lte->out_refcnt = 1;
1524 lookup_table_insert(lookup_table, lte);
1529 lte_delete_if_new(struct wim_lookup_table_entry *lte, void *_lookup_table)
1531 struct wim_lookup_table *lookup_table = _lookup_table;
1533 if (lte->out_refcnt) {
1534 lookup_table_unlink(lookup_table, lte);
1535 free_lookup_table_entry(lte);
1540 /* API function documented in wimlib.h */
1542 wimlib_reference_resources(WIMStruct *wim,
1543 WIMStruct **resource_wims, unsigned num_resource_wims,
1550 return WIMLIB_ERR_INVALID_PARAM;
1552 if (num_resource_wims != 0 && resource_wims == NULL)
1553 return WIMLIB_ERR_INVALID_PARAM;
1555 for (i = 0; i < num_resource_wims; i++)
1556 if (resource_wims[i] == NULL)
1557 return WIMLIB_ERR_INVALID_PARAM;
1559 for_lookup_table_entry(wim->lookup_table, lte_zero_out_refcnt, NULL);
1561 for (i = 0; i < num_resource_wims; i++) {
1562 ret = for_lookup_table_entry(resource_wims[i]->lookup_table,
1571 for_lookup_table_entry(wim->lookup_table, lte_delete_if_new,
1577 reference_resource_paths(WIMStruct *wim,
1578 const tchar * const *resource_wimfiles,
1579 unsigned num_resource_wimfiles,
1582 wimlib_progress_func_t progress_func)
1584 WIMStruct **resource_wims;
1588 resource_wims = CALLOC(num_resource_wimfiles, sizeof(resource_wims[0]));
1590 return WIMLIB_ERR_NOMEM;
1592 for (i = 0; i < num_resource_wimfiles; i++) {
1593 DEBUG("Referencing resources from path \"%"TS"\"",
1594 resource_wimfiles[i]);
1595 ret = wimlib_open_wim(resource_wimfiles[i], open_flags,
1596 &resource_wims[i], progress_func);
1598 goto out_free_resource_wims;
1601 ret = wimlib_reference_resources(wim, resource_wims,
1602 num_resource_wimfiles, ref_flags);
1604 goto out_free_resource_wims;
1606 for (i = 0; i < num_resource_wimfiles; i++)
1607 list_add_tail(&resource_wims[i]->subwim_node, &wim->subwims);
1610 goto out_free_array;
1612 out_free_resource_wims:
1613 for (i = 0; i < num_resource_wimfiles; i++)
1614 wimlib_free(resource_wims[i]);
1616 FREE(resource_wims);
1621 reference_resource_glob(WIMStruct *wim, const tchar *refglob,
1622 int ref_flags, int open_flags,
1623 wimlib_progress_func_t progress_func)
1628 /* Note: glob() is replaced in Windows native builds. */
1629 ret = tglob(refglob, GLOB_ERR | GLOB_NOSORT, NULL, &globbuf);
1631 if (ret == GLOB_NOMATCH) {
1632 if (ref_flags & WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH) {
1633 ERROR("Found no files for glob \"%"TS"\"", refglob);
1634 return WIMLIB_ERR_GLOB_HAD_NO_MATCHES;
1636 return reference_resource_paths(wim,
1644 ERROR_WITH_ERRNO("Failed to process glob \"%"TS"\"", refglob);
1645 if (ret == GLOB_NOSPACE)
1646 return WIMLIB_ERR_NOMEM;
1648 return WIMLIB_ERR_READ;
1652 ret = reference_resource_paths(wim,
1653 (const tchar * const *)globbuf.gl_pathv,
1662 /* API function documented in wimlib.h */
1664 wimlib_reference_resource_files(WIMStruct *wim,
1665 const tchar * const * resource_wimfiles_or_globs,
1669 wimlib_progress_func_t progress_func)
1674 if (ref_flags & WIMLIB_REF_FLAG_GLOB_ENABLE) {
1675 for (i = 0; i < count; i++) {
1676 ret = reference_resource_glob(wim,
1677 resource_wimfiles_or_globs[i],
1686 return reference_resource_paths(wim, resource_wimfiles_or_globs,
1688 open_flags, progress_func);