From 7ea6f3d91aff77356faf093f227db4b780b8044f Mon Sep 17 00:00:00 2001 From: DH Date: Sun, 20 Aug 2023 15:39:18 +0300 Subject: [PATCH] [orbis-kernel] impi: implement server ops stub mkdir/rmdir syscalls --- orbis-kernel/include/orbis/KernelContext.hpp | 5 +- orbis-kernel/include/orbis/file.hpp | 2 + orbis-kernel/include/orbis/thread/Process.hpp | 1 + .../include/orbis/thread/ProcessOps.hpp | 2 + orbis-kernel/src/sys/sys_sce.cpp | 51 ++++++++++++++++++- orbis-kernel/src/sys/sys_vfs.cpp | 21 +++++++- 6 files changed, 76 insertions(+), 6 deletions(-) diff --git a/orbis-kernel/include/orbis/KernelContext.hpp b/orbis-kernel/include/orbis/KernelContext.hpp index 618375e..3987dbc 100644 --- a/orbis-kernel/include/orbis/KernelContext.hpp +++ b/orbis-kernel/include/orbis/KernelContext.hpp @@ -106,10 +106,7 @@ public: return {}; } - std::pair createIpmiServer(utils::kstring name, - std::uint32_t attrs, - std::int32_t initCount, - std::int32_t maxCount) { + std::pair createIpmiServer(utils::kstring name) { std::lock_guard lock(m_sem_mtx); auto [it, inserted] = mIpmiServers.try_emplace(std::move(name), nullptr); if (inserted) { diff --git a/orbis-kernel/include/orbis/file.hpp b/orbis-kernel/include/orbis/file.hpp index d6963cd..ef19226 100644 --- a/orbis-kernel/include/orbis/file.hpp +++ b/orbis-kernel/include/orbis/file.hpp @@ -30,6 +30,8 @@ struct FileOps { ErrorCode (*stat)(File *file, Stat *sb, Thread *thread) = nullptr; + ErrorCode (*mkdir)(File *file, const char *path, std::int32_t mode) = nullptr; + // TODO: chown // TODO: chmod diff --git a/orbis-kernel/include/orbis/thread/Process.hpp b/orbis-kernel/include/orbis/thread/Process.hpp index f2af8ae..6fd7b49 100644 --- a/orbis-kernel/include/orbis/thread/Process.hpp +++ b/orbis-kernel/include/orbis/thread/Process.hpp @@ -60,6 +60,7 @@ struct Process final { utils::RcIdMap evfMap; utils::RcIdMap semMap; utils::RcIdMap ipmiClientMap; + utils::RcIdMap ipmiServerMap; utils::RcIdMap modulesMap; utils::OwningIdMap threadsMap; utils::RcIdMap fileDescriptors; diff --git a/orbis-kernel/include/orbis/thread/ProcessOps.hpp b/orbis-kernel/include/orbis/thread/ProcessOps.hpp index 019af04..7de1699 100644 --- a/orbis-kernel/include/orbis/thread/ProcessOps.hpp +++ b/orbis-kernel/include/orbis/thread/ProcessOps.hpp @@ -40,6 +40,8 @@ struct ProcessOps { Ref *file); SysResult (*shm_open)(Thread *thread, const char *path, sint flags, sint mode, Ref *file); + SysResult (*mkdir)(Thread *thread, ptr path, sint mode); + SysResult (*rmdir)(Thread *thread, ptr path) = nullptr; SysResult (*blockpool_open)(Thread *thread, Ref *file); SysResult (*blockpool_map)(Thread *thread, caddr_t addr, size_t len, sint prot, sint flags); diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index dda0972..499833e 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -977,6 +977,19 @@ struct IpmiSyncCallParams { orbis::uint32_t resultCount; }; +struct IpmiCreateServerParams { + orbis::uint64_t arg0; + orbis::ptr name; + orbis::uint64_t arg2; +}; + +struct IpmiClientConnectParams { + orbis::ptr arg0; + orbis::ptr name; + orbis::ptr arg2; + orbis::ptr arg3; +}; + static_assert(sizeof(IpmiSyncCallParams) == 0x30); orbis::SysResult orbis::sys_ipmimgr_call(Thread *thread, uint op, uint kid, @@ -985,6 +998,36 @@ orbis::SysResult orbis::sys_ipmimgr_call(Thread *thread, uint op, uint kid, ORBIS_LOG_TODO("sys_ipmimgr_call", op, kid, result, params, paramsSz, arg6); thread->where(); + if (op == kImpiCreateServer) { + if (paramsSz != sizeof(IpmiCreateServerParams)) { + return ErrorCode::INVAL; + } + + auto createParams = (ptr)params; + + ORBIS_LOG_TODO("IPMI: create server", createParams->arg0, + createParams->name, createParams->arg2); + + auto [server, inserted] = g_context.createIpmiServer(createParams->name); + if (!inserted) { + return ErrorCode::EXIST; + } + + auto id = thread->tproc->ipmiServerMap.insert(server); + return uwrite(result, id); + } + + if (op == 0x10) { + // IPMI server start? + + return uwrite(result, 0); + } + + if (op == 0x201) { + // IPMI server receive packet? + return uwrite(result, 0x80020023); + } + if (op == kIpmiCreateClient) { if (paramsSz != sizeof(IpmiCreateClientParams)) { return ErrorCode::INVAL; @@ -1029,7 +1072,13 @@ orbis::SysResult orbis::sys_ipmimgr_call(Thread *thread, uint op, uint kid, } if (op == 0x400) { - ORBIS_LOG_TODO("IMPI: connect?"); + if (paramsSz != sizeof(IpmiClientConnectParams)) { + return ErrorCode::INVAL; + } + + auto connectParams = (ptr)params; + ORBIS_LOG_TODO("IMPI: connect?", connectParams->arg0, connectParams->name, + connectParams->arg2, connectParams->arg3); if (result) { return uwrite(result, 0); } diff --git a/orbis-kernel/src/sys/sys_vfs.cpp b/orbis-kernel/src/sys/sys_vfs.cpp index c42d78a..690fd8e 100644 --- a/orbis-kernel/src/sys/sys_vfs.cpp +++ b/orbis-kernel/src/sys/sys_vfs.cpp @@ -292,13 +292,32 @@ orbis::SysResult orbis::sys_renameat(Thread *thread, sint oldfd, ptr old, return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_mkdir(Thread *thread, ptr path, sint mode) { + if (auto mkdir = thread->tproc->ops->mkdir) { + return mkdir(thread, path, mode); + } return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_mkdirat(Thread *thread, sint fd, ptr path, mode_t mode) { - return ErrorCode::NOSYS; + Ref file = thread->tproc->fileDescriptors.get(fd); + if (file == nullptr) { + return ErrorCode::BADF; + } + + auto mkdir = file->ops->mkdir; + + if (mkdir == nullptr) { + return ErrorCode::NOTSUP; + } + std::lock_guard lock(file->mtx); + + return mkdir(file.get(), path, mode); } + orbis::SysResult orbis::sys_rmdir(Thread *thread, ptr path) { + if (auto rmdir = thread->tproc->ops->rmdir) { + return rmdir(thread, path); + } return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_getdirentries(Thread *thread, sint fd,