mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-30 06:25:20 -04:00
fs.mitm: WIP LayeredFS impl (NOTE: UNUSABLE ATM)
Also greatly refactors libstratosphere, and does a lot of other things. There is a lot of code in this one.
This commit is contained in:
parent
82b248aeac
commit
c2d9ac8f5c
56 changed files with 1615 additions and 243 deletions
|
@ -3,10 +3,10 @@
|
|||
#include <atomic>
|
||||
|
||||
#include "sm_mitm.h"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "fsmitm_utils.hpp"
|
||||
|
||||
static FsFileSystem g_sd_filesystem;
|
||||
static FsFileSystem g_sd_filesystem = {0};
|
||||
static bool g_has_initialized = false;
|
||||
|
||||
static Result EnsureInitialized() {
|
||||
|
@ -19,7 +19,7 @@ static Result EnsureInitialized() {
|
|||
Result rc = smMitMUninstall(required_active_services[i]);
|
||||
if (rc == 0xE15) {
|
||||
return rc;
|
||||
} else if (rc != 0x1015) {
|
||||
} else if (R_FAILED(rc) && rc != 0x1015) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,93 @@ static Result EnsureInitialized() {
|
|||
return rc;
|
||||
}
|
||||
|
||||
bool Utils::IsSdInitialized() {
|
||||
return R_SUCCEEDED(EnsureInitialized());
|
||||
}
|
||||
|
||||
Result Utils::OpenSdFile(const char *fn, int flags, FsFile *out) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = EnsureInitialized()))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return fsFsOpenFile(&g_sd_filesystem, fn, flags, out);
|
||||
}
|
||||
|
||||
Result Utils::OpenSdFileForAtmosphere(u64 title_id, const char *fn, int flags, FsFile *out) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = EnsureInitialized()))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
char path[FS_MAX_PATH];
|
||||
strcpy(path, fn);
|
||||
if (*fn == '/') {
|
||||
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx%s", title_id, fn);
|
||||
} else {
|
||||
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/%s", title_id, fn);
|
||||
}
|
||||
return fsFsOpenFile(&g_sd_filesystem, path, flags, out);
|
||||
}
|
||||
}
|
||||
|
||||
Result Utils::OpenRomFSSdFile(u64 title_id, const char *fn, int flags, FsFile *out) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = EnsureInitialized()))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return OpenRomFSFile(&g_sd_filesystem, title_id, fn, flags, out);
|
||||
}
|
||||
|
||||
Result Utils::OpenSdDir(const char *path, FsDir *out) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = EnsureInitialized()))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return fsFsOpenDirectory(&g_sd_filesystem, path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
||||
}
|
||||
|
||||
Result Utils::OpenSdDirForAtmosphere(u64 title_id, const char *path, FsDir *out) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = EnsureInitialized()))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
char safe_path[FS_MAX_PATH];
|
||||
if (*path == '/') {
|
||||
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx%s", title_id, path);
|
||||
} else {
|
||||
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx/%s", title_id, path);
|
||||
}
|
||||
return fsFsOpenDirectory(&g_sd_filesystem, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
||||
}
|
||||
|
||||
Result Utils::OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = EnsureInitialized()))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return OpenRomFSDir(&g_sd_filesystem, title_id, path, out);
|
||||
}
|
||||
|
||||
|
||||
Result Utils::OpenRomFSFile(FsFileSystem *fs, u64 title_id, const char *fn, int flags, FsFile *out) {
|
||||
char path[FS_MAX_PATH];
|
||||
if (*fn == '/') {
|
||||
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/romfs%s", title_id, fn);
|
||||
} else {
|
||||
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/romfs/%s", title_id, fn);
|
||||
}
|
||||
return fsFsOpenFile(fs, path, flags, out);
|
||||
}
|
||||
|
||||
Result Utils::OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsDir *out) {
|
||||
char safe_path[FS_MAX_PATH];
|
||||
if (*path == '/') {
|
||||
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx/romfs%s", title_id, path);
|
||||
} else {
|
||||
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx/romfs/%s", title_id, path);
|
||||
}
|
||||
return fsFsOpenDirectory(fs, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue