kernel: implement sceKernelUtimes #2579

Open
github-bot wants to merge 1 commit from github-bot/gh-2579 into main AGit
Owner

@⁠lordra9-svg on GitHub · 2026-11-27 02:00 UTC · original
lordra9-svg:fix/kernel-utimes → main · +116 −0 · 4 files · 1 commits · open

Abiotic Factor (PPSA26012, #2163) and WUCHANG: Fallen Feathers
(PPSA09518, #541) import sceKernelUtimes from libkernel_v1 as NID
0Cq8ipKr9n0; Returnal (PPSA01285) imports the same NID. The export was not
registered, so these games logged an unresolved-import stub.

Implement the FreeBSD/PS5 contract: validate microseconds before resolving
the path, report EFAULT for a null path, ENOENT for an empty or unmapped
path and EROFS for a read-only mount. times[0] is the access time and
times[1] the modification time; a null times sets both to the current
time. Use utimes on POSIX and _wutime on Windows.

Refs #2163, #541.

Tests

  • kernel_file_system_tests passes on 61db2f88: export lookup, explicit
    times, current-time mode, invalid microseconds and the path errors.

Files: src/kernel/fileSystem.cpp, src/kernel/fileSystem.h,
src/libs/libKernel.cpp, tests/KernelFileSystemTests.cpp.

AI assistance

Drafted with AI assistance; I reviewed the change and ran the tests above.

**@⁠lordra9-svg** on GitHub · 2026-11-27 02:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2579) `lordra9-svg:fix/kernel-utimes` → `main` · +116 −0 · 4 files · 1 commits · open Abiotic Factor (PPSA26012, #2163) and WUCHANG: Fallen Feathers (PPSA09518, #541) import `sceKernelUtimes` from `libkernel_v1` as NID `0Cq8ipKr9n0`; Returnal (PPSA01285) imports the same NID. The export was not registered, so these games logged an unresolved-import stub. Implement the FreeBSD/PS5 contract: validate microseconds before resolving the path, report `EFAULT` for a null path, `ENOENT` for an empty or unmapped path and `EROFS` for a read-only mount. `times[0]` is the access time and `times[1]` the modification time; a null `times` sets both to the current time. Use `utimes` on POSIX and `_wutime` on Windows. Refs #2163, #541. ## Tests - `kernel_file_system_tests` passes on `61db2f88`: export lookup, explicit times, current-time mode, invalid microseconds and the path errors. Files: `src/kernel/fileSystem.cpp`, `src/kernel/fileSystem.h`, `src/libs/libKernel.cpp`, `tests/KernelFileSystemTests.cpp`. ## AI assistance Drafted with AI assistance; I reviewed the change and ran the tests above.
Abiotic Factor (PPSA26012, #2163) and WUCHANG: Fallen Feathers
(PPSA09518, #541) import sceKernelUtimes from libkernel_v1 as NID
0Cq8ipKr9n0. The export was not registered, so the games logged an
unresolved import stub.

Implement the call with the FreeBSD/PS5 contract: the microseconds are
validated before the path, a null path reports EFAULT, an empty or
unmapped path reports ENOENT, and a read-only mount reports EROFS. The
two time values are access then modification; a null times pointer sets
both to the current time. Use utimes on POSIX and _wutime on Windows.

Cover the export lookup, explicit times, current-time mode, invalid
microseconds and the path errors in kernel_file_system_tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:12:27 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-27 02:04 UTC · original

Explain Change →

Walkthrough

The change adds and registers KernelUtimes. The function validates paths and timestamp values, checks mount writability, and updates timestamps through the platform API. Tests cover timestamp updates, null timestamps, invalid microseconds, path errors, and fixture cleanup.

Suggested reviewers: nmzik, senaxx, neveshenry

Change: Feature

Merge Risk: Low · up to da36d

This adds the missing sceKernelUtimes export so affected titles can resolve the import. On Windows, sub-second precision is lost and directory timestamp updates may fail. Guest-visible directory times from stat remain current-time by existing design. These are narrow gaps and the change is mergeable with owner awareness.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "kernel: implement sceKernelUtimes" matches the main change: the PR adds the sceKernelUtimes export (KernelUtimes in fileSystem.cpp/.h, registered in libKernel.cpp) with its tests. It is sho…
Description check Passed The description states which games import the NID, the FreeBSD/PS5 error contract (EFAULT, ENOENT, EROFS, EINVAL ordering), the times[0]/times[1] semantics, the POSIX and Windows calls, and the test r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "kernel: implement sceKernelUtimes" matches the main change: the PR adds the sceKernelUtimes export (KernelUtimes in fileSystem.cpp/.h, registered in libKernel.cpp) with its tests. It is short and specific, and it names the API.

Full details: Description check

Explanation

The description states which games import the NID, the FreeBSD/PS5 error contract (EFAULT, ENOENT, EROFS, EINVAL ordering), the times[0]/times[1] semantics, the POSIX and Windows calls, and the test run. These match the raw summary's changes to fileSystem.cpp, fileSystem.h, libKernel.cpp, and the new TestUtimes test.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-27 02:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2579#issuecomment-7207812348) <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/2579?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The change adds and registers `KernelUtimes`. The function validates paths and timestamp values, checks mount writability, and updates timestamps through the platform API. Tests cover timestamp updates, null timestamps, invalid microseconds, path errors, and fixture cleanup. **Suggested reviewers:** `nmzik`, `senaxx`, `neveshenry` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"da36d053cc5c0d706bc671c8067c0070603f89ba" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Feature <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · up to <code>da36d</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `da36d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"da36d053cc5c0d706bc671c8067c0070603f89ba","coveredCommitId":"da36d053cc5c0d706bc671c8067c0070603f89ba","kind":"reviewed"} --> This adds the missing sceKernelUtimes export so affected titles can resolve the import. On Windows, sub-second precision is lost and directory timestamp updates may fail. Guest-visible directory times from stat remain current-time by existing design. These are narrow gaps and the change is mergeable with owner awareness. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title "kernel: implement sceKernelUtimes" matches the main change: the PR adds the sceKernelUtimes export (KernelUtimes in fileSystem.cpp/.h, registered in libKernel.cpp) with its tests. It is sho… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states which games import the NID, the FreeBSD/PS5 error contract (EFAULT, ENOENT, EROFS, EINVAL ordering), the times[0]/times[1] semantics, the POSIX and Windows calls, and the test r… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title "kernel: implement sceKernelUtimes" matches the main change: the PR adds the sceKernelUtimes export (KernelUtimes in fileSystem.cpp/.h, registered in libKernel.cpp) with its tests. It is short and specific, and it names the API. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states which games import the NID, the FreeBSD/PS5 error contract (EFAULT, ENOENT, EROFS, EINVAL ordering), the times[0]/times[1] semantics, the POSIX and Windows calls, and the test run. These match the raw summary's changes to fileSystem.cpp, fileSystem.h, libKernel.cpp, and the new TestUtimes test. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2579)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end -->
@ -1454,0 +1490,4 @@
values.modtime = static_cast<time_t>(times[1].tv_sec);
native_times = &values;
}
result = ::_wutime(real_name.wstring().c_str(), native_times);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-27 02:04 UTC · original

Minor · Functional Correctness · Quick win

Support writable directories on Windows.

For an existing writable directory such as /savedata0/dir, this call returns EACCES because _wutime rejects directories. The function then returns KERNEL_ERROR_EACCES for an otherwise valid timestamp update. This also affects null-times calls. (learn.microsoft.com)

Use a directory-capable backend, such as SetFileTime with a directory handle. Preserve regular-file updates and test explicit-time and current-time directory updates. (learn.microsoft.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-27 02:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2579#discussion_r4714963081) <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** **Support writable directories on Windows.** For an existing writable directory such as `/savedata0/dir`, this call returns `EACCES` because `_wutime` rejects directories. The function then returns `KERNEL_ERROR_EACCES` for an otherwise valid timestamp update. This also affects null-times calls. ([learn.microsoft.com](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/utime-utime32-utime64-wutime-wutime32-wutime64?view=msvc-170)) Use a directory-capable backend, such as `SetFileTime` with a directory handle. Preserve regular-file updates and test explicit-time and current-time directory updates. ([learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:b5cfde4e36341dd4f57e7012 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-27 02:04 UTC · original · reviewed

Actionable comments posted: 1

Minor comments: 1

src/kernel/fileSystem.cpp: 1

1489-1490: Minor · Data Integrity & Integration · Poor tradeoff

Preserve microseconds in the Windows time update.

On Windows, KernelUtimes validates tv_usec and then passes only tv_sec to _wutime through _utimbuf. That structure has only time_t seconds fields, so both fractions are dropped. The call still returns OK. For example, {{1600000000,123456},{1700000000,654321}} sets both times to whole seconds.

Replace the Windows branch with a backend that accepts fractional times, such as SetFileTime. Open the target with FILE_WRITE_ATTRIBUTES. Use FILE_FLAG_BACKUP_SEMANTICS so directories can be opened. Convert each tv_sec/tv_usec pair to FILETIME units of 100 ns, using the 1601 epoch. Map GetLastError to the existing errno values, and close the handle on every path. Keep the null-times and zero-fraction behavior unchanged.

Add a Windows test that reads back the file time and checks the microseconds.

Additional comments: 1

src/kernel/fileSystem.cpp: 1

1197-1197: Minor · Data Integrity & Integration · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Return directory timestamps set by the new export.

After a successful POSIX KernelUtimes call sets historical directory timestamps, KernelStat still reports current time. Line 1197 passes std::nullopt for every directory, and SetStatTimes replaces it with the current time. KernelFstat has the same problem because its directory branch never populates times.

Read actual directory timestamps in both stat paths. Keep directory size and dirent calculations unchanged. Add a directory update followed by both stat calls.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 61db2f8874 and da36d053cc.

Files selected for processing: 4

  • src/kernel/fileSystem.cpp
  • src/kernel/fileSystem.h
  • src/libs/libKernel.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-27 02:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2579#pullrequestreview-6082555222) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>src/kernel/fileSystem.cpp: 1</summary><blockquote> <dl> <dd> <br> `1489-1490`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Data Integrity & Integration** · **Poor tradeoff** **Preserve microseconds in the Windows time update.** On Windows, `KernelUtimes` validates `tv_usec` and then passes only `tv_sec` to `_wutime` through `_utimbuf`. That structure has only `time_t` seconds fields, so both fractions are dropped. The call still returns `OK`. For example, `{{1600000000,123456},{1700000000,654321}}` sets both times to whole seconds. Replace the Windows branch with a backend that accepts fractional times, such as `SetFileTime`. Open the target with `FILE_WRITE_ATTRIBUTES`. Use `FILE_FLAG_BACKUP_SEMANTICS` so directories can be opened. Convert each `tv_sec`/`tv_usec` pair to `FILETIME` units of 100 ns, using the 1601 epoch. Map `GetLastError` to the existing errno values, and close the handle on every path. Keep the null-`times` and zero-fraction behavior unchanged. Add a Windows test that reads back the file time and checks the microseconds. <!-- cr-comment:v1:67324a98af8cbcede6ace7e2 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/message-square-off-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/message-square-off.svg" width="16" height="16" align="absmiddle" alt=""></picture> Additional comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>src/kernel/fileSystem.cpp: 1</summary><blockquote> <dl> <dd> <br> `1197-1197`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Data Integrity & Integration** · **Quick win** <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg" width="20" height="20" align="absmiddle" alt=""></picture> **Unverified finding** Verification ran but could not confirm this finding. It is shown for review, not as a verified issue. **Return directory timestamps set by the new export.** After a successful POSIX `KernelUtimes` call sets historical directory timestamps, `KernelStat` still reports current time. Line 1197 passes `std::nullopt` for every directory, and `SetStatTimes` replaces it with the current time. `KernelFstat` has the same problem because its directory branch never populates `times`. Read actual directory timestamps in both stat paths. Keep directory size and dirent calculations unchanged. Add a directory update followed by both stat calls. <!-- cr-comment:v1:d14f04924407b8a95cc4cee7 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/61db2f8874d4a94fd2908a87cefa973ddc48ef6e/.coderabbit.yaml>) - **Commit**: [61db2f8](<https://github.com/KytyPS5/KytyPS5/commit/61db2f8874d4a94fd2908a87cefa973ddc48ef6e>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `1569f2c8-973b-4618-af59-322612115f98` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 61db2f8874d4a94fd2908a87cefa973ddc48ef6e and da36d053cc5c0d706bc671c8067c0070603f89ba. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 4</summary> <dl> <dd> <br> * `src/kernel/fileSystem.cpp` * `src/kernel/fileSystem.h` * `src/libs/libKernel.cpp` * `tests/KernelFileSystemTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=b47c112a-4cef-4e18-859f-207d06d7557c attempt=b9f0ac95-e58e-4e6f-a53a-ed115935c21e batch=1/1 -->
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2579/head:github-bot/gh-2579'
git switch 'github-bot/gh-2579'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2579'
git switch 'github-bot/gh-2579'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2579'
git switch 'github-bot/gh-2579'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2579'
git switch 'main'
git merge --squash 'github-bot/gh-2579'
git switch 'main'
git merge --ff-only 'github-bot/gh-2579'
git switch 'main'
git merge 'github-bot/gh-2579'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.