Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release these reserved names: COM1-COM9, LPT1-LPT9, CON, AUX, PRN, and NUL #18245

Closed
be5invis opened this issue Aug 21, 2016 · 6 comments
Closed
Assignees
Milestone

Comments

@be5invis
Copy link

Use the \\?\ prefix to access them internally.

@JeremyKuhne
Copy link
Member

@be5invis Can you clarify what you're asking for? Reserved where? Thanks!

@be5invis
Copy link
Author

be5invis commented Sep 6, 2016

@JeremyKuhne You cannot create ANY file named them, in ANY directory, with ANY extension, on Windows. This is a limitation of the “default” win32 API, because they are mapped to device names (like, NUL means “Null Device”), early in 1970s. Prefixing these paths with \\?\ will can this problem.

@JeremyKuhne
Copy link
Member

Thanks for the details!

.NET allows you to create them yourself now if you really want to as we allow you to use \\?\ and we don't mess with the path if you do (\\?\C:\Test\LPT1).

I don't, however, recommend doing so. As you point out, the Win32 API will treat these differently. Most applications aren't going to have logic to allow for legacy device names used as file names. I would also be shocked if .NET was bug free with these- too many places where filenames are recombined with base paths.

Windows is unlikely to ever remove the mapping as the command shell and batch files depend on the current behavior (copy con foo, copy foo bar > nul). That said, if Windows ever does remove it everything should work fine for .NET apps.

@be5invis
Copy link
Author

be5invis commented Sep 7, 2016

@JeremyKuhne Maybe at least .NET can limit these names in "direct occur" manner. That is, ./LPT1 -> file, LPT -> device.

@JeremyKuhne
Copy link
Member

JeremyKuhne commented Sep 7, 2016

Generally speaking we're trying very hard to not code specifically to internal details of Windows APIs. Even if we do get things right, doing so risks breaking on future versions of Windows. Trying to be helpful here is risky and could either break with a future Windows change or inhibit them from making a change (say, if they decided to remove or alter the way they handle legacy device names).

As a concrete example: The well-meaning code we had in Path.GetFullPath() was full of issues because we didn't mimic GetFullPathName correctly. Paths that you could create from the command prompt without \\?\ .NET couldn't handle.

What I have been doing that impacts this is using \\?\ internally in some cases where we're iterating a fully normalized path (recursive directory deletion for example). I can't do it everywhere, however- allocating extra strings can really impact perf, as paths can be up to 64K in size.

@JeremyKuhne
Copy link
Member

@be5invis I'm going to close this for now. If you still want to discuss the issue feel free to reopen. If you find any places where we fall over on legacy device filenames please open issues so we can investigate the plausibility of handling them.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants