Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace System.Management.Automation
{
/// <summary>
/// </summary>
public static class CompletionCompleters
public static partial class CompletionCompleters
{
static CompletionCompleters()
{
Expand Down Expand Up @@ -4751,8 +4751,8 @@ private struct SHARE_INFO_1
AttributesToSkip = 0 // Default is to skip Hidden and System files, so we clear this to retain existing behavior
};

[DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
private static extern int NetShareEnum(string serverName, int level, out IntPtr bufptr, int prefMaxLen,
[LibraryImport("Netapi32.dll", StringMarshalling = StringMarshalling.Utf16)]
private static partial int NetShareEnum(string serverName, int level, out IntPtr bufptr, int prefMaxLen,
out uint entriesRead, out uint totalEntries, ref uint resumeHandle);

internal static List<string> GetFileShares(string machine, bool ignoreHidden)
Expand Down
87 changes: 47 additions & 40 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7150,7 +7150,7 @@ internal static bool WinPathIsNetworkPath(string path)
return NativeMethods.PathIsNetworkPath(path); // call the native method
}

private static class NativeMethods
private static partial class NativeMethods
{
/// <summary>
/// WNetAddConnection2 API makes a connection to a network resource
Expand Down Expand Up @@ -7196,8 +7196,8 @@ private static class NativeMethods
/// else the error code describing the type of failure that occurred while
/// trying to remove the connection is returned.
/// </returns>
[DllImport("mpr.dll", CharSet = CharSet.Unicode)]
internal static extern int WNetCancelConnection2(string driveName, int flags, bool force);
[LibraryImport("mpr.dll", EntryPoint ="WNetCancelConnection2W", StringMarshalling = StringMarshalling.Utf16)]
internal static partial int WNetCancelConnection2(string driveName, int flags, [MarshalAs(UnmanagedType.Bool)] bool force);

/// <summary>
/// WNetGetConnection function retrieves the name of the network resource associated with a local device.
Expand All @@ -7223,8 +7223,8 @@ private static class NativeMethods
/// Path of the file being executed
/// </param>
/// <returns>Returns 0 through 25 (corresponding to 'A' through 'Z') if the path has a drive letter, or -1 otherwise.</returns>
[DllImport("api-ms-win-core-shlwapi-legacy-l1-1-0.dll", CharSet = CharSet.Unicode)]
internal static extern int PathGetDriveNumber(string path);
[LibraryImport("api-ms-win-core-shlwapi-legacy-l1-1-0.dll", EntryPoint ="PathGetDriveNumberW", StringMarshalling = StringMarshalling.Utf16)]
internal static partial int PathGetDriveNumber(string path);

private static bool _WNetApiAvailable = true;

Expand Down Expand Up @@ -7288,9 +7288,9 @@ internal static bool PathIsNetworkPath(string path)
/// Path of the file being executed.
/// </param>
/// <returns>True if the path is a network path or else returns false.</returns>
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
[LibraryImport("shlwapi.dll", EntryPoint = "PathIsNetworkPathW", StringMarshalling = StringMarshalling.Utf16)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool PathIsNetworkPath(string path);
internal static partial bool PathIsNetworkPath(string path);
#endif

/// <summary>
Expand Down Expand Up @@ -7320,9 +7320,9 @@ internal static bool PathIsNetworkPath(string path)
/// <param name="destination">Path of the target of the symbolic link.</param>
/// <param name="symbolicLinkFlags">Flag values from SymbolicLinkFlags enum.</param>
/// <returns>1 on successful creation.</returns>
[DllImport(PinvokeDllNames.CreateSymbolicLinkDllName, CharSet = CharSet.Unicode, SetLastError = true)]
[LibraryImport(PinvokeDllNames.CreateSymbolicLinkDllName, EntryPoint = "CreateSymbolicLinkW", StringMarshalling = StringMarshalling.Utf16)]
[return: MarshalAs(UnmanagedType.I1)]
internal static extern bool CreateSymbolicLink(string name, string destination, SymbolicLinkFlags symbolicLinkFlags);
internal static partial bool CreateSymbolicLink(string name, string destination, SymbolicLinkFlags symbolicLinkFlags);

/// <summary>
/// Flags used when creating a symbolic link.
Expand Down Expand Up @@ -7353,26 +7353,26 @@ internal enum SymbolicLinkFlags
/// <param name="existingFileName">Path to the target of the hard link.</param>
/// <param name="SecurityAttributes"></param>
/// <returns></returns>
[DllImport(PinvokeDllNames.CreateHardLinkDllName, CharSet = CharSet.Unicode, SetLastError = true)]
[LibraryImport(PinvokeDllNames.CreateHardLinkDllName, EntryPoint = "CreateHardLinkW", StringMarshalling = StringMarshalling.Utf16)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CreateHardLink(string name, string existingFileName, IntPtr SecurityAttributes);
internal static partial bool CreateHardLink(string name, string existingFileName, IntPtr SecurityAttributes);

// OneDrive placeholder support
#if !UNIX
/// <summary>
/// Returns the placeholder compatibility mode for the current process.
/// </summary>
/// <returns>The process's placeholder compatibily mode (PHCM_xxx), or a negative value on error (PCHM_ERROR_xxx).</returns>
[DllImport("ntdll.dll")]
internal static extern sbyte RtlQueryProcessPlaceholderCompatibilityMode();
[LibraryImport("ntdll.dll")]
internal static partial sbyte RtlQueryProcessPlaceholderCompatibilityMode();

/// <summary>
/// Sets the placeholder compatibility mode for the current process.
/// </summary>
/// <param name="pcm">The placeholder compatibility mode to set.</param>
/// <returns>The process's previous placeholder compatibily mode (PHCM_xxx), or a negative value on error (PCHM_ERROR_xxx).</returns>
[DllImport("ntdll.dll")]
internal static extern sbyte RtlSetProcessPlaceholderCompatibilityMode(sbyte pcm);
[LibraryImport("ntdll.dll")]
internal static partial sbyte RtlSetProcessPlaceholderCompatibilityMode(sbyte pcm);

internal const sbyte PHCM_APPLICATION_DEFAULT = 0;
internal const sbyte PHCM_DISGUISE_PLACEHOLDER = 1;
Expand Down Expand Up @@ -7870,7 +7870,7 @@ public class FileSystemProviderRemoveItemDynamicParameters
/// <summary>
/// Class to find the symbolic link target.
/// </summary>
public static class InternalSymbolicLinkLinkCodeMethods
public static partial class InternalSymbolicLinkLinkCodeMethods
{
// This size comes from measuring the size of the header of REPARSE_GUID_DATA_BUFFER
private const int REPARSE_GUID_DATA_BUFFER_HEADER_SIZE = 24;
Expand Down Expand Up @@ -7984,9 +7984,9 @@ private struct REPARSE_DATA_BUFFER_MOUNTPOINT
private struct BY_HANDLE_FILE_INFORMATION
{
public uint FileAttributes;
public System.Runtime.InteropServices.ComTypes.FILETIME CreationTime;
public System.Runtime.InteropServices.ComTypes.FILETIME LastAccessTime;
public System.Runtime.InteropServices.ComTypes.FILETIME LastWriteTime;
public FILE_TIME CreationTime;
public FILE_TIME LastAccessTime;
public FILE_TIME LastWriteTime;
public uint VolumeSerialNumber;
public uint FileSizeHigh;
public uint FileSizeLow;
Expand All @@ -7995,6 +7995,12 @@ private struct BY_HANDLE_FILE_INFORMATION
public uint FileIndexLow;
}

internal struct FILE_TIME
{
public uint dwLowDateTime;
public uint dwHighDateTime;
}

[StructLayout(LayoutKind.Sequential)]
private struct GUID
{
Expand All @@ -8018,20 +8024,21 @@ private struct REPARSE_GUID_DATA_BUFFER
public char[] DataBuffer;
}

[DllImport(PinvokeDllNames.DeviceIoControlDllName, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
private static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,
[LibraryImport(PinvokeDllNames.DeviceIoControlDllName, StringMarshalling = StringMarshalling.Utf16, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,
IntPtr InBuffer, int nInBufferSize,
IntPtr OutBuffer, int nOutBufferSize,
out int pBytesReturned, IntPtr lpOverlapped);

[DllImport(PinvokeDllNames.GetFileInformationByHandleDllName, SetLastError = true, CharSet = CharSet.Unicode)]
[LibraryImport(PinvokeDllNames.GetFileInformationByHandleDllName)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetFileInformationByHandle(
private static partial bool GetFileInformationByHandle(
IntPtr hFile,
out BY_HANDLE_FILE_INFORMATION lpFileInformation);

[DllImport(PinvokeDllNames.CreateFileDllName, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern IntPtr CreateFile(
[LibraryImport(PinvokeDllNames.CreateFileDllName, EntryPoint = "CreateFileW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
internal static partial IntPtr CreateFile(
string lpFileName,
FileDesiredAccess dwDesiredAccess,
FileShareMode dwShareMode,
Expand All @@ -8040,7 +8047,7 @@ internal static extern IntPtr CreateFile(
FileAttributes dwFlagsAndAttributes,
IntPtr hTemplateFile);

internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
internal sealed partial class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private SafeFindHandle() : base(true) { }

Expand All @@ -8049,23 +8056,23 @@ protected override bool ReleaseHandle()
return FindClose(this.handle);
}

[DllImport(PinvokeDllNames.FindCloseDllName)]
[LibraryImport(PinvokeDllNames.FindCloseDllName)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FindClose(IntPtr handle);
private static partial bool FindClose(IntPtr handle);
}

// We use 'FindFirstFileW' instead of 'FindFirstFileExW' because the latter doesn't work correctly with Unicode file names on FAT32.
// See https://github.com/PowerShell/PowerShell/issues/16804
[DllImport(PinvokeDllNames.FindFirstFileDllName, EntryPoint = "FindFirstFileW", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern SafeFindHandle FindFirstFile(string lpFileName, ref WIN32_FIND_DATA lpFindFileData);
[LibraryImport(PinvokeDllNames.FindFirstFileDllName, EntryPoint = "FindFirstFileW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
private static partial SafeFindHandle FindFirstFile(string lpFileName, ref WIN32_FIND_DATA lpFindFileData);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal unsafe struct WIN32_FIND_DATA
{
internal uint dwFileAttributes;
internal System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
internal System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;
internal System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
internal FILE_TIME ftCreationTime;
internal FILE_TIME ftLastAccessTime;
internal FILE_TIME ftLastWriteTime;
internal uint nFileSizeHigh;
internal uint nFileSizeLow;
internal uint dwReserved0;
Expand Down Expand Up @@ -8539,7 +8546,7 @@ public class AlternateStreamData
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes",
Justification = "Needed by both the FileSystem provider and Unblock-File cmdlet.")]
public static class AlternateDataStreamUtilities
public static partial class AlternateDataStreamUtilities
{
/// <summary>
/// List all of the streams on a file.
Expand Down Expand Up @@ -8704,15 +8711,15 @@ internal static void SetZoneOfOrigin(string path, SecurityZone securityZone)
// the code above seems cleaner and more robust than the IAttachmentExecute approach
}

internal static class NativeMethods
internal static partial class NativeMethods
{
internal const int ERROR_HANDLE_EOF = 38;
internal const int ERROR_INVALID_PARAMETER = 87;

internal enum StreamInfoLevels { FindStreamInfoStandard = 0 }

[DllImport(PinvokeDllNames.CreateFileDllName, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern SafeFileHandle CreateFile(string lpFileName,
[LibraryImport(PinvokeDllNames.CreateFileDllName, EntryPoint = "CreateFileW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
internal static partial SafeFileHandle CreateFile(string lpFileName,
FileAccess dwDesiredAccess, FileShare dwShareMode,
IntPtr lpSecurityAttributes, FileMode dwCreationDisposition,
int dwFlagsAndAttributes, IntPtr hTemplateFile);
Expand All @@ -8733,7 +8740,7 @@ internal static extern bool FindNextStreamW(
AlternateStreamNativeData lpFindStreamData);
}

internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
internal sealed partial class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private SafeFindHandle() : base(true) { }

Expand All @@ -8742,9 +8749,9 @@ protected override bool ReleaseHandle()
return FindClose(this.handle);
}

[DllImport(PinvokeDllNames.FindCloseDllName)]
[LibraryImport(PinvokeDllNames.FindCloseDllName)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FindClose(IntPtr handle);
private static partial bool FindClose(IntPtr handle);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/System.Management.Automation/utils/ClrFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace System.Management.Automation
/// ClrFacade contains all diverging code (different implementation for FullCLR and CoreCLR using if/def).
/// It exposes common APIs that can be used by the rest of the code base.
/// </summary>
internal static class ClrFacade
internal static partial class ClrFacade
{
/// <summary>
/// Initialize powershell AssemblyLoadContext and register the 'Resolving' event, if it's not done already.
Expand Down Expand Up @@ -366,13 +366,13 @@ internal static string ToDmtfDateTime(DateTime date)
/// <summary>
/// Native methods that are used by facade methods.
/// </summary>
private static class NativeMethods
private static partial class NativeMethods
{
/// <summary>
/// Pinvoke for GetOEMCP to get the OEM code page.
/// </summary>
[DllImport(PinvokeDllNames.GetOEMCPDllName, SetLastError = false, CharSet = CharSet.Unicode)]
internal static extern uint GetOEMCP();
[LibraryImport(PinvokeDllNames.GetOEMCPDllName)]
internal static partial uint GetOEMCP();
}
}
}