libkernel: fsync and fdatasync fail on read-only and directory descriptors on Windows; fix branch ready #3317
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-11T07:14:39Z.
On Windows,
fsyncandfdatasync(andsceKernelFsync,sceKernelFdatasync) fail withEBADFon a descriptor the guest opened read-only and on a directory descriptor. FreeBSD's fsync(2) listsEBADFonly for "not a valid descriptor" and has no error for the open mode or for directories; the Linux build returns 0 for both.Opening a directory and calling
fsyncon it is the usual way to make a created or renamed file durable, so a title that checks the result sees its save or cache step fail.Cause.
sceKernelFsyncandsceKernelFdatasynccall_commit.FlushFileBuffersneeds write access to the handle, and_commitreports its failure asEBADF. A directory descriptor is a placeholder descriptor onNUL, which cannot be flushed either.Observed on
main1690db9a2, Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release:sceKernelFsync(fd), file openedO_RDONLYfsync(fd), file openedO_RDONLYsceKernelFdatasync(fd), file openedO_RDONLY0x80020009(EBADF)sceKernelFsync(fd), directorysceKernelFdatasync(fd), directory0x80020009(EBADF)O_RDWRI have not found a title that stops on this; it was found by probing the file functions, not from a title.
Fix, ready to cherry-pick.
DavidSamir:fix/libkernel-fsync-read-only-windows(d9bafbde, one commit onmain1690db9a2, two files, +30/-2). I can't open it as a PR because of the intake check.Windows only, in a
NativeSynchelper both functions call:GENERIC_WRITEandFILE_FLAG_BACKUP_SEMANTICS, the wayFlushPathalready does forsceKernelSync._commitruns first, so a writable descriptor behaves exactly as before. When it fails and the descriptor is an open disk file, the file is flushed through a write handle fromReOpenFile.FlushPathdoes: no handle that could flush it can be opened.EBADF, anderrnois left untouched on success.guest_filesystemgains checks:sceKernelFsync,fdatasyncandsceKernelFdatasyncreturn 0 on a directory descriptor and on a file opened read-only, andsceKernelFsyncreturns 0 on a read-only descriptor of a file made read-only withsceKernelChmod(0400). The existing checks for a closed descriptor, a socket and descriptor0x7fffffffare unchanged and still pass.Checked on Windows (d9bafbde on
main1690db9a2, WinLibs GCC 15.2.0 r7, Release):guest_filesystemfails at the directorysceKernelFsynccheck (guest errno 9). With the fix it passes 5/5 (--repeat until-fail:5).FlushFileBufferson a directory handle opened as above succeeds; on a read-only handle it fails with access denied; on theReOpenFilewrite handle it succeeds;ReOpenFilefor write on a read-only-attribute file fails with access denied.main0e90079fand from the branch: DOOM (PPSA99666), OpenRCT2 (PPSA99728), ScreenTester5 (PPSA69420) and Prospero Vibrate (PPSA99920) keep running with the same log line counts; Yamagi Quake II (PPSA99007) exits with code 0 in both; Middle Ages Ping Pong (PPSA28319, Unity) stops at the same multisampling check in both.ctest --parallel 4passes 770/770 (5 skipped, no display in the session).check_conventions.py --base origin/mainpasses;pr_overlap.py --branchreports no overlap with open pull requests.Checked on Linux (same commit, WSL2 Ubuntu 24.04, GCC 13.3.0, Release):
guest_filesystempasses 3/3, so the new checks match the existing Linux behaviour. Only that test was built and run there.Not checked on a console. That the data reaches the disk was not measured; only the return values and the Win32 calls above were.
AI-assisted: yes