X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flookup_table.c;h=f6d4244af126681174983af88b924aae022f50f6;hb=f6f4c63e772e9dc4264ee4ffc4f9c4b615a851bc;hp=364f469ed08ab7a89426d72f6d41df8868385023;hpb=9b9a502863318d6208da2818b1d522346e5eee9e;p=wimlib diff --git a/src/lookup_table.c b/src/lookup_table.c index 364f469e..f6d4244a 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -26,7 +26,7 @@ #include "wimlib_internal.h" #include "lookup_table.h" -#include "io.h" +#include "buffer_io.h" #include #ifdef WITH_FUSE @@ -39,21 +39,20 @@ struct lookup_table *new_lookup_table(size_t capacity) struct hlist_head *array; table = MALLOC(sizeof(struct lookup_table)); - if (!table) - goto err; - array = CALLOC(capacity, sizeof(array[0])); - if (!array) { - FREE(table); - goto err; + if (table) { + array = CALLOC(capacity, sizeof(array[0])); + if (array) { + table->num_entries = 0; + table->capacity = capacity; + table->array = array; + } else { + FREE(table); + table = NULL; + ERROR("Failed to allocate memory for lookup table with capacity %zu", + capacity); + } } - table->num_entries = 0; - table->capacity = capacity; - table->array = array; return table; -err: - ERROR("Failed to allocate memory for lookup table with capacity %zu", - capacity); - return NULL; } struct lookup_table_entry *new_lookup_table_entry() @@ -203,8 +202,6 @@ static void finalize_lte(struct lookup_table_entry *lte) #ifdef WITH_FUSE if (lte->resource_location == RESOURCE_IN_STAGING_FILE) { unlink(lte->staging_file_name); - wimlib_assert(lte->staging_list.next); - wimlib_assert(lte->staging_list.prev); list_del(<e->staging_list); } #endif @@ -232,11 +229,9 @@ void lte_decrement_refcnt(struct lookup_table_entry *lte, #ifdef WITH_FUSE void lte_decrement_num_opened_fds(struct lookup_table_entry *lte) { - wimlib_assert(lte != NULL); - if (lte->num_opened_fds != 0) { + if (lte->num_opened_fds != 0) if (--lte->num_opened_fds == 0 && lte->refcnt == 0) finalize_lte(lte); - } } #endif @@ -270,12 +265,18 @@ int for_lookup_table_entry(struct lookup_table *table, */ int read_lookup_table(WIMStruct *w) { - u64 num_entries; - u8 buf[WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE]; - int ret; + u64 num_entries; + u8 buf[WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE]; + int ret; struct lookup_table *table; struct lookup_table_entry *cur_entry = NULL, *duplicate_entry; + if (resource_is_compressed(&w->hdr.lookup_table_res_entry)) { + ERROR("Didn't expect a compressed lookup table!"); + ERROR("Ask the author to implement support for this."); + return WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE; + } + DEBUG("Reading lookup table: offset %"PRIu64", size %"PRIu64"", w->hdr.lookup_table_res_entry.offset, w->hdr.lookup_table_res_entry.original_size); @@ -458,12 +459,6 @@ int lte_zero_out_refcnt(struct lookup_table_entry *lte, void *ignore) return 0; } -int lte_zero_extracted_file(struct lookup_table_entry *lte, void *ignore) -{ - lte->extracted_file = NULL; - return 0; -} - int lte_free_extracted_file(struct lookup_table_entry *lte, void *ignore) { if (lte->extracted_file != NULL) { @@ -626,65 +621,70 @@ out: } #endif +/* 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. + */ void inode_resolve_ltes(struct inode *inode, struct lookup_table *table) { - struct lookup_table_entry *lte; - - wimlib_assert(!inode->resolved); - /* Resolve the default file stream */ - lte = __lookup_resource(table, inode->hash); - inode->lte = lte; - inode->resolved = true; - - /* Resolve the alternate data streams */ - for (u16 i = 0; i < inode->num_ads; i++) { - struct ads_entry *cur_entry = &inode->ads_entries[i]; - lte = __lookup_resource(table, cur_entry->hash); - cur_entry->lte = lte; + if (!inode->resolved) { + struct lookup_table_entry *lte; + /* Resolve the default file stream */ + lte = __lookup_resource(table, inode->hash); + inode->lte = lte; + inode->resolved = 1; + + /* Resolve the alternate data streams */ + for (u16 i = 0; i < inode->num_ads; i++) { + struct ads_entry *cur_entry = &inode->ads_entries[i]; + lte = __lookup_resource(table, cur_entry->hash); + cur_entry->lte = lte; + } } } -static void inode_unresolve_ltes(struct inode *inode) +void inode_unresolve_ltes(struct inode *inode) { - wimlib_assert(inode->resolved); - if (inode->lte) - copy_hash(inode->hash, inode->lte->hash); - else - zero_out_hash(inode->hash); - - for (u16 i = 0; i < inode->num_ads; i++) { - if (inode->ads_entries[i].lte) - copy_hash(inode->ads_entries[i].hash, - inode->ads_entries[i].lte->hash); + if (inode->resolved) { + if (inode->lte) + copy_hash(inode->hash, inode->lte->hash); else - zero_out_hash(inode->ads_entries[i].hash); + zero_out_hash(inode->hash); + + for (u16 i = 0; i < inode->num_ads; i++) { + if (inode->ads_entries[i].lte) + copy_hash(inode->ads_entries[i].hash, + inode->ads_entries[i].lte->hash); + else + zero_out_hash(inode->ads_entries[i].hash); + } + inode->resolved = 0; } - inode->resolved = false; } -/* 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. +/* + * Returns the lookup table entry for stream @stream_idx of the inode, where + * stream_idx = 0 means the default un-named file stream, and stream_idx >= 1 + * corresponds to an alternate data stream. * - * This function always succeeds; unresolved lookup table entries are given a - * NULL pointer. + * This works for both resolved and un-resolved dentries. */ -int dentry_resolve_ltes(struct dentry *dentry, void *table) +struct lookup_table_entry * +inode_stream_lte(const struct inode *inode, unsigned stream_idx, + const struct lookup_table *table) { - if (!dentry->d_inode->resolved) - inode_resolve_ltes(dentry->d_inode, table); - return 0; + if (inode->resolved) + return inode_stream_lte_resolved(inode, stream_idx); + else + return inode_stream_lte_unresolved(inode, stream_idx, table); } -int dentry_unresolve_ltes(struct dentry *dentry, void *ignore) -{ - if (dentry->d_inode->resolved) - inode_unresolve_ltes(dentry->d_inode); - return 0; -} /* Return the lookup table entry for the unnamed data stream of an inode, or * NULL if there is none.