From ad8acaefec3392b7aac876601b82ec2450cadf61 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 26 Mar 2019 09:05:19 -0700 Subject: [PATCH] fs.mitm: fix some filesystem issues --- stratosphere/ams_mitm/source/fs_mitm/fs_ifile.hpp | 2 +- stratosphere/ams_mitm/source/fs_mitm/fs_ifilesystem.hpp | 6 +++++- stratosphere/ams_mitm/source/fs_mitm/fs_path_utils.cpp | 8 ++++---- .../source/fs_mitm/fs_subdirectory_filesystem.cpp | 1 + stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp | 8 +++++--- stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp | 2 +- stratosphere/ams_mitm/source/utils.cpp | 4 ++++ stratosphere/ams_mitm/source/utils.hpp | 1 + 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_ifile.hpp b/stratosphere/ams_mitm/source/fs_mitm/fs_ifile.hpp index be5de142f..8da0e5838 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_ifile.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_ifile.hpp @@ -72,7 +72,7 @@ class IFile { } Result Write(uint64_t offset, void *buffer, uint64_t size) { - return Write(offset, buffer, size, false); + return WriteImpl(offset, buffer, size, false); } Result SetSize(uint64_t size) { diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_ifilesystem.hpp b/stratosphere/ams_mitm/source/fs_mitm/fs_ifilesystem.hpp index 803f1916c..2b3fda4c0 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_ifilesystem.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_ifilesystem.hpp @@ -18,6 +18,8 @@ #include #include +#include "../utils.hpp" + #include "fs_results.hpp" #include "fs_filesystem_types.hpp" #include "fs_path_utils.hpp" @@ -108,7 +110,7 @@ class IFileSystem { if (mode & ~DirectoryOpenMode_All) { return ResultFsInvalidArgument; } - return OpenDirectory(out_dir, path, mode); + return OpenDirectoryImpl(out_dir, path, mode); } Result Commit() { @@ -333,10 +335,12 @@ class IFileSystemInterface : public IServiceObject { } rc = this->base_fs->OpenDirectory(out_dir, path, static_cast(mode)); + if (R_SUCCEEDED(rc)) { out_intf.SetValue(std::make_shared(std::move(out_dir))); /* TODO: Nintendo checks allocation success here, should we?. */ } + return rc; } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_path_utils.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_path_utils.cpp index 8b9d9bd9f..d4e6f26ea 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_path_utils.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_path_utils.cpp @@ -150,13 +150,13 @@ Result FsPathUtils::IsNormalized(bool *out, const char *path) { case PathState::WindowsDriveLetter: return ResultFsInvalidPathFormat; case PathState::FirstSeparator: - case PathState::Separator: - *out = false; - break; case PathState::Normal: + *out = true; + break; case PathState::CurrentDir: case PathState::ParentDir: - *out = true; + case PathState::Separator: + *out = false; break; } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_subdirectory_filesystem.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_subdirectory_filesystem.cpp index 0b17a5e8c..6d14c418a 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_subdirectory_filesystem.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_subdirectory_filesystem.cpp @@ -18,6 +18,7 @@ #include #include +#include "../utils.hpp" #include "fs_subdirectory_filesystem.hpp" #include "fs_path_utils.hpp" diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp index 49e2e8153..3dfbb7a50 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp @@ -111,7 +111,8 @@ Result FsMitmService::OpenHblWebContentFileSystem(Out> out_fs, u64 title_id, u32 filesystem_type) { FsDir d; - if (filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) || R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) { + if (!Utils::IsWebAppletTid(this->title_id) || filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) || + R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) { return RESULT_FORWARD_TO_SESSION; } fsDirClose(&d); @@ -121,11 +122,12 @@ Result FsMitmService::OpenFileSystemWithPatch(Out> out_fs, InPointer path, u64 title_id, u32 filesystem_type) { FsDir d; - if (filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) || R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) { + if (!Utils::IsWebAppletTid(this->title_id) || filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) || + R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) { return RESULT_FORWARD_TO_SESSION; } fsDirClose(&d); - + return this->OpenHblWebContentFileSystem(out_fs); } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp index f7cbad84b..f19f3e588 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp @@ -80,7 +80,7 @@ class FsMitmService : public IMitmServiceObject { DEFINE_SERVICE_DISPATCH_TABLE { /* TODO MakeServiceCommandMeta(), */ MakeServiceCommandMeta(), - MakeServiceCommandMeta(), + MakeServiceCommandMeta(), MakeServiceCommandMeta(), MakeServiceCommandMeta(), MakeServiceCommandMeta(), diff --git a/stratosphere/ams_mitm/source/utils.cpp b/stratosphere/ams_mitm/source/utils.cpp index f200305f4..df507ae54 100644 --- a/stratosphere/ams_mitm/source/utils.cpp +++ b/stratosphere/ams_mitm/source/utils.cpp @@ -383,6 +383,10 @@ bool Utils::IsHblTid(u64 tid) { return (g_hbl_override_config.override_any_app && IsApplicationTid(tid)) || (tid == g_hbl_override_config.title_id); } +bool Utils::IsWebAppletTid(u64 tid) { + return tid == 0x010000000000100Aul || tid == 0x010000000000100Ful || tid == 0x0100000000001010ul || tid == 0x0100000000001011ul; +} + bool Utils::HasTitleFlag(u64 tid, const char *flag) { if (IsSdInitialized()) { FsFile f; diff --git a/stratosphere/ams_mitm/source/utils.hpp b/stratosphere/ams_mitm/source/utils.hpp index e8e9155d8..bebdf974b 100644 --- a/stratosphere/ams_mitm/source/utils.hpp +++ b/stratosphere/ams_mitm/source/utils.hpp @@ -65,6 +65,7 @@ class Utils { static void InitializeThreadFunc(void *args); static bool IsHblTid(u64 tid); + static bool IsWebAppletTid(u64 tid); static bool HasTitleFlag(u64 tid, const char *flag); static bool HasHblFlag(const char *flag);