Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Explain why a PS5 title could not be reserved

Leonardo Lobato7245479ca5f9
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index e0b9247..d47d286 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -10,6 +10,7 @@
#include "stores/local/copy_runner.h"
#include "stores/local/library_source.h"
#include "app/diagnostic_log.h"
+#include "platform/ps5/title_registry.h"
#include "platform/ps5/title_remover.h"
#include "platform/ps5/title_runtime.h"
#include "platform/ps5/native_startup.h"
@@ -440,7 +441,8 @@ int main() {
config.admit_kit = [](std::string* reason) -> std::optional<playden::homebrew::RuntimeKit> {
const auto firmware = playden::ps5::ConsoleFirmwareVersion();
playden::app::AppendLogLine(log_root, "runtime.log", "console_firmware=" + firmware.value_or("unknown") + " " +
- playden::ps5::ConsoleFirmwareDiagnostics());
+ playden::ps5::ConsoleFirmwareDiagnostics() + " " +
+ playden::ps5::TitleRegistry(playden::ps5::ShadowMountPost).DescribeVersion());
const auto admission = rt::DevelopmentKitAdmission();
auto admitted = rt::VerifyInstalledKit(rt::kDevelopmentKitRoot, admission);
std::string ignored;
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 5b63d4a..9cae1af 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -2970,7 +2970,39 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&
(c.retired_titles.count(title) ? retired : reserve.kit_title_variants).push_back(std::move(title));
reserve.kit_title_variants.insert(reserve.kit_title_variants.end(), retired.begin(), retired.end());
auto reserved = c.repository.Reserve(reserve);
- if (!reserved.ok()) return "A PS5 title could not be reserved: " + reserved.message();
+ if (!reserved.ok()) {
+ if (reserved.error() != rt::RepositoryError::kTitleVariantsExhausted)
+ return "A PS5 title could not be reserved: " + reserved.message();
+ // Every ID refused at once usually means one source cannot answer, not that every ID is taken:
+ // ask the IDs no other game holds what each source says, until one is not clearly in use.
+ std::set<std::string> held;
+ for (const auto& install : c.repository.Snapshot()) held.insert(install.title_id);
+ const auto log_prefix = "title reservation refused app=" + std::to_string(request.runtime_number) +
+ " candidates=" + std::to_string(reserve.kit_title_variants.size()) +
+ " held=" + std::to_string(held.size());
+ std::size_t occupied = 0;
+ std::string first_occupied;
+ for (const auto& title : reserve.kit_title_variants) {
+ if (held.count(title)) continue;
+ const auto report = c.coordinator->ReportAvailability(title);
+ const bool unknown = report.database == rt::TitleAvailability::kUnknown ||
+ report.folder == rt::TitleAvailability::kUnknown ||
+ report.shadowmount.state == ps5::RegistrationState::kUnavailable ||
+ report.activity == rt::NativeActivity::kUnknown;
+ if (!unknown) {
+ if (!occupied++) first_occupied = title + " " + report.Text();
+ continue;
+ }
+ Log(log_prefix + " occupied=" + std::to_string(occupied) + " " + title + " " + report.Text());
+ // Only a ShadowMountPlus that does not answer at all is fixed by loading it again.
+ if (report.shadowmount.reason == "no-response")
+ return "ShadowMountPlus isn't answering. Load it again (or restart the PS5 and jailbreak it again), then try again.";
+ return "Playden could not check that a PS5 title is free for this game. Try again; if it still fails, "
+ "open Logs in Settings for details.";
+ }
+ Log(log_prefix + " occupied=" + std::to_string(occupied) + (first_occupied.empty() ? "" : " first=" + first_occupied));
+ return "Every PS5 title this runtime kit offers is in use. Uninstall a game, then try again.";
+ }
auto record = reserved.value();
// Before the title exists: it may only start once its helper lists it.
Log("prepare reserved app=" + std::to_string(request.runtime_number) + " title=" + record.title_id + " ms=" + elapsed_ms());
diff --git a/src/platform/ps5/native_coordinator.cpp b/src/platform/ps5/native_coordinator.cpp
index 3bc5a0a..64d5ae5 100644
--- a/src/platform/ps5/native_coordinator.cpp
+++ b/src/platform/ps5/native_coordinator.cpp
@@ -100,6 +100,31 @@ runtime::NativeTitleAvailability Ps5NativeCoordinator::Availability(const std::s
if (activity == runtime::NativeActivity::kUnknown) database.inventory = TitleAvailability::kUnknown;
return {database.inventory, source.availability};
}
+Ps5NativeCoordinator::AvailabilityReport Ps5NativeCoordinator::ReportAvailability(const std::string& title) {
+ AvailabilityReport report;
+ if (!IsPlaydenGameTitle(title)) return report;
+ report.database = operations_.database(title).inventory;
+ report.folder = ReadTitleSource(root_, title).availability;
+ report.shadowmount = registry_.Query(title);
+ report.activity = Activity(title);
+ return report;
+}
+std::string Ps5NativeCoordinator::AvailabilityReport::Text() const {
+ const auto text = [](TitleAvailability value) {
+ return value == TitleAvailability::kFree ? "free" : value == TitleAvailability::kOccupied ? "occupied" : "unknown";
+ };
+ const char* state = "unavailable";
+ switch (shadowmount.state) {
+ case RegistrationState::kUnavailable: break;
+ case RegistrationState::kAbsent: state = "absent"; break;
+ case RegistrationState::kPending: state = "pending"; break;
+ case RegistrationState::kReady: state = "ready"; break;
+ case RegistrationState::kCollision: state = "collision"; break;
+ }
+ return std::string("app.db=") + text(database) + " folder=" + text(folder) + " shadowmount=" + state +
+ (shadowmount.reason.empty() ? "" : "(" + shadowmount.reason + ")") + " activity=" +
+ (activity == runtime::NativeActivity::kActive ? "active" : activity == runtime::NativeActivity::kStopped ? "stopped" : "unknown");
+}
runtime::TitleAvailability Ps5NativeCoordinator::Inventory(const std::string& title) {
return IsPlaydenGameTitle(title) ? operations_.database(title).inventory : TitleAvailability::kUnknown;
}
diff --git a/src/platform/ps5/native_coordinator.h b/src/platform/ps5/native_coordinator.h
index c323829..6514db1 100644
--- a/src/platform/ps5/native_coordinator.h
+++ b/src/platform/ps5/native_coordinator.h
@@ -29,6 +29,16 @@ class Ps5NativeCoordinator final : public runtime::NativeCoordinator {
TitleRegistry& registry, std::filesystem::path homebrew_root = "/data/homebrew",
NativeCoordinatorOperations operations = {});
runtime::NativeTitleAvailability Availability(const std::string& title_id);
+ // What each source says about a title. Availability() needs every source to say free.
+ struct AvailabilityReport {
+ runtime::TitleAvailability database = runtime::TitleAvailability::kUnknown;
+ runtime::TitleAvailability folder = runtime::TitleAvailability::kUnknown;
+ TitleRegistration shadowmount;
+ runtime::NativeActivity activity = runtime::NativeActivity::kUnknown;
+ // For logs, e.g. "app.db=free folder=free shadowmount=unavailable(no-response) activity=stopped".
+ std::string Text() const;
+ };
+ AvailabilityReport ReportAvailability(const std::string& title_id);
// The console's own inventory (app.db) only: ShadowMount's cache is left out
// because it does not refresh while any title, Playden included, runs.
runtime::TitleAvailability Inventory(const std::string& title_id);
diff --git a/src/platform/ps5/title_registry.cpp b/src/platform/ps5/title_registry.cpp
index 26aea3b..8786dec 100644
--- a/src/platform/ps5/title_registry.cpp
+++ b/src/platform/ps5/title_registry.cpp
@@ -24,44 +24,71 @@ bool IsPlaydenGameTitle(const std::string& title) {
return ValidTitleId(title) && title.compare(0, 6, "FAKE78") == 0;
}
TitleRegistration TitleRegistry::Query(const std::string& title) {
- if (!ValidTitleId(title) || !transport_) return {};
+ const auto unavailable = [](std::string reason) {
+ return TitleRegistration{RegistrationState::kUnavailable, {}, std::move(reason)};
+ };
+ if (!ValidTitleId(title)) return unavailable("title-id");
+ if (!transport_) return unavailable("no-transport");
const auto bytes = transport_("/api/v1/games", "{}");
- if (!bytes || bytes->size() > 1024*1024) return {};
+ if (!bytes) return unavailable("no-response");
+ if (bytes->size() > 1024*1024) return unavailable("response-too-large");
const auto v = json::Parse(*bytes, {1024*1024, 16, 65536, 4096});
- if (!v || !Success(*v)) return {};
+ if (!v) return unavailable("bad-json");
+ if (!Success(*v)) return unavailable("status");
const auto* games = v->Find("games");
- if (!games || !games->is_array()) return {};
- TitleRegistration result{RegistrationState::kAbsent, {}};
+ if (!games || !games->is_array()) return unavailable("no-games");
+ const auto source = "/data/homebrew/" + title;
+ TitleRegistration result{RegistrationState::kAbsent, {}, {}};
unsigned matches = 0;
for (const auto& game : games->array()) {
const auto id = Text(game, "title_id");
- if (!ValidTitleId(id)) return {}; // Incomplete inventory cannot imply absence.
- if (id != title) continue;
const auto path = Text(game, "path");
- if (++matches > 1) return {RegistrationState::kCollision, path};
- if (path.empty()) return {};
+ if (!ValidTitleId(id)) {
+ // Another source's odd ID (homebrew, backups) says nothing about this title. One that
+ // names this title's folder may be it, and an incomplete inventory cannot imply absence.
+ if (path.empty() || path == source) return unavailable("bad-title-id");
+ continue;
+ }
+ if (id != title) continue;
+ if (++matches > 1) return {RegistrationState::kCollision, path, {}};
+ if (path.empty()) return unavailable("no-path");
const auto managed = Flag(game, "managed");
- if (!managed) return {};
+ if (!managed) return unavailable("no-managed");
// ShadowMount retains a removed title's row after its manual source,
// registration and directory are gone. This explicit tombstone is absent;
// the coordinator still checks the directory, native database and activity.
- if (!*managed && path == "/data/homebrew/" + title &&
+ if (!*managed && path == source &&
Text(game, "runtime_path") == path && Text(game, "source_type") == "folder" &&
Flag(game, "installed") == false && Flag(game, "mounted") == false &&
Flag(game, "source_available") == false)
continue;
- if (path != "/data/homebrew/" + title || !*managed)
- result = {RegistrationState::kCollision, path};
+ if (path != source || !*managed)
+ result = {RegistrationState::kCollision, path, {}};
else {
const auto installed = Flag(game, "installed"), available = Flag(game, "source_available");
const auto type = Text(game, "source_type");
- if (!installed || !available || type.empty()) return {};
- result = {*installed && *available && type == "folder" ? RegistrationState::kReady : RegistrationState::kPending, path};
+ if (!installed || !available || type.empty()) return unavailable("incomplete-entry");
+ result = {*installed && *available && type == "folder" ? RegistrationState::kReady : RegistrationState::kPending, path, {}};
}
}
return result;
}
+std::string TitleRegistry::DescribeVersion() {
+ if (!transport_) return "shadowmount=no-transport";
+ const auto bytes = transport_("/api/v1/version", "{}");
+ if (!bytes) return "shadowmount=unreachable";
+ const auto v = bytes->size() <= 65536 ? json::Parse(*bytes, {65536, 16, 4096, 4096}) : std::nullopt;
+ if (!v || !Success(*v)) return "shadowmount=bad-answer";
+ auto version = Text(*v, "shadowmount_version");
+ // Keep a log line one line whatever the API sends.
+ if (version.size() > 64) version.resize(64);
+ for (auto& c : version) if (c < 0x21 || c > 0x7e) c = '?';
+ const auto* api = v->Find("api_version");
+ const auto api_number = api ? api->AsUint64() : std::nullopt;
+ return "shadowmount=" + (version.empty() ? std::string("unknown") : version) +
+ " api=" + (api_number ? std::to_string(*api_number) : std::string("unknown"));
+}
TitleResult TitleRegistry::Post(const std::string& route, const std::string& body) {
if (!transport_) return {false, ENOSYS, "shadowmount"};
const auto bytes = transport_(route, body);
diff --git a/src/platform/ps5/title_registry.h b/src/platform/ps5/title_registry.h
index 7c3118c..08e51af 100644
--- a/src/platform/ps5/title_registry.h
+++ b/src/platform/ps5/title_registry.h
@@ -9,6 +9,8 @@ enum class RegistrationState { kUnavailable, kAbsent, kPending, kReady, kCollisi
struct TitleRegistration {
RegistrationState state = RegistrationState::kUnavailable;
std::string path;
+ // Why the state is kUnavailable, for logs.
+ std::string reason;
};
// Synchronous worker-only boundary to the existing ShadowMountPlus local API.
class TitleRegistry {
@@ -16,6 +18,8 @@ class TitleRegistry {
using Transport = std::function<std::optional<std::string>(const std::string&, const std::string&)>;
explicit TitleRegistry(Transport transport) : transport_(std::move(transport)) {}
TitleRegistration Query(const std::string& title_id);
+ // For logs: "shadowmount=<version> api=<n>", or why ShadowMountPlus did not answer.
+ std::string DescribeVersion();
// Caller must independently check native install/source paths and establish
// ownership before registration. ShadowMount inventory alone cannot reserve IDs.
TitleResult Register(const std::string& title_id);
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index 19f8eb6..3b44aa4 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -751,6 +751,43 @@ void PrepareNamesUnfixableFolder() {
CHECK(chmod(homebrew.c_str(), 0755) == 0); // so the fixture can clean up
}
+// No free title is rarely the truth: the refusal names the source that could not answer.
+void TitleRefusalNamesTheSourceThatCannotAnswer() {
+ // ShadowMountPlus silent, answering with bad data, app.db unreadable, and the only title truly in use.
+ for (const int scenario : {0, 1, 2, 3}) {
+ Fixture fixture;
+ const auto kit = SyntheticKit(fixture.root / "kit");
+ auto config = WritableFoldersConfig(fixture, kit);
+ if (scenario == 0)
+ config.registry_transport = [](const std::string&, const std::string&) -> std::optional<std::string> { return {}; };
+ else if (scenario == 1)
+ config.registry_transport = [](const std::string&, const std::string&) -> std::optional<std::string> {
+ return std::string(R"({"status":0,"games":[{"title_id":"odd"}]})");
+ };
+ else
+ config.native.database = [scenario](const std::string&) {
+ return TitleDatabaseObservation{scenario == 2 ? TitleAvailability::kUnknown : TitleAvailability::kOccupied, {}};
+ };
+ Write(fixture.root / "data/homebrew/FAKE77031/games/220/hl2.exe", "existing-game", 0644);
+ config.writable_folders.clear();
+ RuntimeHost host(config);
+ CHECK(host.Start());
+ CHECK(WaitFor(host, Started).kit_available);
+ host.Prepare(Hl2());
+ const auto done = WaitFor(host, [](const RuntimeSnapshot& s) { return !s.preparing_app && s.refusals.count(220); }, 60);
+ const auto& refusal = done.refusals.at(220);
+ if (scenario == 0)
+ CHECK(refusal == "ShadowMountPlus isn't answering. Load it again (or restart the PS5 and jailbreak it again), then try again.");
+ else if (scenario == 3)
+ CHECK(refusal == "Every PS5 title this runtime kit offers is in use. Uninstall a game, then try again.");
+ else
+ CHECK(refusal == "Playden could not check that a PS5 title is free for this game. Try again; if it still fails, "
+ "open Logs in Settings for details.");
+ CHECK(done.installs.empty() && fixture.registry_mutations == 0);
+ host.Shutdown();
+ }
+}
+
// A capture refused after control setup (the console's world-writable game
// folder) leaves a settings-control journal. An explicit Prepare resumes the
// saved request and reaches Ready with one registration.
@@ -5226,6 +5263,7 @@ int main(int argc, char** argv) {
PreparesGameOnUnownedDrive();
PrepareFixesRootOwnedHomebrewFolder();
PrepareNamesUnfixableFolder();
+ TitleRefusalNamesTheSourceThatCannotAnswer();
AnyTitleKitMakesTheGameItsOwnTitle();
PreparationEndsAwaitingRegistration();
PreparesGameWithoutShippedRecipe();
diff --git a/tests/native_coordinator_test.cpp b/tests/native_coordinator_test.cpp
index 9226c6d..0a58da5 100644
--- a/tests/native_coordinator_test.cpp
+++ b/tests/native_coordinator_test.cpp
@@ -48,6 +48,11 @@ int main() {
auto available = native.Availability(record.title_id);
CHECK(available.inventory == TitleAvailability::kFree && available.source_path == TitleAvailability::kFree);
CHECK(native.Activity(record.title_id) == NativeActivity::kStopped);
+ CHECK(native.ReportAvailability(record.title_id).Text() == "app.db=free folder=free shadowmount=absent activity=stopped");
+ response = "{}";
+ const auto report = native.ReportAvailability(record.title_id);
+ CHECK(report.shadowmount.state == RegistrationState::kUnavailable && report.database == TitleAvailability::kFree);
+ CHECK(report.Text() == "app.db=free folder=free shadowmount=unavailable(status) activity=stopped");
response = R"({"status":0,"games":[{"title_id":"FAKE78001","installed":false,"managed":false,"mounted":false,"source_available":false,"source_type":"folder","runtime_path":"/data/homebrew/FAKE78001","path":"/data/homebrew/FAKE78001"}]})";
available = native.Availability(record.title_id);
CHECK(available.inventory == TitleAvailability::kFree && available.source_path == TitleAvailability::kFree);
diff --git a/tests/title_registry_test.cpp b/tests/title_registry_test.cpp
index a09d530..fec1cc1 100644
--- a/tests/title_registry_test.cpp
+++ b/tests/title_registry_test.cpp
@@ -92,8 +92,42 @@ int main() {
answer_add = true; answer_scan = false;
const auto deferred = flaky.Register("FAKE78000");
CHECK(deferred.ok && deferred.stage == "scan-deferred");
+ // Another source's malformed ID says nothing about this title; one in this title's folder does.
+ response = R"({"status":0,"games":[{"title_id":"homebrew","path":"/data/homebrew/other"},{"title_id":"ABCD1234"}]})";
+ auto odd = registry.Query("FAKE78000");
+ CHECK(odd.state == RegistrationState::kUnavailable && odd.reason == "bad-title-id");
+ response = R"({"status":0,"games":[{"title_id":"homebrew","path":"/data/homebrew/other"},{"path":"/mnt/usb0/x"}]})";
+ CHECK(registry.Query("FAKE78000").state == RegistrationState::kAbsent);
+ response = R"({"status":0,"games":[{"title_id":"fake78000","path":"/data/homebrew/FAKE78000"}]})";
+ CHECK(registry.Query("FAKE78000").reason == "bad-title-id");
+ // An odd entry elsewhere never hides a real collision, in either order.
+ const std::string foreign_valid = R"({"title_id":"FAKE78000","installed":true,"managed":true,"source_available":true,"source_type":"folder","path":"/mnt/usb0/x"})";
+ const std::string unrelated = R"({"title_id":"odd","path":"/data/homebrew/other"})";
+ response = "{\"status\":0,\"games\":[" + unrelated + "," + foreign_valid + "]}";
+ CHECK(registry.Query("FAKE78000").state == RegistrationState::kCollision);
+ response = "{\"status\":0,\"games\":[" + foreign_valid + "," + unrelated + "]}";
+ CHECK(registry.Query("FAKE78000").state == RegistrationState::kCollision);
+ response = R"({"status":0,"games":[{"title_id":"x","path":"/data/homebrew/other"},{"title_id":"FAKE78000","installed":true,"managed":true,"source_available":true,"source_type":"folder","path":"/data/homebrew/FAKE78000"}]})";
+ CHECK(registry.Query("FAKE78000").state == RegistrationState::kReady);
+ response = "{}";
+ CHECK(registry.Query("FAKE78000").reason == "status");
+ response = "not json";
+ CHECK(registry.Query("FAKE78000").reason == "bad-json");
TitleRegistry offline([](const auto&, const auto&) -> std::optional<std::string> { return {}; });
CHECK(offline.Query("FAKE78000").state == RegistrationState::kUnavailable);
+ CHECK(offline.Query("FAKE78000").reason == "no-response");
+ CHECK(offline.DescribeVersion() == "shadowmount=unreachable");
+ TitleRegistry versioned([&](const std::string& route, const std::string&) -> std::optional<std::string> {
+ return route == "/api/v1/version" ? response : std::string("{}");
+ });
+ response = R"({"status":0,"api_version":1,"shadowmount_version":"1.7beta2","capabilities":["list_games"]})";
+ CHECK(versioned.DescribeVersion() == "shadowmount=1.7beta2 api=1");
+ response = R"({"status":0,"shadowmount_version":"1.7 beta\n5"})";
+ CHECK(versioned.DescribeVersion() == "shadowmount=1.7?beta?5 api=unknown");
+ response = R"({"status":2})";
+ CHECK(versioned.DescribeVersion() == "shadowmount=bad-answer");
+ response = "{\"status\":0,\"shadowmount_version\":\"" + std::string(100, 'v') + "\"}";
+ CHECK(versioned.DescribeVersion() == "shadowmount=" + std::string(64, 'v') + " api=unknown");
CHECK(!offline.Register("FAKE78000").ok);
std::puts("title registry tests passed");
}