mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Added ATA IOCTLs.
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
2015-10-07 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* Linux/Enums.cs:
|
||||||
|
* Linux/Extern.cs:
|
||||||
|
* Linux/Structs.cs:
|
||||||
|
* Windows/Enums.cs:
|
||||||
|
* Windows/Extern.cs:
|
||||||
|
* Windows/Structs.cs:
|
||||||
|
Added ATA IOCTLs.
|
||||||
|
|
||||||
2015-10-06 Natalia Portillo <claunia@claunia.com>
|
2015-10-06 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* Linux/Enums.cs:
|
* Linux/Enums.cs:
|
||||||
|
|||||||
@@ -109,10 +109,16 @@ namespace DiscImageChef.Devices.Linux
|
|||||||
|
|
||||||
enum LinuxIoctl : ulong
|
enum LinuxIoctl : ulong
|
||||||
{
|
{
|
||||||
|
// SCSI IOCtls
|
||||||
SG_EMULATED_HOST = 0x2203,
|
SG_EMULATED_HOST = 0x2203,
|
||||||
SG_GET_VERSION_NUM = 0x2282,
|
SG_GET_VERSION_NUM = 0x2282,
|
||||||
SG_IO = 0x2285,
|
SG_IO = 0x2285,
|
||||||
SG_GET_SCSI_ID = 0x2276,
|
SG_GET_SCSI_ID = 0x2276,
|
||||||
|
|
||||||
|
// ATA IOCtls
|
||||||
|
HDIO_DRIVE_CMD = 0x031F,
|
||||||
|
HDIO_DRIVE_TASK = 0x031E,
|
||||||
|
HDIO_DRIVE_TASKFILE = 0x031D
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ namespace DiscImageChef.Devices.Linux
|
|||||||
|
|
||||||
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
|
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
|
||||||
internal static extern int ioctlSg(int fd, ulong request, ref sg_io_hdr_t value);
|
internal static extern int ioctlSg(int fd, ulong request, ref sg_io_hdr_t value);
|
||||||
|
|
||||||
|
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
|
||||||
|
internal static extern int ioctlHdTaskfile(int fd, ulong request, ref hd_drive_task_hdr value);
|
||||||
|
|
||||||
|
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
|
||||||
|
internal static extern int ioctlHdTask(int fd, ulong request, ref byte[] value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,5 +32,39 @@ namespace DiscImageChef.Devices.Linux
|
|||||||
public uint duration; /* [o] */
|
public uint duration; /* [o] */
|
||||||
public SgInfo info; /* [o] */
|
public SgInfo info; /* [o] */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
struct hd_drive_task_hdr
|
||||||
|
{
|
||||||
|
public byte data;
|
||||||
|
public byte feature;
|
||||||
|
public byte sector_count;
|
||||||
|
public byte sector_number;
|
||||||
|
public byte low_cylinder;
|
||||||
|
public byte high_cylinder;
|
||||||
|
public byte device_head;
|
||||||
|
public byte command;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
struct hd_drive_task_array
|
||||||
|
{
|
||||||
|
public byte command;
|
||||||
|
public byte features;
|
||||||
|
public byte sector_count;
|
||||||
|
public byte sector_number;
|
||||||
|
public byte low_cylinder;
|
||||||
|
public byte high_cylinder;
|
||||||
|
public byte device_head;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
struct hd_drive_cmd
|
||||||
|
{
|
||||||
|
public byte command;
|
||||||
|
public byte sector;
|
||||||
|
public byte feature;
|
||||||
|
public byte nsector;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,8 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
|
|
||||||
enum WindowsIoctl : uint
|
enum WindowsIoctl : uint
|
||||||
{
|
{
|
||||||
|
IOCTL_ATA_PASS_THROUGH = 0x4D02C,
|
||||||
|
IOCTL_ATA_PASS_THROUGH_DIRECT = 0x4D030,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ScsiPassThrough
|
/// ScsiPassThrough
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -236,5 +238,33 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IOCTL_SCSI_GET_ADDRESS = 0x41018
|
IOCTL_SCSI_GET_ADDRESS = 0x41018
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
enum AtaFlags : ushort
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ATA_FLAGS_DRDY_REQUIRED
|
||||||
|
/// </summary>
|
||||||
|
DrdyRequired = 0x01,
|
||||||
|
/// <summary>
|
||||||
|
/// ATA_FLAGS_DATA_IN
|
||||||
|
/// </summary>
|
||||||
|
DataIn = 0x02,
|
||||||
|
/// <summary>
|
||||||
|
/// ATA_FLAGS_DATA_OUT
|
||||||
|
/// </summary>
|
||||||
|
DataOut = 0x04,
|
||||||
|
/// <summary>
|
||||||
|
/// ATA_FLAGS_48BIT_COMMAND
|
||||||
|
/// </summary>
|
||||||
|
ExtendedCommand = 0x08,
|
||||||
|
/// <summary>
|
||||||
|
/// ATA_FLAGS_USE_DMA
|
||||||
|
/// </summary>
|
||||||
|
DMA = 0x10,
|
||||||
|
/// <summary>
|
||||||
|
/// ATA_FLAGS_NO_MULTIPLE
|
||||||
|
/// </summary>
|
||||||
|
NoMultiple = 0x20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
|
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
|
||||||
IntPtr templateFile);
|
IntPtr templateFile);
|
||||||
|
|
||||||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint="ioctl", CharSet = CharSet.Auto)]
|
||||||
public static extern bool DeviceIoControl(
|
public static extern bool DeviceIoControlScsi(
|
||||||
SafeFileHandle hDevice,
|
SafeFileHandle hDevice,
|
||||||
uint IoControlCode,
|
uint IoControlCode,
|
||||||
ref ScsiPassThroughDirectAndSenseBuffer InBuffer,
|
ref ScsiPassThroughDirectAndSenseBuffer InBuffer,
|
||||||
@@ -28,6 +28,18 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
IntPtr Overlapped
|
IntPtr Overlapped
|
||||||
);
|
);
|
||||||
|
|
||||||
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint="ioctl", CharSet = CharSet.Auto)]
|
||||||
|
public static extern bool DeviceIoControlAta(
|
||||||
|
SafeFileHandle hDevice,
|
||||||
|
uint IoControlCode,
|
||||||
|
ref AtaPassThroughDirect InBuffer,
|
||||||
|
uint nInBufferSize,
|
||||||
|
ref AtaPassThroughDirect OutBuffer,
|
||||||
|
uint nOutBufferSize,
|
||||||
|
ref uint pBytesReturned,
|
||||||
|
IntPtr Overlapped
|
||||||
|
);
|
||||||
|
|
||||||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||||
public static extern bool CloseHandle(SafeFileHandle hDevice);
|
public static extern bool CloseHandle(SafeFileHandle hDevice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,51 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
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 {
|
struct ScsiPassThroughDirectAndSenseBuffer
|
||||||
|
{
|
||||||
public ScsiPassThroughDirect sptd;
|
public ScsiPassThroughDirect sptd;
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
||||||
public byte[] SenseBuf;
|
public byte[] SenseBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AtaPassThroughDirect
|
||||||
|
{
|
||||||
|
public ushort Length;
|
||||||
|
public AtaFlags AtaFlags;
|
||||||
|
public byte PathId;
|
||||||
|
public byte TargetId;
|
||||||
|
public byte Lun;
|
||||||
|
public byte ReservedAsUchar;
|
||||||
|
public uint DataTransferLength;
|
||||||
|
public uint TimeOutValue;
|
||||||
|
public uint ReservedAsUlong;
|
||||||
|
public IntPtr DataBuffer;
|
||||||
|
public AtaTaskFile PreviousTaskFile;
|
||||||
|
public AtaTaskFile CurrentTaskFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
|
struct AtaTaskFile
|
||||||
|
{
|
||||||
|
// Fields for commands sent
|
||||||
|
[FieldOffset(0)] public byte Features;
|
||||||
|
[FieldOffset(6)] public byte Command;
|
||||||
|
|
||||||
|
// Fields on command return
|
||||||
|
[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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user