public ulong SeekU(ulong offset, SeekOrigin origin) { ulong n = 0; if (!DeviceIO.SetFilePointerEx(this.fileHandle, offset, out n, (uint)origin)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return(n); }
public override void Close() { if (this.fileHandle != null) { DeviceIO.CloseHandle(this.fileHandle); this.fileHandle.SetHandleAsInvalid(); this.fileHandle = null; } base.Close(); }
public unsafe void Write(byte[] buffer, uint offset, uint count) { uint n = 0; fixed(byte *p = buffer) { if (!DeviceIO.WriteFile(this.fileHandle, p + offset, count, &n, IntPtr.Zero)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } }
private SafeFileHandle openFile(string id, FileAccess desiredAccess) { uint access; switch (desiredAccess) { case FileAccess.Read: access = DeviceIO.GENERIC_READ; break; case FileAccess.Write: access = DeviceIO.GENERIC_WRITE; break; case FileAccess.ReadWrite: access = DeviceIO.GENERIC_READ | DeviceIO.GENERIC_WRITE; break; default: access = DeviceIO.GENERIC_READ; break; } SafeFileHandle ptr = DeviceIO.CreateFile( id, access, DeviceIO.FILE_SHARE_WRITE, IntPtr.Zero, DeviceIO.OPEN_EXISTING, DeviceIO.FILE_FLAG_WRITE_THROUGH, IntPtr.Zero); if (ptr.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return(ptr); }