stat: fit AT_EMPTY_PATH

This commit is contained in:
Matheus
2026-06-28 11:45:17 -03:00
parent 13ccd19c1f
commit 85e12f7e7b
+20 -5
View File
@@ -65,7 +65,24 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
if (ret.errno) if (ret.errno)
return ret; return ret;
char *path = alloc(pathlen + 1); vnode_t *node = NULL;
vnode_t *dirnode = NULL;
file_t *file = NULL;
char *path = NULL;
if (pathlen == 0 && (flags & AT_EMPTY_PATH)) {
file = fd_get(dirfd);
if (file == NULL) {
ret.errno = EBADF;
goto cleanup;
}
node = file->vnode;
VOP_HOLD(node);
fd_release(file);
VOP_LOCK(node);
file = NULL;
} else {
path = alloc(pathlen + 1);
if (path == NULL) { if (path == NULL) {
ret.errno = ENOMEM; ret.errno = ENOMEM;
return ret; return ret;
@@ -77,9 +94,6 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
return ret; return ret;
} }
vnode_t *node = NULL;
vnode_t *dirnode = NULL;
file_t *file = NULL;
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode); ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
@@ -87,10 +101,10 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0); ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
}
stat_t buf; stat_t buf;
ret.errno = dostat(node, &buf); ret.errno = dostat(node, &buf);
// locked by vfs_lookup
VOP_UNLOCK(node); VOP_UNLOCK(node);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
@@ -105,6 +119,7 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
if (dirnode) if (dirnode)
dirfd_leave(dirnode, file); dirfd_leave(dirnode, file);
if (path)
free(path); free(path);
return ret; return ret;