mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
stat: fit AT_EMPTY_PATH
This commit is contained in:
@@ -65,32 +65,46 @@ 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);
|
|
||||||
if (path == NULL) {
|
|
||||||
ret.errno = ENOMEM;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.errno = usercopy_fromuser(path, upath, pathlen);
|
|
||||||
if (ret.errno) {
|
|
||||||
free(path);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
vnode_t *node = NULL;
|
vnode_t *node = NULL;
|
||||||
vnode_t *dirnode = NULL;
|
vnode_t *dirnode = NULL;
|
||||||
file_t *file = NULL;
|
file_t *file = NULL;
|
||||||
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
char *path = NULL;
|
||||||
if (ret.errno)
|
if (pathlen == 0 && (flags & AT_EMPTY_PATH)) {
|
||||||
goto cleanup;
|
file = fd_get(dirfd);
|
||||||
|
if (file == NULL) {
|
||||||
|
ret.errno = EBADF;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
|
node = file->vnode;
|
||||||
if (ret.errno)
|
VOP_HOLD(node);
|
||||||
goto cleanup;
|
fd_release(file);
|
||||||
|
VOP_LOCK(node);
|
||||||
|
file = NULL;
|
||||||
|
} else {
|
||||||
|
path = alloc(pathlen + 1);
|
||||||
|
if (path == NULL) {
|
||||||
|
ret.errno = ENOMEM;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.errno = usercopy_fromuser(path, upath, pathlen);
|
||||||
|
if (ret.errno) {
|
||||||
|
free(path);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
||||||
|
if (ret.errno)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
|
||||||
|
if (ret.errno)
|
||||||
|
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,7 +119,8 @@ 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);
|
||||||
|
|
||||||
free(path);
|
if (path)
|
||||||
|
free(path);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user