Correct name of ATA pass thru structure in Windows.

This commit is contained in:
2019-10-27 20:46:24 +00:00
parent 625442a221
commit 059362b0fe
2 changed files with 158 additions and 158 deletions

View File

@@ -37,102 +37,100 @@ using Microsoft.Win32.SafeHandles;
namespace DiscImageChef.Devices.Windows namespace DiscImageChef.Devices.Windows
{ {
static class Extern internal static class Extern
{ {
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename, internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename,
[MarshalAs(UnmanagedType.U4)] FileAccess access, [MarshalAs(UnmanagedType.U4)] FileAccess access,
[MarshalAs(UnmanagedType.U4)] FileShare share, [MarshalAs(UnmanagedType.U4)] FileShare share,
IntPtr IntPtr
securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
[MarshalAs(UnmanagedType.U4)] [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
FileMode creationDisposition, [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, IntPtr templateFile);
[MarshalAs(UnmanagedType.U4)]
FileAttributes flagsAndAttributes, IntPtr templateFile);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice, internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice,
WindowsIoctl ioControlCode, WindowsIoctl ioControlCode,
ref ScsiPassThroughDirectAndSenseBuffer inBuffer, ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
uint nInBufferSize, uint nInBufferSize,
ref ScsiPassThroughDirectAndSenseBuffer outBuffer, ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
ref uint pBytesReturned, ref uint pBytesReturned,
IntPtr overlapped); IntPtr overlapped);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControlAta(SafeFileHandle hDevice, internal static extern bool DeviceIoControlAta(SafeFileHandle hDevice,
WindowsIoctl ioControlCode, WindowsIoctl ioControlCode,
ref AtaPassThroughDirectWithBuffer inBuffer, ref AtaPassThroughExBuffer inBuffer,
uint nInBufferSize, uint nInBufferSize,
ref AtaPassThroughDirectWithBuffer outBuffer, ref AtaPassThroughExBuffer outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
ref uint pBytesReturned, IntPtr overlapped); ref uint pBytesReturned, IntPtr overlapped);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControlStorageQuery(SafeFileHandle hDevice, internal static extern bool DeviceIoControlStorageQuery(SafeFileHandle hDevice,
WindowsIoctl ioControlCode, WindowsIoctl ioControlCode,
ref StoragePropertyQuery inBuffer, ref StoragePropertyQuery inBuffer,
uint nInBufferSize, uint nInBufferSize,
IntPtr outBuffer, IntPtr outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
ref uint pBytesReturned, ref uint pBytesReturned,
IntPtr overlapped); IntPtr overlapped);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControlIde(SafeFileHandle hDevice, internal static extern bool DeviceIoControlIde(SafeFileHandle hDevice,
WindowsIoctl ioControlCode, WindowsIoctl ioControlCode,
ref IdePassThroughDirect inBuffer, ref IdePassThroughDirect inBuffer,
uint nInBufferSize, uint nInBufferSize,
ref IdePassThroughDirect outBuffer, ref IdePassThroughDirect outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
ref uint pBytesReturned, ref uint pBytesReturned,
IntPtr overlapped); IntPtr overlapped);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice,
WindowsIoctl ioControlCode, WindowsIoctl ioControlCode,
IntPtr inBuffer, IntPtr inBuffer,
uint nInBufferSize, uint nInBufferSize,
ref StorageDeviceNumber outBuffer, ref StorageDeviceNumber outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
ref uint pBytesReturned, ref uint pBytesReturned,
IntPtr overlapped); IntPtr overlapped);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControl(SafeFileHandle hDevice, internal static extern bool DeviceIoControl(SafeFileHandle hDevice,
WindowsIoctl ioControlCode, IntPtr inBuffer, WindowsIoctl ioControlCode, IntPtr inBuffer,
uint nInBufferSize, uint nInBufferSize,
ref SffdiskQueryDeviceProtocolData outBuffer, ref SffdiskQueryDeviceProtocolData outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
out uint pBytesReturned, out uint pBytesReturned,
IntPtr overlapped); IntPtr overlapped);
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
byte[] inBuffer, byte[] inBuffer,
uint nInBufferSize, byte[] outBuffer, uint nInBufferSize, byte[] outBuffer,
uint nOutBufferSize, uint nOutBufferSize,
out uint pBytesReturned, IntPtr overlapped); out uint pBytesReturned, IntPtr overlapped);
[DllImport("setupapi.dll", CharSet = CharSet.Auto)] [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, IntPtr enumerator, internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, IntPtr enumerator,
IntPtr hwndParent, DeviceGetClassFlags flags); IntPtr hwndParent, DeviceGetClassFlags flags);
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo,
IntPtr devInfo, IntPtr devInfo,
ref Guid interfaceClassGuid, ref Guid interfaceClassGuid,
uint memberIndex, uint memberIndex,
ref DeviceInterfaceData deviceInterfaceData); ref DeviceInterfaceData deviceInterfaceData);
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo, public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo,
ref DeviceInterfaceData deviceInterfaceData, ref DeviceInterfaceData deviceInterfaceData,
IntPtr deviceInterfaceDetailData, IntPtr deviceInterfaceDetailData,
uint deviceInterfaceDetailDataSize, uint deviceInterfaceDetailDataSize,
ref uint requiredSize, ref uint requiredSize,
IntPtr deviceInfoData); IntPtr deviceInfoData);
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo); public static extern bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);

