loader: refactor to use fs bindings
This commit is contained in:
40
libraries/libstratosphere/source/fs/fs_application.cpp
Normal file
40
libraries/libstratosphere/source/fs/fs_application.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fsa/fs_mount_utils.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
Result MountApplicationPackage(const char *name, const char *common_path) {
|
||||
/* Validate the mount name. */
|
||||
R_TRY(impl::CheckMountName(name));
|
||||
|
||||
/* Validate the path. */
|
||||
R_UNLESS(common_path != nullptr, fs::ResultInvalidPath());
|
||||
|
||||
/* Open a filesystem using libnx bindings. */
|
||||
FsFileSystem fs;
|
||||
R_TRY(fsOpenFileSystemWithId(std::addressof(fs), ncm::InvalidProgramId.value, static_cast<::FsFileSystemType>(impl::FileSystemProxyType_Package), common_path));
|
||||
|
||||
/* Allocate a new filesystem wrapper. */
|
||||
auto fsa = std::make_unique<RemoteFileSystem>(fs);
|
||||
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInApplicationA());
|
||||
|
||||
/* Register. */
|
||||
return fsa::Register(name, std::move(fsa));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,261 @@
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
namespace {
|
||||
|
||||
Result OpenCodeFileSystemImpl(std::unique_ptr<fsa::IFileSystem> *out, const char *path, ncm::ProgramId program_id) {
|
||||
/* Print a path suitable for the remote service. */
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(FspPathPrintf(std::addressof(sf_path), "%s", path));
|
||||
|
||||
/* Open the filesystem using libnx bindings. */
|
||||
::FsFileSystem fs;
|
||||
R_TRY(fsldrOpenCodeFileSystem(program_id.value, sf_path.str, std::addressof(fs)));
|
||||
|
||||
/* Allocate a new filesystem wrapper. */
|
||||
auto fsa = std::make_unique<RemoteFileSystem>(fs);
|
||||
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInCodeA());
|
||||
|
||||
*out = std::move(fsa);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenPackageFileSystemImpl(std::unique_ptr<fsa::IFileSystem> *out, const char *common_path) {
|
||||
/* Open a filesystem using libnx bindings. */
|
||||
FsFileSystem fs;
|
||||
R_TRY(fsOpenFileSystemWithId(std::addressof(fs), ncm::InvalidProgramId.value, static_cast<::FsFileSystemType>(impl::FileSystemProxyType_Package), common_path));
|
||||
|
||||
/* Allocate a new filesystem wrapper. */
|
||||
auto fsa = std::make_unique<RemoteFileSystem>(fs);
|
||||
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInCodeA());
|
||||
|
||||
*out = std::move(fsa);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenSdCardCodeFileSystemImpl(std::unique_ptr<fsa::IFileSystem> *out, ncm::ProgramId program_id) {
|
||||
/* Ensure we don't access the SD card too early. */
|
||||
R_UNLESS(cfg::IsSdCardInitialized(), fs::ResultSdCardNotPresent());
|
||||
|
||||
/* Print a path to the program's package. */
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(FspPathPrintf(std::addressof(sf_path), "%s:/atmosphere/contents/%016lx/exefs.nsp", impl::SdCardFileSystemMountName, program_id.value));
|
||||
|
||||
return OpenPackageFileSystemImpl(out, sf_path.str);
|
||||
}
|
||||
|
||||
Result OpenSdCardCodeOrCodeFileSystemImpl(std::unique_ptr<fsa::IFileSystem> *out, const char *path, ncm::ProgramId program_id) {
|
||||
/* If we can open an sd card code fs, use it. */
|
||||
R_SUCCEED_IF(R_SUCCEEDED(OpenSdCardCodeFileSystemImpl(out, program_id)));
|
||||
|
||||
/* Otherwise, fall back to a normal code fs. */
|
||||
return OpenCodeFileSystemImpl(out, path, program_id);
|
||||
}
|
||||
|
||||
Result OpenHblCodeFileSystemImpl(std::unique_ptr<fsa::IFileSystem> *out) {
|
||||
/* Get the HBL path. */
|
||||
const char *hbl_path = cfg::GetHblPath();
|
||||
|
||||
/* Print a path to the hbl package. */
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(FspPathPrintf(std::addressof(sf_path), "%s:/%s", impl::SdCardFileSystemMountName, hbl_path[0] == '/' ? hbl_path + 1 : hbl_path));
|
||||
|
||||
return OpenPackageFileSystemImpl(out, sf_path.str);
|
||||
}
|
||||
|
||||
Result OpenSdCardFileSystemImpl(std::unique_ptr<fsa::IFileSystem> *out) {
|
||||
/* Open the SD card. This uses libnx bindings. */
|
||||
FsFileSystem fs;
|
||||
R_TRY(fsOpenSdCardFileSystem(std::addressof(fs)));
|
||||
|
||||
/* Allocate a new filesystem wrapper. */
|
||||
auto fsa = std::make_unique<RemoteFileSystem>(fs);
|
||||
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInCodeA());
|
||||
|
||||
*out = std::move(fsa);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
class OpenFileOnlyFileSystem : public fsa::IFileSystem, public impl::Newable {
|
||||
private:
|
||||
virtual Result CommitImpl() override final {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
virtual Result OpenDirectoryImpl(std::unique_ptr<fsa::IDirectory> *out_dir, const char *path, OpenDirectoryMode mode) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result GetEntryTypeImpl(DirectoryEntryType *out, const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result CreateFileImpl(const char *path, s64 size, int flags) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result DeleteFileImpl(const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result CreateDirectoryImpl(const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result DeleteDirectoryImpl(const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result DeleteDirectoryRecursivelyImpl(const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result RenameFileImpl(const char *old_path, const char *new_path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result RenameDirectoryImpl(const char *old_path, const char *new_path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result CleanDirectoryRecursivelyImpl(const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result GetFreeSpaceSizeImpl(s64 *out, const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result GetTotalSpaceSizeImpl(s64 *out, const char *path) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
|
||||
virtual Result CommitProvisionallyImpl(s64 counter) override final {
|
||||
return fs::ResultUnsupportedOperation();
|
||||
}
|
||||
};
|
||||
|
||||
class SdCardRedirectionCodeFileSystem : public OpenFileOnlyFileSystem {
|
||||
private:
|
||||
std::optional<ReadOnlyFileSystem> sd_content_fs;
|
||||
ReadOnlyFileSystem code_fs;
|
||||
bool is_redirect;
|
||||
public:
|
||||
SdCardRedirectionCodeFileSystem(std::unique_ptr<fsa::IFileSystem> &&code, ncm::ProgramId program_id, bool redirect) : code_fs(std::move(code)), is_redirect(redirect) {
|
||||
if (!cfg::IsSdCardInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Open an SD card filesystem. */
|
||||
std::unique_ptr<fsa::IFileSystem> sd_fs;
|
||||
if (R_FAILED(OpenSdCardFileSystemImpl(std::addressof(sd_fs)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create a redirection filesystem to the relevant content folder. */
|
||||
char path[fs::EntryNameLengthMax + 1];
|
||||
std::snprintf(path, sizeof(path), "/atmosphere/contents/%016lx/exefs", program_id.value);
|
||||
|
||||
auto subdir_fs = std::make_unique<fssystem::SubDirectoryFileSystem>(std::move(sd_fs), path);
|
||||
if (subdir_fs == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
sd_content_fs.emplace(std::move(subdir_fs));
|
||||
}
|
||||
private:
|
||||
bool IsFileStubbed(const char *path) {
|
||||
/* If we don't have an sd content fs, nothing is stubbed. */
|
||||
if (!this->sd_content_fs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Create a path representing the stub. */
|
||||
char stub_path[fs::EntryNameLengthMax + 1];
|
||||
std::snprintf(stub_path, sizeof(stub_path), "%s.stub", path);
|
||||
|
||||
/* Query whether we have the file. */
|
||||
bool has_file;
|
||||
if (R_FAILED(fssystem::HasFile(std::addressof(has_file), std::addressof(*this->sd_content_fs), stub_path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return has_file;
|
||||
}
|
||||
|
||||
virtual Result OpenFileImpl(std::unique_ptr<fsa::IFile> *out_file, const char *path, OpenMode mode) override final {
|
||||
/* Only allow opening files with mode = read. */
|
||||
R_UNLESS((mode & fs::OpenMode_All) == fs::OpenMode_Read, fs::ResultInvalidArgument());
|
||||
|
||||
/* If we support redirection, we'd like to prefer a file from the sd card. */
|
||||
if (this->is_redirect) {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(this->sd_content_fs->OpenFile(out_file, path, mode)));
|
||||
}
|
||||
|
||||
/* Otherwise, check if the file is stubbed. */
|
||||
R_UNLESS(!this->IsFileStubbed(path), fs::ResultPathNotFound());
|
||||
|
||||
/* Open a file from the base code fs. */
|
||||
return this->code_fs.OpenFile(out_file, path, mode);
|
||||
}
|
||||
};
|
||||
|
||||
class AtmosphereCodeFileSystem : public OpenFileOnlyFileSystem {
|
||||
private:
|
||||
std::optional<SdCardRedirectionCodeFileSystem> code_fs;
|
||||
std::optional<ReadOnlyFileSystem> hbl_fs;
|
||||
ncm::ProgramId program_id;
|
||||
bool initialized;
|
||||
public:
|
||||
AtmosphereCodeFileSystem() : initialized(false) { /* ... */ }
|
||||
|
||||
Result Initialize(const char *path, ncm::ProgramId program_id, bool is_hbl, bool is_specific) {
|
||||
AMS_ABORT_UNLESS(!this->initialized);
|
||||
|
||||
/* If we're hbl, we need to open a hbl fs. */
|
||||
if (is_hbl) {
|
||||
std::unique_ptr<fsa::IFileSystem> fsa;
|
||||
R_TRY(OpenHblCodeFileSystemImpl(std::addressof(fsa)));
|
||||
this->hbl_fs.emplace(std::move(fsa));
|
||||
}
|
||||
|
||||
/* Open the code filesystem. */
|
||||
std::unique_ptr<fsa::IFileSystem> fsa;
|
||||
R_TRY(OpenSdCardCodeOrCodeFileSystemImpl(std::addressof(fsa), path, program_id));
|
||||
this->code_fs.emplace(std::move(fsa), program_id, is_specific);
|
||||
|
||||
this->initialized = true;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
private:
|
||||
virtual Result OpenFileImpl(std::unique_ptr<fsa::IFile> *out_file, const char *path, OpenMode mode) override final {
|
||||
/* Ensure that we're initialized. */
|
||||
R_UNLESS(this->initialized, fs::ResultNotInitialized());
|
||||
|
||||
/* Only allow opening files with mode = read. */
|
||||
R_UNLESS((mode & fs::OpenMode_All) == fs::OpenMode_Read, fs::ResultInvalidArgument());
|
||||
|
||||
/* First, check if there's an external code. */
|
||||
{
|
||||
fsa::IFileSystem *ecs = fssystem::GetExternalCodeFileSystem(this->program_id);
|
||||
if (ecs != nullptr) {
|
||||
return ecs->OpenFile(out_file, path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're hbl, open from the hbl fs. */
|
||||
if (this->hbl_fs) {
|
||||
return this->hbl_fs->OpenFile(out_file, path, mode);
|
||||
}
|
||||
|
||||
/* If we're not hbl, fall back to our code filesystem. */
|
||||
return this->code_fs->OpenFile(out_file, path, mode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Result MountCode(const char *name, const char *path, ncm::ProgramId program_id) {
|
||||
/* Validate the mount name. */
|
||||
R_TRY(impl::CheckMountName(name));
|
||||
@@ -25,20 +280,49 @@ namespace ams::fs {
|
||||
/* Validate the path isn't null. */
|
||||
R_UNLESS(path != nullptr, fs::ResultInvalidPath());
|
||||
|
||||
/* Print a path suitable for the remove service. */
|
||||
fssrv::sf::Path sf_path;
|
||||
R_TRY(FspPathPrintf(std::addressof(sf_path), "%s", path));
|
||||
|
||||
/* Open the filesystem using libnx bindings. */
|
||||
::FsFileSystem fs;
|
||||
R_TRY(fsldrOpenCodeFileSystem(program_id.value, sf_path.str, std::addressof(fs)));
|
||||
|
||||
/* Allocate a new filesystem wrapper. */
|
||||
auto fsa = std::make_unique<RemoteFileSystem>(fs);
|
||||
R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInCodeA());
|
||||
/* Open the code file system. */
|
||||
std::unique_ptr<fsa::IFileSystem> fsa;
|
||||
R_TRY(OpenCodeFileSystemImpl(std::addressof(fsa), path, program_id));
|
||||
|
||||
/* Register. */
|
||||
return fsa::Register(name, std::move(fsa));
|
||||
}
|
||||
|
||||
Result MountCodeForAtmosphereWithRedirection(const char *name, const char *path, ncm::ProgramId program_id, bool is_hbl, bool is_specific) {
|
||||
/* Validate the mount name. */
|
||||
R_TRY(impl::CheckMountName(name));
|
||||
|
||||
/* Validate the path isn't null. */
|
||||
R_UNLESS(path != nullptr, fs::ResultInvalidPath());
|
||||
|
||||
/* Create an AtmosphereCodeFileSystem. */
|
||||
auto ams_code_fs = std::make_unique<AtmosphereCodeFileSystem>();
|
||||
R_UNLESS(ams_code_fs != nullptr, fs::ResultAllocationFailureInCodeA());
|
||||
|
||||
/* Initialize the code file system. */
|
||||
R_TRY(ams_code_fs->Initialize(path, program_id, is_hbl, is_specific));
|
||||
|
||||
/* Register. */
|
||||
return fsa::Register(name, std::move(ams_code_fs));
|
||||
}
|
||||
|
||||
Result MountCodeForAtmosphere(const char *name, const char *path, ncm::ProgramId program_id) {
|
||||
/* Validate the mount name. */
|
||||
R_TRY(impl::CheckMountName(name));
|
||||
|
||||
/* Validate the path isn't null. */
|
||||
R_UNLESS(path != nullptr, fs::ResultInvalidPath());
|
||||
|
||||
/* Open the code file system. */
|
||||
std::unique_ptr<fsa::IFileSystem> fsa;
|
||||
R_TRY(OpenSdCardCodeOrCodeFileSystemImpl(std::addressof(fsa), path, program_id));
|
||||
|
||||
/* Create a wrapper fs. */
|
||||
auto wrap_fsa = std::make_unique<SdCardRedirectionCodeFileSystem>(std::move(fsa), program_id, false);
|
||||
R_UNLESS(wrap_fsa != nullptr, fs::ResultAllocationFailureInCodeA());
|
||||
|
||||
/* Register. */
|
||||
return fsa::Register(name, std::move(wrap_fsa));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,26 +19,6 @@
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
namespace {
|
||||
|
||||
Result HasEntry(bool *out, const char *path, fs::DirectoryEntryType type) {
|
||||
/* Set out to false initially. */
|
||||
*out = false;
|
||||
|
||||
/* Try to get the entry type. */
|
||||
fs::DirectoryEntryType entry_type;
|
||||
R_TRY_CATCH(fs::GetEntryType(std::addressof(entry_type), path)) {
|
||||
/* If the path doesn't exist, nothing has gone wrong. */
|
||||
R_CONVERT(fs::ResultPathNotFound, ResultSuccess());
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* We succeeded. */
|
||||
*out = entry_type == type;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result EnsureDirectoryRecursively(const char *path) {
|
||||
/* Get the filesystem accessor and sub path. */
|
||||
impl::FileSystemAccessor *accessor;
|
||||
@@ -60,11 +40,21 @@ namespace ams::fs {
|
||||
}
|
||||
|
||||
Result HasFile(bool *out, const char *path) {
|
||||
return HasEntry(out, path, fs::DirectoryEntryType_File);
|
||||
/* Get the filesystem accessor and sub path. */
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
return fssystem::HasFile(out, accessor->GetRawFileSystemUnsafe(), sub_path);
|
||||
}
|
||||
|
||||
Result HasDirectory(bool *out, const char *path) {
|
||||
return HasEntry(out, path, fs::DirectoryEntryType_Directory);
|
||||
/* Get the filesystem accessor and sub path. */
|
||||
impl::FileSystemAccessor *accessor;
|
||||
const char *sub_path;
|
||||
R_TRY(impl::FindFileSystem(std::addressof(accessor), std::addressof(sub_path), path));
|
||||
|
||||
return fssystem::HasDirectory(out, accessor->GetRawFileSystemUnsafe(), sub_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::fssystem {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr inline size_t MaxExternalCodeFileSystem = 0x10;
|
||||
|
||||
util::BoundedMap<ncm::ProgramId, fs::RemoteFileSystem, MaxExternalCodeFileSystem> g_ecs_map;
|
||||
util::BoundedMap<ncm::ProgramId, os::ManagedHandle, MaxExternalCodeFileSystem> g_hnd_map;
|
||||
|
||||
}
|
||||
|
||||
|
||||
fs::fsa::IFileSystem *GetExternalCodeFileSystem(ncm::ProgramId program_id) {
|
||||
/* Return a fs from the map if one exists. */
|
||||
if (auto *fs = g_ecs_map.Find(program_id); fs != nullptr) {
|
||||
return fs;
|
||||
}
|
||||
|
||||
/* Otherwise, we may have a handle. */
|
||||
if (auto *hnd = g_hnd_map.Find(program_id); hnd != nullptr) {
|
||||
/* Create a service using libnx bindings. */
|
||||
Service srv;
|
||||
serviceCreate(std::addressof(srv), hnd->Move());
|
||||
g_hnd_map.Remove(program_id);
|
||||
|
||||
/* Create a remote filesystem. */
|
||||
const FsFileSystem fs = { srv };
|
||||
g_ecs_map.Emplace(program_id, fs);
|
||||
|
||||
/* Return the created filesystem. */
|
||||
return g_ecs_map.Find(program_id);
|
||||
}
|
||||
|
||||
/* Otherwise, we have no filesystem. */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Result CreateExternalCode(Handle *out, ncm::ProgramId program_id) {
|
||||
/* Create a handle pair. */
|
||||
Handle server, client;
|
||||
R_TRY(svcCreateSession(std::addressof(server), std::addressof(client), false, 0));
|
||||
|
||||
/* Insert the handle into the map. */
|
||||
g_hnd_map.Emplace(program_id, client);
|
||||
|
||||
*out = server;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void DestroyExternalCode(ncm::ProgramId program_id) {
|
||||
g_ecs_map.Remove(program_id);
|
||||
g_hnd_map.Remove(program_id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,22 @@ namespace ams::fssystem {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result HasEntry(bool *out, fs::fsa::IFileSystem *fsa, const char *path, fs::DirectoryEntryType type) {
|
||||
/* Set out to false initially. */
|
||||
*out = false;
|
||||
|
||||
/* Try to get the entry type. */
|
||||
fs::DirectoryEntryType entry_type;
|
||||
R_TRY_CATCH(fsa->GetEntryType(std::addressof(entry_type), path)) {
|
||||
/* If the path doesn't exist, nothing has gone wrong. */
|
||||
R_CONVERT(fs::ResultPathNotFound, ResultSuccess());
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* We succeeded. */
|
||||
*out = entry_type == type;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result CopyFile(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *entry, void *work_buf, size_t work_buf_size) {
|
||||
@@ -117,6 +133,14 @@ namespace ams::fssystem {
|
||||
);
|
||||
}
|
||||
|
||||
Result HasFile(bool *out, fs::fsa::IFileSystem *fs, const char *path) {
|
||||
return HasEntry(out, fs, path, fs::DirectoryEntryType_File);
|
||||
}
|
||||
|
||||
Result HasDirectory(bool *out, fs::fsa::IFileSystem *fs, const char *path) {
|
||||
return HasEntry(out, fs, path, fs::DirectoryEntryType_Directory);
|
||||
}
|
||||
|
||||
Result EnsureDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path) {
|
||||
return EnsureDirectoryRecursivelyImpl(fs, path, true);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace ams::patcher {
|
||||
}
|
||||
{
|
||||
size_t remaining = read_size;
|
||||
size_t copy_offset = 0;
|
||||
size_t copy_offset = patch_offset;
|
||||
while (remaining > 0) {
|
||||
const size_t cur_read = std::min(remaining, sizeof(g_patch_read_buffer));
|
||||
ReadData(g_patch_read_buffer, cur_read);
|
||||
@@ -211,13 +211,13 @@ namespace ams::patcher {
|
||||
|
||||
}
|
||||
|
||||
void LocateAndApplyIpsPatchesToModule(const char *patch_dir_name, size_t protected_size, size_t offset, const ro::ModuleId *module_id, u8 *mapped_module, size_t mapped_size) {
|
||||
void LocateAndApplyIpsPatchesToModule(const char *mount_name, const char *patch_dir_name, size_t protected_size, size_t offset, const ro::ModuleId *module_id, u8 *mapped_module, size_t mapped_size) {
|
||||
/* Ensure only one thread tries to apply patches at a time. */
|
||||
std::scoped_lock lk(apply_patch_lock);
|
||||
|
||||
/* Inspect all patches from /atmosphere/<patch_dir>/<*>/<*>.ips */
|
||||
char path[fs::EntryNameLengthMax + 1];
|
||||
std::snprintf(path, sizeof(path), "sdmc:/atmosphere/%s", patch_dir_name);
|
||||
std::snprintf(path, sizeof(path), "%s:/atmosphere/%s", mount_name, patch_dir_name);
|
||||
const size_t patches_dir_path_len = std::strlen(path);
|
||||
|
||||
/* Open the patch directory. */
|
||||
|
||||
Reference in New Issue
Block a user