From b0166046befb23110a729044b489774dfada3bcd Mon Sep 17 00:00:00 2001 From: DH Date: Sun, 12 Nov 2023 01:27:51 +0300 Subject: [PATCH] [rpcsx-os] shm: implement unlink --- rpcsx-os/iodev/shm.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/rpcsx-os/iodev/shm.cpp b/rpcsx-os/iodev/shm.cpp index c62df62..270c7ef 100644 --- a/rpcsx-os/iodev/shm.cpp +++ b/rpcsx-os/iodev/shm.cpp @@ -11,13 +11,11 @@ struct ShmDevice : IoDevice { orbis::ErrorCode open(orbis::Ref *file, const char *path, std::uint32_t flags, std::uint32_t mode, orbis::Thread *thread) override; + orbis::ErrorCode unlink(const char *path, bool recursive, + orbis::Thread *thread) override; }; -orbis::ErrorCode ShmDevice::open(orbis::Ref *file, - const char *path, std::uint32_t flags, - std::uint32_t mode, orbis::Thread *thread) { - ORBIS_LOG_WARNING("shm_open", path, flags, mode); - +static std::string realShmPath(const char *path) { std::string name = "/rpcsx-"; if (path[0] == '/') { name += path + 1; @@ -25,10 +23,19 @@ orbis::ErrorCode ShmDevice::open(orbis::Ref *file, name += path; } - for (auto pos = name.find('/', 1); pos != std::string::npos; pos = name.find('/', pos + 1)) { + for (auto pos = name.find('/', 1); pos != std::string::npos; + pos = name.find('/', pos + 1)) { name[pos] = '$'; } + return name; +} + +orbis::ErrorCode ShmDevice::open(orbis::Ref *file, + const char *path, std::uint32_t flags, + std::uint32_t mode, orbis::Thread *thread) { + ORBIS_LOG_WARNING("shm_open", path, flags, mode); + auto name = realShmPath(path); auto realFlags = O_RDWR; // TODO std::size_t size = 0; @@ -49,4 +56,15 @@ orbis::ErrorCode ShmDevice::open(orbis::Ref *file, return {}; } +orbis::ErrorCode ShmDevice::unlink(const char *path, bool recursive, + orbis::Thread *thread) { + ORBIS_LOG_WARNING("shm_unlink", path); + auto name = realShmPath(path); + + if (shm_unlink(name.c_str())) { + return convertErrno(); + } + + return{}; +} IoDevice *createShmDevice() { return orbis::knew(); }