Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7840,8 +7840,6 @@ public static class InternalSymbolicLinkLinkCodeMethods
// data is 16KB, plus there's a header.
private const int MAX_REPARSE_SIZE = (16 * 1024) + REPARSE_GUID_DATA_BUFFER_HEADER_SIZE;

private const int ERROR_NOT_A_REPARSE_POINT = 4390;

private const int FSCTL_GET_REPARSE_POINT = 0x000900A8;

private const int FSCTL_SET_REPARSE_POINT = 0x000900A4;
Expand Down Expand Up @@ -8156,16 +8154,20 @@ private static string WinInternalGetLinkType(string filePath)
// Get Buffer size
IntPtr dangerousHandle = handle.DangerousGetHandle();

bool result = DeviceIoControl(dangerousHandle, FSCTL_GET_REPARSE_POINT,
IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned, IntPtr.Zero);
bool result = DeviceIoControl(
dangerousHandle,
FSCTL_GET_REPARSE_POINT,
InBuffer: IntPtr.Zero,
nInBufferSize: 0,
outBuffer,
outBufferSize,
out bytesReturned,
lpOverlapped: IntPtr.Zero);

if (!result)
{
int lastError = Marshal.GetLastWin32Error();
if (lastError == ERROR_NOT_A_REPARSE_POINT)
linkType = null;
else
throw new Win32Exception(lastError);
// It's not a reparse point or the file system doesn't support reparse points.
return IsHardLink(ref dangerousHandle) ? "HardLink" : null;
}

REPARSE_DATA_BUFFER_SYMBOLICLINK reparseDataBuffer = Marshal.PtrToStructure<REPARSE_DATA_BUFFER_SYMBOLICLINK>(outBuffer);
Expand All @@ -8185,7 +8187,7 @@ private static string WinInternalGetLinkType(string filePath)
break;

default:
linkType = IsHardLink(ref dangerousHandle) ? "HardLink" : null;
linkType = null;
break;
}

Expand Down Expand Up @@ -8402,16 +8404,20 @@ private static string WinInternalGetTarget(SafeFileHandle handle)
// According to MSDN guidance DangerousAddRef() and DangerousRelease() have been used.
handle.DangerousAddRef(ref success);

bool result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_GET_REPARSE_POINT,
IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned, IntPtr.Zero);
bool result = DeviceIoControl(
handle.DangerousGetHandle(),
FSCTL_GET_REPARSE_POINT,
InBuffer: IntPtr.Zero,
nInBufferSize: 0,
outBuffer,
outBufferSize,
out bytesReturned,
lpOverlapped: IntPtr.Zero);

if (!result)
{
int lastError = Marshal.GetLastWin32Error();
if (lastError == ERROR_NOT_A_REPARSE_POINT)
return null;

throw new Win32Exception(lastError);
// It's not a reparse point or the file system doesn't support reparse points.
return null;
}

string targetDir = null;
Expand Down