-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[FileStream] handle UNC and device paths #54483
Conversation
Tagging subscribers to this area: @dotnet/area-system-io |
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Windows.cs
Outdated
Show resolved
Hide resolved
|
||
// this method works only for `fullPath` returned by Path.GetFullPath | ||
// currently we don't have interest in supporting relative paths | ||
internal static void DosToNtPath(ReadOnlySpan<char> fullPath, ref ValueStringBuilder vsb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume for the opposite, translate NT to DOS, a helper like this should be needed, right?
For context #54253 (comment) , a Symlinks API uses DeviceIoControl
which returns an NT path that I need to translate to DOS.
This is my silly attempt on doing it:
https://github.com/dotnet/runtime/blob/908530a70613af1172138e48d041d6c5d710d866/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs#L513-L518
Also, I think I mixed the names (DOS and NT) in the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jozkee You could use RtlNtPathNameToDosPathName
, but the problem is that it's internal and not documented, so we should not be using that.
The mapping that you have pointed to seems to be missing a few translations:
\??\UNC\
to\\
(files located on a remote machine)\??\
to\\.\
for devices like names pipes:\\.\pipe\$pipeName
But the question is: are they valid in this context? Can someone create a link to a named pipe or a file located on a network share?
FWIW the best doc about the paths I've found so far: https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbolic links to files on network shares are possible; fsutil behavior set symlinkevaluation can enable or disable them. I don't know about symbolic links to named pipes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mapping that you have pointed to seems to be missing a few translations:
The first example you pointed should still work, as far as I know: Converting \??\UNC\
to \\?\UNC
, should be equivalent. The difference is that you do not want to pass a path prefixed with \??\
to the user, and should always translate it to \\?\
.
Regarding the second example: Have you seen cases where Windows gives you a path prefixed with \??\
but you were expecting it to start with \\.\
? And how would you know this?
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/tests/Tests/System/IO/PathInternal.Windows.Tests.cs
Outdated
Show resolved
Hide resolved
…ping DOS to NT paths
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
{ | ||
uint ntStatus; | ||
IntPtr fileHandle; | ||
Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default
isn't really needed, right?
// probably be consistent w/ every other directory. | ||
int errorCode = Marshal.GetLastPInvokeError(); | ||
|
||
if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND && fullPath!.Length == PathInternal.GetRootLength(fullPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND && fullPath!.Length == PathInternal.GetRootLength(fullPath)) | |
if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND && fullPath.Length == PathInternal.GetRootLength(fullPath)) |
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
Show resolved
Hide resolved
/backport to release/6.0-preview6 |
Started backporting to release/6.0-preview6: https://github.com/dotnet/runtime/actions/runs/963422709 |
…nitial_config * origin/main: (362 commits) [wasm][debugger] Reuse debugger-agent on wasm debugger (dotnet#52300) Put Crossgen2 in sync with dotnet#54235 (dotnet#54438) Move System.Object serialization to ObjectConverter (dotnet#54436) Move setting fHasVirtualStaticMethods out of sanity check section (dotnet#54574) [wasm] Compile .bc->.o in parallel, before passing to the linker (dotnet#54053) Change PathInternal.IsCaseSensitive to a constant (dotnet#54340) Make mono_polling_required a public symbol (dotnet#54592) Respect EventSource::IsSupported setting in more codepaths (dotnet#51977) Root ComActivator for hosting (dotnet#54524) Add ILLink annotations to S.D.Common related to DbConnectionStringBuilder (dotnet#54280) Fix finalizer issue with regions (dotnet#54550) Add support for multi-arch install locations (dotnet#53763) Update library testing docs page to reduce confusion (dotnet#54324) [FileStream] handle UNC and device paths (dotnet#54483) Update NetAnalyzers version (dotnet#54511) Added runtime dependency to fix the intermittent test failures (dotnet#54587) Disable failing System.Reflection.Tests.ModuleTests.GetMethods (dotnet#54564) [wasm] Move AOT builds from `runtime-staging` to `runtime` (dotnet#54577) Keep obj node for ArrayIndex. (dotnet#54584) Disable another failing MemoryCache test (dotnet#54578) ...
Fixes #54474
Fixes #54475
Fixes #54337