Merge pull request dotnet/corert#3654 from dotnet/nmirror
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Fri, 19 May 2017 04:47:46 +0000 (21:47 -0700)
committerJan Kotas <jkotas@microsoft.com>
Fri, 19 May 2017 22:53:20 +0000 (15:53 -0700)
Merge nmirror to master

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs [new file with mode: 0644]
src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs [new file with mode: 0644]
src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs [new file with mode: 0644]
src/mscorlib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs [new file with mode: 0644]
src/mscorlib/shared/System.Private.CoreLib.Shared.projitems

diff --git a/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs b/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs
new file mode 100644 (file)
index 0000000..725a25a
--- /dev/null
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal partial class Interop
+{
+    internal partial class Kernel32
+    {
+        internal partial class FileAttributes
+        {
+            internal const int FILE_ATTRIBUTE_NORMAL = 0x00000080;
+            internal const int FILE_ATTRIBUTE_READONLY = 0x00000001;
+            internal const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
+            internal const int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
+        }
+    }
+}
diff --git a/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs b/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs
new file mode 100644 (file)
index 0000000..03d8c8b
--- /dev/null
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Kernel32
+    {
+        [DllImport(Libraries.Kernel32, SetLastError = true)]
+        internal extern static bool FindClose(IntPtr hFindFile);
+    }
+}
diff --git a/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs b/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs
new file mode 100644 (file)
index 0000000..80b1ddd
--- /dev/null
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Kernel32
+    {
+        /// <summary>
+        /// WARNING: This method does not implicitly handle long paths. Use FindFirstFile.
+        /// </summary>
+        [DllImport(Libraries.Kernel32, EntryPoint = "FindFirstFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
+
+        internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
+        {
+            fileName = PathInternal.EnsureExtendedPrefixOverMaxPath(fileName);
+
+            // use FindExInfoBasic since we don't care about short name and it has better perf
+            return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
+        }
+
+        internal enum FINDEX_INFO_LEVELS : uint
+        {
+            FindExInfoStandard = 0x0u,
+            FindExInfoBasic = 0x1u,
+            FindExInfoMaxInfoLevel = 0x2u,
+        }
+
+        internal enum FINDEX_SEARCH_OPS : uint
+        {
+            FindExSearchNameMatch = 0x0u,
+            FindExSearchLimitToDirectories = 0x1u,
+            FindExSearchLimitToDevices = 0x2u,
+            FindExSearchMaxSearchOp = 0x3u,
+        }
+    }
+}
diff --git a/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs b/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs
new file mode 100644 (file)
index 0000000..4cce56b
--- /dev/null
@@ -0,0 +1,94 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Kernel32
+    {
+        /// <summary>
+        /// WARNING: This method does not implicitly handle long paths. Use GetFileAttributesEx.
+        /// </summary>
+        [DllImport(Libraries.Kernel32, EntryPoint = "GetFileAttributesExW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
+
+        internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
+        {
+            name = PathInternal.EnsureExtendedPrefixOverMaxPath(name);
+            return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
+        }
+
+        internal enum GET_FILEEX_INFO_LEVELS : uint
+        {
+            GetFileExInfoStandard = 0x0u,
+            GetFileExMaxInfoLevel = 0x1u,
+        }
+
+        internal struct WIN32_FILE_ATTRIBUTE_DATA
+        {
+            internal int fileAttributes;
+            internal uint ftCreationTimeLow;
+            internal uint ftCreationTimeHigh;
+            internal uint ftLastAccessTimeLow;
+            internal uint ftLastAccessTimeHigh;
+            internal uint ftLastWriteTimeLow;
+            internal uint ftLastWriteTimeHigh;
+            internal uint fileSizeHigh;
+            internal uint fileSizeLow;
+
+            internal void PopulateFrom(ref WIN32_FIND_DATA findData)
+            {
+                // Copy the information to data
+                fileAttributes = (int)findData.dwFileAttributes;
+                ftCreationTimeLow = findData.ftCreationTime.dwLowDateTime;
+                ftCreationTimeHigh = findData.ftCreationTime.dwHighDateTime;
+                ftLastAccessTimeLow = findData.ftLastAccessTime.dwLowDateTime;
+                ftLastAccessTimeHigh = findData.ftLastAccessTime.dwHighDateTime;
+                ftLastWriteTimeLow = findData.ftLastWriteTime.dwLowDateTime;
+                ftLastWriteTimeHigh = findData.ftLastWriteTime.dwHighDateTime;
+                fileSizeHigh = findData.nFileSizeHigh;
+                fileSizeLow = findData.nFileSizeLow;
+            }
+        }
+
+        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+        [BestFitMapping(false)]
+        internal unsafe struct WIN32_FIND_DATA
+        {
+            internal uint dwFileAttributes;
+            internal FILE_TIME ftCreationTime;
+            internal FILE_TIME ftLastAccessTime;
+            internal FILE_TIME ftLastWriteTime;
+            internal uint nFileSizeHigh;
+            internal uint nFileSizeLow;
+            internal uint dwReserved0;
+            internal uint dwReserved1;
+            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
+            internal string cFileName;
+            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
+            internal string cAlternateFileName;
+        }
+
+        internal struct FILE_TIME
+        {
+            internal uint dwLowDateTime;
+            internal uint dwHighDateTime;
+
+            internal FILE_TIME(long fileTime)
+            {
+                dwLowDateTime = (uint)fileTime;
+                dwHighDateTime = (uint)(fileTime >> 32);
+            }
+
+            internal long ToTicks()
+            {
+                return ((long)dwHighDateTime << 32) + dwLowDateTime;
+            }
+        }
+    }
+}
index 981d35811e91b5c0b84c784091843590856056f9..ae98a97c7a37c8b1259826fcd72ce34da08fc57f 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CloseHandle.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile.cs" Condition="'$(IsProjectNLibrary)' != 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile2.cs" Condition="'$(IsProjectNLibrary)' == 'true'" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FileAttributes.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FILE_INFO_BY_HANDLE_CLASS.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FileTypes.cs"/>
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FindClose.cs"/>
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FindFirstFileEx.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FlushFileBuffers.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FormatMessage.cs"/>
-    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetCPInfo.cs" />    
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetCPInfo.cs" /> 
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFileAttributesEx.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFileInformationByHandleEx.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFileType_SafeHandle.cs"/>
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFullPathNameW.cs"/>