mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Send buffer to SDHCI before sending command in Windows.
This commit is contained in:
@@ -40,7 +40,7 @@ using Microsoft.Win32.SafeHandles;
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
|
||||
static class Command
|
||||
internal static class Command
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a SCSI command
|
||||
@@ -68,7 +68,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if (buffer == null) return -1;
|
||||
|
||||
ScsiPassThroughDirectAndSenseBuffer sptdSb = new ScsiPassThroughDirectAndSenseBuffer
|
||||
var sptdSb = new ScsiPassThroughDirectAndSenseBuffer
|
||||
{
|
||||
SenseBuf = new byte[32],
|
||||
sptd = new ScsiPassThroughDirect
|
||||
@@ -87,15 +87,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
Array.Copy(cdb, sptdSb.sptd.Cdb, cdb.Length);
|
||||
|
||||
uint k = 0;
|
||||
int error = 0;
|
||||
var error = 0;
|
||||
|
||||
Marshal.Copy(buffer, 0, sptdSb.sptd.DataBuffer, buffer.Length);
|
||||
|
||||
DateTime start = DateTime.Now;
|
||||
bool hasError = !Extern.DeviceIoControlScsi(fd, WindowsIoctl.IoctlScsiPassThroughDirect, ref sptdSb,
|
||||
var start = DateTime.Now;
|
||||
var hasError = !Extern.DeviceIoControlScsi(fd, WindowsIoctl.IoctlScsiPassThroughDirect, ref sptdSb,
|
||||
(uint) Marshal.SizeOf(sptdSb), ref sptdSb,
|
||||
(uint) Marshal.SizeOf(sptdSb), ref k, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
var end = DateTime.Now;
|
||||
|
||||
if (hasError) error = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -136,15 +136,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if (buffer == null) return -1;
|
||||
|
||||
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
|
||||
var offsetForBuffer = (uint) (Marshal.SizeOf(typeof(AtaPassThroughEx)) + Marshal.SizeOf(typeof(uint)));
|
||||
|
||||
AtaPassThroughDirectWithBuffer aptdBuf = new AtaPassThroughDirectWithBuffer
|
||||
var aptdBuf = new AtaPassThroughExBuffer
|
||||
{
|
||||
aptd = new AtaPassThroughDirect
|
||||
aptd = new AtaPassThroughEx
|
||||
{
|
||||
TimeOutValue = timeout,
|
||||
DataBuffer = (IntPtr)offsetForBuffer,
|
||||
Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughDirect)),
|
||||
DataBufferOffset = (IntPtr) offsetForBuffer,
|
||||
Length = (ushort) Marshal.SizeOf(typeof(AtaPassThroughEx)),
|
||||
DataTransferLength = (uint) buffer.Length,
|
||||
PreviousTaskFile = new AtaTaskFile(),
|
||||
CurrentTaskFile = new AtaTaskFile
|
||||
@@ -189,15 +189,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
||||
|
||||
uint k = 0;
|
||||
int error = 0;
|
||||
var error = 0;
|
||||
|
||||
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
|
||||
|
||||
DateTime start = DateTime.Now;
|
||||
var start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IoctlAtaPassThrough, ref aptdBuf,
|
||||
(uint) Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
||||
(uint) Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
var end = DateTime.Now;
|
||||
|
||||
if (sense) error = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -241,15 +241,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if (buffer == null) return -1;
|
||||
|
||||
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
|
||||
var offsetForBuffer = (uint) (Marshal.SizeOf(typeof(AtaPassThroughEx)) + Marshal.SizeOf(typeof(uint)));
|
||||
|
||||
AtaPassThroughDirectWithBuffer aptdBuf = new AtaPassThroughDirectWithBuffer
|
||||
var aptdBuf = new AtaPassThroughExBuffer
|
||||
{
|
||||
aptd = new AtaPassThroughDirect
|
||||
aptd = new AtaPassThroughEx
|
||||
{
|
||||
TimeOutValue = timeout,
|
||||
DataBuffer = (IntPtr)offsetForBuffer,
|
||||
Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughDirect)),
|
||||
DataBufferOffset = (IntPtr) offsetForBuffer,
|
||||
Length = (ushort) Marshal.SizeOf(typeof(AtaPassThroughEx)),
|
||||
DataTransferLength = (uint) buffer.Length,
|
||||
PreviousTaskFile = new AtaTaskFile(),
|
||||
CurrentTaskFile = new AtaTaskFile
|
||||
@@ -294,15 +294,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
||||
|
||||
uint k = 0;
|
||||
int error = 0;
|
||||
var error = 0;
|
||||
|
||||
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
|
||||
|
||||
DateTime start = DateTime.Now;
|
||||
var start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IoctlAtaPassThrough, ref aptdBuf,
|
||||
(uint) Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
||||
(uint) Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
var end = DateTime.Now;
|
||||
|
||||
if (sense) error = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -346,15 +346,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if (buffer == null) return -1;
|
||||
|
||||
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
|
||||
var offsetForBuffer = (uint) (Marshal.SizeOf(typeof(AtaPassThroughEx)) + Marshal.SizeOf(typeof(uint)));
|
||||
|
||||
AtaPassThroughDirectWithBuffer aptdBuf = new AtaPassThroughDirectWithBuffer
|
||||
var aptdBuf = new AtaPassThroughExBuffer
|
||||
{
|
||||
aptd = new AtaPassThroughDirect
|
||||
aptd = new AtaPassThroughEx
|
||||
{
|
||||
TimeOutValue = timeout,
|
||||
DataBuffer = (IntPtr)offsetForBuffer,
|
||||
Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughDirect)),
|
||||
DataBufferOffset = (IntPtr) offsetForBuffer,
|
||||
Length = (ushort) Marshal.SizeOf(typeof(AtaPassThroughEx)),
|
||||
DataTransferLength = (uint) buffer.Length,
|
||||
PreviousTaskFile =
|
||||
new AtaTaskFile
|
||||
@@ -403,19 +403,21 @@ namespace DiscImageChef.Devices.Windows
|
||||
break;
|
||||
}
|
||||
|
||||
aptdBuf.aptd.AtaFlags |= AtaFlags.ExtendedCommand;
|
||||
|
||||
// Unknown if needed
|
||||
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
||||
|
||||
uint k = 0;
|
||||
int error = 0;
|
||||
var error = 0;
|
||||
|
||||
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
|
||||
|
||||
DateTime start = DateTime.Now;
|
||||
var start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IoctlAtaPassThrough, ref aptdBuf,
|
||||
(uint) Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
||||
(uint) Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
var end = DateTime.Now;
|
||||
|
||||
if (sense) error = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -445,9 +447,9 @@ namespace DiscImageChef.Devices.Windows
|
||||
/// </summary>
|
||||
/// <param name="deviceHandle">Device handle</param>
|
||||
/// <returns>Device number</returns>
|
||||
static uint GetDeviceNumber(SafeFileHandle deviceHandle)
|
||||
private static uint GetDeviceNumber(SafeFileHandle deviceHandle)
|
||||
{
|
||||
StorageDeviceNumber sdn = new StorageDeviceNumber {deviceNumber = -1};
|
||||
var sdn = new StorageDeviceNumber {deviceNumber = -1};
|
||||
uint k = 0;
|
||||
if (!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IoctlStorageGetDeviceNumber,
|
||||
IntPtr.Zero, 0, ref sdn, (uint) Marshal.SizeOf(sdn), ref k,
|
||||
@@ -463,11 +465,12 @@ namespace DiscImageChef.Devices.Windows
|
||||
/// <returns><c>true</c> if SDHCI, false otherwise</returns>
|
||||
internal static bool IsSdhci(SafeFileHandle fd)
|
||||
{
|
||||
SffdiskQueryDeviceProtocolData queryData1 = new SffdiskQueryDeviceProtocolData();
|
||||
var queryData1 = new SffdiskQueryDeviceProtocolData();
|
||||
queryData1.size = (ushort) Marshal.SizeOf(queryData1);
|
||||
Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskQueryDeviceProtocol, IntPtr.Zero, 0, ref queryData1,
|
||||
queryData1.size, out _, IntPtr.Zero);
|
||||
return queryData1.protocolGuid.Equals(Consts.GuidSffProtocolSd);
|
||||
return queryData1.protocolGuid.Equals(Consts.GuidSffProtocolSd) ||
|
||||
queryData1.protocolGuid.Equals(Consts.GuidSffProtocolMmc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -495,8 +498,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
out bool sense,
|
||||
uint timeout = 0)
|
||||
{
|
||||
SffdiskDeviceCommandData commandData = new SffdiskDeviceCommandData();
|
||||
SdCmdDescriptor commandDescriptor = new SdCmdDescriptor();
|
||||
var commandData = new SffdiskDeviceCommandData();
|
||||
var commandDescriptor = new SdCmdDescriptor();
|
||||
commandData.size = (ushort) Marshal.SizeOf(commandData);
|
||||
commandData.command = SffdiskDcmd.DeviceCommand;
|
||||
commandData.protocolArgumentSize = (ushort) Marshal.SizeOf(commandDescriptor);
|
||||
@@ -523,20 +526,23 @@ namespace DiscImageChef.Devices.Windows
|
||||
commandDescriptor.responseType = SdResponseType.R5;
|
||||
if (flags.HasFlag(MmcFlags.ResponseR6)) commandDescriptor.responseType = SdResponseType.R6;
|
||||
|
||||
byte[] commandB = new byte[commandData.size + commandData.protocolArgumentSize +
|
||||
var commandB = new byte[commandData.size + commandData.protocolArgumentSize +
|
||||
commandData.deviceDataBufferSize];
|
||||
IntPtr hBuf = Marshal.AllocHGlobal(commandB.Length);
|
||||
|
||||
Array.Copy(buffer, 0, commandB, commandData.size + commandData.protocolArgumentSize, buffer.Length);
|
||||
var hBuf = Marshal.AllocHGlobal(commandB.Length);
|
||||
Marshal.StructureToPtr(commandData, hBuf, true);
|
||||
IntPtr descriptorOffset = IntPtr.Add(hBuf, commandData.size);
|
||||
var descriptorOffset = IntPtr.Add(hBuf, commandData.size);
|
||||
Marshal.StructureToPtr(commandDescriptor, descriptorOffset, true);
|
||||
Marshal.Copy(hBuf, commandB, 0, commandB.Length);
|
||||
Marshal.FreeHGlobal(hBuf);
|
||||
|
||||
int error = 0;
|
||||
DateTime start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB, (uint)commandB.Length,
|
||||
var error = 0;
|
||||
var start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB,
|
||||
(uint) commandB.Length,
|
||||
commandB, (uint) commandB.Length, out _, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
var end = DateTime.Now;
|
||||
|
||||
if (sense) error = Marshal.GetLastWin32Error();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user