rpcsx/rpcs3/Emu/VFS.cpp

52 lines
1.1 KiB
C++
Raw Normal View History

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