Windows: guest file names that are DOS device names or end in a dot or space are rewritten by Win32 #12550

Closed
opened 2026-10-28 19:15:48 +00:00 by JJenkx · 0 comments
JJenkx commented 2026-10-28 19:15:48 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T19:15:48Z.


What happens

On Windows, a guest file whose name is a DOS device name, or ends in a dot or a space, doesn't map to a file with that name. On the PS5 (FreeBSD), these are ordinary names.

The cause is that host paths shorter than MAX_PATH reach the Win32 API without the \?\ verbatim prefix. Only longer paths get it, in NativeMetadataPath (core/libs/prx/libkernel/File/src/Open.cpp) and HostOpenName (core/libs/prx/libc/src/FileAndHeap.cpp). Win32 path normalization then rewrites the name.

Measured

Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7. A small native program creates each name with _wopen(dir + L"\\" + name, _O_WRONLY | _O_CREAT | _O_TRUNC), writes one byte, reports GetFileType and then lists the directory:

name result
nul opens the character device; the write "succeeds" and the data is discarded, and no file is created
file. and file both create file, so the two names collapse into one file
name. creates name
con, CON, con.txt, aux, aux.json, com1, com1.bin, lpt1.txt, prn, conin$, nul.dat ordinary disk files on this build

The last row is a Windows 11 relaxation. On Windows 10, CON, PRN, AUX, NUL, COM1–COM9 and LPT1–LPT9, with or without an extension, are devices, so the affected set is larger there. I haven't measured it on Windows 10.

Impact

Probably rare: save data and asset names are usually fixed identifiers. A guest name that is exactly nul, or that ends in . or , would silently lose data or alias another file. On Windows 10, so would aux.dat, con.txt and the like.

Possible direction

Use the verbatim \?\ form for any host path with a component that Win32 would rewrite (a trailing . or space, or a reserved device stem), not only for long paths. Since the verbatim form is already used for long paths, the remaining work is making every guest-path entry point go through one such helper. Right now open, mkdir, rename, directory listing and stat build host paths in different places.

AnyPS5 commit

main 319621ba2e.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6085800769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/12550). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T19:15:48Z. --- ### What happens On Windows, a guest file whose name is a DOS device name, or ends in a dot or a space, doesn't map to a file with that name. On the PS5 (FreeBSD), these are ordinary names. The cause is that host paths shorter than `MAX_PATH` reach the Win32 API without the `\?\` verbatim prefix. Only longer paths get it, in `NativeMetadataPath` (`core/libs/prx/libkernel/File/src/Open.cpp`) and `HostOpenName` (`core/libs/prx/libc/src/FileAndHeap.cpp`). Win32 path normalization then rewrites the name. ### Measured Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7. A small native program creates each name with `_wopen(dir + L"\\" + name, _O_WRONLY | _O_CREAT | _O_TRUNC)`, writes one byte, reports `GetFileType` and then lists the directory: | name | result | |---|---| | `nul` | opens the **character device**; the write "succeeds" and the data is discarded, and no file is created | | `file.` and `file ` | both create **`file`**, so the two names collapse into one file | | `name. ` | creates `name` | | `con`, `CON`, `con.txt`, `aux`, `aux.json`, `com1`, `com1.bin`, `lpt1.txt`, `prn`, `conin$`, `nul.dat` | ordinary disk files on this build | The last row is a Windows 11 relaxation. On Windows 10, `CON`, `PRN`, `AUX`, `NUL`, `COM1`–`COM9` and `LPT1`–`LPT9`, **with or without an extension**, are devices, so the affected set is larger there. I haven't measured it on Windows 10. ### Impact Probably rare: save data and asset names are usually fixed identifiers. A guest name that is exactly `nul`, or that ends in `.` or ` `, would silently lose data or alias another file. On Windows 10, so would `aux.dat`, `con.txt` and the like. ### Possible direction Use the verbatim `\?\` form for any host path with a component that Win32 would rewrite (a trailing `.` or space, or a reserved device stem), not only for long paths. Since the verbatim form is already used for long paths, the remaining work is making every guest-path entry point go through one such helper. Right now `open`, `mkdir`, `rename`, directory listing and `stat` build host paths in different places. ### AnyPS5 commit `main` `319621ba2e`. AI-assisted: yes (Claude Code).
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
boykopovar/AnyPS5#12550
No description provided.