public unsafe void Execute(FileWriteResult target) { target.Pin(buffer.Data); Overlapped overlapped = new Overlapped { AsyncResult = target, OffsetLow = (int)(target.Position & 0xffffffff), OffsetHigh = (int)((target.Position >> 32) & 0xffffffff) }; NativeOverlapped *native = overlapped.UnsafePack(null, null); IntPtr array = Marshal.UnsafeAddrOfPinnedArrayElement(buffer.Data, buffer.Offset); int read; int result = FileInterop.WriteFile(handle, array, buffer.Count, out read, native); uint error = FileInterop.GetLastError(); if (result == 0 && error != 997) { target.Fail(error); } if (result == 1) { target.Complete(native, read); } }
public File OpenOrCreate(string path) { IntPtr handle = FileInterop.CreateFile(path, 0x80000000 | 0x40000000, 0x01 | 0x02, IntPtr.Zero, 0x04, 0x40000000 | 0x00000080, IntPtr.Zero); uint error = FileInterop.GetLastError(); worker.Add(handle); return(new FileInstance(handle, worker)); }
public File Open(string path) { IntPtr handle = FileInterop.CreateFile(path, 0x80000000 | 0x40000000, 0x01 | 0x02, IntPtr.Zero, 0x03, 0x40000000 | 0x00000080, IntPtr.Zero); if (handle == new IntPtr(-1)) { return(null); } worker.Add(handle); return(new FileInstance(handle, worker)); }
public unsafe void Complete(NativeOverlapped *overlapped, int affected) { uint ignore; uint result = FileInterop.GetOverlappedResult(Handle, overlapped, out ignore, false); Affected = affected; IsCompleted = true; if (result != 0 || affected > 0) { Release(); Complete(); } else { Fail(); } }
public void Fail() { Fail(FileInterop.GetLastError()); }
public void Dispose() { FileInterop.CloseHandle(handle); }
public bool Flush() { return(FileInterop.FlushFileBuffers(handle)); }
public bool SetLength(long length) { return (FileInterop.SetFilePointerEx(handle, length, IntPtr.Zero, 0x00) && FileInterop.SetEndOfFile(handle)); }