diff --git a/stratosphere/loader/source/ldr_content_management.cpp b/stratosphere/loader/source/ldr_content_management.cpp index c4ad0b425..ff31a9c39 100644 --- a/stratosphere/loader/source/ldr_content_management.cpp +++ b/stratosphere/loader/source/ldr_content_management.cpp @@ -16,9 +16,12 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) { Result rc; /* We defer SD card mounting, so if relevant ensure it is mounted. */ - TryMountSdCard(); - - if (R_FAILED(rc = GetContentPath(path, tid, sid))) { + if (!g_has_initialized_fs_dev) { + TryMountSdCard(); + } + + + if (R_FAILED(rc = ResolveContentPath(path, tid, sid))) { return rc; } @@ -53,31 +56,34 @@ Result ContentManagement::MountCodeForTidSid(Registration::TidSid *tid_sid) { return MountCode(tid_sid->title_id, tid_sid->storage_id); } -Result ContentManagement::GetContentPath(char *out_path, u64 tid, FsStorageId sid) { +Result ContentManagement::ResolveContentPath(char *out_path, u64 tid, FsStorageId sid) { Result rc; LrRegisteredLocationResolver reg; LrLocationResolver lr; char path[FS_MAX_PATH] = {0}; /* Try to get the path from the registered resolver. */ - if (R_FAILED(rc = lrGetRegisteredLocationResolver(®))) { + if (R_FAILED(rc = lrOpenRegisteredLocationResolver(®))) { return rc; } - if (R_SUCCEEDED(rc = lrRegLrGetProgramPath(®, tid, path))) { + if (R_SUCCEEDED(rc = lrRegLrResolveProgramPath(®, tid, path))) { strncpy(out_path, path, sizeof(path)); } else if (rc != 0x408) { return rc; } serviceClose(®.s); - - /* If getting the path from the registered resolver fails, fall back to the normal resolver. */ - if (R_FAILED(rc = lrGetLocationResolver(sid, &lr))) { + if (R_SUCCEEDED(rc)) { return rc; } - if (R_SUCCEEDED(rc = lrLrGetProgramPath(&lr, tid, path))) { + /* If getting the path from the registered resolver fails, fall back to the normal resolver. */ + if (R_FAILED(rc = lrOpenLocationResolver(sid, &lr))) { + return rc; + } + + if (R_SUCCEEDED(rc = lrLrResolveProgramPath(&lr, tid, path))) { strncpy(out_path, path, sizeof(path)); } @@ -86,27 +92,27 @@ Result ContentManagement::GetContentPath(char *out_path, u64 tid, FsStorageId si return rc; } -Result ContentManagement::GetContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid) { - return GetContentPath(out_path, tid_sid->title_id, tid_sid->storage_id); +Result ContentManagement::ResolveContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid) { + return ResolveContentPath(out_path, tid_sid->title_id, tid_sid->storage_id); } -Result ContentManagement::SetContentPath(const char *path, u64 tid, FsStorageId sid) { +Result ContentManagement::RedirectContentPath(const char *path, u64 tid, FsStorageId sid) { Result rc; LrLocationResolver lr; - if (R_FAILED(rc = lrGetLocationResolver(sid, &lr))) { + if (R_FAILED(rc = lrOpenLocationResolver(sid, &lr))) { return rc; } - rc = lrLrSetProgramPath(&lr, tid, path); + rc = lrLrRedirectProgramPath(&lr, tid, path); serviceClose(&lr.s); return rc; } -Result ContentManagement::SetContentPathForTidSid(const char *path, Registration::TidSid *tid_sid) { - return SetContentPath(path, tid_sid->title_id, tid_sid->storage_id); +Result ContentManagement::RedirectContentPathForTidSid(const char *path, Registration::TidSid *tid_sid) { + return RedirectContentPath(path, tid_sid->title_id, tid_sid->storage_id); } bool ContentManagement::HasCreatedTitle(u64 tid) { @@ -122,8 +128,18 @@ void ContentManagement::SetCreatedTitle(u64 tid) { void ContentManagement::TryMountSdCard() { /* Mount SD card, if psc, bus, and pcv have been created. */ if (!g_has_initialized_fs_dev && HasCreatedTitle(0x0100000000000021) && HasCreatedTitle(0x010000000000000A) && HasCreatedTitle(0x010000000000001A)) { + Handle tmp_hnd = 0; + static const char *required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"}; + for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) { + if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) { + return; + } else { + svcCloseHandle(tmp_hnd); + } + } + if (R_SUCCEEDED(fsdevMountSdmc())) { g_has_initialized_fs_dev = true; } } -} \ No newline at end of file +} diff --git a/stratosphere/loader/source/ldr_content_management.hpp b/stratosphere/loader/source/ldr_content_management.hpp index e74996c84..dded7398e 100644 --- a/stratosphere/loader/source/ldr_content_management.hpp +++ b/stratosphere/loader/source/ldr_content_management.hpp @@ -9,10 +9,10 @@ class ContentManagement { static Result UnmountCode(); static Result MountCodeForTidSid(Registration::TidSid *tid_sid); - static Result GetContentPath(char *out_path, u64 tid, FsStorageId sid); - static Result SetContentPath(const char *path, u64 tid, FsStorageId sid); - static Result GetContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid); - static Result SetContentPathForTidSid(const char *path, Registration::TidSid *tid_sid); + static Result ResolveContentPath(char *out_path, u64 tid, FsStorageId sid); + static Result RedirectContentPath(const char *path, u64 tid, FsStorageId sid); + static Result ResolveContentPathForTidSid(char *out_path, Registration::TidSid *tid_sid); + static Result RedirectContentPathForTidSid(const char *path, Registration::TidSid *tid_sid); static bool HasCreatedTitle(u64 tid); static void SetCreatedTitle(u64 tid); diff --git a/stratosphere/loader/source/ldr_process_manager.cpp b/stratosphere/loader/source/ldr_process_manager.cpp index 2b34b873d..be3a434a8 100644 --- a/stratosphere/loader/source/ldr_process_manager.cpp +++ b/stratosphere/loader/source/ldr_process_manager.cpp @@ -42,7 +42,7 @@ std::tuple ProcessManagerService::create_process(u64 flags, return {rc, MovedHandle{process_h}}; } - rc = ContentManagement::GetContentPathForTidSid(nca_path, &tid_sid); + rc = ContentManagement::ResolveContentPathForTidSid(nca_path, &tid_sid); if (R_FAILED(rc)) { return {rc, MovedHandle{process_h}}; } @@ -71,12 +71,12 @@ std::tuple ProcessManagerService::get_program_info(Registration::TidSid } if (tid_sid.title_id != out_program_info.pointer->title_id) { - rc = ContentManagement::GetContentPathForTidSid(nca_path, &tid_sid); + rc = ContentManagement::ResolveContentPathForTidSid(nca_path, &tid_sid); if (R_FAILED(rc)) { return {rc}; } - rc = ContentManagement::SetContentPath(nca_path, out_program_info.pointer->title_id, tid_sid.storage_id); + rc = ContentManagement::RedirectContentPath(nca_path, out_program_info.pointer->title_id, tid_sid.storage_id); if (R_FAILED(rc)) { return {rc}; }