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;
}
}
{
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);
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: ¶meters);
fileHandle.IsAsync = _useAsyncIO;
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
}
}