From 84a8523568b926f53ebd0689491e0d5380c31083 Mon Sep 17 00:00:00 2001 From: DH Date: Fri, 10 Nov 2023 21:01:55 +0300 Subject: [PATCH] [orbis-kernel] devfs: implement device as directory --- rpcsx-os/vfs.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/rpcsx-os/vfs.cpp b/rpcsx-os/vfs.cpp index c419e6102..c84ac3395 100644 --- a/rpcsx-os/vfs.cpp +++ b/rpcsx-os/vfs.cpp @@ -10,13 +10,23 @@ #include struct DevFs : IoDevice { - std::map> devices; + std::map, std::less<>> devices; orbis::ErrorCode open(orbis::Ref *file, const char *path, std::uint32_t flags, std::uint32_t mode, orbis::Thread *thread) override { - if (auto it = devices.find(path); it != devices.end()) { - return it->second->open(file, path, flags, mode, thread); + std::string_view devPath = path; + if (auto pos = devPath.find('/'); pos != std::string_view::npos) { + auto deviceName = devPath.substr(0, pos); + devPath.remove_prefix(pos + 1); + + if (auto it = devices.find(deviceName); it != devices.end()) { + return it->second->open(file, std::string(devPath).c_str(), flags, mode, thread); + } + } else { + if (auto it = devices.find(devPath); it != devices.end()) { + return it->second->open(file, "", flags, mode, thread); + } } std::fprintf(stderr, "device %s not exists\n", path);