Play your Steam library's Windows games on a jailbroken PS5.
C++
Start when a hand copy drops empty folders
Leonardo Lobato78c6b6b13d2a
diff --git a/README.md b/README.mdindex 52760ce..f423b20 100644--- a/README.md+++ b/README.md@@ -124,7 +124,8 @@ ShadowMountPlus adds its tile to the Home screen.1. Copy the `FAKE77031` folder from `playden-ps5-<version>` into `/data/homebrew/` on the console. Use any FTP client(FileZilla, Cyberduck, etc.) or the web file manager in a browser. Create `/data/homebrew` first if it isn't there.You do not need to `chmod` anything: Playden checks the folders it writes to and fixes their permissions before- it writes. If it can't fix one, it names that folder.+ it writes. If it can't fix one, it names that folder. If your FTP client leaves out the empty `logs` and+ `playden-data` folders, Playden makes them again when it starts.Or, from a computer with Python 3, run this in the `playden-ps5-<version>` folder. It creates the folders, copiesonly what changed, and keeps a backup of the files it replaces:@@ -314,9 +315,18 @@ build/homebrew-host/playden-homebrew --simulation --scenario signed-outReload ShadowMountPlus.Until the game is registered, its Cloud saves are not synced before its first launch.- If every game hangs on its loading spinner, the ELF loader has stopped. Reload it.-- If Playden opens on **Root access is missing**, it could not get the root access it needs to reach its data in- `/data`, so it can't show your games, download or play. Load kstuff and the autoloader (the ELF loader must- run too), then open Playden again. The screen's startup error is worth quoting in a report.+- If Playden can't start, its first screen says which step failed. The startup error under it is worth quoting+ in a report:+ - **Playden's app folder is incomplete:** files such as `lapy.elf` or `playden-package.identity` are missing+ from the app folder or can't be read. Copy the whole app folder from the release zip again, or use+ `tools/console_title_deploy.py`.+ - **The ELF loader isn't running:** nothing answers on port 9021, so Playden can't run its root helper. Load+ the ELF loader (most autoloaders start it), then open Playden again.+ - **Root access is missing:** the root helper could not give Playden access to `/data`, or the ELF loader+ stopped while it received the helper. The screen says which. Load kstuff and the autoloader, then open Playden+ again. If it stays, report it with your firmware version.+ - **Playden can't start:** the console's network did not start, or Playden has root access but can't use+ `/data/playden`. The screen says which, and what to try.- Some controller games show a mouse pointer in a corner of the screen.- Playden can crash if you open a game page in the first seconds after start-up.- 32-bit games can run through an x86 translator, which is slower than native. For 32-bit OpenGL games thisdiff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cppindex 85b12ce..aabf5be 100644--- a/src/homebrew/simulation.cpp+++ b/src/homebrew/simulation.cpp@@ -687,6 +687,55 @@ std::vector<LiveImportCandidate> fixture_import_candidates() {// The fixture's imported game (Night Sky, already added from the USB drive).GameId fixture_imported_game() { return GameId::Local("6d1f3a52-0c55-4f3e-9b2a-5d1c7e0a9f11"); }+struct StartupProblem {+ std::string title;+ std::string subtitle;+};++// What the startup error means for the player: the step that failed and how to fix it. The error+// itself stays on the screen as the detail line, for reports.+StartupProblem describe_startup_problem(const std::string& detail, bool granted) {+ const auto has = [&detail](const char* text) { return detail.find(text) != std::string::npos; };+ const auto stage = [&detail](std::initializer_list<const char*> stages) {+ for (const char* name : stages)+ if (detail.find(std::string("helper stage=") + name + " ") != std::string::npos) return true;+ return false;+ };+ const StartupProblem incomplete{"Playden's app folder is incomplete",+ "Some of Playden's files in /data/homebrew are missing or can't be read. Copy the whole app folder from the "+ "release zip again (or use tools/console_title_deploy.py), then open Playden again."};+ if (granted) {+ if (has("stable launcher source is invalid")) return incomplete;+ if (has("stable launcher source identity does not match"))+ return {"Playden can't start",+ "The Playden that started is not the copy in /data/homebrew. If you just copied a new version, "+ "restart the PS5; if it stays, copy the whole app folder to /data/homebrew again."};+ return {"Playden can't start", "Playden has root access but can't use its data in /data/playden. "+ "Restart Playden; if it stays, check that folder's permissions over FTP."};+ }+ if (has("launcher source is invalid") || has("launcher source identity is unavailable") ||+ stage({"find-helper", "validate-helper", "open-helper", "stat-helper"}))+ return incomplete;+ if (stage({"network", "socket", "socket-options"}))+ return {"Playden can't start", "The console's network did not start, and Playden needs it to ask for root "+ "access. Restart the PS5, jailbreak it again, then open Playden again."};+ if (stage({"stream-helper"}))+ return {"Root access is missing",+ "The ELF loader on port 9021 stopped while Playden sent it the root helper. Load the ELF loader "+ "again, then open Playden again."};+ if (stage({"connect"}))+ return {"The ELF loader isn't running",+ "Playden gets root access through the ELF loader (elfldr) on port 9021, and nothing answered there. "+ "Load the ELF loader (most autoloaders start it), then open Playden again."};+ if (has("helper stage="))+ return {"Root access is missing",+ "The ELF loader ran Playden's root helper, but the helper could not give Playden access. "+ "Load kstuff and the autoloader, then open Playden again. If it stays, report the startup error "+ "below with your firmware version."};+ return {"Root access is missing", "Without it, Playden can't reach its data, so it can't show your games, "+ "download or play. Load kstuff and the autoloader, then open Playden again."};+}+} // namespacestd::string JobStateText(const Job& job) {@@ -4453,15 +4502,9 @@ void Simulation::rebuild_view() {else if (modal.id == "installed-games") view_.legends = {"Cross Select", "Triangle Uninstall", "Circle Close"};else if (!modal.setting_id.empty()) view_.legends = {"Cross Select", "Triangle Reset", "L1/R1 Jump", "Circle Back"};} else if (state_.navigation.route == Route::Startup && state_.root_access_missing) {- if (state_.root_access_granted) {- view_.title = "Playden can't start";- view_.subtitle = "Playden has root access but can't use its data in /data/playden. "- "Restart Playden; if it stays, check that folder's permissions over FTP.";- } else {- view_.title = "Root access is missing";- view_.subtitle = "Without it, Playden can't reach its data, so it can't show your games, download or play. "- "Load kstuff and the autoloader, then open Playden again.";- }+ auto problem = describe_startup_problem(state_.root_access_detail, state_.root_access_granted);+ view_.title = std::move(problem.title);+ view_.subtitle = std::move(problem.subtitle);if (!state_.root_access_detail.empty())row("root-detail", RowKind::Status, "Startup error: " + state_.root_access_detail, "").enabled = false;row("root-quit", RowKind::Action, "Quit to Home", "root-quit");diff --git a/src/platform/ps5/native_access.cpp b/src/platform/ps5/native_access.cppindex 3e23c68..2ee243b 100644--- a/src/platform/ps5/native_access.cpp+++ b/src/platform/ps5/native_access.cpp@@ -35,6 +35,9 @@ bool ValidatePaths(const NativeAccessOps& ops, const NativePaths& paths,bool known_fresh_state, StubState stubs, std::string* error) {const auto stub_access = stubs == StubState::kWritable ? NativePathAccess::kReadWrite: NativePathAccess::kRead;+ // The grant's checks take a missing stub: since 0.6.0 the stubs hold no state, a hand copy can+ // leave empty folders out, and startup makes them after the grant.+ const bool stub_may_be_missing = known_fresh_state || stubs == StubState::kReadable;if (ops.path_kind(ops.context, paths.title_root.c_str()) !=NativePathKind::kDirectory ||!ops.path_accessible(ops.context, paths.title_root.c_str(),@@ -58,7 +61,7 @@ bool ValidatePaths(const NativeAccessOps& ops, const NativePaths& paths,}const auto state = ops.path_kind(ops.context, paths.steam_state_root.c_str());if (state != NativePathKind::kDirectory &&- !(known_fresh_state && state == NativePathKind::kMissing)) {+ !(stub_may_be_missing && state == NativePathKind::kMissing)) {*error = "existing Steam state root is unavailable";return false;}@@ -70,7 +73,7 @@ bool ValidatePaths(const NativeAccessOps& ops, const NativePaths& paths,}const auto logs = ops.path_kind(ops.context, paths.log_root.c_str());if (logs != NativePathKind::kDirectory &&- !(known_fresh_state && logs == NativePathKind::kMissing)) {+ !(stub_may_be_missing && logs == NativePathKind::kMissing)) {*error = "existing log root is unavailable";return false;}diff --git a/src/platform/ps5/native_access.h b/src/platform/ps5/native_access.hindex 4c1e4b2..5febb50 100644--- a/src/platform/ps5/native_access.h+++ b/src/platform/ps5/native_access.h@@ -52,8 +52,9 @@ struct NativeAccessOptions {// Package paths: the title, its assets and trust store, and the stub// playden-data/logs folders. Granted starts need the stubs only as readable-// folders; the fallback without the grant still checks them as writable (its-// live launcher only shows "Root access is missing"). After the grant, the+// folders, and take a missing one (startup makes it after the grant); the+// fallback without the grant still checks them as writable (its live launcher+// only shows "Root access is missing"). After the grant, the// 0.6 layout move fills user_root, user_log_root and games_root (each at the// new place once its step has moved, else the old in-app one). Not granted:// they stay empty and the package paths are used.diff --git a/src/platform/ps5/native_startup.cpp b/src/platform/ps5/native_startup.cppindex 442ef23..2592c53 100644--- a/src/platform/ps5/native_startup.cpp+++ b/src/platform/ps5/native_startup.cpp@@ -92,7 +92,11 @@ int RequestData(void* data) {#if PLAYDEN_NATIVE_ACCESS_SOURCEauto& context = *static_cast<StartupContext*>(data);app::AppendLogLine("/app0/logs", "native-startup.log", "data grant starting");- if (!steam::internal::InitializeNativeNetworkForBootstrap()) return ENETDOWN;+ // Each failure names its stage: the startup screen tells the player which step to fix.+ if (!steam::internal::InitializeNativeNetworkForBootstrap()) {+ context.grant_diagnostic = "helper stage=network status=unavailable error=" + std::to_string(ENETDOWN);+ return ENETDOWN;+ }const auto ops = context.filesystem->Ops();std::string helper;for (const auto& root : {std::string("/app0"), "/data/homebrew/" + context.title_id}) {@@ -105,7 +109,10 @@ int RequestData(void* data) {break;}}- if (helper.empty()) return ENOENT;+ if (helper.empty()) {+ context.grant_diagnostic = "helper stage=find-helper status=unavailable error=" + std::to_string(ENOENT);+ return ENOENT;+ }const uid_t original_effective_uid = geteuid();ReportSessionAccess("/app0/playden-data", "/app0/logs", "before-grant");struct pw_lapy_elevation_diagnostics diagnostic{};@@ -168,6 +175,10 @@ NativeAccessResult PrepareNativeStartup(const std::string& title_id) {if (result.runtime_ready && !result.paths.runtime_data_root.empty()) {namespace fs = std::filesystem;const fs::path data_root = result.paths.runtime_data_root;+ // The app folder's empty stubs, before the move writes MOVED.txt into them. A failure is only+ // logged: the move takes a missing one.+ runtime::PrepareAppFolderStubs(result.paths.title_root, WithRoot,+ [&layout_lines](const std::string& line) { layout_lines.push_back(line); });runtime::LayoutPaths layout;layout.app_root = result.paths.title_root;layout.user_root = data_root / "user";diff --git a/src/runtime/writable_folders.cpp b/src/runtime/writable_folders.cppindex 3eab405..79e9148 100644--- a/src/runtime/writable_folders.cpp+++ b/src/runtime/writable_folders.cpp@@ -182,4 +182,54 @@ std::string PrepareDropFolder(const std::filesystem::path& folder, const Writablreturn "Playden can't make " + folder.string() + " (" + detail + "). Games can still be imported from a drive.";}+std::string PrepareAppFolderStubs(const std::filesystem::path& app_root, const WritableFoldersAsRoot& as_root,+ const std::function<void(const std::string&)>& log,+ const std::filesystem::path& namespace_root) {+ const auto name = app_root.filename().string();+ if (app_root.parent_path() != namespace_root / "data/homebrew" || name.empty() || name == "." || name == "..") {+ if (log) log("app folder stubs refused path=" + app_root.string());+ return "Playden can't repair this app folder.";+ }+ std::string failed = "root access", stub;+ int failed_error = 0;+ std::vector<std::string> made;+ const bool prepared = as_root && as_root([&] {+ const auto fail = [&](const char* step) { failed = step; failed_error = errno; return false; };+ constexpr int kFlags = O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC;+ bool ok = true;+ for (const char* child : {"playden-data", "logs"}) {+ // The app folder is opened again for each stub: the by-path walk reads the parent's listing,+ // whose offset a second lookup through the same descriptor would continue from.+ const int parent = platform::OpenDirectoryWalk(app_root);+ if (parent < 0) return fail("open the app folder");+ stub = child;+ int fd = platform::OpenWalkChild(parent, child, kFlags);+ bool created = false;+ if (fd < 0 && errno == ENOENT) {+ created = platform::MakeWalkChild(parent, child, 0777) == 0;+ if (created || errno == EEXIST) fd = platform::OpenWalkChild(parent, child, kFlags);+ }+ // A link or a file in its place is left alone (O_NOFOLLOW, O_DIRECTORY).+ ok = fd >= 0 || fail("open the folder");+ // mkdir is umasked: the app user writes the first log lines. An existing folder keeps its+ // mode, since before the layout move it can still hold the user's data.+ if (ok && created && ::fchmod(fd, 0777) != 0) ok = fail("chmod");+ if (fd >= 0) ::close(fd);+ if (ok && created && ::fsync(parent) != 0 && log)+ log("app folder stubs path=" + app_root.string() + " parent fsync=" + Error(errno));+ ::close(parent);+ if (!ok) break;+ if (created) made.push_back(child);+ }+ return ok;+ });+ if (!prepared && failed == "root access") failed_error = as_root ? errno : ENOSYS;+ if (log) for (const auto& child : made) log("app folder stub made path=" + (app_root / child).string());+ if (prepared) return {};+ const std::string detail = failed + " failed" + (failed_error ? " error=" + Error(failed_error) : "");+ const auto where = stub.empty() ? app_root : app_root / stub;+ if (log) log("app folder stub failed path=" + where.string() + " " + detail);+ return "Playden can't make " + where.string() + " (" + detail + ").";+}+} // namespace playden::runtimediff --git a/src/runtime/writable_folders.h b/src/runtime/writable_folders.hindex 2a3f32a..cee44a8 100644--- a/src/runtime/writable_folders.h+++ b/src/runtime/writable_folders.h@@ -36,4 +36,13 @@ std::string PrepareDropFolder(const std::filesystem::path& folder, const Writablconst std::function<void(const std::string&)>& log,const std::filesystem::path& namespace_root = "/");+// The app folder's empty playden-data and logs folders (0777): since 0.6.0 they hold only MOVED.txt,+// and the first startup lines go into logs before the grant. A hand copy can leave either out (some+// FTP clients and browser uploads skip empty folders). A missing one is made 0777 as root after the+// grant; an existing one is left as it is, and a link or a file in its place is refused. Only a folder directly in+// /data/homebrew is accepted. Failing doesn't stop Playden: the message is for the log.+std::string PrepareAppFolderStubs(const std::filesystem::path& app_root, const WritableFoldersAsRoot& as_root,+ const std::function<void(const std::string&)>& log,+ const std::filesystem::path& namespace_root = "/");+} // namespace playden::runtimediff --git a/tests/homebrew_live_model_test.cpp b/tests/homebrew_live_model_test.cppindex c8c860c..287de13 100644--- a/tests/homebrew_live_model_test.cpp+++ b/tests/homebrew_live_model_test.cpp@@ -1047,6 +1047,46 @@ void live_root_access_missing() {check(!granted.action("connect") && granted.action("cross") && granted.state().quit_requested,"root access: the data failure only quits to Home");+ // Each failed step has its own title and fix; the startup error stays as the detail line.+ struct Case { const char* error; bool granted; const char* title; const char* advice; };+ const Case cases[] = {+ {"native data grant failed (code 2); helper stage=find-helper status=unavailable error=2", false,+ "Playden's app folder is incomplete", "Copy the whole app folder"},+ {"launcher source identity is unavailable", false, "Playden's app folder is incomplete", "release zip"},+ {"launcher source is invalid: trust store is unavailable", false, "Playden's app folder is incomplete",+ "console_title_deploy.py"},+ {"native data grant failed (code 2); helper stage=open-helper status=unavailable error=2", false,+ "Playden's app folder is incomplete", "Copy the whole app folder"},+ {"native data grant failed (code 61); helper stage=connect status=unavailable error=61", false,+ "The ELF loader isn't running", "port 9021"},+ {"native data grant failed (code 50); helper stage=network status=unavailable error=50", false,+ "Playden can't start", "network did not start"},+ {"native data grant failed (code 55); helper stage=socket status=unavailable error=55", false,+ "Playden can't start", "network did not start"},+ {"native data grant failed (code 32); helper stage=stream-helper status=unavailable error=32", false,+ "Root access is missing", "Load the ELF loader again"},+ {"native data grant failed (code 60); helper stage=receive-prepare status=unavailable error=60", false,+ "Root access is missing", "firmware version"},+ {"native data grant failed (code 13); helper stage=helper-prepare status=6 error=1", false,+ "Root access is missing", "Load kstuff and the autoloader"},+ {"stable launcher source is invalid: assets root is unavailable", true, "Playden's app folder is incomplete",+ "Copy the whole app folder"},+ {"stable launcher source identity does not match", true, "Playden can't start", "restart the PS5"},+ };+ for (const auto& item : cases) {+ Simulation model_case({}, {}, ModelMode::Live);+ model_case.ShowRootAccessMissing(item.error, item.granted);+ const auto& case_view = model_case.view();+ const auto case_detail = std::find_if(case_view.rows.begin(), case_view.rows.end(),+ [](const auto& row) { return row.key == "root-detail"; });+ check(case_view.title == item.title && case_view.subtitle.find(item.advice) != std::string::npos &&+ case_detail != case_view.rows.end() && case_detail->title == std::string("Startup error: ") + item.error,+ (std::string("root access: ") + item.error + " has its own title and fix").c_str());+ check(item.granted || std::string(item.advice) != "Load kstuff and the autoloader" ||+ case_view.subtitle.find("kstuff") != std::string::npos,+ "root access: a helper failure keeps the kstuff advice");+ }+Simulation fixture({}, {}, ModelMode::Simulation);fixture.ShowRootAccessMissing(error);check(!fixture.state().root_access_missing, "root access: the fixture model ignores it");diff --git a/tests/native_access_test.cpp b/tests/native_access_test.cppindex ffba220..3dfc7fc 100644--- a/tests/native_access_test.cpp+++ b/tests/native_access_test.cpp@@ -313,14 +313,34 @@ void RetryIsIdempotentAndDoesNotResetStorage() {NativePathKind::kDirectory);}+// A hand copy can leave the empty stubs out: the grant still runs, and startup makes them afterwards.+// Only the fallback without the grant, which would write into them, needs them or an explicit fresh install.void MissingStateRequiresAnExplicitFreshInstall() {auto existing = OrdinaryLauncher();existing.paths.erase(std::string(kAppRoot) + "/playden-data");+ existing.paths.erase(std::string(kAppRoot) + "/logs");NativeAccessBootstrap existing_bootstrap(Ops(existing), Options());- const auto rejected = existing_bootstrap.Prepare();+ const auto granted = existing_bootstrap.Prepare();+ CHECK(granted.launcher_ready && granted.runtime_ready && granted.error.empty());+ CHECK(existing.grants == 1);++ auto stable_missing = OrdinaryLauncher();+ stable_missing.paths.erase(std::string(kAppRoot) + "/logs");+ stable_missing.expose_stable_after_grant = false;+ AddTree(stable_missing, kStableRoot, false);+ stable_missing.identities[kStableRoot] = stable_missing.identities[kAppRoot];+ NativeAccessBootstrap stable_missing_bootstrap(Ops(stable_missing), Options());+ const auto stubless = stable_missing_bootstrap.Prepare();+ CHECK(stubless.runtime_ready && stubless.paths.log_root == std::string(kStableRoot) + "/logs");+ CHECK(stable_missing.grants == 1);++ auto denied = OrdinaryLauncher();+ denied.paths.erase(std::string(kAppRoot) + "/playden-data");+ denied.grant_result = 2;+ NativeAccessBootstrap denied_bootstrap(Ops(denied), Options());+ const auto rejected = denied_bootstrap.Prepare();CHECK(!rejected.launcher_ready && !rejected.runtime_ready);CHECK(rejected.error.find("state") != std::string::npos);- CHECK(existing.grants == 0);auto fresh = OrdinaryLauncher();fresh.paths.erase(std::string(kAppRoot) + "/playden-data");diff --git a/tests/runtime_writable_folders_test.cpp b/tests/runtime_writable_folders_test.cppindex 28072a7..fa090f7 100644--- a/tests/runtime_writable_folders_test.cpp+++ b/tests/runtime_writable_folders_test.cpp@@ -157,6 +157,30 @@ int main() {CHECK(!PrepareDropFolder(drop, runs, log, root).empty() && Mode(target) == 0755 && fs::is_symlink(drop));CHECK(unlink(drop.c_str()) == 0);}+ // The app folder's stubs: missing ones made 0777, an existing one (it can hold old user data) kept, a link refused.+ {+ const auto app = root / "data/homebrew/FAKE77031";+ fs::create_directories(app);+ const auto before = calls;+ CHECK(!PrepareAppFolderStubs(root / "data/FAKE77031", runs, log, root).empty() && calls == before);+ CHECK(!PrepareAppFolderStubs(root / "data/homebrew", runs, log, root).empty() && calls == before);+ lines.clear();+ CHECK(PrepareAppFolderStubs(app, runs, log, root).empty() && calls == before + 1);+ CHECK(Mode(app / "playden-data") == 0777 && Mode(app / "logs") == 0777 && lines.size() == 2);+ CHECK(Empty(app / "playden-data") && Empty(app / "logs"));+ CHECK(fs::remove(app / "logs") && chmod((app / "playden-data").c_str(), 0755) == 0);+ CHECK(PrepareAppFolderStubs(app, runs, log, root).empty());+ CHECK(Mode(app / "playden-data") == 0755 && Mode(app / "logs") == 0777);+ CHECK(!PrepareAppFolderStubs(app, nullptr, log, root).empty());+ CHECK(!PrepareAppFolderStubs(app, refuses, log, root).empty());+ CHECK(fs::remove(app / "logs") && symlink(target.c_str(), (app / "logs").c_str()) == 0);+ const auto refused = PrepareAppFolderStubs(app, runs, log, root);+ CHECK(refused.find("/logs") != std::string::npos && Mode(target) == 0755 && fs::is_symlink(app / "logs"));+ CHECK(unlink((app / "logs").c_str()) == 0);+ // Missing app folder: nothing is made.+ CHECK(!PrepareAppFolderStubs(root / "data/homebrew/PPSA97031", runs, log, root).empty());+ CHECK(!fs::exists(root / "data/homebrew/PPSA97031"));+ }// /data swapped for a link to an outside folder: neither repair follows it as root.{const auto outside = root / "outside-data";