Skip to content

ps2client: open host: files read-write as O_RDWR - #34

Merged
fjtrujy merged 1 commit into
ps2dev:masterfrom
rickgaiser:fix/rdwr-open-flags
Nov 1, 2026
Merged

fjtrujy merged 1 commit into
ps2dev:masterfrom
rickgaiser:fix/rdwr-open-flags

Conversation

@rickgaiser

Copy link
Copy Markdown
Member

A host: file opened read-write (PS2 open flags 3) could not be read: every read returned 0 bytes, and the file was emptied when it was opened.

fix_flags turned each access bit into its own host flag. For flags 3 that gives O_RDONLY | O_WRONLY | O_TRUNC, and since O_RDONLY is 0 on POSIX hosts, that is O_WRONLY | O_TRUNC. The fix maps the access mode (the low two bits) as a whole:

PS2 flags Before After
1 (read) O_RDONLY O_RDONLY
2 (write) O_WRONLY | O_TRUNC O_WRONLY | O_TRUNC (unchanged, see the FIXME)
3 (read and write) O_WRONLY | O_TRUNC O_RDWR

Found with a swap file on host: on a real PS2: pages written to the file read back as nothing.

Test: tests/run-tests.sh gets a check that a file opened with flags 3 reads back with the right size and CRC (rdwrback in the fake ps2link). It fails without the fix and passes with it; all 40 checks pass, as does make check.

🤖 Generated with Claude Code

The PS2's open flags hold the access mode in the low two bits (1 read,
2 write, 3 both). fix_flags or-ed O_RDONLY and O_WRONLY for 3, which is
O_WRONLY | O_TRUNC on POSIX hosts: a file opened read-write was emptied
and every read of it returned 0 bytes. Map the mode as a whole; 3 is now
O_RDWR (without O_TRUNC).

tests: the fake's rdwrback reads a file opened with flags 3; its size and
CRC must match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fjtrujy
fjtrujy merged commit b917a44 into ps2dev:master Nov 1, 2026
8 checks passed
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