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);
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;
}
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;
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,