__dcache_hash(struct v_dnode* parent, uint32_t* hash)
{
uint32_t _hash = *hash;
- // 与parent的指针值做加法,来减小碰撞的可能性。
- _hash += (uint32_t)parent;
// 确保低位更加随机
_hash = _hash ^ (_hash >> VFS_HASHBITS);
+ // 与parent的指针值做加法,来减小碰撞的可能性。
+ _hash += (uint32_t)parent;
*hash = _hash;
return &dnode_cache[_hash & VFS_HASH_MASK];
}
assert(dnode->ref_count == 1);
llist_delete(&dnode->siblings);
+ llist_delete(&dnode->aka_list);
hlist_delete(&dnode->hash_list);
dnode->parent = NULL;
vfs_assign_inode(struct v_dnode* assign_to, struct v_inode* inode)
{
if (assign_to->inode) {
+ llist_delete(&assign_to->aka_list);
assign_to->inode->link_count--;
}
+ llist_append(&inode->aka_dnodes, &assign_to->aka_list);
assign_to->inode = inode;
inode->link_count++;
}
return vfs_pclose(file, __current->pid);
}
+void
+vfs_free_fd(struct v_fd* fd)
+{
+ cake_release(fd_pile, fd);
+}
+
int
vfs_fsync(struct v_file* file)
{
memset(dnode, 0, sizeof(*dnode));
llist_init_head(&dnode->children);
llist_init_head(&dnode->siblings);
+ llist_init_head(&dnode->aka_list);
mutex_init(&dnode->lock);
dnode->ref_count = ATOMIC_VAR_INIT(0);
memset(inode, 0, sizeof(*inode));
mutex_init(&inode->lock);
llist_init_head(&inode->xattrs);
+ llist_init_head(&inode->aka_dnodes);
sb->ops.init_inode(sb, inode);
struct v_inode* o_inode = ofile->inode;
if (!errno && !(errno = vfs_alloc_fdslot(&fd))) {
- struct v_fd* fd_s = vzalloc(sizeof(*fd_s));
+ struct v_fd* fd_s = cake_grab(fd_pile);
+ memset(fd_s, 0, sizeof(*fd_s));
+
ofile->f_pos = ofile->inode->fsize & -((options & FO_APPEND) != 0);
fd_s->file = ofile;
fd_s->flags = options;
goto done_err;
}
- vfree(fd_s);
+ cake_release(fd_pile, fd_s);
__current->fdtable->fds[fd] = 0;
done_err: