libSaveData: persist save metadata so saved games can be loaded #434
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!434
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/434/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@CheesyPoofs346 on GitHub · 2026-08-31 22:20 UTC · original
CheesyPoofs346:fix/savedata-param-persistence→main· +75 −5 · 2 files · 1 commits · closed without mergingSummary
SaveDataSetParamdiscarded what it was given,SaveDataGetParamalways returned zeros, andSaveDataDirNameSearchblanked the params of every save it listed.Problem
SaveDataSetParamlogged the parameters and returnedOKwithout storing them:SaveDataGetParamzeroed its output regardless of what was on disk:And
SaveDataDirNameSearchfound the save directories correctly but cleared their params:So the metadata round-trip was entirely missing. A game enumerating its saves received a valid directory name with an empty title and
mtime = 0, which is indistinguishable from an empty slot.Observed in Grand Theft Auto V (PPSA04264): the game wrote a valid 565 KB save to
SAVEDATASGTA50000and mounted it successfully, but on the next launch the load menu did not offer it and starting the game began a new playthrough. The save data itself was intact the whole time — only its description was lost.This change stores the
SaveDataParamnext to the save data assce_param.bin, reads it back inSaveDataGetParam, and fills it in for each entry returned bySaveDataDirNameSearch.mtimeis set from the wall clock when a title does not supply one. Saves written before this change have no metadata file; the search still lists them, and they gain metadata on the next save.SaveDataMountSlotsgains aDirectory()accessor so a mount point can be resolved back to the directory its metadata belongs in.Validation
AI assistance
AI assistance was used for this change.
@ -345,0 +351,4 @@return Common::FixDirectorySlash(std::string(SAVE_DATA_DIR) + "/" + get_title_id() + "/" +dir_name) +"/sce_param.bin";}@Copilot on GitHub · 2026-08-31 22:24 UTC · original
param_file_path() currently produces a path with a double slash (FixDirectorySlash() already appends '/', then the code adds "/sce_param.bin"). While most filesystems tolerate it, it’s easy to avoid and keeps paths consistent.
@ -322,2 +324,3 @@return SAVE_DATA_ERROR_BUSY;::printf("SaveDataMount3: refused (%s)\n", "SAVE_DATA_ERROR_BUSY");return SAVE_DATA_ERROR_BUSY;}@Copilot on GitHub · 2026-08-31 22:24 UTC · original
SaveDataTerminate logs "SaveDataMount3" on the busy path, which is misleading and makes debugging harder. Also the return line is misindented compared to the surrounding style.
@ -454,2 +500,3 @@return SAVE_DATA_ERROR_MOUNT_FULL;::printf("SaveDataMount3: refused (%s)\n", "SAVE_DATA_ERROR_MOUNT_FULL");return SAVE_DATA_ERROR_MOUNT_FULL;}@Copilot on GitHub · 2026-08-31 22:24 UTC · original
The return statement in this error path is misindented, which makes it look like it might not be part of the if-block. Please indent consistently to avoid confusion during future edits.
This issue also appears in the following locations of the same file:
@ -718,0 +774,4 @@(void)read_save_param(g_mount_slots.Directory(static_cast<size_t>(slot)),static_cast<SaveDataParam*>(param_buf));}}@Copilot on GitHub · 2026-08-31 22:24 UTC · original
SaveDataGetParam holds g_mount_mutex while doing disk I/O via read_save_param(). If the filesystem stalls, this can block unrelated mount/umount operations. Consider copying the directory string under the lock, then releasing the lock before reading the metadata file.
@copilot-pull-request-reviewer[bot] on GitHub · 2026-08-31 22:24 UTC · original · reviewed
Pull request overview
This PR implements persistence for save metadata in
libSaveDataso that titles can enumerate saves and display/load them correctly across restarts, by storing and reloadingSaveDataParamdata from disk.Changes:
SaveDataParam(read/writesce_param.bin) and populate it inSaveDataGetParamandSaveDataDirNameSearch.SaveDataSetParamand synthesizemtimewhen missing.SaveDataMountSlots::Directory()to resolve a mount point back to its source save directory.Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
SaveDataParamto disk and wires it into search/get/set flows (plus extra mount diagnostics).Suppressed comments (2)
src/libs/libSaveData.cpp:511
src/libs/libSaveData.cpp:516
💡 Add a
code-reviewagent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.@ -840,0 +900,4 @@Common::LockGuard lock(g_mount_mutex);const int slot = g_mount_slots.Find(mount_point->data);if (slot >= 0) {write_save_param(g_mount_slots.Directory(static_cast<size_t>(slot)), *p);@Copilot on GitHub · 2026-08-31 22:24 UTC · original
SaveDataSetParam persists *p to disk but still doesn’t validate param_buf/param_buf_size before dereferencing it (both for logging and for write_save_param). Also, doing file I/O while holding g_mount_mutex can block other save/mount operations if the filesystem is slow. Validate the buffer and copy the directory under the lock, then write after releasing it.
@chatgpt-codex-connector[bot] on GitHub · 2026-08-31 22:27 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
279573b5d5ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@ -345,0 +377,4 @@}std::ofstream file(param_file_path(dir_name), std::ios::binary | std::ios::trunc);if (file.is_open()) {file.write(reinterpret_cast<const char*>(&stored), sizeof(stored));@chatgpt-codex-connector[bot] on GitHub · 2026-08-31 22:27 UTC · original
When the host filesystem is full, read-only, or a write is interrupted, opening with
trunccan destroy the previously valid metadata andfile.writemay leave a short file, yetwrite_save_paramdiscards the stream state andSaveDataSetParamstill returnsOK. On the next launch,read_save_paramrejects that file and callers receive a zeroed parameter, making an otherwise intact save inaccessible. Write a temporary file, verify the complete write, atomically replace the old file, and return an appropriate save-data error on failure.Useful? React with 👍 / 👎.
@ -345,0 +373,4 @@static void write_save_param(const std::string& dir_name, const SaveDataParam& param) {SaveDataParam stored = param;if (stored.mtime == 0) {stored.mtime = static_cast<int64_t>(::time(nullptr));@chatgpt-codex-connector[bot] on GitHub · 2026-08-31 22:27 UTC · original
When a title supplies
mtime == 0, this stores Unixtime_tseconds directly in the save-datamtimefield, whose guest ABI uses an RTC tick value with a different epoch and microsecond units. Games that convert the returned value to a calendar date will therefore see a timestamp near the RTC epoch, and comparisons with title-supplied RTC ticks will place these saves incorrectly. Generate the timestamp in the guest RTC representation instead of copying Unix seconds.Useful? React with 👍 / 👎.
@ -345,0 +350,4 @@static std::string param_file_path(const std::string& dir_name) {return Common::FixDirectorySlash(std::string(SAVE_DATA_DIR) + "/" + get_title_id() + "/" +dir_name) +"/sce_param.bin";@chatgpt-codex-connector[bot] on GitHub · 2026-08-31 22:27 UTC · original
This path places
sce_param.bininside the same directory thatmount_save_dataexposes wholesale as/savedataN. Consequently, titles that enumerate, checksum, copy, clear, or create all files in their save mount can observe or overwrite the emulator's private metadata; deleting or replacing it makes the next search return blank parameters again. Store the control file outside the mounted directory, or explicitly hide and protect it in the filesystem layer.Useful? React with 👍 / 👎.
@Nmzik on GitHub · 2026-09-23 18:51 UTC · original
Credited
Pull request closed