mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-10 06:01:52 +00:00
fs.mitm: Only create storage interface when needed.
This commit is contained in:
parent
158f7224a7
commit
e786bc7e9a
4 changed files with 39 additions and 28 deletions
|
@ -79,15 +79,21 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
|||
|
||||
Log(armGetTls(), 0x100);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
||||
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(this->title_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), this->title_id));
|
||||
if (Utils::HasSdRomfsContent(this->title_id)) {
|
||||
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
||||
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(this->title_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), this->title_id));
|
||||
} else {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, this->title_id));
|
||||
}
|
||||
this->romfs_storage = storage;
|
||||
if (out_storage.IsDomain()) {
|
||||
out_domain_id = data_storage.s.object_id;
|
||||
}
|
||||
} else {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, this->title_id));
|
||||
}
|
||||
this->romfs_storage = storage;
|
||||
if (out_storage.IsDomain()) {
|
||||
out_domain_id = data_storage.s.object_id;
|
||||
/* If we don't have anything to modify, there's no sense in maintaining a copy of the metadata tables. */
|
||||
fsStorageClose(&data_storage);
|
||||
rc = RESULT_FORWARD_TO_SESSION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,14 +123,20 @@ Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterf
|
|||
rc = fsOpenDataStorageByDataIdFwd(this->forward_service.get(), storage_id, data_id, &data_storage);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
||||
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(data_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), data_id));
|
||||
if (Utils::HasSdRomfsContent(data_id)) {
|
||||
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
||||
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(data_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), data_id));
|
||||
} else {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, data_id));
|
||||
}
|
||||
if (out_storage.IsDomain()) {
|
||||
out_domain_id = data_storage.s.object_id;
|
||||
}
|
||||
} else {
|
||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, data_id));
|
||||
}
|
||||
if (out_storage.IsDomain()) {
|
||||
out_domain_id = data_storage.s.object_id;
|
||||
/* If we don't have anything to modify, there's no sense in maintaining a copy of the metadata tables. */
|
||||
fsStorageClose(&data_storage);
|
||||
rc = RESULT_FORWARD_TO_SESSION;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -201,20 +201,18 @@ Result Utils::OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsD
|
|||
return fsFsOpenDirectory(fs, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
||||
}
|
||||
|
||||
Result Utils::HasSdRomfsContent(u64 title_id, bool *out) {
|
||||
Result rc;
|
||||
bool Utils::HasSdRomfsContent(u64 title_id) {
|
||||
FsDir dir;
|
||||
if (R_FAILED((rc = Utils::OpenRomFSSdDir(title_id, "", &dir)))) {
|
||||
return rc;
|
||||
if (R_FAILED(Utils::OpenRomFSSdDir(title_id, "", &dir))) {
|
||||
return false;
|
||||
}
|
||||
ON_SCOPE_EXIT {
|
||||
fsDirClose(&dir);
|
||||
};
|
||||
|
||||
FsDirectoryEntry dir_entry;
|
||||
u64 read_entries;
|
||||
if (R_SUCCEEDED((rc = fsDirRead(&dir, 0, &read_entries, 1, &dir_entry)))) {
|
||||
*out = (read_entries == 1);
|
||||
}
|
||||
fsDirClose(&dir);
|
||||
return rc;
|
||||
return R_SUCCEEDED(fsDirRead(&dir, 0, &read_entries, 1, &dir_entry)) && read_entries == 1;
|
||||
}
|
||||
|
||||
bool Utils::HasSdMitMFlag(u64 tid) {
|
||||
|
|
|
@ -26,13 +26,12 @@ class Utils {
|
|||
static Result OpenRomFSSdFile(u64 title_id, const char *fn, int flags, FsFile *out);
|
||||
static Result OpenSdDir(const char *path, FsDir *out);
|
||||
static Result OpenSdDirForAtmosphere(u64 title_id, const char *path, FsDir *out);
|
||||
static Result OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out);
|
||||
|
||||
static Result OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out);
|
||||
|
||||
static Result OpenRomFSFile(FsFileSystem *fs, u64 title_id, const char *fn, int flags, FsFile *out);
|
||||
static Result OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsDir *out);
|
||||
|
||||
static Result HasSdRomfsContent(u64 title_id, bool *out);
|
||||
static bool HasSdRomfsContent(u64 title_id);
|
||||
|
||||
/* SD card Initialization + MitM detection. */
|
||||
static void InitializeSdThreadFunc(void *args);
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "mitm_query_service.hpp"
|
||||
|
||||
#define RESULT_FORWARD_TO_SESSION 0xCAFEFC
|
||||
|
||||
class MitmSession final : public ServiceSession {
|
||||
private:
|
||||
/* This will be for the actual session. */
|
||||
|
@ -149,7 +151,7 @@ class MitmSession final : public ServiceSession {
|
|||
}
|
||||
}
|
||||
|
||||
if (!found_entry) {
|
||||
if (!found_entry || rc == RESULT_FORWARD_TO_SESSION) {
|
||||
memcpy(armGetTls(), this->backup_tls, sizeof(this->backup_tls));
|
||||
rc = ForwardRequest(ctx);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue