X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Flookup_table.c;h=66c4670076f61dfabf8e278d91caef7d3276f427;hp=d3ed585445a225f53b91e82e7d437d127f9560ee;hb=d125eeb310e7e4d3e4288293acc32997462a39ca;hpb=5e770a99c374e24bf2a174e0fb675aaa57df0af4 diff --git a/src/lookup_table.c b/src/lookup_table.c index d3ed5854..66c46700 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -66,6 +66,7 @@ struct lookup_table_entry *new_lookup_table_entry() lte->part_number = 1; lte->refcnt = 1; + INIT_LIST_HEAD(<e->lte_group_list); return lte; } @@ -157,6 +158,23 @@ lookup_table_decrement_refcnt(struct lookup_table* table, const u8 hash[]) return entry; } +/* Like lookup_table_decrement_refcnt(), but for when we already know the lookup + * table entry. */ +struct lookup_table_entry * +lte_decrement_refcnt(struct lookup_table_entry *lte, struct lookup_table *table) +{ + if (lte) { + wimlib_assert(lte->refcnt); + if (--lte->refcnt == 0) { + lookup_table_unlink(table, lte); + if (lte->num_opened_fds == 0) { + free_lookup_table_entry(lte); + lte = NULL; + } + } + } + return lte; +} /* * Calls a function on all the entries in the lookup table. Stop early and @@ -367,21 +385,32 @@ __lookup_resource(const struct lookup_table *lookup_table, const u8 hash[]) return NULL; } +/* + * Finds the dentry, lookup table entry, and stream index for a WIM file stream, + * given a path name. + * + * This is only for pre-resolved dentries. + */ int lookup_resource(WIMStruct *w, const char *path, int lookup_flags, struct dentry **dentry_ret, struct lookup_table_entry **lte_ret, unsigned *stream_idx_ret) { - struct dentry *dentry = get_dentry(w, path); + struct dentry *dentry; struct lookup_table_entry *lte; - unsigned stream_idx = 0; - const u8 *hash = dentry->hash; + unsigned stream_idx; + dentry = get_dentry(w, path); if (!dentry) return -ENOENT; + + wimlib_assert(dentry->resolved); + + lte = dentry->lte; if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK) && dentry_is_directory(dentry)) return -EISDIR; + stream_idx = 0; if (lookup_flags & LOOKUP_FLAG_ADS_OK) { const char *stream_name = path_stream_name(path); if (stream_name) { @@ -392,15 +421,14 @@ int lookup_resource(WIMStruct *w, const char *path, stream_name_len)) { stream_idx = i + 1; - hash = dentry->ads_entries[i].hash; - goto do_lookup; + lte = dentry->ads_entries[i].lte; + goto out; } } return -ENOENT; } } -do_lookup: - lte = __lookup_resource(w->lookup_table, hash); +out: if (dentry_ret) *dentry_ret = dentry; if (lte_ret) @@ -409,3 +437,47 @@ do_lookup: *stream_idx_ret = stream_idx; return 0; } + +/* Resolve a dentry'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 dentry_resolve_ltes(struct dentry *dentry, void *__table) +{ + struct lookup_table *table = __table; + struct lookup_table_entry *lte; + + wimlib_assert(!dentry->resolved); + + /* Resolve the default file stream */ + lte = __lookup_resource(table, dentry->hash); + if (lte) + list_add(&dentry->lte_group_list.list, <e->lte_group_list); + else + INIT_LIST_HEAD(&dentry->lte_group_list.list); + dentry->lte = lte; + dentry->lte_group_list.type = STREAM_TYPE_NORMAL; + dentry->resolved = true; + + /* Resolve the alternate data streams */ + if (dentry->ads_entries_status != ADS_ENTRIES_USER) { + for (u16 i = 0; i < dentry->num_ads; i++) { + struct ads_entry *cur_entry = &dentry->ads_entries[i]; + + lte = __lookup_resource(table, cur_entry->hash); + if (lte) + list_add(&cur_entry->lte_group_list.list, + <e->lte_group_list); + else + INIT_LIST_HEAD(&cur_entry->lte_group_list.list); + cur_entry->lte = lte; + cur_entry->lte_group_list.type = STREAM_TYPE_ADS; + } + } + return 0; +}