View File

@@ -39,82 +39,93 @@ namespace DiscImageChef.Devices.Windows
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct ScsiPassThroughDirect internal struct ScsiPassThroughDirect
{ {
public ushort Length; public ushort Length;
public byte ScsiStatus; public byte ScsiStatus;
public byte PathId; public byte PathId;
public byte TargetId; public byte TargetId;
public byte Lun; public byte Lun;
public byte CdbLength; public byte CdbLength;
public byte SenseInfoLength; public byte SenseInfoLength;
[MarshalAs(UnmanagedType.U1)] [MarshalAs(UnmanagedType.U1)] public ScsiIoctlDirection DataIn;
public ScsiIoctlDirection DataIn; public uint DataTransferLength;
public uint DataTransferLength; public uint TimeOutValue;
public uint TimeOutValue;
public IntPtr DataBuffer; public IntPtr DataBuffer;
public uint SenseInfoOffset; public uint SenseInfoOffset;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] Cdb; public byte[] Cdb;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct ScsiPassThroughDirectAndSenseBuffer internal struct ScsiPassThroughDirectAndSenseBuffer
{ {
public ScsiPassThroughDirect sptd; public ScsiPassThroughDirect sptd;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] SenseBuf; public byte[] SenseBuf;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct AtaPassThroughDirect internal struct AtaPassThroughEx
{ {
/// <summary> /// <summary>
/// Length in bytes of this structure /// Length in bytes of this structure
/// </summary> /// </summary>
public ushort Length; public ushort Length;
/// <summary> /// <summary>
/// Indicates transfer direction and kind of operation /// Indicates transfer direction and kind of operation
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.U2)] [MarshalAs(UnmanagedType.U2)] public AtaFlags AtaFlags;
public AtaFlags AtaFlags;
/// <summary> /// <summary>
/// Indicates IDE port or bus, set by driver /// Indicates IDE port or bus, set by driver
/// </summary> /// </summary>
public byte PathId; public byte PathId;
/// <summary> /// <summary>
/// Indicates target device on bus, set by driver /// Indicates target device on bus, set by driver
/// </summary> /// </summary>
public byte TargetId; public byte TargetId;
/// <summary> /// <summary>
/// Indicates logical unit number of device, set by driver /// Indicates logical unit number of device, set by driver
/// </summary> /// </summary>
public byte Lun; public byte Lun;
/// <summary> /// <summary>
/// Reserved /// Reserved
/// </summary> /// </summary>
public byte ReservedAsUchar; public byte ReservedAsUchar;
/// <summary> /// <summary>
/// Data transfer length in bytes /// Data transfer length in bytes
/// </summary> /// </summary>
public uint DataTransferLength; public uint DataTransferLength;
/// <summary> /// <summary>
/// Timeout value in seconds /// Timeout value in seconds
/// </summary> /// </summary>
public uint TimeOutValue; public uint TimeOutValue;
/// <summary> /// <summary>
/// Reserved /// Reserved
/// </summary> /// </summary>
public uint ReservedAsUlong; public uint ReservedAsUlong;
/// <summary> /// <summary>
/// Pointer to data buffer relative to start of this structure /// Pointer to data buffer relative to start of this structure
/// </summary> /// </summary>
public IntPtr DataBuffer; public IntPtr DataBufferOffset;
/// <summary> /// <summary>
/// Previous ATA registers, for LBA48 /// Previous ATA registers, for LBA48
/// </summary> /// </summary>
public AtaTaskFile PreviousTaskFile; public AtaTaskFile PreviousTaskFile;
/// <summary> /// <summary>
/// ATA registers /// ATA registers
/// </summary> /// </summary>
@@ -123,95 +134,85 @@ namespace DiscImageChef.Devices.Windows
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct AtaPassThroughDirectWithBuffer internal struct AtaPassThroughExBuffer
{ {
public AtaPassThroughDirect aptd; public AtaPassThroughEx aptd;
public uint filler; public uint filler;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64 * 512)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64 * 512)]
public byte[] dataBuffer; public byte[] dataBuffer;
} }
[StructLayout(LayoutKind.Explicit)] [StructLayout(LayoutKind.Explicit)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct AtaTaskFile internal struct AtaTaskFile
{ {
// Fields for commands sent // Fields for commands sent
[FieldOffset(0)] [FieldOffset(0)] public byte Features;
public byte Features; [FieldOffset(6)] public byte Command;
[FieldOffset(6)]
public byte Command;
// Fields on command return // Fields on command return
[FieldOffset(0)] [FieldOffset(0)] public byte Error;
public byte Error; [FieldOffset(6)] public byte Status;
[FieldOffset(6)]
public byte Status;
// Common fields // Common fields
[FieldOffset(1)] [FieldOffset(1)] public byte SectorCount;
public byte SectorCount; [FieldOffset(2)] public byte SectorNumber;
[FieldOffset(2)] [FieldOffset(3)] public byte CylinderLow;
public byte SectorNumber; [FieldOffset(4)] public byte CylinderHigh;
[FieldOffset(3)] [FieldOffset(5)] public byte DeviceHead;
public byte CylinderLow; [FieldOffset(7)] public byte Reserved;
[FieldOffset(4)]
public byte CylinderHigh;
[FieldOffset(5)]
public byte DeviceHead;
[FieldOffset(7)]
public byte Reserved;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct StoragePropertyQuery internal struct StoragePropertyQuery
{ {
[MarshalAs(UnmanagedType.U4)] [MarshalAs(UnmanagedType.U4)] public StoragePropertyId PropertyId;
public StoragePropertyId PropertyId; [MarshalAs(UnmanagedType.U4)] public StorageQueryType QueryType;
[MarshalAs(UnmanagedType.U4)]
public StorageQueryType QueryType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] AdditionalParameters; public byte[] AdditionalParameters;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct StorageDescriptorHeader internal struct StorageDescriptorHeader
{ {
public uint Version; public uint Version;
public uint Size; public uint Size;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct StorageDeviceDescriptor internal struct StorageDeviceDescriptor
{ {
public uint Version; public uint Version;
public uint Size; public uint Size;
public byte DeviceType; public byte DeviceType;
public byte DeviceTypeModifier; public byte DeviceTypeModifier;
[MarshalAs(UnmanagedType.U1)] [MarshalAs(UnmanagedType.U1)] public bool RemovableMedia;
public bool RemovableMedia; [MarshalAs(UnmanagedType.U1)] public bool CommandQueueing;
[MarshalAs(UnmanagedType.U1)] public int VendorIdOffset;
public bool CommandQueueing; public int ProductIdOffset;
public int VendorIdOffset; public int ProductRevisionOffset;
public int ProductIdOffset; public int SerialNumberOffset;
public int ProductRevisionOffset;
public int SerialNumberOffset;
public StorageBusType BusType; public StorageBusType BusType;
public uint RawPropertiesLength; public uint RawPropertiesLength;
public byte[] RawDeviceProperties; public byte[] RawDeviceProperties;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct IdePassThroughDirect internal struct IdePassThroughDirect
{ {
/// <summary> /// <summary>
/// ATA registers /// ATA registers
/// </summary> /// </summary>
public AtaTaskFile CurrentTaskFile; public AtaTaskFile CurrentTaskFile;
/// <summary> /// <summary>
/// Size of data buffer /// Size of data buffer
/// </summary> /// </summary>
public uint DataBufferSize; public uint DataBufferSize;
/// <summary> /// <summary>
/// Data buffer /// Data buffer
/// </summary> /// </summary>
@@ -221,7 +222,7 @@ namespace DiscImageChef.Devices.Windows
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct StorageDeviceNumber internal struct StorageDeviceNumber
{ {
public int deviceType; public int deviceType;
public int deviceNumber; public int deviceNumber;
@@ -230,30 +231,30 @@ namespace DiscImageChef.Devices.Windows
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct DeviceInfoData internal struct DeviceInfoData
{ {
public int cbSize; public int cbSize;
public Guid classGuid; public Guid classGuid;
public uint devInst; public uint devInst;
public IntPtr reserved; public IntPtr reserved;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct DeviceInterfaceData internal struct DeviceInterfaceData
{ {
public int cbSize; public int cbSize;
public Guid interfaceClassGuid; public Guid interfaceClassGuid;
public uint flags; public uint flags;
IntPtr reserved; private readonly IntPtr reserved;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct UsbSetupPacket internal struct UsbSetupPacket
{ {
public byte bmRequest; public byte bmRequest;
public byte bRequest; public byte bRequest;
public short wValue; public short wValue;
public short wIndex; public short wIndex;
public short wLength; public short wLength;
@@ -261,41 +262,42 @@ namespace DiscImageChef.Devices.Windows
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct UsbDescriptorRequest internal struct UsbDescriptorRequest
{ {
public int ConnectionIndex; public int ConnectionIndex;
public UsbSetupPacket SetupPacket; public UsbSetupPacket SetupPacket;
//public byte[] Data; //public byte[] Data;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct SffdiskQueryDeviceProtocolData internal struct SffdiskQueryDeviceProtocolData
{ {
public ushort size; public ushort size;
public ushort reserved; public ushort reserved;
public Guid protocolGuid; public Guid protocolGuid;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
struct SffdiskDeviceCommandData internal struct SffdiskDeviceCommandData
{ {
public ushort size; public ushort size;
public ushort reserved; public ushort reserved;
public SffdiskDcmd command; public SffdiskDcmd command;
public ushort protocolArgumentSize; public ushort protocolArgumentSize;
public uint deviceDataBufferSize; public uint deviceDataBufferSize;
public uint information; public uint information;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct SdCmdDescriptor internal struct SdCmdDescriptor
{ {
public byte commandCode; public byte commandCode;
public SdCommandClass cmdClass; public SdCommandClass cmdClass;
public SdTransferDirection transferDirection; public SdTransferDirection transferDirection;
public SdTransferType transferType; public SdTransferType transferType;
public SdResponseType responseType; public SdResponseType responseType;
} }
} }