hle(host_posix): the file calls a title manages its saves with (MoveFileW, CopyFileW, ReplaceFileW, GetFileType, CreateFileMappingA) are stubs #623

Closed
opened 2026-11-28 15:54:09 +00:00 by AnastasisKon · 3 comments
AnastasisKon commented 2026-11-28 15:54:09 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T15:54:09Z.


Summary

Five file calls a title makes when it manages its own files were unimplemented and answered through the loader's import stub: MoveFileW, CopyFileW, ReplaceFileW, GetFileType and CreateFileMappingA.

The first three are how a title writes a save file without leaving a half-written one: write a new file, copy the old one to a backup, then replace. With stubs, every one of those steps silently failed, and a title that checks the return value gives up on saving (or worse, saves nothing and reports success to the wrong layer). GetFileType is what a title asks before reading or seeking a handle, and CreateFileMappingA is the ANSI form of the mapping added in #619.

What the change does

  • MoveFileW: the plain form of MoveFileExW.
  • CopyFileW: copies the bytes; FAIL_IF_EXISTS on an existing target is ERROR_FILE_EXISTS, otherwise the copy replaces what was there. A missing source is ERROR_FILE_NOT_FOUND.
  • ReplaceFileW: gives the backup the file being replaced, then the replacement takes its name, which is the order Windows uses.
  • GetFileType: reads the handle's own node — a disk, a character device (a console, /dev/null), or a pipe (a fifo or a socket) — and ERROR_INVALID_HANDLE with FILE_TYPE_UNKNOWN for a handle that is no handle.
  • CreateFileMappingA: the ANSI form of CreateFileMappingW; a section name is not a path, so it is widened byte by byte rather than through the drive table.

Tests

Three new ones in files.rs: a file is copied (including the FAIL_IF_EXISTS refusal and the replace-with-backup order) and moved; a file handle is a disk, /dev/null is a character device and a garbage handle is unknown with its error; and the ANSI mapping form makes a section that maps and unmaps like the wide one.

One thing the tests taught me and the code now says: the standard handles are not asserted on. This suite's stdout is a pipe when cargo pipes it and a file when it is redirected, and FILE_TYPE_PIPE and FILE_TYPE_DISK are both right for the handle in those cases — a test that insisted on one of them failed the gate while passing when run by hand.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6667738746 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/623). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T15:54:09Z. --- ## Summary Five file calls a title makes when it manages its own files were unimplemented and answered through the loader's import stub: `MoveFileW`, `CopyFileW`, `ReplaceFileW`, `GetFileType` and `CreateFileMappingA`. The first three are how a title writes a save file without leaving a half-written one: write a new file, copy the old one to a backup, then replace. With stubs, every one of those steps silently failed, and a title that checks the return value gives up on saving (or worse, saves nothing and reports success to the wrong layer). `GetFileType` is what a title asks before reading or seeking a handle, and `CreateFileMappingA` is the ANSI form of the mapping added in #619. ## What the change does - `MoveFileW`: the plain form of `MoveFileExW`. - `CopyFileW`: copies the bytes; `FAIL_IF_EXISTS` on an existing target is `ERROR_FILE_EXISTS`, otherwise the copy replaces what was there. A missing source is `ERROR_FILE_NOT_FOUND`. - `ReplaceFileW`: gives the backup the file being replaced, then the replacement takes its name, which is the order Windows uses. - `GetFileType`: reads the handle's own node — a disk, a character device (a console, `/dev/null`), or a pipe (a fifo or a socket) — and `ERROR_INVALID_HANDLE` with `FILE_TYPE_UNKNOWN` for a handle that is no handle. - `CreateFileMappingA`: the ANSI form of `CreateFileMappingW`; a section name is not a path, so it is widened byte by byte rather than through the drive table. ## Tests Three new ones in `files.rs`: a file is copied (including the `FAIL_IF_EXISTS` refusal and the replace-with-backup order) and moved; a file handle is a disk, `/dev/null` is a character device and a garbage handle is unknown with its error; and the ANSI mapping form makes a section that maps and unmaps like the wide one. One thing the tests taught me and the code now says: the *standard* handles are not asserted on. This suite's stdout is a pipe when cargo pipes it and a file when it is redirected, and `FILE_TYPE_PIPE` and `FILE_TYPE_DISK` are both right for the handle in those cases — a test that insisted on one of them failed the gate while passing when run by hand.
AnastasisKon commented 2026-11-28 15:54:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T15:54:20Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7241826184 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/623#issuecomment-7241826184). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T15:54:20Z. --- /claim
github-actions[bot] commented 2026-11-28 15:54:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T15:54:29Z.


Claimed by @AnastasisKon. Open a draft pull request with Refs #623 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7241828215 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/623#issuecomment-7241828215). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T15:54:29Z. --- Claimed by @AnastasisKon. Open a draft pull request with `Refs #623` in its description within 24 hours, or the claim expires.
AnastasisKon commented 2026-11-28 16:31:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T16:31:49Z.


Merged with the PR that serves these calls; closing.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7242312794 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/623#issuecomment-7242312794). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T16:31:49Z. --- Merged with the PR that serves these calls; closing.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#623
No description provided.