Fix FileStream for ProjectN
authorJan Kotas <jkotas@microsoft.com>
Sun, 19 Mar 2017 02:41:39 +0000 (19:41 -0700)
committerdotnet-bot <dotnet-bot@microsoft.com>
Mon, 20 Mar 2017 19:06:26 +0000 (19:06 +0000)
[tfs-changeset: 1651325]

Commit migrated from https://github.com/dotnet/coreclr/commit/40fee095de80676ffb6e60bd2e9d38d85bfa40b3

src/coreclr/src/mscorlib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs
src/coreclr/src/mscorlib/shared/System/IO/FileStream.WinRT.cs

index d8cfabd..0909d3a 100644 (file)
@@ -11,20 +11,20 @@ internal partial class Interop
     internal partial class Kernel32
     {
         [DllImport(Libraries.Kernel32, EntryPoint = "CreateFile2", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
-        internal static extern SafeFileHandle CreateFile2(
+        internal static extern unsafe SafeFileHandle CreateFile2(
             string lpFileName,
             int dwDesiredAccess,
             System.IO.FileShare dwShareMode,
             System.IO.FileMode dwCreationDisposition,
-            ref CREATEFILE2_EXTENDED_PARAMETERS parameters);
+            CREATEFILE2_EXTENDED_PARAMETERS* pCreateExParams);
 
-        internal struct CREATEFILE2_EXTENDED_PARAMETERS
+        internal unsafe struct CREATEFILE2_EXTENDED_PARAMETERS
         {
             internal uint dwSize;
             internal uint dwFileAttributes;
             internal uint dwFileFlags;
             internal uint dwSecurityQosFlags;
-            internal IntPtr lpSecurityAttributes;
+            internal SECURITY_ATTRIBUTES* lpSecurityAttributes;
             internal IntPtr hTemplateFile;
         }
     }
index df5e996..062b160 100644 (file)
@@ -9,7 +9,7 @@ namespace System.IO
 {
     public partial class FileStream : Stream
     {
-        private SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions options)
+        private unsafe SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions options)
         {
             Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(share);
 
@@ -26,14 +26,16 @@ namespace System.IO
                 mode = FileMode.OpenOrCreate;
 
             Interop.Kernel32.CREATEFILE2_EXTENDED_PARAMETERS parameters = new Interop.Kernel32.CREATEFILE2_EXTENDED_PARAMETERS();
+            parameters.dwSize = (uint)sizeof(Interop.Kernel32.CREATEFILE2_EXTENDED_PARAMETERS);
             parameters.dwFileFlags = (uint)options;
+            parameters.lpSecurityAttributes = &secAttrs;
 
             SafeFileHandle fileHandle = Interop.Kernel32.CreateFile2(
                 lpFileName: _path,
                 dwDesiredAccess: fAccess,
                 dwShareMode: share,
                 dwCreationDisposition: mode,
-                parameters: ref parameters);
+                pCreateExParams: &parameters);
 
             fileHandle.IsAsync = _useAsyncIO;
 
@@ -55,21 +57,22 @@ namespace System.IO
             return fileHandle;
         }
 
+#if PROJECTN
         // TODO: These internal methods should be removed once we start consuming updated CoreFX builds
-        internal static FileStream InternalOpen(string path, int bufferSize = 4096, bool useAsync = true)
+        public static FileStream InternalOpen(string path, int bufferSize = 4096, bool useAsync = true)
         {
             return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, useAsync);
         }
 
-        internal static FileStream InternalCreate(string path, int bufferSize = 4096, bool useAsync = true)
+        public static FileStream InternalCreate(string path, int bufferSize = 4096, bool useAsync = true)
         {
             return new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, bufferSize, useAsync);
         }
 
-        internal static FileStream InternalAppend(string path, int bufferSize = 4096, bool useAsync = true)
+        public static FileStream InternalAppend(string path, int bufferSize = 4096, bool useAsync = true)
         {
             return new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read, bufferSize, useAsync);
         }
-
+#endif
     }
 }