fd table fix
authorEric Biggers <ebiggers3@gmail.com>
Sun, 19 Aug 2012 04:50:22 +0000 (23:50 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 19 Aug 2012 04:50:22 +0000 (23:50 -0500)
src/dentry.c
src/dentry.h
src/lookup_table.c
src/lookup_table.h
src/mount.c

index cf77adc765c6180100c43cbea5726a844ca86881..095af557f7a137eb98ea6774fa6c520469fd453e 100644 (file)
@@ -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)
index fd65b02dbab008d207434abbe023c6ce1cb7c31b..50021322f5cbbe0d6e1eebf15d377b3c5bd0b2cb 100644 (file)
@@ -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.  */
index 2177cb1bca25075945257373dcdcf3c516f2940a..9693cc1b8c823624821d88f62aa29cabb7899c1d 100644 (file)
@@ -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;
                                }
index 9e082c77761b7b9bbd727201b80fd48672006518..423af6dc702566b11cac42ce8745b25d7c6016f4 100644 (file)
@@ -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
index 3d0b6396d5c79622f787058c8592168b52bd13a1..9e285c6c739da4fc5191b42ac48a1347dcd8f209 100644 (file)
@@ -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;
                }