Skip to content

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

C++

Keep the space the PS5 holds back out of free storage

Leonardo Lobato3c0fc9c74c39
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index ce4bb7e..b375379 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -348,7 +348,7 @@ int main() {
// The title's folders under /data and /user are root-owned: renames there need root briefly.
update_config.as_root = [](const std::function<bool()>& work) { return playden::ps5::WithRoot(work); };
update_config.free_bytes = [](const std::string& path) -> std::optional<std::uint64_t> {
- const auto space = playden::steam::QueryVolumeSpace(path);
+ const auto space = playden::steam::QueryVolumeSpace(path, playden::steam::kConsoleSystemReserve);
if (!space) return std::nullopt;
return space->free_bytes;
};
@@ -397,7 +397,7 @@ int main() {
config.package_operations.hash_file = rt::HashArtifactFile;
config.package_operations.hash_bytes = rt::HashArtifactBytes;
config.package_operations.free_bytes = [](const std::filesystem::path& path) -> std::optional<std::uint64_t> {
- const auto space = playden::steam::QueryVolumeSpace(path.string());
+ const auto space = playden::steam::QueryVolumeSpace(path.string(), playden::steam::kConsoleSystemReserve);
return space ? std::optional<std::uint64_t>{space->free_bytes} : std::nullopt;
};
config.package_operations.free_space_unverifiable = !playden::steam::VolumeSpaceSupported();
diff --git a/src/steam/install_volumes.cpp b/src/steam/install_volumes.cpp
index cb38bd7..5fdcb3d 100644
--- a/src/steam/install_volumes.cpp
+++ b/src/steam/install_volumes.cpp
@@ -8,6 +8,7 @@ extern "C" int sceKernelDlsym(int, const char*, void**);
#include <sys/statvfs.h>
#endif
+#include <algorithm>
#include <cerrno>
#include <cstdio>
#include <cstring>
@@ -131,6 +132,11 @@ std::optional<VolumeSpace> detail::VolumeSpaceFromBlocks(std::int64_t block_size
return VolumeSpace{blocks * unit, available * unit};
}
+VolumeSpace detail::WithoutConsoleReserve(VolumeSpace space, std::uint64_t reserve) {
+ space.free_bytes -= std::min(space.free_bytes, reserve);
+ return space;
+}
+
bool detail::VolumeMountMatches(const std::string& path, const std::string& mount) {
const auto root = ExternalRoot(path);
return root.empty() || mount == root;
@@ -165,7 +171,7 @@ std::vector<VolumeCandidate> ConsoleVolumeCandidates(const std::string& title_ro
};
}
-std::optional<VolumeSpace> QueryVolumeSpace(const std::string& path) {
+std::optional<VolumeSpace> QueryVolumeSpace(const std::string& path, std::uint64_t console_reserve) {
std::string directory = QueryPath(path);
if (directory.empty()) return std::nullopt;
const auto external_root = ExternalRoot(directory);
@@ -195,7 +201,10 @@ std::optional<VolumeSpace> QueryVolumeSpace(const std::string& path) {
return std::nullopt;
if (info.f_bsize > static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max()))
return std::nullopt;
- return detail::VolumeSpaceFromBlocks(static_cast<std::int64_t>(info.f_bsize), info.f_blocks, info.f_bavail);
+ const auto space = detail::VolumeSpaceFromBlocks(static_cast<std::int64_t>(info.f_bsize), info.f_blocks, info.f_bavail);
+ // Console storage (no external drive root) keeps space for the system.
+ if (space && external_root.empty()) return detail::WithoutConsoleReserve(*space, console_reserve);
+ return space;
#else
struct statvfs info {};
const bool ok = fstatvfs(fd, &info) == 0;
diff --git a/src/steam/install_volumes.h b/src/steam/install_volumes.h
index 631d890..49499a0 100644
--- a/src/steam/install_volumes.h
+++ b/src/steam/install_volumes.h
@@ -44,6 +44,11 @@ struct VolumeSpace {
};
inline constexpr std::uint64_t kInstallSpaceMargin = 64ull * 1024 * 1024;
+// Console storage refuses writes (ENOSPC) while statfs still reports about 5.3 GB available: the PS5 keeps that
+// for itself. Free space there leaves out a reserve: the system's share for Playden's own writes (preparations,
+// updates), and more for downloads, so a finished one still leaves room to prepare the game and save.
+inline constexpr std::uint64_t kConsoleSystemReserve = 6ull * 1024 * 1024 * 1024;
+inline constexpr std::uint64_t kConsoleStorageReserve = 8ull * 1024 * 1024 * 1024;
// Space a download still needs: its install estimate less what it already holds on disk, which
// the drive's free space already reflects. Without a report (not started this session) the
@@ -55,7 +60,8 @@ inline std::uint64_t PendingInstallBytes(std::optional<std::uint64_t> estimate,
// Total and available bytes for the directory's drive, or nothing if it cannot be verified.
// Missing destination directories use an existing ancestor, without leaving an external root.
-std::optional<VolumeSpace> QueryVolumeSpace(const std::string& path);
+std::optional<VolumeSpace> QueryVolumeSpace(const std::string& path,
+ std::uint64_t console_reserve = kConsoleStorageReserve);
// False when the platform has no way to read free space (a console whose libkernel lacks the
// query). Installs then go ahead unchecked, as before free space was readable, and a full drive
@@ -67,6 +73,8 @@ namespace detail {
std::optional<VolumeSpace> VolumeSpaceFromBlocks(std::int64_t block_size, std::uint64_t blocks,
std::int64_t available_blocks);
bool VolumeMountMatches(const std::string& path, const std::string& mount);
+// Space on console storage, less a reserve.
+VolumeSpace WithoutConsoleReserve(VolumeSpace space, std::uint64_t reserve);
} // namespace detail
} // namespace playden::steam
diff --git a/tests/install_volumes_test.cpp b/tests/install_volumes_test.cpp
index ddfaf78..486b74a 100644
--- a/tests/install_volumes_test.cpp
+++ b/tests/install_volumes_test.cpp
@@ -96,6 +96,10 @@ int main() {
CHECK(missing && missing->total_bytes == space->total_bytes);
CHECK(!std::filesystem::exists(base / "absent"));
CHECK(!QueryVolumeSpace(""));
+ // Console storage leaves out what the PS5 keeps for itself; never below zero.
+ CHECK(detail::WithoutConsoleReserve({100ull << 30, 20ull << 30}, kConsoleStorageReserve).free_bytes == 12ull << 30);
+ CHECK(detail::WithoutConsoleReserve({100ull << 30, 5ull << 30}, kConsoleStorageReserve).free_bytes == 0 &&
+ detail::WithoutConsoleReserve({100ull << 30, 5ull << 30}, kConsoleStorageReserve).total_bytes == 100ull << 30);
CHECK(QueryVolumeSpace(base.string() + "//./"));
CHECK(!QueryVolumeSpace(base.string() + "/../games"));
CHECK(QueryVolumeSpace("."));