kernel: flush synced writes and export the POSIX fsync #1478
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1478
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1478/head"
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?
@mariobob on GitHub · 2026-10-13 14:47 UTC · original
mariobob:kernel-fsync→main· +76 −9 · 4 files · 2 commits · closed without mergingSummary
sceKernelFsync(fTx66l5iWIA) returns OK without touching the descriptor, and the POSIXfsync(juWbTNM+8hw) is not registered, so titles that call it get the unresolved-import stub. Neither flushes anything.That matters on Linux and macOS. There
Common::Filewrites through stdio (fwriteinsysLinuxFileIO.cpp), so bytes a title writes stay in the emulator's user-space buffer until the descriptor is closed or the buffer fills. After a title writes a file and syncs it:sceKernelStaton the path still reports the old size, because it asks the host;EXITpaths are fine:DbgExitflushes every stream before_Exit.)On Windows,
WriteFilemakes the data visible straight away, butfsyncstill does not reach the disk.Changes:
KernelFsyncmoves intokernel/fileSystem.cppnext toKernelFtruncateand uses the same descriptor checks. Writable regular files are flushed withCommon::File::Flush(fflushon Linux and macOS,FlushFileBufferson Windows), the callO_SYNCwrites already use. Read-only, directory and device descriptors return OK, unknown or closed descriptors returnEBADF, and sockets returnEINVAL.fsyncis registered in the Posix module and wrapsKernelFsyncwithPOSIX_CALL, likeftruncate.Evidence
Insomniac's titles call the POSIX export during startup, right after
Title ID, and reach the stub:The stub returns 0, which is also what
fsyncreturns on success, so I'm not claiming this changes how far either game gets. What changes is that the data they sync is flushed, as it is on the console.Testing
TestFsyncVisibilityintests/KernelFileSystemTests.cppwrites 15 bytes to a file under/savedata0and syncs it. While the writer is still open it checks thatKernelStatreports 15 bytes and that a second descriptor reads the payload. It also checks that a read-only descriptor syncs, that the POSIX export resolves and returns 0, and that a closed descriptor returnsEBADF(and-1with errnoEBADFthrough POSIX).I did not build the full emulator or run
kernel_file_system_tests: it creates a Vulkan device first, and I only have macOS with MoltenVK (see #1448). CI does not build that target either. What I ran instead:src/kernel/fileSystem.cpp,src/common/file.cpp,src/common/platform/sysLinuxFileIO.cppandsrc/common/dateTime.cpp, with logging, mutexes, archives, guest-memory invalidation and socket lookup stubbed. macOS builds use the same POSIX file backend as Linux (KYTY_PLATFORM_LINUX). It runs the same sequence as the test:main(df5b9b92)statsize after write + fsync, writer still openstatsize after closeEBADFclang++ -std=c++20 -Wall -Wextra -fsyntax-onlyfor x86-64 onfileSystem.cpp,libKernel.cppandKernelFileSystemTests.cppagainst the pinned submodule headers: no errors and no warnings on the changed lines.git clang-formatreports no changes on the diff.AI assistance
Claude Code found the missing export in the issue logs, wrote the change, the test and the harness, and ran the checks above.
@coderabbitai[bot] on GitHub · 2026-10-13 14:50 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
dd62dae5-0b53-4009-91df-2d1a3f34f881📥 Commits
Reviewing files that changed from the base of the PR and between
df5b9b92beand27b16f67c8.📒 Files selected for processing (4)
src/kernel/fileSystem.cppsrc/kernel/fileSystem.hsrc/libs/libKernel.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
The filesystem API now implements
KernelFsyncwith descriptor validation and file flushing. POSIXfsyncforwards to this API. The change registers both entry points and adds tests for file visibility, read-only descriptors, and closed-descriptor errors.Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
27b16No concrete fsync issue remains that should block merging. Run the normal build and test checks.
Pre-merge checks ·
4 ·
1
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@Nmzik on GitHub · 2026-10-21 19:41 UTC · original
Superseded by
7675579e7.Pull request closed