Skip to content

Conversation

StevenMiller123
Copy link
Collaborator

The standard library functions we're using for opening files will erase files when opening with write access. This differs from real hardware behavior, where the file opens without getting erased.

To properly emulate this behavior, I've made write-only access identical to read-write access, and added checks in read, posix_preadv, and readv to ensure that reading from a file with write-only access fails in a hardware-accurate way. I've also created a separate create mode that uses write-access to create files to simplify the process of creating a file in open since read-write mode doesn't create files.

Handling this behavior properly fixes saving in Catherine: Full Body (CUSA15036)
image

Opening with access mode w will erase the opened file. We do not want this.
Opening with write access was previously the only way to create a file through open, so add a separate FileAccessMode that uses the write access mode to create files.
Remove a hack added to posix_rename to bypass the file clearing behaviors of FileAccessMode::Write
Write-only files cause the EBADF return on the various read functions. Now that we're opening files differently, properly handling this is necessary.
Fixes a potential regression from one of my prior PRs, and ensures the Write | Append flag combo also behaves properly in read-related functions.
file->f is only valid for files, so checking this before checking for sockets/devices will cause access violations.
Now that Write is identical to ReadWrite, internal uses of Write need to be swapped to my new Create mode
@StevenMiller123
Copy link
Collaborator Author

This PR should probably receive further testing before any merge, to ensure there aren't any other issues I've caused by messing with FileAccessMode::Write.

@rafael-57
Copy link
Contributor

image image

Tested loading, updating older saves and also making a new one. No issues found in Bloodborne, even with multiple sessions.

@rafael-57
Copy link
Contributor

Anything blocking this other than need of more testing?

@StevenMiller123
Copy link
Collaborator Author

I think the main holdup here comes from PR #3368. Once that's ready for merge, this PR becomes an unnecessary hack.

@rafael-57
Copy link
Contributor

I think the main holdup here comes from PR #3368. Once that's ready for merge, this PR becomes an unnecessary hack.

ah nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants