2018-01-17 03:20:12 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-19 14:34:09 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
#include "common/assert.h"
|
2018-02-19 05:32:00 +00:00
|
|
|
#include "common/file_util.h"
|
2018-07-19 01:07:11 +00:00
|
|
|
#include "core/core.h"
|
2018-08-21 00:36:36 +00:00
|
|
|
#include "core/file_sys/bis_factory.h"
|
2018-07-17 19:42:15 +00:00
|
|
|
#include "core/file_sys/errors.h"
|
2018-08-21 14:48:24 +00:00
|
|
|
#include "core/file_sys/mode.h"
|
2018-09-04 21:01:40 +00:00
|
|
|
#include "core/file_sys/registered_cache.h"
|
2018-08-21 00:36:36 +00:00
|
|
|
#include "core/file_sys/romfs_factory.h"
|
2018-07-08 03:24:51 +00:00
|
|
|
#include "core/file_sys/savedata_factory.h"
|
|
|
|
#include "core/file_sys/sdmc_factory.h"
|
2018-07-19 01:07:11 +00:00
|
|
|
#include "core/file_sys/vfs.h"
|
|
|
|
#include "core/file_sys/vfs_offset.h"
|
2018-01-17 03:20:12 +00:00
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
2018-08-01 20:55:07 +00:00
|
|
|
#include "core/hle/service/filesystem/fsp_ldr.h"
|
|
|
|
#include "core/hle/service/filesystem/fsp_pr.h"
|
2018-01-17 03:20:12 +00:00
|
|
|
#include "core/hle/service/filesystem/fsp_srv.h"
|
|
|
|
|
2018-04-20 01:41:44 +00:00
|
|
|
namespace Service::FileSystem {
|
2018-01-17 03:20:12 +00:00
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
// Size of emulated sd card free space, reported in bytes.
|
|
|
|
// Just using 32GB because thats reasonable
|
|
|
|
// TODO(DarkLordZach): Eventually make this configurable in settings.
|
|
|
|
constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000;
|
|
|
|
|
|
|
|
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
|
2018-07-24 02:40:35 +00:00
|
|
|
std::string_view dir_name_) {
|
|
|
|
std::string dir_name(FileUtil::SanitizePath(dir_name_));
|
2018-07-19 14:32:21 +00:00
|
|
|
if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\")
|
2018-07-19 01:07:11 +00:00
|
|
|
return base;
|
|
|
|
|
|
|
|
return base->GetDirectoryRelative(dir_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
VfsDirectoryServiceWrapper::VfsDirectoryServiceWrapper(FileSys::VirtualDir backing_)
|
2018-07-19 14:34:09 +00:00
|
|
|
: backing(std::move(backing_)) {}
|
2018-07-19 01:07:11 +00:00
|
|
|
|
hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.
The cause of the above mentioned non-obvious errors can be demonstrated
as follows:
------- Demonstrative example, if you know how the described error happens, skip forwards -------
Assume we have the following in the header, which we'll call "thing.h":
\#include <memory>
// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;
class Thing {
public:
// assume no constructors or destructors are specified here,
// or the constructors/destructors are defined as:
//
// Thing() = default;
// ~Thing() = default;
//
// ... Some interface member functions would be defined here
private:
std::shared_ptr<Object> obj;
};
If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:
1. Decrement the shared reference count of the object being pointed to,
and if the reference count decrements to zero,
2. Free the Object instance's memory (aka deallocate the memory it's
pointing to).
And so the compiler generates the code for the destructor doing this inside main.cpp.
Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.
Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.
---------------------- End example ----------------------------
Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-11 01:20:52 +00:00
|
|
|
VfsDirectoryServiceWrapper::~VfsDirectoryServiceWrapper() = default;
|
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
std::string VfsDirectoryServiceWrapper::GetName() const {
|
|
|
|
return backing->GetName();
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
|
|
|
auto file = dir->CreateFile(FileUtil::GetFilename(path));
|
|
|
|
if (file == nullptr) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
if (!file->Resize(size)) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-08-03 15:44:40 +00:00
|
|
|
if (path.empty()) {
|
2018-07-19 01:07:11 +00:00
|
|
|
// TODO(DarkLordZach): Why do games call this and what should it do? Works as is but...
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-09-02 13:17:45 +00:00
|
|
|
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
|
|
|
if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) {
|
2018-07-19 01:07:11 +00:00
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2018-09-02 13:17:45 +00:00
|
|
|
}
|
2018-07-24 02:40:35 +00:00
|
|
|
if (!dir->DeleteFile(FileUtil::GetFilename(path))) {
|
2018-07-19 01:07:11 +00:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
2018-09-02 13:17:45 +00:00
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
|
|
|
if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty())
|
|
|
|
dir = backing;
|
|
|
|
auto new_dir = dir->CreateSubdirectory(FileUtil::GetFilename(path));
|
|
|
|
if (new_dir == nullptr) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
|
|
|
if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
|
|
|
if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
|
|
|
|
const std::string& dest_path_) const {
|
|
|
|
std::string src_path(FileUtil::SanitizePath(src_path_));
|
|
|
|
std::string dest_path(FileUtil::SanitizePath(dest_path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto src = backing->GetFileRelative(src_path);
|
|
|
|
if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) {
|
|
|
|
// Use more-optimized vfs implementation rename.
|
|
|
|
if (src == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
|
|
|
if (!src->Rename(FileUtil::GetFilename(dest_path))) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move by hand -- TODO(DarkLordZach): Optimize
|
|
|
|
auto c_res = CreateFile(dest_path, src->GetSize());
|
|
|
|
if (c_res != RESULT_SUCCESS)
|
|
|
|
return c_res;
|
|
|
|
|
|
|
|
auto dest = backing->GetFileRelative(dest_path);
|
|
|
|
ASSERT_MSG(dest != nullptr, "Newly created file with success cannot be found.");
|
|
|
|
|
|
|
|
ASSERT_MSG(dest->WriteBytes(src->ReadAllBytes()) == src->GetSize(),
|
|
|
|
"Could not write all of the bytes but everything else has succeded.");
|
|
|
|
|
|
|
|
if (!src->GetContainingDirectory()->DeleteFile(FileUtil::GetFilename(src_path))) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_,
|
|
|
|
const std::string& dest_path_) const {
|
|
|
|
std::string src_path(FileUtil::SanitizePath(src_path_));
|
|
|
|
std::string dest_path(FileUtil::SanitizePath(dest_path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto src = GetDirectoryRelativeWrapped(backing, src_path);
|
|
|
|
if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) {
|
|
|
|
// Use more-optimized vfs implementation rename.
|
|
|
|
if (src == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
|
|
|
if (!src->Rename(FileUtil::GetFilename(dest_path))) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(DarkLordZach): Implement renaming across the tree (move).
|
|
|
|
ASSERT_MSG(false,
|
|
|
|
"Could not rename directory with path \"{}\" to new path \"{}\" because parent dirs "
|
|
|
|
"don't match -- UNIMPLEMENTED",
|
|
|
|
src_path, dest_path);
|
|
|
|
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
|
2018-07-19 01:07:11 +00:00
|
|
|
FileSys::Mode mode) const {
|
2018-07-24 02:40:35 +00:00
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto npath = path;
|
|
|
|
while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\'))
|
|
|
|
npath = npath.substr(1);
|
|
|
|
auto file = backing->GetFileRelative(npath);
|
|
|
|
if (file == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
|
|
|
|
|
|
|
if (mode == FileSys::Mode::Append) {
|
|
|
|
return MakeResult<FileSys::VirtualFile>(
|
|
|
|
std::make_shared<FileSys::OffsetVfsFile>(file, 0, file->GetSize()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return MakeResult<FileSys::VirtualFile>(file);
|
|
|
|
}
|
|
|
|
|
2018-07-24 02:40:35 +00:00
|
|
|
ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, path);
|
|
|
|
if (dir == nullptr) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2018-09-19 13:25:00 +00:00
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2018-07-19 01:07:11 +00:00
|
|
|
}
|
|
|
|
return MakeResult(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 VfsDirectoryServiceWrapper::GetFreeSpaceSize() const {
|
|
|
|
if (backing->IsWritable())
|
|
|
|
return EMULATED_SD_REPORTED_SIZE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(
|
2018-07-24 02:40:35 +00:00
|
|
|
const std::string& path_) const {
|
|
|
|
std::string path(FileUtil::SanitizePath(path_));
|
2018-07-19 01:07:11 +00:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
|
|
|
if (dir == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
|
|
|
auto filename = FileUtil::GetFilename(path);
|
2018-07-19 18:11:09 +00:00
|
|
|
// TODO(Subv): Some games use the '/' path, find out what this means.
|
|
|
|
if (filename.empty())
|
|
|
|
return MakeResult(FileSys::EntryType::Directory);
|
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
if (dir->GetFile(filename) != nullptr)
|
|
|
|
return MakeResult(FileSys::EntryType::File);
|
|
|
|
if (dir->GetSubdirectory(filename) != nullptr)
|
|
|
|
return MakeResult(FileSys::EntryType::Directory);
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2018-01-17 03:20:12 +00:00
|
|
|
/**
|
|
|
|
* Map of registered file systems, identified by type. Once an file system is registered here, it
|
|
|
|
* is never removed until UnregisterFileSystems is called.
|
|
|
|
*/
|
2018-07-17 19:42:15 +00:00
|
|
|
static std::unique_ptr<FileSys::RomFSFactory> romfs_factory;
|
|
|
|
static std::unique_ptr<FileSys::SaveDataFactory> save_data_factory;
|
|
|
|
static std::unique_ptr<FileSys::SDMCFactory> sdmc_factory;
|
2018-08-10 00:50:10 +00:00
|
|
|
static std::unique_ptr<FileSys::BISFactory> bis_factory;
|
2018-07-17 19:42:15 +00:00
|
|
|
|
|
|
|
ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory) {
|
|
|
|
ASSERT_MSG(romfs_factory == nullptr, "Tried to register a second RomFS");
|
|
|
|
romfs_factory = std::move(factory);
|
|
|
|
LOG_DEBUG(Service_FS, "Registered RomFS");
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-01-17 03:20:12 +00:00
|
|
|
|
2018-07-17 19:42:15 +00:00
|
|
|
ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory) {
|
|
|
|
ASSERT_MSG(romfs_factory == nullptr, "Tried to register a second save data");
|
|
|
|
save_data_factory = std::move(factory);
|
|
|
|
LOG_DEBUG(Service_FS, "Registered save data");
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-01-17 03:20:12 +00:00
|
|
|
|
2018-07-17 19:42:15 +00:00
|
|
|
ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory) {
|
|
|
|
ASSERT_MSG(sdmc_factory == nullptr, "Tried to register a second SDMC");
|
|
|
|
sdmc_factory = std::move(factory);
|
|
|
|
LOG_DEBUG(Service_FS, "Registered SDMC");
|
2018-01-17 03:20:12 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-08-10 00:50:10 +00:00
|
|
|
ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory) {
|
|
|
|
ASSERT_MSG(bis_factory == nullptr, "Tried to register a second BIS");
|
|
|
|
bis_factory = std::move(factory);
|
2018-08-24 02:12:31 +00:00
|
|
|
LOG_DEBUG(Service_FS, "Registered BIS");
|
2018-08-10 00:50:10 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-10-05 12:53:45 +00:00
|
|
|
void SetPackedUpdate(FileSys::VirtualFile update_raw) {
|
|
|
|
LOG_TRACE(Service_FS, "Setting packed update for romfs");
|
|
|
|
|
|
|
|
if (romfs_factory == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
romfs_factory->SetPackedUpdate(std::move(update_raw));
|
|
|
|
}
|
|
|
|
|
2018-08-19 01:28:17 +00:00
|
|
|
ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess() {
|
|
|
|
LOG_TRACE(Service_FS, "Opening RomFS for current process");
|
2018-01-17 03:20:12 +00:00
|
|
|
|
2018-07-17 19:42:15 +00:00
|
|
|
if (romfs_factory == nullptr) {
|
2018-01-17 03:20:12 +00:00
|
|
|
// TODO(bunnei): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
|
2018-08-19 01:28:17 +00:00
|
|
|
return romfs_factory->OpenCurrentProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
|
|
|
FileSys::ContentRecordType type) {
|
|
|
|
LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}",
|
|
|
|
title_id, static_cast<u8>(storage_id), static_cast<u8>(type));
|
|
|
|
|
|
|
|
if (romfs_factory == nullptr) {
|
|
|
|
// TODO(bunnei): Find a better error code for this
|
|
|
|
return ResultCode(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return romfs_factory->Open(title_id, storage_id, type);
|
2018-01-17 03:20:12 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
|
|
|
|
FileSys::SaveDataDescriptor save_struct) {
|
2018-07-17 19:42:15 +00:00
|
|
|
LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}",
|
2018-07-19 01:07:11 +00:00
|
|
|
static_cast<u8>(space), save_struct.DebugInfo());
|
2018-03-04 18:03:58 +00:00
|
|
|
|
2018-07-17 19:42:15 +00:00
|
|
|
if (save_data_factory == nullptr) {
|
2018-07-19 01:07:11 +00:00
|
|
|
return ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound);
|
2018-07-17 19:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return save_data_factory->Open(space, save_struct);
|
|
|
|
}
|
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
ResultVal<FileSys::VirtualDir> OpenSDMC() {
|
2018-07-17 19:42:15 +00:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr) {
|
|
|
|
return ResultCode(ErrorModule::FS, FileSys::ErrCodes::SdCardNotFound);
|
2018-03-04 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 19:42:15 +00:00
|
|
|
return sdmc_factory->Open();
|
2018-03-04 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:05:47 +00:00
|
|
|
std::unique_ptr<FileSys::RegisteredCacheUnion> GetUnionContents() {
|
|
|
|
return std::make_unique<FileSys::RegisteredCacheUnion>(std::vector<FileSys::RegisteredCache*>{
|
|
|
|
GetSystemNANDContents(), GetUserNANDContents(), GetSDMCContents()});
|
2018-08-25 23:00:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:05:47 +00:00
|
|
|
FileSys::RegisteredCache* GetSystemNANDContents() {
|
2018-08-16 21:03:31 +00:00
|
|
|
LOG_TRACE(Service_FS, "Opening System NAND Contents");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
2018-08-10 00:50:10 +00:00
|
|
|
return bis_factory->GetSystemNANDContents();
|
|
|
|
}
|
|
|
|
|
2018-10-16 13:05:47 +00:00
|
|
|
FileSys::RegisteredCache* GetUserNANDContents() {
|
2018-08-16 21:03:31 +00:00
|
|
|
LOG_TRACE(Service_FS, "Opening User NAND Contents");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
2018-08-10 00:50:10 +00:00
|
|
|
return bis_factory->GetUserNANDContents();
|
|
|
|
}
|
|
|
|
|
2018-10-16 13:05:47 +00:00
|
|
|
FileSys::RegisteredCache* GetSDMCContents() {
|
2018-08-16 21:03:31 +00:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC Contents");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return sdmc_factory->GetSDMCContents();
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:04:15 +00:00
|
|
|
FileSys::VirtualDir GetModificationLoadRoot(u64 title_id) {
|
|
|
|
LOG_TRACE(Service_FS, "Opening mod load root for tid={:016X}", title_id);
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetModificationLoadRoot(title_id);
|
|
|
|
}
|
|
|
|
|
2018-10-13 15:25:13 +00:00
|
|
|
void CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite) {
|
2018-08-16 21:03:31 +00:00
|
|
|
if (overwrite) {
|
|
|
|
bis_factory = nullptr;
|
|
|
|
save_data_factory = nullptr;
|
|
|
|
sdmc_factory = nullptr;
|
|
|
|
}
|
2018-02-19 05:32:00 +00:00
|
|
|
|
2018-10-13 15:25:13 +00:00
|
|
|
auto nand_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir),
|
|
|
|
FileSys::Mode::ReadWrite);
|
|
|
|
auto sd_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir),
|
|
|
|
FileSys::Mode::ReadWrite);
|
|
|
|
auto load_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
|
|
|
FileSys::Mode::ReadWrite);
|
2018-02-19 05:32:00 +00:00
|
|
|
|
2018-08-10 00:50:10 +00:00
|
|
|
if (bis_factory == nullptr)
|
2018-09-20 02:04:15 +00:00
|
|
|
bis_factory = std::make_unique<FileSys::BISFactory>(nand_directory, load_directory);
|
2018-08-16 21:04:38 +00:00
|
|
|
if (save_data_factory == nullptr)
|
|
|
|
save_data_factory = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory));
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory));
|
2018-01-17 03:20:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-13 15:25:13 +00:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, FileSys::VfsFilesystem& vfs) {
|
2018-08-16 21:04:38 +00:00
|
|
|
romfs_factory = nullptr;
|
|
|
|
CreateFactories(vfs, false);
|
2018-08-01 20:55:07 +00:00
|
|
|
std::make_shared<FSP_LDR>()->InstallAsService(service_manager);
|
|
|
|
std::make_shared<FSP_PR>()->InstallAsService(service_manager);
|
2018-01-17 03:20:12 +00:00
|
|
|
std::make_shared<FSP_SRV>()->InstallAsService(service_manager);
|
|
|
|
}
|
|
|
|
|
2018-04-20 01:41:44 +00:00
|
|
|
} // namespace Service::FileSystem
|