public bool Ioctl(ScsiPassThroughWrapper sptw) { IntPtr bufferPointer = IntPtr.Zero; bool ioresult = false; try { Int32 bufferSize = Marshal.SizeOf(sptw.sptBuffered); bufferPointer = Marshal.AllocHGlobal(bufferSize); Marshal.StructureToPtr(sptw.sptBuffered, bufferPointer, true); ioresult = DeviceIoControl(this.handle, (uint)IoctlCodes.IOCTL_SCSI_PASS_THROUGH_DIRECT, bufferPointer, (UInt32)bufferSize, bufferPointer, (UInt32)bufferSize, out UInt32 bytesReturned, IntPtr.Zero) && (bytesReturned > 0); if (ioresult) { sptw.sptBuffered = (ScsiPassThroughBuffered)Marshal.PtrToStructure(bufferPointer, typeof(ScsiPassThroughBuffered)); } } finally { Marshal.FreeHGlobal(bufferPointer); } return(ioresult); }
/// <summary> /// Wrapper calling low level function DeviceIoControl /// </summary> /// <param name="sptw">scsi params</param> /// <returns></returns> public bool Ioctl(ScsiPassThroughWrapper sptw) { IntPtr bufferPointer = IntPtr.Zero; bool ioresult = false; try { Int32 bufferSize = Marshal.SizeOf(sptw.sptBuffered); bufferPointer = Marshal.AllocHGlobal(bufferSize); Marshal.StructureToPtr(sptw.sptBuffered, bufferPointer, true); ioresult = DeviceIoControl(this.handle, (uint)IoctlCodes.IOCTL_SCSI_PASS_THROUGH_DIRECT, bufferPointer, (UInt32)bufferSize, bufferPointer, (UInt32)bufferSize, out UInt32 bytesReturned, IntPtr.Zero) && (bytesReturned > 0); if (ioresult) { sptw.sptBuffered = (ScsiPassThroughBuffered)Marshal.PtrToStructure(bufferPointer, typeof(ScsiPassThroughBuffered)); } else { this.lastError = GetLastError(); } } catch (Exception e) { Console.WriteLine("IO Ctl FAIL: {0}", e.Message); } finally { Marshal.FreeHGlobal(bufferPointer); } return(ioresult); }
public ScsiCommand(ScsiPassThroughWrapper sptw) { this.Sptw = sptw; }