syscalls: make the *at syscalls use the dirfd_enter and dirfd_leave functions

This commit is contained in:
Matheus
2023-07-06 19:59:19 -03:00
parent c769735068
commit fd9f9b65fe
6 changed files with 25 additions and 115 deletions
+5 -22
View File
@@ -68,24 +68,9 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
vnode_t *dirnode = NULL;
file_t *file = NULL;
if (*path == '/') {
dirnode = sched_getroot();
} else if (dirfd == AT_FDCWD) {
dirnode = sched_getcwd();
} else {
file = fd_get(dirfd);
if (file == NULL) {
ret.errno = EBADF;
goto cleanup;
}
dirnode = file->vnode;
if (dirnode->type != V_TYPE_DIR) {
ret.errno = ENOTDIR;
goto cleanup;
}
}
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
if (ret.errno)
goto cleanup;
vnode_t *node = NULL;
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
@@ -105,10 +90,8 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
if (node)
VOP_RELEASE(node);
if (file)
fd_release(file);
else
VOP_RELEASE(dirnode);
if (dirnode)
dirfd_leave(dirnode, file);
free(path);