From 059362b0fe1ecddcaa5d61636a98363ad6a18488 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 27 Oct 2019 20:46:24 +0000 Subject: [PATCH] Correct name of ATA pass thru structure in Windows. --- DiscImageChef.Devices/Windows/Extern.cs | 144 ++++++++++--------- DiscImageChef.Devices/Windows/Structs.cs | 172 ++++++++++++----------- 2 files changed, 158 insertions(+), 158 deletions(-) diff --git a/DiscImageChef.Devices/Windows/Extern.cs b/DiscImageChef.Devices/Windows/Extern.cs index 6c48865d9..09145e637 100644 --- a/DiscImageChef.Devices/Windows/Extern.cs +++ b/DiscImageChef.Devices/Windows/Extern.cs @@ -37,102 +37,100 @@ using Microsoft.Win32.SafeHandles; namespace DiscImageChef.Devices.Windows { - static class Extern + internal static class Extern { [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename, - [MarshalAs(UnmanagedType.U4)] FileAccess access, - [MarshalAs(UnmanagedType.U4)] FileShare share, - IntPtr - securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero - [MarshalAs(UnmanagedType.U4)] - FileMode creationDisposition, - [MarshalAs(UnmanagedType.U4)] - FileAttributes flagsAndAttributes, IntPtr templateFile); + internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename, + [MarshalAs(UnmanagedType.U4)] FileAccess access, + [MarshalAs(UnmanagedType.U4)] FileShare share, + IntPtr + securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero + [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition, + [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, IntPtr templateFile); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] - internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice, - WindowsIoctl ioControlCode, - ref ScsiPassThroughDirectAndSenseBuffer inBuffer, - uint nInBufferSize, - ref ScsiPassThroughDirectAndSenseBuffer outBuffer, - uint nOutBufferSize, - ref uint pBytesReturned, - IntPtr overlapped); + internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice, + WindowsIoctl ioControlCode, + ref ScsiPassThroughDirectAndSenseBuffer inBuffer, + uint nInBufferSize, + ref ScsiPassThroughDirectAndSenseBuffer outBuffer, + uint nOutBufferSize, + ref uint pBytesReturned, + IntPtr overlapped); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] - internal static extern bool DeviceIoControlAta(SafeFileHandle hDevice, - WindowsIoctl ioControlCode, - ref AtaPassThroughDirectWithBuffer inBuffer, - uint nInBufferSize, - ref AtaPassThroughDirectWithBuffer outBuffer, - uint nOutBufferSize, - ref uint pBytesReturned, IntPtr overlapped); + internal static extern bool DeviceIoControlAta(SafeFileHandle hDevice, + WindowsIoctl ioControlCode, + ref AtaPassThroughExBuffer inBuffer, + uint nInBufferSize, + ref AtaPassThroughExBuffer outBuffer, + uint nOutBufferSize, + ref uint pBytesReturned, IntPtr overlapped); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] - internal static extern bool DeviceIoControlStorageQuery(SafeFileHandle hDevice, - WindowsIoctl ioControlCode, - ref StoragePropertyQuery inBuffer, - uint nInBufferSize, - IntPtr outBuffer, - uint nOutBufferSize, - ref uint pBytesReturned, - IntPtr overlapped); + internal static extern bool DeviceIoControlStorageQuery(SafeFileHandle hDevice, + WindowsIoctl ioControlCode, + ref StoragePropertyQuery inBuffer, + uint nInBufferSize, + IntPtr outBuffer, + uint nOutBufferSize, + ref uint pBytesReturned, + IntPtr overlapped); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] - internal static extern bool DeviceIoControlIde(SafeFileHandle hDevice, - WindowsIoctl ioControlCode, - ref IdePassThroughDirect inBuffer, - uint nInBufferSize, - ref IdePassThroughDirect outBuffer, - uint nOutBufferSize, - ref uint pBytesReturned, - IntPtr overlapped); + internal static extern bool DeviceIoControlIde(SafeFileHandle hDevice, + WindowsIoctl ioControlCode, + ref IdePassThroughDirect inBuffer, + uint nInBufferSize, + ref IdePassThroughDirect outBuffer, + uint nOutBufferSize, + ref uint pBytesReturned, + IntPtr overlapped); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] - internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, - WindowsIoctl ioControlCode, - IntPtr inBuffer, - uint nInBufferSize, - ref StorageDeviceNumber outBuffer, - uint nOutBufferSize, - ref uint pBytesReturned, - IntPtr overlapped); + internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, + WindowsIoctl ioControlCode, + IntPtr inBuffer, + uint nInBufferSize, + ref StorageDeviceNumber outBuffer, + uint nOutBufferSize, + ref uint pBytesReturned, + IntPtr overlapped); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] - internal static extern bool DeviceIoControl(SafeFileHandle hDevice, - WindowsIoctl ioControlCode, IntPtr inBuffer, - uint nInBufferSize, - ref SffdiskQueryDeviceProtocolData outBuffer, - uint nOutBufferSize, - out uint pBytesReturned, - IntPtr overlapped); + internal static extern bool DeviceIoControl(SafeFileHandle hDevice, + WindowsIoctl ioControlCode, IntPtr inBuffer, + uint nInBufferSize, + ref SffdiskQueryDeviceProtocolData outBuffer, + uint nOutBufferSize, + out uint pBytesReturned, + IntPtr overlapped); [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)] internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, - byte[] inBuffer, - uint nInBufferSize, byte[] outBuffer, - uint nOutBufferSize, - out uint pBytesReturned, IntPtr overlapped); + byte[] inBuffer, + uint nInBufferSize, byte[] outBuffer, + uint nOutBufferSize, + out uint pBytesReturned, IntPtr overlapped); [DllImport("setupapi.dll", CharSet = CharSet.Auto)] - internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, IntPtr enumerator, - IntPtr hwndParent, DeviceGetClassFlags flags); + internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, IntPtr enumerator, + IntPtr hwndParent, DeviceGetClassFlags flags); [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, - IntPtr devInfo, - ref Guid interfaceClassGuid, - uint memberIndex, - ref DeviceInterfaceData deviceInterfaceData); + public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, + IntPtr devInfo, + ref Guid interfaceClassGuid, + uint memberIndex, + ref DeviceInterfaceData deviceInterfaceData); [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo, - ref DeviceInterfaceData deviceInterfaceData, - IntPtr deviceInterfaceDetailData, - uint deviceInterfaceDetailDataSize, - ref uint requiredSize, - IntPtr deviceInfoData); + public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo, + ref DeviceInterfaceData deviceInterfaceData, + IntPtr deviceInterfaceDetailData, + uint deviceInterfaceDetailDataSize, + ref uint requiredSize, + IntPtr deviceInfoData); [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo); diff --git a/DiscImageChef.Devices/Windows/Structs.cs b/DiscImageChef.Devices/Windows/Structs.cs index a0ce5d503..127103cef 100644 --- a/DiscImageChef.Devices/Windows/Structs.cs +++ b/DiscImageChef.Devices/Windows/Structs.cs @@ -39,82 +39,93 @@ namespace DiscImageChef.Devices.Windows { [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct ScsiPassThroughDirect + internal struct ScsiPassThroughDirect { public ushort Length; - public byte ScsiStatus; - public byte PathId; - public byte TargetId; - public byte Lun; - public byte CdbLength; - public byte SenseInfoLength; - [MarshalAs(UnmanagedType.U1)] - public ScsiIoctlDirection DataIn; - public uint DataTransferLength; - public uint TimeOutValue; + public byte ScsiStatus; + public byte PathId; + public byte TargetId; + public byte Lun; + public byte CdbLength; + public byte SenseInfoLength; + [MarshalAs(UnmanagedType.U1)] public ScsiIoctlDirection DataIn; + public uint DataTransferLength; + public uint TimeOutValue; public IntPtr DataBuffer; - public uint SenseInfoOffset; + public uint SenseInfoOffset; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] Cdb; } [StructLayout(LayoutKind.Sequential)] - struct ScsiPassThroughDirectAndSenseBuffer + internal struct ScsiPassThroughDirectAndSenseBuffer { public ScsiPassThroughDirect sptd; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] SenseBuf; } [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct AtaPassThroughDirect + internal struct AtaPassThroughEx { /// /// Length in bytes of this structure /// public ushort Length; + /// /// Indicates transfer direction and kind of operation /// - [MarshalAs(UnmanagedType.U2)] - public AtaFlags AtaFlags; + [MarshalAs(UnmanagedType.U2)] public AtaFlags AtaFlags; + /// /// Indicates IDE port or bus, set by driver /// public byte PathId; + /// /// Indicates target device on bus, set by driver /// public byte TargetId; + /// /// Indicates logical unit number of device, set by driver /// public byte Lun; + /// /// Reserved /// public byte ReservedAsUchar; + /// /// Data transfer length in bytes /// public uint DataTransferLength; + /// /// Timeout value in seconds /// public uint TimeOutValue; + /// /// Reserved /// public uint ReservedAsUlong; + /// /// Pointer to data buffer relative to start of this structure /// - public IntPtr DataBuffer; + public IntPtr DataBufferOffset; + /// /// Previous ATA registers, for LBA48 /// public AtaTaskFile PreviousTaskFile; + /// /// ATA registers /// @@ -123,95 +134,85 @@ namespace DiscImageChef.Devices.Windows [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct AtaPassThroughDirectWithBuffer + internal struct AtaPassThroughExBuffer { - public AtaPassThroughDirect aptd; - public uint filler; + public AtaPassThroughEx aptd; + public uint filler; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64 * 512)] public byte[] dataBuffer; } [StructLayout(LayoutKind.Explicit)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct AtaTaskFile + internal struct AtaTaskFile { // Fields for commands sent - [FieldOffset(0)] - public byte Features; - [FieldOffset(6)] - public byte Command; + [FieldOffset(0)] public byte Features; + [FieldOffset(6)] public byte Command; // Fields on command return - [FieldOffset(0)] - public byte Error; - [FieldOffset(6)] - public byte Status; + [FieldOffset(0)] public byte Error; + [FieldOffset(6)] public byte Status; // Common fields - [FieldOffset(1)] - public byte SectorCount; - [FieldOffset(2)] - public byte SectorNumber; - [FieldOffset(3)] - public byte CylinderLow; - [FieldOffset(4)] - public byte CylinderHigh; - [FieldOffset(5)] - public byte DeviceHead; - [FieldOffset(7)] - public byte Reserved; + [FieldOffset(1)] public byte SectorCount; + [FieldOffset(2)] public byte SectorNumber; + [FieldOffset(3)] public byte CylinderLow; + [FieldOffset(4)] public byte CylinderHigh; + [FieldOffset(5)] public byte DeviceHead; + [FieldOffset(7)] public byte Reserved; } [StructLayout(LayoutKind.Sequential)] - struct StoragePropertyQuery + internal struct StoragePropertyQuery { - [MarshalAs(UnmanagedType.U4)] - public StoragePropertyId PropertyId; - [MarshalAs(UnmanagedType.U4)] - public StorageQueryType QueryType; + [MarshalAs(UnmanagedType.U4)] public StoragePropertyId PropertyId; + [MarshalAs(UnmanagedType.U4)] public StorageQueryType QueryType; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] AdditionalParameters; } [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct StorageDescriptorHeader + internal struct StorageDescriptorHeader { public uint Version; public uint Size; } [StructLayout(LayoutKind.Sequential)] - struct StorageDeviceDescriptor + internal struct StorageDeviceDescriptor { public uint Version; public uint Size; public byte DeviceType; public byte DeviceTypeModifier; - [MarshalAs(UnmanagedType.U1)] - public bool RemovableMedia; - [MarshalAs(UnmanagedType.U1)] - public bool CommandQueueing; - public int VendorIdOffset; - public int ProductIdOffset; - public int ProductRevisionOffset; - public int SerialNumberOffset; + [MarshalAs(UnmanagedType.U1)] public bool RemovableMedia; + [MarshalAs(UnmanagedType.U1)] public bool CommandQueueing; + public int VendorIdOffset; + public int ProductIdOffset; + public int ProductRevisionOffset; + public int SerialNumberOffset; public StorageBusType BusType; - public uint RawPropertiesLength; - public byte[] RawDeviceProperties; + public uint RawPropertiesLength; + public byte[] RawDeviceProperties; } [StructLayout(LayoutKind.Sequential)] - struct IdePassThroughDirect + internal struct IdePassThroughDirect { /// /// ATA registers /// public AtaTaskFile CurrentTaskFile; + /// /// Size of data buffer /// public uint DataBufferSize; + /// /// Data buffer /// @@ -221,7 +222,7 @@ namespace DiscImageChef.Devices.Windows [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct StorageDeviceNumber + internal struct StorageDeviceNumber { public int deviceType; public int deviceNumber; @@ -230,30 +231,30 @@ namespace DiscImageChef.Devices.Windows [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct DeviceInfoData + internal struct DeviceInfoData { - public int cbSize; - public Guid classGuid; - public uint devInst; + public int cbSize; + public Guid classGuid; + public uint devInst; public IntPtr reserved; } [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct DeviceInterfaceData + internal struct DeviceInterfaceData { - public int cbSize; + public int cbSize; public Guid interfaceClassGuid; public uint flags; - IntPtr reserved; + private readonly IntPtr reserved; } [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct UsbSetupPacket + internal struct UsbSetupPacket { - public byte bmRequest; - public byte bRequest; + public byte bmRequest; + public byte bRequest; public short wValue; public short wIndex; public short wLength; @@ -261,41 +262,42 @@ namespace DiscImageChef.Devices.Windows [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct UsbDescriptorRequest + internal struct UsbDescriptorRequest { - public int ConnectionIndex; + public int ConnectionIndex; + public UsbSetupPacket SetupPacket; //public byte[] Data; } [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct SffdiskQueryDeviceProtocolData + internal struct SffdiskQueryDeviceProtocolData { public ushort size; public ushort reserved; - public Guid protocolGuid; + public Guid protocolGuid; } [StructLayout(LayoutKind.Sequential)] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - struct SffdiskDeviceCommandData + internal struct SffdiskDeviceCommandData { - public ushort size; - public ushort reserved; + public ushort size; + public ushort reserved; public SffdiskDcmd command; - public ushort protocolArgumentSize; - public uint deviceDataBufferSize; - public uint information; + public ushort protocolArgumentSize; + public uint deviceDataBufferSize; + public uint information; } [StructLayout(LayoutKind.Sequential)] - struct SdCmdDescriptor + internal struct SdCmdDescriptor { - public byte commandCode; - public SdCommandClass cmdClass; + public byte commandCode; + public SdCommandClass cmdClass; public SdTransferDirection transferDirection; - public SdTransferType transferType; - public SdResponseType responseType; + public SdTransferType transferType; + public SdResponseType responseType; } } \ No newline at end of file