From: Eric Biggers Date: Sun, 19 Aug 2012 04:50:22 +0000 (-0500) Subject: fd table fix X-Git-Tag: v1.0.0~138 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=3c849b4c439224b08183413f34cf97c3ab0721a3 fd table fix --- diff --git a/src/dentry.c b/src/dentry.c index cf77adc7..095af557 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -51,14 +51,6 @@ static bool dentry_has_name(const struct dentry *dentry, const char *name, return memcmp(dentry->file_name_utf8, name, name_len) == 0; } -static bool ads_entry_has_name(const struct ads_entry *entry, - const char *name, size_t name_len) -{ - if (entry->stream_name_utf8_len != name_len) - return false; - return memcmp(entry->stream_name_utf8, name, name_len) == 0; -} - /* Real length of a dentry, including the alternate data stream entries, which * are not included in the dentry->length field... */ u64 dentry_total_length(const struct dentry *dentry) diff --git a/src/dentry.h b/src/dentry.h index fd65b02d..50021322 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -83,6 +83,14 @@ static inline void destroy_ads_entry(struct ads_entry *entry) memset(entry, 0, sizeof(entry)); } +static inline bool ads_entry_has_name(const struct ads_entry *entry, + const char *name, size_t name_len) +{ + if (entry->stream_name_utf8_len != name_len) + return false; + return memcmp(entry->stream_name_utf8, name, name_len) == 0; +} + /* In-memory structure for a directory entry. There is a directory tree for * each image in the WIM. */ diff --git a/src/lookup_table.c b/src/lookup_table.c index 2177cb1b..9693cc1b 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -370,8 +370,12 @@ int lookup_resource(WIMStruct *w, const char *path, if (lookup_flags & LOOKUP_FLAG_ADS_OK) { const char *stream_name = path_stream_name(path); if (stream_name) { + size_t stream_name_len = strlen(stream_name); for (u16 i = 0; i < dentry->num_ads; i++) { - if (strcmp(stream_name, dentry->ads_entries[i].stream_name) == 0) { + if (ads_entry_has_name(&dentry->ads_entries[i], + stream_name, + stream_name_len)) + { hash = dentry->ads_entries[i].hash; goto do_lookup; } diff --git a/src/lookup_table.h b/src/lookup_table.h index 9e082c77..423af6dc 100644 --- a/src/lookup_table.h +++ b/src/lookup_table.h @@ -82,9 +82,11 @@ struct lookup_table_entry { /* Compression type used in other WIM. */ int other_wim_ctype; }; - struct wimlib_fd **fds; - u16 num_allocated_fds; - u16 num_opened_fds; + struct { + struct wimlib_fd **fds; + u16 num_allocated_fds; + u16 num_opened_fds; + }; }; /* When a WIM file is written, out_refcnt starts at 0 and is incremented diff --git a/src/mount.c b/src/mount.c index 3d0b6396..9e285c6c 100644 --- a/src/mount.c +++ b/src/mount.c @@ -90,29 +90,37 @@ static inline int flags_writable(int open_flags) static int alloc_wimlib_fd(struct lookup_table_entry *lte, struct wimlib_fd **fd_ret) { + static const u16 fds_per_alloc = 8; + static const u16 max_fds = 0xffff; + if (lte->num_opened_fds == lte->num_allocated_fds) { struct wimlib_fd **fds; - if (lte->num_allocated_fds > 0xffff - 8) + u16 num_new_fds; + + if (lte->num_allocated_fds == max_fds) return -ENFILE; + num_new_fds = min(fds_per_alloc, max_fds - lte->num_allocated_fds); - fds = CALLOC(lte->num_allocated_fds + 8, sizeof(lte->fds[0])); + fds = CALLOC(lte->num_allocated_fds + num_new_fds, + sizeof(lte->fds[0])); if (!fds) return -ENOMEM; memcpy(fds, lte->fds, lte->num_allocated_fds * sizeof(lte->fds[0])); FREE(lte->fds); lte->fds = fds; + lte->num_allocated_fds += num_new_fds; } for (u16 i = 0; ; i++) { - struct wimlib_fd *fd = lte->fds[i]; - if (!fd) { - fd = CALLOC(1, sizeof(*fd)); + if (!lte->fds[i]) { + struct wimlib_fd *fd = CALLOC(1, sizeof(*fd)); if (!fd) return -ENOMEM; fd->staging_fd = -1; fd->idx = i; fd->lte = lte; lte->fds[i] = fd; + lte->num_opened_fds++; *fd_ret = fd; return 0; }