#include "stdafx.h" #include "IdManager.h" #include "VFS.h" #include struct vfs_manager { shared_mutex mutex; // Device name -> Real path std::unordered_map mounted; }; const std::regex s_regex_ps3("^/+(.*?)(?:$|/)(.*)", std::regex::optimize); const std::regex s_regex_psv("^(.*?):(.*)", std::regex::optimize); bool vfs::mount(const std::string& dev_name, const std::string& path) { const auto table = fxm::get_always(); writer_lock lock(table->mutex); return table->mounted.emplace(dev_name, path).second; } std::string vfs::get(const std::string& vpath, vfs::type _type) { const auto table = fxm::get_always(); reader_lock lock(table->mutex); std::smatch match; if (!std::regex_match(vpath, match, _type == type::ps3 ? s_regex_ps3 : s_regex_psv)) { const auto found = table->mounted.find(""); if (found == table->mounted.end()) { LOG_WARNING(GENERAL, "vfs::get(): no default directory: %s", vpath); return {}; } return found->second + vpath; } if (_type == type::ps3 && match.length(1) == 0) { return "/"; } const auto found = table->mounted.find(match.str(1)); if (found == table->mounted.end()) { LOG_WARNING(GENERAL, "vfs::get(): device not found: %s", vpath); return {}; } // Concatenate return found->second + match.str(2); }