fix(libkernel): honour open flags when Windows falls back to a directory descriptor #1628

Merged
babyhuey merged 1 commit from upstream-pr/1628 into main 2026-10-10 04:39:54 +00:00
babyhuey commented 2026-10-08 15:17:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T15:17:07Z.


What

On Windows _wopen cannot open a directory, so sceKernelOpen falls back to a directory descriptor when the path is a directory. The fallback ignored the flags: O_CREAT | O_EXCL on an existing directory returned a descriptor instead of EEXIST, and write access returned a read-only descriptor instead of EISDIR.

The fallback now follows FreeBSD vn_open_cred/vn_open_vnode (sys/kern/vfs_vnops.c):

  • O_CREAT | O_EXCL: EEXIST
  • O_CREAT without O_EXCL, O_TRUNC, O_WRONLY or O_RDWR: EISDIR
  • otherwise: directory descriptor, as before

Linux opens directories natively and already returns these errors.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): guest_filesystem passes with --repeat until-fail:3; the new assertions open the test directory with each flag combination above and a plain read-only open. On Linux they check host behaviour, which is the reference; the Windows job runs the same assertions against the changed fallback. Windows: Open.cpp compiles with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows locally. check_conventions.py passes. No title run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4788961143 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1628). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T15:17:07Z. --- ### What On Windows `_wopen` cannot open a directory, so `sceKernelOpen` falls back to a directory descriptor when the path is a directory. The fallback ignored the flags: `O_CREAT | O_EXCL` on an existing directory returned a descriptor instead of `EEXIST`, and write access returned a read-only descriptor instead of `EISDIR`. The fallback now follows FreeBSD `vn_open_cred`/`vn_open_vnode` (`sys/kern/vfs_vnops.c`): - `O_CREAT | O_EXCL`: `EEXIST` - `O_CREAT` without `O_EXCL`, `O_TRUNC`, `O_WRONLY` or `O_RDWR`: `EISDIR` - otherwise: directory descriptor, as before Linux opens directories natively and already returns these errors. ### Tested Linux (Ubuntu 24.04, GCC 13, Release): `guest_filesystem` passes with `--repeat until-fail:3`; the new assertions open the test directory with each flag combination above and a plain read-only open. On Linux they check host behaviour, which is the reference; the Windows job runs the same assertions against the changed fallback. Windows: `Open.cpp` compiles with MinGW-w64 GCC 13 (`-Wall -Wextra -fsyntax-only`); not run on Windows locally. `check_conventions.py` passes. No title run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
klosixgaming-arch commented 2026-10-08 15:34:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T15:34:22Z.

Review: APPROVED


LGTM. Clean fix that makes the Windows directory open fallback properly honor open flags, matching FreeBSD behavior. The flag checking logic is correct - EEXIST for O_CREAT|O_EXCL on existing directories, EISDIR for write access or truncation, and allowing plain read-only opens as before. Test coverage is thorough with all failing flag combinations verified plus confirmation that valid directory opens still work.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5459136240 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1628#pullrequestreview-5459136240). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T15:34:22Z. **Review:** APPROVED --- LGTM. Clean fix that makes the Windows directory open fallback properly honor open flags, matching FreeBSD behavior. The flag checking logic is correct - EEXIST for O_CREAT|O_EXCL on existing directories, EISDIR for write access or truncation, and allowing plain read-only opens as before. Test coverage is thorough with all failing flag combinations verified plus confirmation that valid directory opens still work.
babyhuey commented 2026-10-08 17:37:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T17:37:05Z.


Fork CI while the upstream run waits for approval: Build run, all jobs green on ce3c5bf8 (Linux 466/466, Windows 457/457, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065572894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1628#issuecomment-6065572894). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T17:37:05Z. --- Fork CI while the upstream run waits for approval: [Build run](https://github.com/babyhuey/AnyPS5/actions/runs/37812351389), all jobs green on ce3c5bf8 (Linux 466/466, Windows 457/457, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with `main`.
popcoder565 commented 2026-10-09 10:00:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:00:50Z.


First Windows run, since the description says it was only compiled with MinGW. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. #1624, #1628, #1633 and #1634 merged together onto main b7218b3c.

guest_filesystem, which carries this PR's directory-fallback cases, passes.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078684195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1628#issuecomment-6078684195). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T10:00:50Z. --- First Windows run, since the description says it was only compiled with MinGW. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. #1624, #1628, #1633 and #1634 merged together onto `main` b7218b3c. `guest_filesystem`, which carries this PR's directory-fallback cases, passes. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1628
No description provided.