From dee73342acaf8183878d7dc27dc48bfa210a2a33 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 | 3 +++ orbis-kernel/src/sys/sys_vfs.cpp | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/orbis-kernel/src/sys/sys_descrip.cpp b/orbis-kernel/src/sys/sys_descrip.cpp index a3957ac6..6a195266 100644 --- a/orbis-kernel/src/sys/sys_descrip.cpp +++ b/orbis-kernel/src/sys/sys_descrip.cpp @@ -1,3 +1,5 @@ +#include "orbis/utils/Logs.hpp" +#include "stat.hpp" #include "sys/sysproto.hpp" orbis::SysResult orbis::sys_getdtablesize(Thread *thread) { @@ -24,6 +26,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 {};