vfs: switch to dirent tracking over inode tracking

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-02 22:09:05 +02:00
commit f9d760993d
4 changed files with 77 additions and 62 deletions

View file

@ -98,22 +98,37 @@ void inode_inc_ref(inode_t *inode)
void inode_dec_ref(inode_t *inode)
{
if (!inode)
return;
write_lock(&inode->rwlock);
inode->refcount -= 1;
if (inode->refcount == 0) {
if (inode->parent_inode) {
write_lock(&inode->parent_inode->rwlock);
inode_dec_ref(inode->parent_inode);
write_unlock(&inode->parent_inode->rwlock);
}
inode->fs->fs_ops.free_inode(inode->fs, inode);
inode_free(inode);
return;
}
write_unlock(&inode->rwlock);
}
void dirent_inc_ref(dirent_t *dent)
{
spinlock_acquire(&dent->lock);
dent->refcount += 1;
spinlock_release(&dent->lock);
}
void dirent_dec_ref(dirent_t *dent)
{
spinlock_acquire(&dent->lock);
dent->refcount -= 1;
if (dent->refcount == 0) {
inode_dec_ref(dent->inode);
dirent_free(dent);
return;
}
spinlock_release(&dent->lock);
}
dirent_t *dirent_create(const char *name)
{
dirent_t *ret = slab_alloc(dirent_slab);