From: Eric Biggers Date: Sun, 19 Aug 2012 05:02:46 +0000 (-0500) Subject: dentry_to_stbuf() fix X-Git-Tag: v1.0.0~137 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=72cc9a31b518ca830fcc7a2ed74a20415d6e13ec dentry_to_stbuf() fix --- diff --git a/src/dentry.c b/src/dentry.c index 095af557..e5362e1b 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -92,18 +92,13 @@ void dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf, else stbuf->st_mode = S_IFREG | 0644; - if (table) - lte = __lookup_resource(table, dentry_hash(dentry)); - else - lte = NULL; - - if (lte) { - stbuf->st_nlink = lte->refcnt; + /* Use the size of the unnamed (default) file stream. */ + if (table && (lte = __lookup_resource(table, dentry_hash(dentry)))) stbuf->st_size = lte->resource_entry.original_size; - } else { - stbuf->st_nlink = 1; + else stbuf->st_size = 0; - } + + stbuf->st_nlink = dentry_link_group_size(dentry); stbuf->st_uid = getuid(); stbuf->st_gid = getgid(); stbuf->st_atime = ms_timestamp_to_unix(dentry->last_access_time); diff --git a/src/dentry.h b/src/dentry.h index 50021322..469946f8 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -213,12 +213,14 @@ static inline const u8 *dentry_hash(const struct dentry *dentry) return dentry->hash; } -static inline size_t dentry_link_group_size(struct dentry *dentry) +static inline size_t dentry_link_group_size(const struct dentry *dentry) { size_t size = 0; struct list_head *list; list_for_each(list, &dentry->link_group_list) size++; + if (size == 0) + size = 1; return size; } diff --git a/src/hardlink.c b/src/hardlink.c index 67be5aab..a5d8b9fa 100644 --- a/src/hardlink.c +++ b/src/hardlink.c @@ -36,8 +36,10 @@ int link_group_table_insert(struct dentry *dentry, struct link_group_table *tabl size_t pos; struct link_group *group; - if (dentry->hard_link == 0) + if (dentry->hard_link == 0) { + INIT_LIST_HEAD(&dentry->link_group_list); return 0; + } /* Try adding to existing hard link group */ pos = dentry->hard_link % table->capacity; diff --git a/src/mount.c b/src/mount.c index 9e285c6c..984666e6 100644 --- a/src/mount.c +++ b/src/mount.c @@ -98,7 +98,7 @@ static int alloc_wimlib_fd(struct lookup_table_entry *lte, u16 num_new_fds; if (lte->num_allocated_fds == max_fds) - return -ENFILE; + return -EMFILE; num_new_fds = min(fds_per_alloc, max_fds - lte->num_allocated_fds); fds = CALLOC(lte->num_allocated_fds + num_new_fds,