From a7b18c7cc24f5532b3471b4658ebbadab1459071 Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Tue, 18 Jul 2023 10:50:23 +0300 Subject: [PATCH] [orbis-kernel] sys_stat: check for dirs --- orbis-kernel/src/sys/sys_descrip.cpp | 1 + orbis-kernel/src/sys/sys_vfs.cpp | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/orbis-kernel/src/sys/sys_descrip.cpp b/orbis-kernel/src/sys/sys_descrip.cpp index a3957ac6..c4273fa5 100644 --- a/orbis-kernel/src/sys/sys_descrip.cpp +++ b/orbis-kernel/src/sys/sys_descrip.cpp @@ -24,6 +24,7 @@ orbis::SysResult orbis::sys_closefrom(Thread *thread, sint lowfd) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_fstat(Thread *thread, sint fd, ptr ub) { + ORBIS_LOG_TODO(__FUNCTION__, fd, ub); return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_nfstat(Thread *thread, sint fd, diff --git a/orbis-kernel/src/sys/sys_vfs.cpp b/orbis-kernel/src/sys/sys_vfs.cpp index 0af165f5..4041c49a 100644 --- a/orbis-kernel/src/sys/sys_vfs.cpp +++ b/orbis-kernel/src/sys/sys_vfs.cpp @@ -105,10 +105,10 @@ orbis::SysResult orbis::sys_eaccess(Thread *thread, ptr path, return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_stat(Thread *thread, ptr path, ptr ub) { - ORBIS_LOG_TODO(__FUNCTION__, path, ub); + ORBIS_LOG_WARNING(__FUNCTION__, path, ub); auto result = sys_open(thread, path, 0, 0); if (result.isError()) { - return result; + return ErrorCode::NOENT; } auto fd = thread->retval[0]; @@ -119,11 +119,18 @@ orbis::SysResult orbis::sys_stat(Thread *thread, ptr path, ptr ub) { } auto len = thread->retval[0]; - *ub = {}; - ub->size = len; - ub->blksize = 1; - ub->blocks = len; - ub->mode = 0777 | 0x8000; + result = sys_pread(thread, fd, ub, 1, 0); + if (result.isError()) { + *ub = {}; + ub->mode = 0777 | 0x4000; + } else { + *ub = {}; + ub->size = len; + ub->blksize = 1; + ub->blocks = len; + ub->mode = 0777 | 0x8000; + } + sys_close(thread, fd); thread->retval[0] = 0; return {};