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)
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. */
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;
}
/* 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
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;
}