From 0bf41495dd9e04585be10794d7745a5baa7165a5 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 20 Aug 2012 01:05:57 -0500 Subject: [PATCH] pre-resolve streams (IN PROGRESS) --- src/dentry.c | 58 +++------- src/dentry.h | 45 ++++++-- src/lookup_table.c | 72 +++++++++++- src/lookup_table.h | 14 ++- src/modify.c | 3 +- src/mount.c | 259 ++++++++++++++++++++++++++++++++++-------- src/symlink.c | 5 +- src/wimlib_internal.h | 3 +- 8 files changed, 349 insertions(+), 110 deletions(-) diff --git a/src/dentry.c b/src/dentry.c index 35c17a48..eb283688 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -80,45 +80,6 @@ void stbuf_to_dentry(const struct stat *stbuf, struct dentry *dentry) ((u64)stbuf->st_dev << (sizeof(ino_t) * 8)); } -/* Transfers file attributes from a struct dentry to a `stat' buffer. */ -int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf, - const struct lookup_table *table) -{ - struct lookup_table_entry *lte; - - if (dentry_is_symlink(dentry)) - stbuf->st_mode = S_IFLNK | 0777; - else if (dentry_is_directory(dentry)) - stbuf->st_mode = S_IFDIR | 0755; - else - stbuf->st_mode = S_IFREG | 0644; - - stbuf->st_ino = (ino_t)dentry->hard_link; - - stbuf->st_nlink = dentry_link_group_size(dentry); - stbuf->st_uid = getuid(); - stbuf->st_gid = getgid(); - - /* Use the size of the unnamed (default) file stream. */ - if (table && (lte = __lookup_resource(table, dentry_hash(dentry)))) { - if (lte->staging_file_name) { - struct stat native_stat; - if (stat(lte->staging_file_name, &native_stat) != 0) - return -errno; - stbuf->st_size = native_stat.st_size; - } else { - stbuf->st_size = lte->resource_entry.original_size; - } - } else { - stbuf->st_size = 0; - } - - stbuf->st_atime = ms_timestamp_to_unix(dentry->last_access_time); - stbuf->st_mtime = ms_timestamp_to_unix(dentry->last_write_time); - stbuf->st_ctime = ms_timestamp_to_unix(dentry->creation_time); - stbuf->st_blocks = (stbuf->st_size + 511) / 512; - return 0; -} /* Makes all timestamp fields for the dentry be the current time. */ void dentry_update_all_timestamps(struct dentry *dentry) @@ -169,12 +130,21 @@ struct ads_entry *dentry_add_ads(struct dentry *dentry, const char *stream_name) return memset(new_entry, 0, sizeof(struct ads_entry)); } -void dentry_remove_ads(struct dentry *dentry, struct ads_entry *sentry) +void dentry_remove_ads(struct dentry *dentry, struct ads_entry *ads_entry) { - destroy_ads_entry(sentry); - memcpy(sentry, sentry + 1, - (dentry->num_ads - (sentry - dentry->ads_entries + 1)) - * sizeof(struct ads_entry)); + u16 idx = ads_entry - dentry->ads_entries; + u16 following = dentry->num_ads - idx - 1; + + destroy_ads_entry(ads_entry); + memcpy(ads_entry, ads_entry + 1, following * sizeof(struct ads_entry)); + + /* We moved the ADS entries. Adjust the stream lists. */ + for (u16 i = 0; i < following; i++) { + struct list_head *cur = &ads_entry[i].lte_group_list.list; + cur->prev->next = cur; + cur->next->prev = cur; + } + dentry->num_ads--; } diff --git a/src/dentry.h b/src/dentry.h index 16cf5f37..96128363 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -52,10 +52,18 @@ typedef struct WIMStruct WIMStruct; #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 #define FILE_ATTRIBUTE_VIRTUAL 0x00010000 +struct lookup_table_entry; + /* Alternate data stream entry */ struct ads_entry { - /* SHA-1 message digest of stream contents */ - u8 hash[WIM_HASH_SIZE]; + union { + /* SHA-1 message digest of stream contents */ + u8 hash[WIM_HASH_SIZE]; + + /* The corresponding lookup table entry (only for resolved + * streams) */ + struct lookup_table_entry *lte; + }; /* Length of stream name (UTF-16) */ u16 stream_name_len; @@ -68,6 +76,8 @@ struct ads_entry { /* Stream name (UTF-8) */ char *stream_name_utf8; + + struct stream_list_head lte_group_list; }; static inline u64 ads_entry_length(const struct ads_entry *entry) @@ -137,8 +147,16 @@ struct dentry { u64 last_access_time; u64 last_write_time; - /* A hash of the file's contents. */ - u8 hash[WIM_HASH_SIZE]; + /* A hash of the file's contents, or a pointer to the lookup table entry + * for this dentry if the lookup table entries have been resolved. + * + * More specifically, this is for the un-named default file stream, as + * opposed to the alternate file streams, which may have their own + * lookup table entries. */ + union { + u8 hash[WIM_HASH_SIZE]; + struct lookup_table_entry *lte; + }; /* Identity of a reparse point. See * http://msdn.microsoft.com/en-us/library/windows/desktop/aa365503(v=vs.85).aspx @@ -200,7 +218,7 @@ struct dentry { enum { /* This dentry is the owner of its ads_entries, although it may * be in a hard link set */ - GROUP_INDEPENDENT, + GROUP_INDEPENDENT = 0, /* This dentry is the owner of the ads_entries in the hard link * set */ @@ -215,6 +233,9 @@ struct dentry { /* List of dentries in the hard link set */ struct list_head link_group_list; + /* List of dentries sharing the same lookup table entry */ + struct stream_list_head lte_group_list; + /* Path to extracted file on disk (used during extraction only) */ char *extracted_file; }; @@ -232,6 +253,17 @@ static inline const u8 *dentry_hash(const struct dentry *dentry) return dentry->hash; } +/* Return lte for the "unnamed" (default) data stream. Only for resolved + * dentries */ +static inline struct lookup_table_entry * +dentry_lte(const struct dentry *dentry) +{ + for (u16 i = 0; i < dentry->num_ads; i++) + if (dentry->ads_entries[i].stream_name_len == 0) + return dentry->ads_entries[i].lte; + return dentry->lte; +} + static inline size_t dentry_link_group_size(const struct dentry *dentry) { const struct list_head *cur = &dentry->link_group_list; @@ -257,9 +289,6 @@ extern u64 dentry_total_length(const struct dentry *dentry); extern void stbuf_to_dentry(const struct stat *stbuf, struct dentry *dentry); -extern int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf, - const struct lookup_table *table); - extern int for_dentry_in_tree(struct dentry *root, int (*visitor)(struct dentry*, void*), void *args); diff --git a/src/lookup_table.c b/src/lookup_table.c index d3ed5854..e0cfaaf9 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -157,6 +157,22 @@ 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) +{ + wimlib_assert(lte->refcnt); + if (lte && --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,6 +383,7 @@ __lookup_resource(const struct lookup_table *lookup_table, const u8 hash[]) return NULL; } +/* Only for resolved lte's */ int lookup_resource(WIMStruct *w, const char *path, int lookup_flags, struct dentry **dentry_ret, @@ -376,7 +393,7 @@ int lookup_resource(WIMStruct *w, const char *path, struct dentry *dentry = get_dentry(w, path); struct lookup_table_entry *lte; unsigned stream_idx = 0; - const u8 *hash = dentry->hash; + lte = dentry->lte; if (!dentry) return -ENOENT; if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK) @@ -392,15 +409,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 +425,49 @@ do_lookup: *stream_idx_ret = stream_idx; return 0; } + +static int lte_init_lte_group_list(struct lookup_table_entry *lte, void *ignore) +{ + INIT_LIST_HEAD(<e->lte_group_list); + return 0; +} + +/* Resolve a dentry's lookup table entries */ +static int dentry_resolve_ltes(struct dentry *dentry, void *__table) +{ + struct lookup_table *table = __table; + struct lookup_table_entry *lte; + + /* 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_group_list.type = STREAM_TYPE_NORMAL; + dentry->lte = lte; + + /* Alternate data streams */ + if (dentry->link_group_master_status != GROUP_SLAVE) { + 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; +} + +/* Resolve all the lookup table entries of a dentry tree */ +void resolve_lookup_table_entries(struct dentry *root, struct lookup_table *table) +{ + for_lookup_table_entry(table, lte_init_lte_group_list, NULL); + for_dentry_in_tree(root, dentry_resolve_ltes, table); +} diff --git a/src/lookup_table.h b/src/lookup_table.h index df780a09..b59eff22 100644 --- a/src/lookup_table.h +++ b/src/lookup_table.h @@ -23,6 +23,7 @@ struct lookup_table { struct wimlib_fd; + /* An entry in the lookup table in the WIM file. */ struct lookup_table_entry { @@ -102,9 +103,11 @@ struct lookup_table_entry { u32 out_refcnt; union { struct resource_entry output_resource_entry; - struct list_head staging_list; + struct { + struct list_head staging_list; + struct list_head lte_group_list; + }; }; - struct dentry *hard_link_sets; }; extern struct lookup_table *new_lookup_table(size_t capacity); @@ -118,6 +121,10 @@ extern void lookup_table_unlink(struct lookup_table *table, extern struct lookup_table_entry * lookup_table_decrement_refcnt(struct lookup_table* table, const u8 hash[]); +extern struct lookup_table_entry * +lte_decrement_refcnt(struct lookup_table_entry *lte, + struct lookup_table *table); + extern struct lookup_table_entry *new_lookup_table_entry(); @@ -146,6 +153,9 @@ extern int write_lookup_table_entry(struct lookup_table_entry *lte, void *__out) extern void free_lookup_table_entry(struct lookup_table_entry *lte); +extern void resolve_lookup_table_entries(struct dentry *root, + struct lookup_table *table); + /* Writes the lookup table to the output file. */ static inline int write_lookup_table(struct lookup_table *table, FILE *out) { diff --git a/src/modify.c b/src/modify.c index 744ab2d7..41c745b4 100644 --- a/src/modify.c +++ b/src/modify.c @@ -153,7 +153,8 @@ static int build_dentry_tree(struct dentry *root, const char *root_disk_path, } deref_name_buf[ret] = '\0'; DEBUG("Read symlink `%s'", deref_name_buf); - ret = dentry_set_symlink(root, deref_name_buf, lookup_table); + ret = dentry_set_symlink(root, deref_name_buf, + lookup_table, NULL); } else { /* Regular file */ struct lookup_table_entry *lte; diff --git a/src/mount.c b/src/mount.c index fd386a8e..ca6197ce 100644 --- a/src/mount.c +++ b/src/mount.c @@ -194,6 +194,46 @@ static void dentry_increment_lookup_table_refcnts(struct dentry *dentry, } } +/* Transfers file attributes from a struct dentry to a `stat' buffer. */ +int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf) +{ + struct lookup_table_entry *lte; + + if (dentry_is_symlink(dentry)) + stbuf->st_mode = S_IFLNK | 0777; + else if (dentry_is_directory(dentry)) + stbuf->st_mode = S_IFDIR | 0755; + else + stbuf->st_mode = S_IFREG | 0644; + + stbuf->st_ino = (ino_t)dentry->hard_link; + + stbuf->st_nlink = dentry_link_group_size(dentry); + stbuf->st_uid = getuid(); + stbuf->st_gid = getgid(); + + /* Use the size of the unnamed (default) file stream. */ + if ((lte = dentry_lte(dentry))) { + if (lte->staging_file_name) { + struct stat native_stat; + if (stat(lte->staging_file_name, &native_stat) != 0) + return -errno; + stbuf->st_size = native_stat.st_size; + } else { + stbuf->st_size = lte->resource_entry.original_size; + } + } else { + stbuf->st_size = 0; + } + + stbuf->st_atime = ms_timestamp_to_unix(dentry->last_access_time); + stbuf->st_mtime = ms_timestamp_to_unix(dentry->last_write_time); + stbuf->st_ctime = ms_timestamp_to_unix(dentry->creation_time); + stbuf->st_blocks = (stbuf->st_size + 511) / 512; + return 0; +} + +#if 0 /* Change the hash value of the main or alternate file stream in a hard link * group. This needs to be done if the hash of the corresponding lookup table * entry was changed. */ @@ -219,6 +259,7 @@ static void link_group_set_stream_hash(struct dentry *dentry, WIM_HASH_SIZE); } } +#endif /* Creates a new staging file and returns its file descriptor opened for * writing. @@ -275,6 +316,152 @@ static int create_staging_file(char **name_ret, int open_flags) return fd; } +/* Removes open file descriptors from a lookup table entry @old_lte where the + * file descriptors have opened the corresponding file resource in the context + * of the hard link group @link_group; these file descriptors are extracted and + * placed in a new lookup table entry, which is returned. */ +static struct lookup_table_entry * +lte_extract_fds(struct lookup_table_entry *old_lte, u64 link_group) +{ + int ret; + u16 num_transferred_fds; + struct lookup_table_entry *new_lte; + + new_lte = new_lookup_table_entry(); + if (!new_lte) + return NULL; + + num_transferred_fds = 0; + for (u16 i = 0; i < old_lte->num_allocated_fds; i++) + if (old_lte->fds[i] && + old_lte->fds[i]->dentry->hard_link == link_group) + num_transferred_fds++; + DEBUG("Transferring %u file descriptors", + num_transferred_fds); + new_lte->fds = MALLOC(num_transferred_fds * sizeof(new_lte->fds[0])); + if (!new_lte->fds) { + FREE(new_lte); + return NULL; + } + for (u16 i = 0, j = 0; ; i++) { + if (old_lte->fds[i] && + old_lte->fds[i]->dentry->hard_link == link_group) { + struct wimlib_fd *fd = old_lte->fds[i]; + old_lte->fds[i] = NULL; + fd->lte = new_lte; + fd->idx = j; + new_lte->fds[j] = fd; + if (++j == num_transferred_fds) + break; + } + } + old_lte->num_opened_fds -= num_transferred_fds; + new_lte->num_opened_fds = num_transferred_fds; + new_lte->num_allocated_fds = num_transferred_fds; + return new_lte; +} + +/* + * Transfers an alternate data stream entry to a new lookup table entry + */ +static void lte_transfer_ads_entry(struct lookup_table_entry *new_lte, + struct ads_entry *ads_entry) +{ + list_del(&ads_entry->lte_group_list.list); + list_add(&ads_entry->lte_group_list.list, &new_lte->lte_group_list); + ads_entry->lte = new_lte; +} + +/* + * Transfers a dentry to a new lookup table entry + */ +static void lte_transfer_dentry(struct lookup_table_entry *new_lte, + struct dentry *dentry) +{ + list_del(&dentry->lte_group_list.list); + list_add(&dentry->lte_group_list.list, &new_lte->lte_group_list); + dentry->lte = new_lte; +} + +static void lte_transfer_stream_entries(struct lookup_table_entry *new_lte, + struct dentry *dentry, + unsigned stream_idx) +{ + INIT_LIST_HEAD(&new_lte->lte_group_list); + if (stream_idx == 0) { + struct list_head *pos; + do { + struct dentry *d; + d = container_of(pos, struct dentry, link_group_list); + lte_transfer_dentry(new_lte, d); + + pos = pos->next; + } while (pos != &dentry->link_group_list); + } else { + struct ads_entry *ads_entry; + ads_entry = &dentry->ads_entries[stream_idx - 1]; + lte_transfer_ads_entry(new_lte, ads_entry); + } +} + +#if 0 +/* + * Transfers streams part of a hard-link group from @old_lte to @new_lte. + * + * @dentry is one of the dentries in the hard link group + * @stream_idx is the index of the stream that we're transferring. + */ +static void lte_transfer_stream_entries(struct lookup_table_entry *old_lte, + struct lookup_table_entry *new_lte, + struct dentry *dentry, unsigned stream_idx) +{ + INIT_LIST_HEAD(&new_lte->lte_group_list); + + if (stream_idx == 0) { + struct list_head *pos; + struct stream_list_head *head; + struct dentry *other_dentry; + list_for_each(pos, &old_lte->lte_group_list) { + head = container_of(pos, struct stream_list_head, head); + if (head->type != STREAM_TYPE_NORMAL) { + continue; + other_dentry = container_of(head, struct dentry, + lte_group_list); + if (other_dentry->hard_link != dentry->link_group) + continue; + + list_del(&other_dentry->lte_group_list.list); + list_add(&other_dentry->lte_group_list.list, + &new_lte->lte_group_list); + other_dentry->lte = new_lte; + } + } else { + /* ADS entries are shared within a hard link group. */ + lte_load_ads_entry(new_lte, &dentry->ads_entries[stream_idx - 1]); + } +} +static void lte__stream_entries(struct lookup_table_entry *new_lte, + struct dentry *dentry, unsigned stream_idx) +{ + INIT_LIST_HEAD(new_lte->lte_group_list); + if (stream_idx == 0) { + struct list_head *cur; + do { + struct dentry *d; + + d = container_of(cur, struct dentry, link_group_list); + list_del(&d->lte_group_list); + list_add(&d->lte_group_list, &new_lte->lte_group_list); + d->lte = new_lte; + cur = cur->next; + } while (cur != &dentry->link_group_list); + } else { + lte_load_ads_entry(new_lte, &dentry->ads_entries[stream_idx - 1]); + } +} +#endif + + /* * Extract a WIM resource to the staging directory. * @@ -287,6 +474,7 @@ static int create_staging_file(char **name_ret, int open_flags) * dentry */ static int extract_resource_to_staging_dir(struct dentry *dentry, + unsigned stream_idx, struct lookup_table_entry **lte, off_t size) { @@ -343,48 +531,14 @@ static int extract_resource_to_staging_dir(struct dentry *dentry, * streams themselves are not hardlinked. */ wimlib_assert(old_lte->refcnt > link_group_size); - new_lte = new_lookup_table_entry(); + new_lte = lte_extract_fds(old_lte, dentry->hard_link); if (!new_lte) { ret = -ENOMEM; goto out_delete_staging_file; } - u16 num_transferred_fds = 0; - for (u16 i = 0; i < old_lte->num_allocated_fds; i++) { - if (old_lte->fds[i] && - old_lte->fds[i]->dentry->hard_link == - dentry->hard_link) - { - num_transferred_fds++; - } - } - DEBUG("Transferring %u file descriptors", - num_transferred_fds); - new_lte->fds = MALLOC(num_transferred_fds * - sizeof(new_lte->fds[0])); - if (!new_lte->fds) { - FREE(new_lte); - ret = -ENOMEM; - goto out_delete_staging_file; - } - for (u16 i = 0, j = 0; ; i++) { - if (old_lte->fds[i] && - old_lte->fds[i]->dentry->hard_link == - dentry->hard_link) - { - struct wimlib_fd *fd = old_lte->fds[i]; - old_lte->fds[i] = NULL; - fd->lte = new_lte; - fd->idx = j; - new_lte->fds[j] = fd; - if (++j == num_transferred_fds) - break; - } - } + lte_transfer_stream_entries(new_lte, dentry, stream_idx); old_lte->refcnt -= link_group_size; - old_lte->num_opened_fds -= num_transferred_fds; - new_lte->num_opened_fds = num_transferred_fds; - new_lte->num_allocated_fds = num_transferred_fds; } } else { /* No old_lte was supplied, so the resource had no lookup table @@ -394,6 +548,7 @@ static int extract_resource_to_staging_dir(struct dentry *dentry, ret = -ENOMEM; goto out_delete_staging_file; } + lte_transfer_stream_entries(new_lte, dentry, stream_idx); } new_lte->resource_entry.original_size = size; new_lte->refcnt = link_group_size; @@ -821,7 +976,7 @@ static int wimfs_fgetattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) { struct wimlib_fd *fd = (struct wimlib_fd*)fi->fh; - return dentry_to_stbuf(fd->dentry, stbuf, w->lookup_table); + return dentry_to_stbuf(fd->dentry, stbuf); } static int wimfs_ftruncate(const char *path, off_t size, @@ -843,7 +998,7 @@ static int wimfs_getattr(const char *path, struct stat *stbuf) struct dentry *dentry = get_dentry(w, path); if (!dentry) return -ENOENT; - return dentry_to_stbuf(dentry, stbuf, w->lookup_table); + return dentry_to_stbuf(dentry, stbuf); } static int wimfs_getxattr(const char *path, const char *name, char *value, @@ -991,10 +1146,10 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi) return 0; } - ret = extract_resource_to_staging_dir(dentry, <e, 0); + ret = extract_resource_to_staging_dir(dentry, stream_idx, + <e, 0); if (ret != 0) return ret; - link_group_set_stream_hash(dentry, stream_idx, lte->hash); } ret = alloc_wimlib_fd(lte, &fd); @@ -1011,11 +1166,10 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi) * but we need to extract the resource to the staging directory * if we are opening it writable. */ if (flags_writable(fi->flags) && !lte->staging_file_name) { - ret = extract_resource_to_staging_dir(dentry, <e, + ret = extract_resource_to_staging_dir(dentry, stream_idx, <e, lte->resource_entry.original_size); if (ret != 0) return ret; - link_group_set_stream_hash(dentry, stream_idx, lte->hash); } if (lte->staging_file_name) { fd->staging_fd = open(lte->staging_file_name, fi->flags); @@ -1267,6 +1421,7 @@ static int wimfs_symlink(const char *to, const char *from) { struct dentry *dentry_parent, *dentry; const char *link_name; + struct lookup_table_entry *lte; dentry_parent = get_parent_dentry(w, from); if (!dentry_parent) @@ -1285,9 +1440,14 @@ static int wimfs_symlink(const char *to, const char *from) dentry->attributes = FILE_ATTRIBUTE_REPARSE_POINT; dentry->reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK; - if (dentry_set_symlink(dentry, to, w->lookup_table) != 0) + if (dentry_set_symlink(dentry, to, w->lookup_table, <e) != 0) goto out_free_dentry; + dentry->ads_entries[1].lte_group_list.type = STREAM_TYPE_ADS; + list_add(&dentry->ads_entries[1].lte_group_list.list, + <e->lte_group_list); + dentry->ads_entries[1].lte = lte; + link_dentry(dentry, dentry_parent); return 0; out_free_dentry: @@ -1302,9 +1462,10 @@ static int wimfs_truncate(const char *path, off_t size) struct dentry *dentry; struct lookup_table_entry *lte; int ret; + unsigned stream_idx; ret = lookup_resource(w, path, get_lookup_flags(), &dentry, - <e, NULL); + <e, &stream_idx); if (ret != 0) return ret; @@ -1320,7 +1481,8 @@ static int wimfs_truncate(const char *path, off_t size) } else { /* File in WIM. Extract it to the staging directory, but only * the first @size bytes of it. */ - ret = extract_resource_to_staging_dir(dentry, <e, size); + ret = extract_resource_to_staging_dir(dentry, stream_idx, + <e, size); } dentry_update_all_timestamps(dentry); return ret; @@ -1350,9 +1512,8 @@ static int wimfs_unlink(const char *path) struct ads_entry *ads_entry; ads_entry = &dentry->ads_entries[stream_idx - 1]; - - lookup_table_decrement_refcnt(w->lookup_table, ads_entry->hash); - + lte_decrement_refcnt(lte, w->lookup_table); + list_del(&ads_entry->lte_group_list.list); dentry_remove_ads(dentry, ads_entry); } /* Beware: The lookup table entry(s) may still be referenced by users @@ -1459,6 +1620,8 @@ WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir, next_link_group_id = assign_link_groups(wim->image_metadata[image - 1].lgt); + resolve_lookup_table_entries(wim_root_dentry(wim), w->lookup_table); + if (flags & WIMLIB_MOUNT_FLAG_READWRITE) wim_get_current_image_metadata(wim)->modified = true; diff --git a/src/symlink.c b/src/symlink.c index e7163e58..c94ba750 100644 --- a/src/symlink.c +++ b/src/symlink.c @@ -184,7 +184,8 @@ static int dentry_set_symlink_buf(struct dentry *dentry, } int dentry_set_symlink(struct dentry *dentry, const char *target, - struct lookup_table *lookup_table) + struct lookup_table *lookup_table, + struct lookup_table_entry **lte_ret) { int ret; @@ -229,6 +230,8 @@ int dentry_set_symlink(struct dentry *dentry, const char *target, if (!existing_lte) lookup_table_insert(lookup_table, lte); + if (lte_ret) + *lte_ret = lte; return 0; out_free_lte: FREE(lte); diff --git a/src/wimlib_internal.h b/src/wimlib_internal.h index 03e76929..40ff8427 100644 --- a/src/wimlib_internal.h +++ b/src/wimlib_internal.h @@ -404,7 +404,8 @@ extern void *make_symlink_reparse_data_buf(const char *symlink_target, size_t *len_ret); extern int dentry_set_symlink(struct dentry *dentry, const char *target, - struct lookup_table *lookup_table); + struct lookup_table *lookup_table, + struct lookup_table_entry **lte_ret); /* wim.c */ extern WIMStruct *new_wim_struct(); -- 2.43.0