Skip to content

fix(libkernel): report a stable file identity from stat and fstat on Windows - #2362

Closed
Aerovity wants to merge 1 commit into
boykopovar:mainfrom
Aerovity:fix/libkernel-windows-stat-identity
Closed

Aerovity wants to merge 1 commit into
boykopovar:mainfrom
Aerovity:fix/libkernel-windows-stat-identity

Conversation

@Aerovity

@Aerovity Aerovity commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What

Fixes #2296.

On Windows, _wstat64/_fstat64 report st_ino 0, and st_dev is the drive number from stat but 0 from fstat. So the guest st_dev/st_ino identity check matched every pair of files from stat and never matched across stat and fstat.

NativeStat.cpp now takes the identity from the file's handle with GetFileInformationByHandle, the same way for path and descriptor stat:

  • st_dev = dwVolumeSerialNumber
  • st_ino = the 64-bit file index folded into the guest's 32-bit ino_t (low ^ high)
  • st_nlink = nNumberOfLinks

Path stat opens the file with FILE_READ_ATTRIBUTES and FILE_FLAG_BACKUP_SEMANTICS (so directories work too) and full sharing. Descriptor stat uses _get_osfhandle. Directory descriptors go through their path. Descriptors that are not disk files (pipes, consoles) keep the previous values, so fstat on them still succeeds. Linux is unchanged.

GuestFilesystem.cpp checks that two files in one directory share st_dev and differ in st_ino, and that sceKernelStat and sceKernelFstat of the same file agree on both.

Note: #1518 also edits NativeStat.cpp (timestamps). The changes are independent. Whichever lands second needs a small rebase.

Tested

Not tested: not built or 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: N/A
  • 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: N/A
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

…Windows

_wstat64/_fstat64 report st_ino 0 and disagree on st_dev (drive number
vs 0), so a guest st_dev/st_ino identity check matched every pair of
files from stat and never matched across stat and fstat. Read the volume
serial number, file index and link count from the file's handle for
disk files, the same way for path and descriptor stat.

Fixes boykopovar#2296

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AnzouBelilita

Copy link
Copy Markdown

Independent Windows validation for PR #2362:

  • OS: Windows 10 Pro, build 19045
  • Toolchain: MinGW-w64 GCC 16.2.0, CMake 4.4.4, Ninja 1.13.2
  • Configured the project in Release mode with BUILD_TESTING=ON.
  • Built guest_filesystem_tests successfully (94 build steps).
  • CTest: guest_filesystem passed (1/1, 0 failures).
  • python tools/check_conventions.py --base d70b89989473ba1f6ae13e44e079e67f1f8a44b0 passed.
  • git diff --check d70b89989473ba1f6ae13e44e079e67f1f8a44b0...HEAD passed.
  • Tested PR head: 3c7ac214ceb912293b8f34421ad48bba33a83214.

This provides independent native-Windows build and test coverage for the stat/fstat change. It does not establish behavior on PS5 hardware.

No production code was modified during validation.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is shown to depend on st_dev/st_ino on main, and this adds a CreateFileW to every stat on Windows without having been built or run here. Reopen with the title that needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: stat and fstat report st_ino 0 and disagree on st_dev, so files cannot be identified

3 participants