public Win32FileJournalWriter(StorageEnvironmentOptions options, VoronPathSetting filename, long journalSize, Win32NativeFileAccess access = Win32NativeFileAccess.GenericWrite, Win32NativeFileShare shareMode = Win32NativeFileShare.Read) { try { _options = options; _filename = filename; _handle = Win32NativeFileMethods.CreateFile(filename.FullPath, access, shareMode, IntPtr.Zero, Win32NativeFileCreationDisposition.OpenAlways, options.WinOpenFlags, IntPtr.Zero); if (_handle.IsInvalid) { throw new IOException("When opening file " + filename, new Win32Exception(Marshal.GetLastWin32Error())); } var length = new FileInfo(filename.FullPath).Length; if (length < journalSize) { try { Win32NativeFileMethods.SetFileLength(_handle, journalSize); } catch (Exception) { try { _handle?.Dispose(); _handle = null; File.Delete(_filename.FullPath); } catch (Exception) { // there's nothing we can do about it } throw; } length = journalSize; } NumberOfAllocated4Kb = (int)(length / (4 * Constants.Size.Kilobyte)); _nativeOverlapped = (NativeOverlapped *)NativeMemory.AllocateMemory(sizeof(NativeOverlapped)); _nativeOverlapped->InternalLow = IntPtr.Zero; _nativeOverlapped->InternalHigh = IntPtr.Zero; } catch { Dispose(); throw; } }
public static extern SafeFileHandle CreateFile(string lpFileName, Win32NativeFileAccess dwDesiredAccess, Win32NativeFileShare dwShareMode, IntPtr lpSecurityAttributes, Win32NativeFileCreationDisposition dwCreationDisposition, Win32NativeFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public static extern SafeFileHandle CreateFile(string lpFileName, Win32NativeFileAccess dwDesiredAccess, Win32NativeFileShare dwShareMode, IntPtr lpSecurityAttributes, Win32NativeFileCreationDisposition dwCreationDisposition, Win32NativeFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);