fix(libkernel): sync read-only and directory descriptors on Windows #3578

Merged
LeandroLP23 merged 1 commit from upstream-pr/3578 into main 2026-10-11 21:37:24 +00:00
LeandroLP23 commented 2026-10-11 13:38:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T13:38:41Z.


Carrying @DavidSamir's fix for #3317 (DavidSamir:fix/libkernel-fsync-read-only-windows, d9bafbde; they can't open PRs yet). The change is theirs, cherry-picked onto current main without conflicts, authorship kept.

What

On Windows, fsync, fdatasync, sceKernelFsync and sceKernelFdatasync fail with EBADF on a descriptor opened read-only and on a directory descriptor, because _commit needs a writable handle and a directory descriptor is a placeholder on NUL. FreeBSD and the Linux build return 0 for both. A new Windows-only NativeSync, which both functions call, does the following:

  • flushes a directory through a write handle opened on its path with FILE_FLAG_BACKUP_SEMANTICS;
  • for any other descriptor, tries _commit first, then flushes an open disk file through a write handle from ReOpenFile;
  • returns 0 when no writable handle can be opened (read-only attribute), as FlushPath already does for sceKernelSync;
  • still returns EBADF for a closed descriptor or one that is not a disk file.

guest_filesystem gains the directory, read-only descriptor and read-only file cases. Details are in #3317.

Tested

  • DavidSamir: Windows 11, WinLibs GCC 15.2.0 r7. Full ctest 770/770, title runs unchanged, and guest_filesystem 3/3 on WSL2 Ubuntu 24.04. All in #3317.
  • My run: Radeon 860M (RDNA 3.5), Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, on main a11c8f7f7, with #3518's one-line test change applied locally so guest_filesystem gets past line 286. guest_filesystem passes 3/3. With main's Stdio.cpp, it fails at the first new check, sceKernelFsync on the directory descriptor (guest errno 9). Outside of the known failures listed below, ctest -E agc_ and ctest -R agc_ match main.

Fork CI: https://github.com/LeandroLP23/AnyPS5/actions/runs/38142442243

  • Windows: 833/836. All three failures fail the same way on plain main: guest_filesystem at line 286 (fixed by #3518), guest_kernel_sys on symlink (fixed by #3510), and windows_exceptions (#3411).
  • Linux: 834/838. The new code is all inside #ifdef _WIN32, so it isn't built on Linux. The failures are main's agc_driver_image_plane_address_on_line_implicit_lod and guest_kernel_stack_protect, the intermittent agc_driver_depth_fast_clear_submit segfault, and agc_driver_emulated_color_compare.

Fixes #3317

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 (Claude Code, for carrying and the Windows run; see #3317 for the author's disclosure)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819466416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3578). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-11T13:38:41Z. --- Carrying @DavidSamir's fix for #3317 (`DavidSamir:fix/libkernel-fsync-read-only-windows`, `d9bafbde`; they can't open PRs yet). The change is theirs, cherry-picked onto current `main` without conflicts, authorship kept. ### What On Windows, `fsync`, `fdatasync`, `sceKernelFsync` and `sceKernelFdatasync` fail with `EBADF` on a descriptor opened read-only and on a directory descriptor, because `_commit` needs a writable handle and a directory descriptor is a placeholder on `NUL`. FreeBSD and the Linux build return 0 for both. A new Windows-only `NativeSync`, which both functions call, does the following: - flushes a directory through a write handle opened on its path with `FILE_FLAG_BACKUP_SEMANTICS`; - for any other descriptor, tries `_commit` first, then flushes an open disk file through a write handle from `ReOpenFile`; - returns 0 when no writable handle can be opened (read-only attribute), as `FlushPath` already does for `sceKernelSync`; - still returns `EBADF` for a closed descriptor or one that is not a disk file. `guest_filesystem` gains the directory, read-only descriptor and read-only file cases. Details are in #3317. ### Tested - DavidSamir: Windows 11, WinLibs GCC 15.2.0 r7. Full `ctest` 770/770, title runs unchanged, and `guest_filesystem` 3/3 on WSL2 Ubuntu 24.04. All in #3317. - My run: Radeon 860M (RDNA 3.5), Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, on `main` `a11c8f7f7`, with #3518's one-line test change applied locally so `guest_filesystem` gets past line 286. `guest_filesystem` passes 3/3. With `main`'s `Stdio.cpp`, it fails at the first new check, `sceKernelFsync` on the directory descriptor (guest errno 9). Outside of the known failures listed below, `ctest -E agc_` and `ctest -R agc_` match `main`. Fork CI: https://github.com/LeandroLP23/AnyPS5/actions/runs/38142442243 - Windows: 833/836. All three failures fail the same way on plain `main`: `guest_filesystem` at line 286 (fixed by #3518), `guest_kernel_sys` on `symlink` (fixed by #3510), and `windows_exceptions` (#3411). - Linux: 834/838. The new code is all inside `#ifdef _WIN32`, so it isn't built on Linux. The failures are `main`'s `agc_driver_image_plane_address_on_line_implicit_lod` and `guest_kernel_stack_protect`, the intermittent `agc_driver_depth_fast_clear_submit` segfault, and `agc_driver_emulated_color_compare`. Fixes #3317 ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 (Claude Code, for carrying and the Windows run; see #3317 for the author's disclosure)
github-actions[bot] commented 2026-10-11 15:28:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T15:28:08Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3682 core/libs/prx/libkernel/File/src/Stdio.cpp L720
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110594493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3578#issuecomment-6110594493). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T15:28:08Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3682 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L720](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/prx/libkernel/File/src/Stdio.cpp#L720) | | |
adriadam10 commented 2026-10-11 21:37:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:37:21Z.


Checked the diff and the build: NativeSync handles directory descriptors (backup-semantics write handle), read-only descriptors (_commit, then ReOpenFile) and returns 0 on ERROR_ACCESS_DENIED, like FlushPath; closed or non-disk descriptors still give EBADF, and errno is restored after the failed _commit. guest_filesystem and the 112 libkernel/libs tests pass on Linux, and DavidSamir's Windows run in #3317 covers the Windows path. The remaining guest_filesystem Windows failure at line 286 is independent (#3518). Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114051832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3578#issuecomment-6114051832). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:37:21Z. --- Checked the diff and the build: `NativeSync` handles directory descriptors (backup-semantics write handle), read-only descriptors (`_commit`, then `ReOpenFile`) and returns 0 on `ERROR_ACCESS_DENIED`, like `FlushPath`; closed or non-disk descriptors still give `EBADF`, and errno is restored after the failed `_commit`. `guest_filesystem` and the 112 libkernel/libs tests pass on Linux, and DavidSamir's Windows run in #3317 covers the Windows path. The remaining `guest_filesystem` Windows failure at line 286 is independent (#3518). Merging.
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!3578
No description provided.