vfs: add dirent parent pointer

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-12 10:47:58 -04:00
commit d2c698ac0a
7 changed files with 25 additions and 13 deletions

View file

@ -11,8 +11,10 @@
static mem_cache_t *inode_slab = NULL;
static mem_cache_t *dirent_slab = NULL;
int inode_populate_dirents(inode_t *inode)
int dirent_populate_children(dirent_t *dir)
{
inode_t *inode = dir->inode;
write_lock(&inode->rwlock);
if (inode->dirents.head != NULL) {
@ -34,6 +36,8 @@ int inode_populate_dirents(inode_t *inode)
if (!insert)
goto cleanup;
insert->parent = dir;
if (!list_insert(&inode->dirents, insert)) {
dirent_free(insert);
goto cleanup;
@ -62,9 +66,9 @@ cleanup:
return -ENOMEM;
}
int inode_find_dirent_locked(inode_t *inode, const char *name, dirent_t **out)
int dirent_lookup_locked(dirent_t *dir, const char *name, dirent_t **out)
{
list_item_t *item = inode->dirents.head;
list_item_t *item = dir->inode->dirents.head;
while (item) {
dirent_t *dent = item->ptr;
if (!strcmp(dent->name, name)) {
@ -77,8 +81,10 @@ int inode_find_dirent_locked(inode_t *inode, const char *name, dirent_t **out)
return -ENOENT;
}
int inode_find_dirent(inode_t *inode, const char *name, dirent_t **out)
int dirent_lookup(dirent_t *dir, const char *name, dirent_t **out)
{
inode_t *inode = dir->inode;
if ((inode->mode & S_IFMT) != S_IFDIR)
return -ENOTDIR;
@ -86,13 +92,13 @@ int inode_find_dirent(inode_t *inode, const char *name, dirent_t **out)
if (inode->dirents.head == NULL) {
read_unlock(&inode->rwlock);
int res = inode_populate_dirents(inode);
int res = dirent_populate_children(dir);
if (res < 0)
return res;
read_lock(&inode->rwlock);
}
int ret = inode_find_dirent_locked(inode, name, out);
int ret = dirent_lookup_locked(dir, name, out);
read_unlock(&inode->rwlock);
return ret;
}
@ -203,6 +209,7 @@ dirent_t *dirent_dup(dirent_t *src)
ret->flags = src->flags;
ret->type = src->type;
ret->fs = src->fs;
ret->parent = src->parent;
if (src->inode) {
inode_inc_ref(src->inode);