host_posix: file calls report host errors as Windows does #132

Manually merged
github merged 1 commit from github-bot/gh-132 into main 2026-11-26 19:08:27 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 18:21 UTC · original
Olima34:fix/files-too-many-open-files → main · +80 −17 · 4 files · 1 commits · merged 2026-11-26 19:01 UTC

host_posix::files::win32_error, which backs CreateFileW, the attribute, delete, directory and find calls in files.rs, plus MoveFileExW and CopyFile2 in system.rs, returned ERROR_ACCESS_DENIED for every host error it did not name: running out of file descriptors, a full disk, a cross-device move, and so on.

What.

  • New crate::win32_errors::code(&io::Error) -> Option<u32>: one table, the UCRT's _dosmaperr read backwards.
    • EBADF→6, EMFILE/ENFILE→4, ENOENT→2, EACCES/EPERM→5, ENOMEM→8, EXDEV→17, EEXIST→80, EINVAL→87, ENOSPC→112, ENOTEMPTY→145.
    • errno values that are the same on every Unix (below 35) match by number. The others match by ErrorKind, so macOS's ENOTEMPTY (66) and Linux's (39) both map.
    • It returns None for the rest, so each caller keeps its own fallback.
  • files::win32_error uses it, keeps ERROR_ACCESS_DENIED as the fallback, and keeps ERROR_PATH_NOT_FOUND when the parent folder is missing. CreateDirectoryW still maps AlreadyExists to ERROR_ALREADY_EXISTS itself.
  • The module is gated to macOS x86_64 for now, its only user, with a shortcut: note. Once this and #130 have both landed, dstorage::from_win32 can share the table too. I kept them separate so the two PRs don't conflict.

Tests.

  • win32_errors::host_errors_have_their_win32_codes checks every row; EIO gives None.
  • files::host_errors_reach_file_calls_as_windows_reports_them checks FILE vs PATH not found, EMFILE→4, ENOTEMPTY→145, EEXIST→80, and EIO→5. On main it fails with "EMFILE: left 5 right 4".

cargo test -p victory-hle --target x86_64-apple-darwin --lib (250), Windows clippy and cargo xtask policy pass. No test or probe asserted the old codes.

(This PR first carried only the EMFILE/ENFILE arm; it now carries the whole table.)

**@⁠Olima34** on GitHub · 2026-11-26 18:21 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/132) `Olima34:fix/files-too-many-open-files` → `main` · +80 −17 · 4 files · 1 commits · merged 2026-11-26 19:01 UTC `host_posix::files::win32_error`, which backs `CreateFileW`, the attribute, delete, directory and find calls in `files.rs`, plus `MoveFileExW` and `CopyFile2` in `system.rs`, returned `ERROR_ACCESS_DENIED` for every host error it did not name: running out of file descriptors, a full disk, a cross-device move, and so on. **What.** - New `crate::win32_errors::code(&io::Error) -> Option<u32>`: one table, the UCRT's `_dosmaperr` read backwards. - EBADF→6, EMFILE/ENFILE→4, ENOENT→2, EACCES/EPERM→5, ENOMEM→8, EXDEV→17, EEXIST→80, EINVAL→87, ENOSPC→112, ENOTEMPTY→145. - errno values that are the same on every Unix (below 35) match by number. The others match by `ErrorKind`, so macOS's ENOTEMPTY (66) and Linux's (39) both map. - It returns `None` for the rest, so each caller keeps its own fallback. - `files::win32_error` uses it, keeps `ERROR_ACCESS_DENIED` as the fallback, and keeps `ERROR_PATH_NOT_FOUND` when the parent folder is missing. `CreateDirectoryW` still maps AlreadyExists to `ERROR_ALREADY_EXISTS` itself. - The module is gated to macOS x86_64 for now, its only user, with a `shortcut:` note. Once this and #130 have both landed, `dstorage::from_win32` can share the table too. I kept them separate so the two PRs don't conflict. **Tests.** - `win32_errors::host_errors_have_their_win32_codes` checks every row; EIO gives `None`. - `files::host_errors_reach_file_calls_as_windows_reports_them` checks FILE vs PATH not found, EMFILE→4, ENOTEMPTY→145, EEXIST→80, and EIO→5. On main it fails with "EMFILE: left 5 right 4". `cargo test -p victory-hle --target x86_64-apple-darwin --lib` (250), Windows clippy and `cargo xtask policy` pass. No test or probe asserted the old codes. (This PR first carried only the EMFILE/ENFILE arm; it now carries the whole table.)
files::win32_error, behind CreateFileW and the other file calls, gave
ERROR_ACCESS_DENIED for every host error it did not name, EMFILE and
ENFILE included, so a title out of descriptors was told it lacked
permission. They now give ERROR_TOO_MANY_OPEN_FILES, as the UCRT's
_dosmaperr table has it in reverse.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:25:32 +00:00
github-bot changed title from files: running out of file descriptors is ERROR_TOO_MANY_OPEN_FILES to host_posix: file calls report host errors as Windows does 2026-11-26 18:30:54 +00:00
github-bot force-pushed github-bot/gh-132 from 0fb9c44556 to 69baf0ade5 2026-11-26 18:30:55 +00:00 Compare
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 18:56 UTC · original · approved these changes

Reviewed and tested together with the other open PRs on main (macOS x86_64 tests for shader, hle, loader and gpu, the setup shell tests, and Windows clippy). Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 18:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/132#pullrequestreview-6079229671) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 tests for shader, hle, loader and gpu, the setup shell tests, and Windows clippy). Thanks!
github manually merged commit a7af031cc4 into main 2026-11-26 19:08:27 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.