X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdentry.c;h=2f0cabd3d577f4eef9581c15fb58e370337e2cb0;hb=b1c4e6a269ae4c969060e33685db12f76a204a58;hp=50351fb0d3d57b0a592e4cd03e419ce721b663e0;hpb=038eaccece575d04de8d647bb93773b7f3e38ce4;p=wimlib diff --git a/src/dentry.c b/src/dentry.c index 50351fb0..2f0cabd3 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -412,13 +412,12 @@ struct file_attr_flag file_attr_flags[] = { * NULL if the resource entry for the dentry is not to be printed. */ int print_dentry(struct dentry *dentry, void *lookup_table) { - struct lookup_table_entry *lte; - unsigned i; + const u8 *hash; printf("[DENTRY]\n"); printf("Length = %"PRIu64"\n", dentry->length); printf("Attributes = 0x%x\n", dentry->attributes); - for (i = 0; i < ARRAY_LEN(file_attr_flags); i++) + for (unsigned i = 0; i < ARRAY_LEN(file_attr_flags); i++) if (file_attr_flags[i].flag & dentry->attributes) printf(" FILE_ATTRIBUTE_%s is set\n", file_attr_flags[i].name); @@ -429,9 +428,12 @@ int print_dentry(struct dentry *dentry, void *lookup_table) printf("Creation Time = 0x%"PRIx64"\n", dentry->creation_time); printf("Last Access Time = 0x%"PRIx64"\n", dentry->last_access_time); printf("Last Write Time = 0x%"PRIx64"\n", dentry->last_write_time); - printf("Hash = 0x"); - print_hash(dentry->hash); - putchar('\n'); + hash = dentry_stream_hash(dentry, 0); + if (hash) { + printf("Hash = 0x"); + print_hash(hash); + putchar('\n'); + } printf("Reparse Tag = 0x%"PRIx32"\n", dentry->reparse_tag); printf("Hard Link Group = 0x%"PRIx64"\n", dentry->hard_link); printf("Number of Alternate Data Streams = %hu\n", dentry->num_ads); @@ -446,25 +448,20 @@ int print_dentry(struct dentry *dentry, void *lookup_table) puts("\""); printf("Short Name Length = %hu\n", dentry->short_name_len); printf("Full Path (UTF-8) = \"%s\"\n", dentry->full_path_utf8); - if (lookup_table && (lte = __lookup_resource(lookup_table, dentry->hash))) - print_lookup_table_entry(lte, NULL); - else - putchar('\n'); + print_lookup_table_entry(dentry_stream_lte(dentry, 0, lookup_table)); for (u16 i = 0; i < dentry->num_ads; i++) { printf("[Alternate Stream Entry %u]\n", i); printf("Name = \"%s\"\n", dentry->ads_entries[i].stream_name_utf8); printf("Name Length (UTF-16) = %u\n", dentry->ads_entries[i].stream_name_len); - printf("Hash = 0x"); - print_hash(dentry->ads_entries[i].hash); - if (lookup_table && - (lte = __lookup_resource(lookup_table, - dentry->ads_entries[i].hash))) - { - print_lookup_table_entry(lte, NULL); - } else { + hash = dentry_stream_hash(dentry, i + 1); + if (hash) { + printf("Hash = 0x"); + print_hash(hash); putchar('\n'); } + print_lookup_table_entry(dentry_stream_lte(dentry, i + 1, + lookup_table)); } return 0; } @@ -579,24 +576,20 @@ struct dentry *clone_dentry(struct dentry *old) return new; } -/* Arguments for do_free_dentry(). */ -struct free_dentry_args { - struct lookup_table *lookup_table; - bool lt_decrement_refcnt; -}; - /* * This function is passed as an argument to for_dentry_in_tree_depth() in order * to free a directory tree. __args is a pointer to a `struct free_dentry_args'. */ -static int do_free_dentry(struct dentry *dentry, void *__args) +static int do_free_dentry(struct dentry *dentry, void *__lookup_table) { - struct free_dentry_args *args = (struct free_dentry_args*)__args; - - if (args->lt_decrement_refcnt && !dentry_is_directory(dentry)) { - wimlib_assert(!dentry->resolved); - lookup_table_decrement_refcnt(args->lookup_table, - dentry->hash); + struct lookup_table *lookup_table = __lookup_table; + if (lookup_table) { + struct lookup_table_entry *lte; + if (dentry->resolved) + lte = dentry->lte; + else + lte = __lookup_resource(lookup_table, dentry->hash); + lte_decrement_refcnt(lte, lookup_table); } wimlib_assert(dentry->refcnt != 0); @@ -609,20 +602,16 @@ static int do_free_dentry(struct dentry *dentry, void *__args) * Unlinks and frees a dentry tree. * * @root: The root of the tree. - * @lookup_table: The lookup table for dentries. - * @decrement_refcnt: True if the dentries in the tree are to have their - * reference counts in the lookup table decremented. + * @lookup_table: The lookup table for dentries. If non-NULL, the + * reference counts in the lookup table for the lookup + * table entries corresponding to the dentries will be + * decremented. */ -void free_dentry_tree(struct dentry *root, struct lookup_table *lookup_table, - bool lt_decrement_refcnt) +void free_dentry_tree(struct dentry *root, struct lookup_table *lookup_table) { if (!root || !root->parent) return; - - struct free_dentry_args args; - args.lookup_table = lookup_table; - args.lt_decrement_refcnt = lt_decrement_refcnt; - for_dentry_in_tree_depth(root, do_free_dentry, &args); + for_dentry_in_tree_depth(root, do_free_dentry, lookup_table); } int increment_dentry_refcnt(struct dentry *dentry, void *ignore) @@ -838,7 +827,7 @@ static int read_ads_entries(const u8 *p, struct dentry *dentry, DEBUG2("ADS length = %"PRIu64, length); p += 8; /* Unused */ - p = get_bytes(p, WIM_HASH_SIZE, (u8*)cur_entry->hash); + p = get_bytes(p, SHA1_HASH_SIZE, (u8*)cur_entry->hash); p = get_u16(p, &cur_entry->stream_name_len); DEBUG2("Stream name length = %u", cur_entry->stream_name_len); @@ -954,7 +943,7 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, p = get_u64(p, &dentry->last_access_time); p = get_u64(p, &dentry->last_write_time); - p = get_bytes(p, WIM_HASH_SIZE, dentry->hash); + p = get_bytes(p, SHA1_HASH_SIZE, dentry->hash); /* * I don't know what's going on here. It seems like M$ screwed up the @@ -1119,7 +1108,7 @@ static u8 *write_dentry(const struct dentry *dentry, u8 *p) hash = dentry->lte->hash; else hash = dentry->hash; - p = put_bytes(p, WIM_HASH_SIZE, hash); + p = put_bytes(p, SHA1_HASH_SIZE, hash); if (dentry->attributes & FILE_ATTRIBUTE_REPARSE_POINT) { p = put_zeroes(p, 4); p = put_u32(p, dentry->reparse_tag); @@ -1149,7 +1138,11 @@ static u8 *write_dentry(const struct dentry *dentry, u8 *p) for (u16 i = 0; i < dentry->num_ads; i++) { p = put_u64(p, ads_entry_length(&dentry->ads_entries[i])); p = put_u64(p, 0); /* Unused */ - p = put_bytes(p, WIM_HASH_SIZE, dentry->ads_entries[i].hash); + if (dentry->resolved && dentry->ads_entries[i].lte) + hash = dentry->ads_entries[i].lte->hash; + else + hash = dentry->ads_entries[i].hash; + p = put_bytes(p, SHA1_HASH_SIZE, hash); p = put_u16(p, dentry->ads_entries[i].stream_name_len); p = put_bytes(p, dentry->ads_entries[i].stream_name_len, (u8*)dentry->ads_entries[i].stream_name);