internal static unsafe SafeFileHandle Open(string fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, long preallocationSize) { using (DisableMediaInsertionPrompt.Create()) { // we don't use NtCreateFile as there is no public and reliable way // of converting DOS to NT file paths (RtlDosPathNameToRelativeNtPathName_U_WithStatus is not documented) SafeFileHandle fileHandle = CreateFile(fullPath, mode, access, share, options); if (FileStreamHelpers.ShouldPreallocate(preallocationSize, access, mode, fileHandle)) { Preallocate(fullPath, preallocationSize, fileHandle); } if ((options & FileOptions.Asynchronous) != 0) { // the handle has not been exposed yet, so we don't need to aquire a lock fileHandle.InitThreadPoolBinding(); } return(fileHandle); } }