2018-01-16 22:20:12 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-19 10:34:09 -04:00
|
|
|
#include <utility>
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
#include "common/assert.h"
|
2018-02-19 00:32:00 -05:00
|
|
|
#include "common/file_util.h"
|
2021-04-14 19:07:40 -04:00
|
|
|
#include "common/settings.h"
|
2018-07-18 21:07:11 -04:00
|
|
|
#include "core/core.h"
|
2018-08-20 20:36:36 -04:00
|
|
|
#include "core/file_sys/bis_factory.h"
|
2019-04-16 09:13:34 -04:00
|
|
|
#include "core/file_sys/card_image.h"
|
2018-12-06 20:29:36 -05:00
|
|
|
#include "core/file_sys/control_metadata.h"
|
2018-07-17 15:42:15 -04:00
|
|
|
#include "core/file_sys/errors.h"
|
2018-08-21 10:48:24 -04:00
|
|
|
#include "core/file_sys/mode.h"
|
2018-12-06 20:29:36 -05:00
|
|
|
#include "core/file_sys/partition_filesystem.h"
|
|
|
|
#include "core/file_sys/patch_manager.h"
|
2018-09-04 17:01:40 -04:00
|
|
|
#include "core/file_sys/registered_cache.h"
|
2018-08-20 20:36:36 -04:00
|
|
|
#include "core/file_sys/romfs_factory.h"
|
2018-07-07 23:24:51 -04:00
|
|
|
#include "core/file_sys/savedata_factory.h"
|
|
|
|
#include "core/file_sys/sdmc_factory.h"
|
2018-07-18 21:07:11 -04:00
|
|
|
#include "core/file_sys/vfs.h"
|
|
|
|
#include "core/file_sys/vfs_offset.h"
|
2021-04-24 01:04:28 -04:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2018-01-16 22:20:12 -05:00
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
2018-08-01 16:55:07 -04:00
|
|
|
#include "core/hle/service/filesystem/fsp_ldr.h"
|
|
|
|
#include "core/hle/service/filesystem/fsp_pr.h"
|
2018-01-16 22:20:12 -05:00
|
|
|
#include "core/hle/service/filesystem/fsp_srv.h"
|
2018-12-06 20:29:36 -05:00
|
|
|
#include "core/loader/loader.h"
|
2018-01-16 22:20:12 -05:00
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::FileSystem {
|
2018-01-16 22:20:12 -05:00
|
|
|
|
2018-12-06 20:29:36 -05:00
|
|
|
// A default size for normal/journal save data size if application control metadata cannot be found.
|
|
|
|
// This should be large enough to satisfy even the most extreme requirements (~4.2GB)
|
|
|
|
constexpr u64 SUFFICIENT_SAVE_DATA_SIZE = 0xF0000000;
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
|
2018-07-23 22:40:35 -04:00
|
|
|
std::string_view dir_name_) {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string dir_name(Common::FS::SanitizePath(dir_name_));
|
2018-07-19 10:32:21 -04:00
|
|
|
if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\")
|
2018-07-18 21:07:11 -04:00
|
|
|
return base;
|
|
|
|
|
|
|
|
return base->GetDirectoryRelative(dir_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
VfsDirectoryServiceWrapper::VfsDirectoryServiceWrapper(FileSys::VirtualDir backing_)
|
2018-07-19 10:34:09 -04:00
|
|
|
: backing(std::move(backing_)) {}
|
2018-07-18 21:07:11 -04: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-10 21:20:52 -04:00
|
|
|
VfsDirectoryServiceWrapper::~VfsDirectoryServiceWrapper() = default;
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
std::string VfsDirectoryServiceWrapper::GetName() const {
|
|
|
|
return backing->GetName();
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
2020-07-15 12:16:31 -04:00
|
|
|
if (dir == nullptr) {
|
2021-05-01 09:33:00 -04:00
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2020-07-15 12:16:31 -04:00
|
|
|
}
|
2021-05-01 09:33:00 -04:00
|
|
|
|
|
|
|
const auto entry_type = GetEntryType(path);
|
|
|
|
if (entry_type.Code() == RESULT_SUCCESS) {
|
|
|
|
return FileSys::ERROR_PATH_ALREADY_EXISTS;
|
|
|
|
}
|
|
|
|
|
2020-08-15 08:33:16 -04:00
|
|
|
auto file = dir->CreateFile(Common::FS::GetFilename(path));
|
2018-07-18 21:07:11 -04:00
|
|
|
if (file == nullptr) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
if (!file->Resize(size)) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
2018-08-03 11:44:40 -04:00
|
|
|
if (path.empty()) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Why do games call this and what should it do? Works as is but...
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-09-02 09:17:45 -04:00
|
|
|
|
2020-08-15 08:33:16 -04:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
2020-10-13 00:57:04 -04:00
|
|
|
if (dir == nullptr || dir->GetFile(Common::FS::GetFilename(path)) == nullptr) {
|
2018-07-18 21:07:11 -04:00
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2018-09-02 09:17:45 -04:00
|
|
|
}
|
2020-08-15 08:33:16 -04:00
|
|
|
if (!dir->DeleteFile(Common::FS::GetFilename(path))) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
2018-09-02 09:17:45 -04:00
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
2020-10-13 00:57:04 -04:00
|
|
|
if (dir == nullptr || Common::FS::GetFilename(Common::FS::GetParentPath(path)).empty()) {
|
2018-07-18 21:07:11 -04:00
|
|
|
dir = backing;
|
2020-10-13 00:57:04 -04:00
|
|
|
}
|
2020-08-15 08:33:16 -04:00
|
|
|
auto new_dir = dir->CreateSubdirectory(Common::FS::GetFilename(path));
|
2018-07-18 21:07:11 -04:00
|
|
|
if (new_dir == nullptr) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
|
|
|
if (!dir->DeleteSubdirectory(Common::FS::GetFilename(path))) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
|
|
|
if (!dir->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path))) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:44:13 -05:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::CleanDirectoryRecursively(const std::string& path) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
const std::string sanitized_path(Common::FS::SanitizePath(path));
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(sanitized_path));
|
2018-11-30 14:44:13 -05:00
|
|
|
|
2020-08-15 08:33:16 -04:00
|
|
|
if (!dir->CleanSubdirectoryRecursive(Common::FS::GetFilename(sanitized_path))) {
|
2018-11-30 14:44:13 -05:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-11-30 14:44:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
|
|
|
|
const std::string& dest_path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string src_path(Common::FS::SanitizePath(src_path_));
|
|
|
|
std::string dest_path(Common::FS::SanitizePath(dest_path_));
|
2018-07-18 21:07:11 -04:00
|
|
|
auto src = backing->GetFileRelative(src_path);
|
2020-08-15 08:33:16 -04:00
|
|
|
if (Common::FS::GetParentPath(src_path) == Common::FS::GetParentPath(dest_path)) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// Use more-optimized vfs implementation rename.
|
|
|
|
if (src == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2020-08-15 08:33:16 -04:00
|
|
|
if (!src->Rename(Common::FS::GetFilename(dest_path))) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
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.");
|
|
|
|
|
2020-08-15 08:33:16 -04:00
|
|
|
if (!src->GetContainingDirectory()->DeleteFile(Common::FS::GetFilename(src_path))) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_,
|
|
|
|
const std::string& dest_path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string src_path(Common::FS::SanitizePath(src_path_));
|
|
|
|
std::string dest_path(Common::FS::SanitizePath(dest_path_));
|
2018-07-18 21:07:11 -04:00
|
|
|
auto src = GetDirectoryRelativeWrapped(backing, src_path);
|
2020-08-15 08:33:16 -04:00
|
|
|
if (Common::FS::GetParentPath(src_path) == Common::FS::GetParentPath(dest_path)) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// Use more-optimized vfs implementation rename.
|
|
|
|
if (src == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2020-08-15 08:33:16 -04:00
|
|
|
if (!src->Rename(Common::FS::GetFilename(dest_path))) {
|
2018-07-18 21:07:11 -04:00
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
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
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
|
2018-07-23 22:40:35 -04:00
|
|
|
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
|
2018-07-18 21:07:11 -04:00
|
|
|
FileSys::Mode mode) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
const std::string path(Common::FS::SanitizePath(path_));
|
2019-04-04 20:48:13 -04:00
|
|
|
std::string_view npath = path;
|
|
|
|
while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) {
|
|
|
|
npath.remove_prefix(1);
|
|
|
|
}
|
|
|
|
|
2018-07-18 21:07:11 -04:00
|
|
|
auto file = backing->GetFileRelative(npath);
|
2019-04-04 20:48:13 -04:00
|
|
|
if (file == nullptr) {
|
2018-07-18 21:07:11 -04:00
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2019-04-04 20:48:13 -04:00
|
|
|
}
|
2018-07-18 21:07:11 -04:00
|
|
|
|
|
|
|
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-23 22:40:35 -04:00
|
|
|
ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
2018-07-18 21:07:11 -04:00
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, path);
|
|
|
|
if (dir == nullptr) {
|
|
|
|
// TODO(DarkLordZach): Find a better error code for this
|
2018-09-19 09:25:00 -04:00
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2018-07-18 21:07:11 -04:00
|
|
|
}
|
|
|
|
return MakeResult(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(
|
2018-07-23 22:40:35 -04:00
|
|
|
const std::string& path_) const {
|
2020-08-15 08:33:16 -04:00
|
|
|
std::string path(Common::FS::SanitizePath(path_));
|
|
|
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
2018-07-18 21:07:11 -04:00
|
|
|
if (dir == nullptr)
|
|
|
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
2020-08-15 08:33:16 -04:00
|
|
|
auto filename = Common::FS::GetFilename(path);
|
2018-07-19 14:11:09 -04:00
|
|
|
// TODO(Subv): Some games use the '/' path, find out what this means.
|
|
|
|
if (filename.empty())
|
|
|
|
return MakeResult(FileSys::EntryType::Directory);
|
|
|
|
|
2018-07-18 21:07:11 -04: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;
|
|
|
|
}
|
|
|
|
|
2019-10-06 13:02:23 -04:00
|
|
|
FileSystemController::FileSystemController(Core::System& system_) : system{system_} {}
|
2019-04-23 14:38:18 -04:00
|
|
|
|
|
|
|
FileSystemController::~FileSystemController() = default;
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
ResultCode FileSystemController::RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory) {
|
2018-07-17 15:42:15 -04:00
|
|
|
romfs_factory = std::move(factory);
|
|
|
|
LOG_DEBUG(Service_FS, "Registered RomFS");
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-01-16 22:20:12 -05:00
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
ResultCode FileSystemController::RegisterSaveData(
|
|
|
|
std::unique_ptr<FileSys::SaveDataFactory>&& factory) {
|
|
|
|
ASSERT_MSG(save_data_factory == nullptr, "Tried to register a second save data");
|
2018-07-17 15:42:15 -04:00
|
|
|
save_data_factory = std::move(factory);
|
|
|
|
LOG_DEBUG(Service_FS, "Registered save data");
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-01-16 22:20:12 -05:00
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
ResultCode FileSystemController::RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory) {
|
2018-07-17 15:42:15 -04:00
|
|
|
ASSERT_MSG(sdmc_factory == nullptr, "Tried to register a second SDMC");
|
|
|
|
sdmc_factory = std::move(factory);
|
|
|
|
LOG_DEBUG(Service_FS, "Registered SDMC");
|
2018-01-16 22:20:12 -05:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
ResultCode FileSystemController::RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory) {
|
2018-08-09 20:50:10 -04:00
|
|
|
ASSERT_MSG(bis_factory == nullptr, "Tried to register a second BIS");
|
|
|
|
bis_factory = std::move(factory);
|
2018-08-23 22:12:31 -04:00
|
|
|
LOG_DEBUG(Service_FS, "Registered BIS");
|
2018-08-09 20:50:10 -04:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
void FileSystemController::SetPackedUpdate(FileSys::VirtualFile update_raw) {
|
2018-10-05 08:53:45 -04:00
|
|
|
LOG_TRACE(Service_FS, "Setting packed update for romfs");
|
|
|
|
|
|
|
|
if (romfs_factory == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
romfs_factory->SetPackedUpdate(std::move(update_raw));
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFSCurrentProcess() const {
|
2018-08-18 21:28:17 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening RomFS for current process");
|
2018-01-16 22:20:12 -05:00
|
|
|
|
2018-07-17 15:42:15 -04:00
|
|
|
if (romfs_factory == nullptr) {
|
2018-01-16 22:20:12 -05:00
|
|
|
// TODO(bunnei): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-01-16 22:20:12 -05:00
|
|
|
}
|
|
|
|
|
2019-10-06 13:02:23 -04:00
|
|
|
return romfs_factory->OpenCurrentProcess(system.CurrentProcess()->GetTitleID());
|
2018-08-18 21:28:17 -04:00
|
|
|
}
|
|
|
|
|
2020-12-03 22:57:28 -05:00
|
|
|
ResultVal<FileSys::VirtualFile> FileSystemController::OpenPatchedRomFS(
|
|
|
|
u64 title_id, FileSys::ContentRecordType type) const {
|
|
|
|
LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}", title_id);
|
|
|
|
|
|
|
|
if (romfs_factory == nullptr) {
|
|
|
|
// TODO: Find a better error code for this
|
|
|
|
return RESULT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return romfs_factory->OpenPatchedRomFS(title_id, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<FileSys::VirtualFile> FileSystemController::OpenPatchedRomFSWithProgramIndex(
|
|
|
|
u64 title_id, u8 program_index, FileSys::ContentRecordType type) const {
|
|
|
|
LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}, program_index={}", title_id,
|
|
|
|
program_index);
|
|
|
|
|
|
|
|
if (romfs_factory == nullptr) {
|
|
|
|
// TODO: Find a better error code for this
|
|
|
|
return RESULT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return romfs_factory->OpenPatchedRomFSWithProgramIndex(title_id, program_index, type);
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFS(
|
|
|
|
u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type) const {
|
2018-08-18 21:28:17 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}",
|
2020-12-07 22:00:34 -05:00
|
|
|
title_id, storage_id, type);
|
2018-08-18 21:28:17 -04:00
|
|
|
|
|
|
|
if (romfs_factory == nullptr) {
|
|
|
|
// TODO(bunnei): Find a better error code for this
|
2019-11-12 05:38:12 -05:00
|
|
|
return RESULT_UNKNOWN;
|
2018-08-18 21:28:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return romfs_factory->Open(title_id, storage_id, type);
|
2018-01-16 22:20:12 -05:00
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
ResultVal<FileSys::VirtualDir> FileSystemController::CreateSaveData(
|
2020-07-30 15:29:39 -04:00
|
|
|
FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const {
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", space,
|
|
|
|
save_struct.DebugInfo());
|
2019-04-16 09:13:34 -04:00
|
|
|
|
|
|
|
if (save_data_factory == nullptr) {
|
|
|
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
return save_data_factory->Create(space, save_struct);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveData(
|
2020-07-30 15:29:39 -04:00
|
|
|
FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& attribute) const {
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", space,
|
|
|
|
attribute.DebugInfo());
|
2018-03-04 13:03:58 -05:00
|
|
|
|
2018-07-17 15:42:15 -04:00
|
|
|
if (save_data_factory == nullptr) {
|
2018-11-15 23:27:29 -05:00
|
|
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
2018-07-17 15:42:15 -04:00
|
|
|
}
|
|
|
|
|
2020-07-30 15:29:39 -04:00
|
|
|
return save_data_factory->Open(space, attribute);
|
2018-07-17 15:42:15 -04:00
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveDataSpace(
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::SaveDataSpaceId space) const {
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_TRACE(Service_FS, "Opening Save Data Space for space_id={:01X}", space);
|
2018-10-28 14:56:43 -04:00
|
|
|
|
|
|
|
if (save_data_factory == nullptr) {
|
2018-11-15 23:27:29 -05:00
|
|
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
2018-10-28 14:56:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return MakeResult(save_data_factory->GetSaveDataSpaceDirectory(space));
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
ResultVal<FileSys::VirtualDir> FileSystemController::OpenSDMC() const {
|
2018-07-17 15:42:15 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr) {
|
2018-11-15 23:27:29 -05:00
|
|
|
return FileSys::ERROR_SD_CARD_NOT_FOUND;
|
2018-03-04 13:03:58 -05:00
|
|
|
}
|
|
|
|
|
2018-07-17 15:42:15 -04:00
|
|
|
return sdmc_factory->Open();
|
2018-03-04 13:03:58 -05:00
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
ResultVal<FileSys::VirtualDir> FileSystemController::OpenBISPartition(
|
|
|
|
FileSys::BisPartitionId id) const {
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_TRACE(Service_FS, "Opening BIS Partition with id={:08X}", id);
|
2019-04-16 09:13:34 -04:00
|
|
|
|
|
|
|
if (bis_factory == nullptr) {
|
|
|
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto part = bis_factory->OpenPartition(id);
|
|
|
|
if (part == nullptr) {
|
|
|
|
return FileSys::ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MakeResult<FileSys::VirtualDir>(std::move(part));
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<FileSys::VirtualFile> FileSystemController::OpenBISPartitionStorage(
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::BisPartitionId id) const {
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_TRACE(Service_FS, "Opening BIS Partition Storage with id={:08X}", id);
|
2019-04-16 09:13:34 -04:00
|
|
|
|
|
|
|
if (bis_factory == nullptr) {
|
|
|
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2020-09-16 18:14:43 -04:00
|
|
|
auto part = bis_factory->OpenPartitionStorage(id, system.GetFilesystem());
|
2019-04-16 09:13:34 -04:00
|
|
|
if (part == nullptr) {
|
|
|
|
return FileSys::ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MakeResult<FileSys::VirtualFile>(std::move(part));
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 FileSystemController::GetFreeSpaceSize(FileSys::StorageId id) const {
|
|
|
|
switch (id) {
|
|
|
|
case FileSys::StorageId::None:
|
|
|
|
case FileSys::StorageId::GameCard:
|
|
|
|
return 0;
|
|
|
|
case FileSys::StorageId::SdCard:
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return sdmc_factory->GetSDMCFreeSpace();
|
|
|
|
case FileSys::StorageId::Host:
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return bis_factory->GetSystemNANDFreeSpace() + bis_factory->GetUserNANDFreeSpace();
|
|
|
|
case FileSys::StorageId::NandSystem:
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return bis_factory->GetSystemNANDFreeSpace();
|
|
|
|
case FileSys::StorageId::NandUser:
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return bis_factory->GetUserNANDFreeSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 FileSystemController::GetTotalSpaceSize(FileSys::StorageId id) const {
|
|
|
|
switch (id) {
|
|
|
|
case FileSys::StorageId::None:
|
|
|
|
case FileSys::StorageId::GameCard:
|
|
|
|
return 0;
|
|
|
|
case FileSys::StorageId::SdCard:
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return sdmc_factory->GetSDMCTotalSpace();
|
|
|
|
case FileSys::StorageId::Host:
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return bis_factory->GetFullNANDTotalSpace();
|
|
|
|
case FileSys::StorageId::NandSystem:
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return bis_factory->GetSystemNANDTotalSpace();
|
|
|
|
case FileSys::StorageId::NandUser:
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return 0;
|
|
|
|
return bis_factory->GetUserNANDTotalSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSys::SaveDataSize FileSystemController::ReadSaveDataSize(FileSys::SaveDataType type,
|
2019-04-23 14:38:18 -04:00
|
|
|
u64 title_id, u128 user_id) const {
|
2018-12-06 20:29:36 -05:00
|
|
|
if (save_data_factory == nullptr) {
|
|
|
|
return {0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto value = save_data_factory->ReadSaveDataSize(type, title_id, user_id);
|
|
|
|
|
|
|
|
if (value.normal == 0 && value.journal == 0) {
|
|
|
|
FileSys::SaveDataSize new_size{SUFFICIENT_SAVE_DATA_SIZE, SUFFICIENT_SAVE_DATA_SIZE};
|
|
|
|
|
|
|
|
FileSys::NACP nacp;
|
2019-10-06 13:02:23 -04:00
|
|
|
const auto res = system.GetAppLoader().ReadControlData(nacp);
|
2018-12-06 20:29:36 -05:00
|
|
|
|
|
|
|
if (res != Loader::ResultStatus::Success) {
|
2020-11-18 07:53:10 -05:00
|
|
|
const FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID(),
|
|
|
|
system.GetFileSystemController(),
|
|
|
|
system.GetContentProvider()};
|
2020-04-15 15:59:23 -04:00
|
|
|
const auto metadata = pm.GetControlMetadata();
|
|
|
|
const auto& nacp_unique = metadata.first;
|
2018-12-06 20:29:36 -05:00
|
|
|
|
|
|
|
if (nacp_unique != nullptr) {
|
|
|
|
new_size = {nacp_unique->GetDefaultNormalSaveSize(),
|
|
|
|
nacp_unique->GetDefaultJournalSaveSize()};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
new_size = {nacp.GetDefaultNormalSaveSize(), nacp.GetDefaultJournalSaveSize()};
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteSaveDataSize(type, title_id, user_id, new_size);
|
|
|
|
return new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
void FileSystemController::WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::SaveDataSize new_value) const {
|
2018-12-06 20:29:36 -05:00
|
|
|
if (save_data_factory != nullptr)
|
|
|
|
save_data_factory->WriteSaveDataSize(type, title_id, user_id, new_value);
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
void FileSystemController::SetGameCard(FileSys::VirtualFile file) {
|
|
|
|
gamecard = std::make_unique<FileSys::XCI>(file);
|
|
|
|
const auto dir = gamecard->ConcatenatedPseudoDirectory();
|
|
|
|
gamecard_registered = std::make_unique<FileSys::RegisteredCache>(dir);
|
|
|
|
gamecard_placeholder = std::make_unique<FileSys::PlaceholderCache>(dir);
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::XCI* FileSystemController::GetGameCard() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
return gamecard.get();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::RegisteredCache* FileSystemController::GetGameCardContents() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
return gamecard_registered.get();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::PlaceholderCache* FileSystemController::GetGameCardPlaceholder() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
return gamecard_placeholder.get();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::RegisteredCache* FileSystemController::GetSystemNANDContents() const {
|
2018-08-16 17:03:31 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening System NAND Contents");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
2018-08-09 20:50:10 -04:00
|
|
|
return bis_factory->GetSystemNANDContents();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::RegisteredCache* FileSystemController::GetUserNANDContents() const {
|
2018-08-16 17:03:31 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening User NAND Contents");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
2018-08-09 20:50:10 -04:00
|
|
|
return bis_factory->GetUserNANDContents();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::RegisteredCache* FileSystemController::GetSDMCContents() const {
|
2018-08-16 17:03:31 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC Contents");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return sdmc_factory->GetSDMCContents();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::PlaceholderCache* FileSystemController::GetSystemNANDPlaceholder() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening System NAND Placeholder");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetSystemNANDPlaceholder();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::PlaceholderCache* FileSystemController::GetUserNANDPlaceholder() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening User NAND Placeholder");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetUserNANDPlaceholder();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::PlaceholderCache* FileSystemController::GetSDMCPlaceholder() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC Placeholder");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return sdmc_factory->GetSDMCPlaceholder();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSys::RegisteredCache* FileSystemController::GetRegisteredCacheForStorage(
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::StorageId id) const {
|
2019-04-16 09:13:34 -04:00
|
|
|
switch (id) {
|
|
|
|
case FileSys::StorageId::None:
|
|
|
|
case FileSys::StorageId::Host:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return nullptr;
|
|
|
|
case FileSys::StorageId::GameCard:
|
|
|
|
return GetGameCardContents();
|
|
|
|
case FileSys::StorageId::NandSystem:
|
|
|
|
return GetSystemNANDContents();
|
|
|
|
case FileSys::StorageId::NandUser:
|
|
|
|
return GetUserNANDContents();
|
|
|
|
case FileSys::StorageId::SdCard:
|
|
|
|
return GetSDMCContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSys::PlaceholderCache* FileSystemController::GetPlaceholderCacheForStorage(
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::StorageId id) const {
|
2019-04-16 09:13:34 -04:00
|
|
|
switch (id) {
|
|
|
|
case FileSys::StorageId::None:
|
|
|
|
case FileSys::StorageId::Host:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return nullptr;
|
|
|
|
case FileSys::StorageId::GameCard:
|
|
|
|
return GetGameCardPlaceholder();
|
|
|
|
case FileSys::StorageId::NandSystem:
|
|
|
|
return GetSystemNANDPlaceholder();
|
|
|
|
case FileSys::StorageId::NandUser:
|
|
|
|
return GetUserNANDPlaceholder();
|
|
|
|
case FileSys::StorageId::SdCard:
|
|
|
|
return GetSDMCPlaceholder();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetSystemNANDContentDirectory() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening system NAND content directory");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetSystemNANDContentDirectory();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetUserNANDContentDirectory() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening user NAND content directory");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetUserNANDContentDirectory();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetSDMCContentDirectory() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC content directory");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return sdmc_factory->GetSDMCContentDirectory();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetNANDImageDirectory() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening NAND image directory");
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetImageDirectory();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetSDMCImageDirectory() const {
|
2019-04-16 09:13:34 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening SDMC image directory");
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return sdmc_factory->GetImageDirectory();
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetContentDirectory(ContentStorageId id) const {
|
2019-04-16 09:13:34 -04:00
|
|
|
switch (id) {
|
|
|
|
case ContentStorageId::System:
|
|
|
|
return GetSystemNANDContentDirectory();
|
|
|
|
case ContentStorageId::User:
|
|
|
|
return GetUserNANDContentDirectory();
|
|
|
|
case ContentStorageId::SdCard:
|
|
|
|
return GetSDMCContentDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetImageDirectory(ImageDirectoryId id) const {
|
2019-04-16 09:13:34 -04:00
|
|
|
switch (id) {
|
|
|
|
case ImageDirectoryId::NAND:
|
|
|
|
return GetNANDImageDirectory();
|
|
|
|
case ImageDirectoryId::SdCard:
|
|
|
|
return GetSDMCImageDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetModificationLoadRoot(u64 title_id) const {
|
2018-09-19 22:04:15 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-04-23 14:38:18 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetModificationDumpRoot(u64 title_id) const {
|
2018-10-29 16:08:03 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening mod dump root for tid={:016X}", title_id);
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetModificationDumpRoot(title_id);
|
|
|
|
}
|
|
|
|
|
2019-10-01 09:13:09 -04:00
|
|
|
FileSys::VirtualDir FileSystemController::GetBCATDirectory(u64 title_id) const {
|
2019-04-28 18:42:36 -04:00
|
|
|
LOG_TRACE(Service_FS, "Opening BCAT root for tid={:016X}", title_id);
|
|
|
|
|
|
|
|
if (bis_factory == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return bis_factory->GetBCATDirectory(title_id);
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:13:34 -04:00
|
|
|
void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool overwrite) {
|
2018-08-16 17:03:31 -04:00
|
|
|
if (overwrite) {
|
|
|
|
bis_factory = nullptr;
|
|
|
|
save_data_factory = nullptr;
|
|
|
|
sdmc_factory = nullptr;
|
|
|
|
}
|
2018-02-19 00:32:00 -05:00
|
|
|
|
2020-08-15 08:33:16 -04:00
|
|
|
auto nand_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir),
|
2018-10-13 11:25:13 -04:00
|
|
|
FileSys::Mode::ReadWrite);
|
2020-08-15 08:33:16 -04:00
|
|
|
auto sd_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir),
|
2018-10-13 11:25:13 -04:00
|
|
|
FileSys::Mode::ReadWrite);
|
2020-08-15 08:33:16 -04:00
|
|
|
auto load_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
|
2018-10-13 11:25:13 -04:00
|
|
|
FileSys::Mode::ReadWrite);
|
2020-08-15 08:33:16 -04:00
|
|
|
auto dump_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::DumpDir),
|
2018-10-29 16:08:03 -04:00
|
|
|
FileSys::Mode::ReadWrite);
|
2018-02-19 00:32:00 -05:00
|
|
|
|
2018-10-29 16:08:03 -04:00
|
|
|
if (bis_factory == nullptr) {
|
|
|
|
bis_factory =
|
|
|
|
std::make_unique<FileSys::BISFactory>(nand_directory, load_directory, dump_directory);
|
2019-10-06 13:02:23 -04:00
|
|
|
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SysNAND,
|
|
|
|
bis_factory->GetSystemNANDContents());
|
|
|
|
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::UserNAND,
|
|
|
|
bis_factory->GetUserNANDContents());
|
2018-10-29 16:08:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (save_data_factory == nullptr) {
|
2020-11-27 01:30:17 -05:00
|
|
|
save_data_factory =
|
|
|
|
std::make_unique<FileSys::SaveDataFactory>(system, std::move(nand_directory));
|
2018-10-29 16:08:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sdmc_factory == nullptr) {
|
2018-08-16 17:04:38 -04:00
|
|
|
sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory));
|
2019-10-06 13:02:23 -04:00
|
|
|
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SDMC,
|
|
|
|
sdmc_factory->GetSDMCContents());
|
2018-10-29 16:08:03 -04:00
|
|
|
}
|
2018-01-16 22:20:12 -05:00
|
|
|
}
|
|
|
|
|
2019-06-28 21:02:34 -04:00
|
|
|
void InstallInterfaces(Core::System& system) {
|
2020-11-26 15:19:08 -05:00
|
|
|
std::make_shared<FSP_LDR>(system)->InstallAsService(system.ServiceManager());
|
|
|
|
std::make_shared<FSP_PR>(system)->InstallAsService(system.ServiceManager());
|
|
|
|
std::make_shared<FSP_SRV>(system)->InstallAsService(system.ServiceManager());
|
2018-01-16 22:20:12 -05:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::FileSystem
|