Registry Mirror
Skip to content

Conversation

@adamsitnik

@adamsitnik adamsitnik commented Jun 21, 2021 •

Copy link
Copy Markdown
Member

Fixes #54474
Fixes #54475
Fixes #54337

@ghost

ghost commented Jun 21, 2021

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #54474

Author: adamsitnik
Assignees: -
Labels:

area-System.IO

Milestone: 6.0.0


// 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)

ghost Jun 22, 2021

Copy link
Copy Markdown
Member

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.

ghost Jun 22, 2021

Copy link
Copy Markdown
Member Author

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

ghost Jun 22, 2021

Copy link
Copy Markdown

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.

ghost Jun 23, 2021

Copy link
Copy Markdown
Contributor

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?

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

ghost left a comment

Copy link
Copy Markdown
Contributor

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;

ghost Jun 23, 2021

Copy link
Copy Markdown
Contributor

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))

ghost Jun 23, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))

@adamsitnik
adamsitnik merged commit 0aafceb into dotnet:main Jun 23, 2021
@adamsitnik

ghost commented Jun 23, 2021

Copy link
Copy Markdown
Member Author

/backport to release/6.0-preview6

@github-actions

ghost commented Jun 23, 2021

Copy link
Copy Markdown
Contributor

Started backporting to release/6.0-preview6: https://github.com/dotnet/runtime/actions/runs/963422709

@ghost ghost locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

5 participants