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
|
namespace DiscImageChef.Devices.Windows
|
||||||
{
|
{
|
||||||
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
|
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
|
||||||
static class Command
|
internal static class Command
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a SCSI command
|
/// Sends a SCSI command
|
||||||
@@ -66,38 +66,38 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
duration = 0;
|
duration = 0;
|
||||||
sense = false;
|
sense = false;
|
||||||
|
|
||||||
if(buffer == null) return -1;
|
if (buffer == null) return -1;
|
||||||
|
|
||||||
ScsiPassThroughDirectAndSenseBuffer sptdSb = new ScsiPassThroughDirectAndSenseBuffer
|
var sptdSb = new ScsiPassThroughDirectAndSenseBuffer
|
||||||
{
|
{
|
||||||
SenseBuf = new byte[32],
|
SenseBuf = new byte[32],
|
||||||
sptd = new ScsiPassThroughDirect
|
sptd = new ScsiPassThroughDirect
|
||||||
{
|
{
|
||||||
Cdb = new byte[16],
|
Cdb = new byte[16],
|
||||||
CdbLength = (byte)cdb.Length,
|
CdbLength = (byte) cdb.Length,
|
||||||
SenseInfoLength = 32,
|
SenseInfoLength = 32,
|
||||||
DataIn = direction,
|
DataIn = direction,
|
||||||
DataTransferLength = (uint)buffer.Length,
|
DataTransferLength = (uint) buffer.Length,
|
||||||
TimeOutValue = timeout,
|
TimeOutValue = timeout,
|
||||||
DataBuffer = Marshal.AllocHGlobal(buffer.Length)
|
DataBuffer = Marshal.AllocHGlobal(buffer.Length)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
sptdSb.sptd.Length = (ushort)Marshal.SizeOf(sptdSb.sptd);
|
sptdSb.sptd.Length = (ushort) Marshal.SizeOf(sptdSb.sptd);
|
||||||
sptdSb.sptd.SenseInfoOffset = (uint)Marshal.SizeOf(sptdSb.sptd);
|
sptdSb.sptd.SenseInfoOffset = (uint) Marshal.SizeOf(sptdSb.sptd);
|
||||||
Array.Copy(cdb, sptdSb.sptd.Cdb, cdb.Length);
|
Array.Copy(cdb, sptdSb.sptd.Cdb, cdb.Length);
|
||||||
|
|
||||||
uint k = 0;
|
uint k = 0;
|
||||||
int error = 0;
|
var error = 0;
|
||||||
|
|
||||||
Marshal.Copy(buffer, 0, sptdSb.sptd.DataBuffer, buffer.Length);
|
Marshal.Copy(buffer, 0, sptdSb.sptd.DataBuffer, buffer.Length);
|
||||||
|
|
||||||
DateTime start = DateTime.Now;
|
var start = DateTime.Now;
|
||||||
bool hasError = !Extern.DeviceIoControlScsi(fd, WindowsIoctl.IoctlScsiPassThroughDirect, ref sptdSb,
|
var hasError = !Extern.DeviceIoControlScsi(fd, WindowsIoctl.IoctlScsiPassThroughDirect, ref sptdSb,
|
||||||
(uint)Marshal.SizeOf(sptdSb), ref sptdSb,
|
(uint) Marshal.SizeOf(sptdSb), ref sptdSb,
|
||||||
(uint)Marshal.SizeOf(sptdSb), ref k, IntPtr.Zero);
|
(uint) Marshal.SizeOf(sptdSb), ref k, IntPtr.Zero);
|
||||||
DateTime end = DateTime.Now;
|
var end = DateTime.Now;
|
||||||
|
|
||||||
if(hasError) error = Marshal.GetLastWin32Error();
|
if (hasError) error = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
Marshal.Copy(sptdSb.sptd.DataBuffer, buffer, 0, buffer.Length);
|
Marshal.Copy(sptdSb.sptd.DataBuffer, buffer, 0, buffer.Length);
|
||||||
|
|
||||||
@@ -134,18 +134,18 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
sense = false;
|
sense = false;
|
||||||
errorRegisters = new AtaErrorRegistersChs();
|
errorRegisters = new AtaErrorRegistersChs();
|
||||||
|
|
||||||
if(buffer == null) return -1;
|
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,
|
TimeOutValue = timeout,
|
||||||
DataBuffer = (IntPtr)offsetForBuffer,
|
DataBufferOffset = (IntPtr) offsetForBuffer,
|
||||||
Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughDirect)),
|
Length = (ushort) Marshal.SizeOf(typeof(AtaPassThroughEx)),
|
||||||
DataTransferLength = (uint)buffer.Length,
|
DataTransferLength = (uint) buffer.Length,
|
||||||
PreviousTaskFile = new AtaTaskFile(),
|
PreviousTaskFile = new AtaTaskFile(),
|
||||||
CurrentTaskFile = new AtaTaskFile
|
CurrentTaskFile = new AtaTaskFile
|
||||||
{
|
{
|
||||||
@@ -161,7 +161,7 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
dataBuffer = new byte[64 * 512]
|
dataBuffer = new byte[64 * 512]
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case AtaProtocol.PioIn:
|
case AtaProtocol.PioIn:
|
||||||
case AtaProtocol.UDmaIn:
|
case AtaProtocol.UDmaIn:
|
||||||
@@ -174,7 +174,7 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case AtaProtocol.Dma:
|
case AtaProtocol.Dma:
|
||||||
case AtaProtocol.DmaQueued:
|
case AtaProtocol.DmaQueued:
|
||||||
@@ -189,17 +189,17 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
||||||
|
|
||||||
uint k = 0;
|
uint k = 0;
|
||||||
int error = 0;
|
var error = 0;
|
||||||
|
|
||||||
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
|
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,
|
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IoctlAtaPassThrough, ref aptdBuf,
|
||||||
(uint)Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
(uint) Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
||||||
(uint)Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
(uint) Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
||||||
DateTime end = DateTime.Now;
|
var end = DateTime.Now;
|
||||||
|
|
||||||
if(sense) error = Marshal.GetLastWin32Error();
|
if (sense) error = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
|
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
|
||||||
|
|
||||||
@@ -239,18 +239,18 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
sense = false;
|
sense = false;
|
||||||
errorRegisters = new AtaErrorRegistersLba28();
|
errorRegisters = new AtaErrorRegistersLba28();
|
||||||
|
|
||||||
if(buffer == null) return -1;
|
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,
|
TimeOutValue = timeout,
|
||||||
DataBuffer = (IntPtr)offsetForBuffer,
|
DataBufferOffset = (IntPtr) offsetForBuffer,
|
||||||
Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughDirect)),
|
Length = (ushort) Marshal.SizeOf(typeof(AtaPassThroughEx)),
|
||||||
DataTransferLength = (uint)buffer.Length,
|
DataTransferLength = (uint) buffer.Length,
|
||||||
PreviousTaskFile = new AtaTaskFile(),
|
PreviousTaskFile = new AtaTaskFile(),
|
||||||
CurrentTaskFile = new AtaTaskFile
|
CurrentTaskFile = new AtaTaskFile
|
||||||
{
|
{
|
||||||
@@ -266,7 +266,7 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
dataBuffer = new byte[64 * 512]
|
dataBuffer = new byte[64 * 512]
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case AtaProtocol.PioIn:
|
case AtaProtocol.PioIn:
|
||||||
case AtaProtocol.UDmaIn:
|
case AtaProtocol.UDmaIn:
|
||||||
@@ -279,7 +279,7 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case AtaProtocol.Dma:
|
case AtaProtocol.Dma:
|
||||||
case AtaProtocol.DmaQueued:
|
case AtaProtocol.DmaQueued:
|
||||||
@@ -294,17 +294,17 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
||||||
|
|
||||||
uint k = 0;
|
uint k = 0;
|
||||||
int error = 0;
|
var error = 0;
|
||||||
|
|
||||||
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
|
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,
|
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IoctlAtaPassThrough, ref aptdBuf,
|
||||||
(uint)Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
(uint) Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
||||||
(uint)Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
(uint) Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
||||||
DateTime end = DateTime.Now;
|
var end = DateTime.Now;
|
||||||
|
|
||||||
if(sense) error = Marshal.GetLastWin32Error();
|
if (sense) error = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
|
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
|
||||||
|
|
||||||
@@ -344,42 +344,42 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
sense = false;
|
sense = false;
|
||||||
errorRegisters = new AtaErrorRegistersLba48();
|
errorRegisters = new AtaErrorRegistersLba48();
|
||||||
|
|
||||||
if(buffer == null) return -1;
|
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,
|
TimeOutValue = timeout,
|
||||||
DataBuffer = (IntPtr)offsetForBuffer,
|
DataBufferOffset = (IntPtr) offsetForBuffer,
|
||||||
Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughDirect)),
|
Length = (ushort) Marshal.SizeOf(typeof(AtaPassThroughEx)),
|
||||||
DataTransferLength = (uint)buffer.Length,
|
DataTransferLength = (uint) buffer.Length,
|
||||||
PreviousTaskFile =
|
PreviousTaskFile =
|
||||||
new AtaTaskFile
|
new AtaTaskFile
|
||||||
{
|
{
|
||||||
CylinderHigh = (byte)((registers.LbaHigh & 0xFF00) >> 8),
|
CylinderHigh = (byte) ((registers.LbaHigh & 0xFF00) >> 8),
|
||||||
CylinderLow = (byte)((registers.LbaMid & 0xFF00) >> 8),
|
CylinderLow = (byte) ((registers.LbaMid & 0xFF00) >> 8),
|
||||||
Features = (byte)((registers.Feature & 0xFF00) >> 8),
|
Features = (byte) ((registers.Feature & 0xFF00) >> 8),
|
||||||
SectorCount = (byte)((registers.SectorCount & 0xFF00) >> 8),
|
SectorCount = (byte) ((registers.SectorCount & 0xFF00) >> 8),
|
||||||
SectorNumber = (byte)((registers.LbaLow & 0xFF00) >> 8)
|
SectorNumber = (byte) ((registers.LbaLow & 0xFF00) >> 8)
|
||||||
},
|
},
|
||||||
CurrentTaskFile = new AtaTaskFile
|
CurrentTaskFile = new AtaTaskFile
|
||||||
{
|
{
|
||||||
Command = registers.Command,
|
Command = registers.Command,
|
||||||
CylinderHigh = (byte)(registers.LbaHigh & 0xFF),
|
CylinderHigh = (byte) (registers.LbaHigh & 0xFF),
|
||||||
CylinderLow = (byte)(registers.LbaMid & 0xFF),
|
CylinderLow = (byte) (registers.LbaMid & 0xFF),
|
||||||
DeviceHead = registers.DeviceHead,
|
DeviceHead = registers.DeviceHead,
|
||||||
Features = (byte)(registers.Feature & 0xFF),
|
Features = (byte) (registers.Feature & 0xFF),
|
||||||
SectorCount = (byte)(registers.SectorCount & 0xFF),
|
SectorCount = (byte) (registers.SectorCount & 0xFF),
|
||||||
SectorNumber = (byte)(registers.LbaLow & 0xFF)
|
SectorNumber = (byte) (registers.LbaLow & 0xFF)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dataBuffer = new byte[64 * 512]
|
dataBuffer = new byte[64 * 512]
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case AtaProtocol.PioIn:
|
case AtaProtocol.PioIn:
|
||||||
case AtaProtocol.UDmaIn:
|
case AtaProtocol.UDmaIn:
|
||||||
@@ -392,7 +392,7 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(protocol)
|
switch (protocol)
|
||||||
{
|
{
|
||||||
case AtaProtocol.Dma:
|
case AtaProtocol.Dma:
|
||||||
case AtaProtocol.DmaQueued:
|
case AtaProtocol.DmaQueued:
|
||||||
@@ -403,33 +403,35 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aptdBuf.aptd.AtaFlags |= AtaFlags.ExtendedCommand;
|
||||||
|
|
||||||
// Unknown if needed
|
// Unknown if needed
|
||||||
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
|
||||||
|
|
||||||
uint k = 0;
|
uint k = 0;
|
||||||
int error = 0;
|
var error = 0;
|
||||||
|
|
||||||
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
|
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,
|
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IoctlAtaPassThrough, ref aptdBuf,
|
||||||
(uint)Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
(uint) Marshal.SizeOf(aptdBuf), ref aptdBuf,
|
||||||
(uint)Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
(uint) Marshal.SizeOf(aptdBuf), ref k, IntPtr.Zero);
|
||||||
DateTime end = DateTime.Now;
|
var end = DateTime.Now;
|
||||||
|
|
||||||
if(sense) error = Marshal.GetLastWin32Error();
|
if (sense) error = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
|
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
|
||||||
|
|
||||||
duration = (end - start).TotalMilliseconds;
|
duration = (end - start).TotalMilliseconds;
|
||||||
|
|
||||||
errorRegisters.SectorCount = (ushort)((aptdBuf.aptd.PreviousTaskFile.SectorCount << 8) +
|
errorRegisters.SectorCount = (ushort) ((aptdBuf.aptd.PreviousTaskFile.SectorCount << 8) +
|
||||||
aptdBuf.aptd.CurrentTaskFile.SectorCount);
|
aptdBuf.aptd.CurrentTaskFile.SectorCount);
|
||||||
errorRegisters.LbaLow = (ushort)((aptdBuf.aptd.PreviousTaskFile.SectorNumber << 8) +
|
errorRegisters.LbaLow = (ushort) ((aptdBuf.aptd.PreviousTaskFile.SectorNumber << 8) +
|
||||||
aptdBuf.aptd.CurrentTaskFile.SectorNumber);
|
aptdBuf.aptd.CurrentTaskFile.SectorNumber);
|
||||||
errorRegisters.LbaMid = (ushort)((aptdBuf.aptd.PreviousTaskFile.CylinderLow << 8) +
|
errorRegisters.LbaMid = (ushort) ((aptdBuf.aptd.PreviousTaskFile.CylinderLow << 8) +
|
||||||
aptdBuf.aptd.CurrentTaskFile.CylinderLow);
|
aptdBuf.aptd.CurrentTaskFile.CylinderLow);
|
||||||
errorRegisters.LbaHigh = (ushort)((aptdBuf.aptd.PreviousTaskFile.CylinderHigh << 8) +
|
errorRegisters.LbaHigh = (ushort) ((aptdBuf.aptd.PreviousTaskFile.CylinderHigh << 8) +
|
||||||
aptdBuf.aptd.CurrentTaskFile.CylinderHigh);
|
aptdBuf.aptd.CurrentTaskFile.CylinderHigh);
|
||||||
errorRegisters.DeviceHead = aptdBuf.aptd.CurrentTaskFile.DeviceHead;
|
errorRegisters.DeviceHead = aptdBuf.aptd.CurrentTaskFile.DeviceHead;
|
||||||
errorRegisters.Error = aptdBuf.aptd.CurrentTaskFile.Error;
|
errorRegisters.Error = aptdBuf.aptd.CurrentTaskFile.Error;
|
||||||
@@ -445,15 +447,15 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deviceHandle">Device handle</param>
|
/// <param name="deviceHandle">Device handle</param>
|
||||||
/// <returns>Device number</returns>
|
/// <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;
|
uint k = 0;
|
||||||
if(!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IoctlStorageGetDeviceNumber,
|
if (!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IoctlStorageGetDeviceNumber,
|
||||||
IntPtr.Zero, 0, ref sdn, (uint)Marshal.SizeOf(sdn), ref k,
|
IntPtr.Zero, 0, ref sdn, (uint) Marshal.SizeOf(sdn), ref k,
|
||||||
IntPtr.Zero)) return uint.MaxValue;
|
IntPtr.Zero)) return uint.MaxValue;
|
||||||
|
|
||||||
return (uint)sdn.deviceNumber;
|
return (uint) sdn.deviceNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -463,11 +465,12 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
/// <returns><c>true</c> if SDHCI, false otherwise</returns>
|
/// <returns><c>true</c> if SDHCI, false otherwise</returns>
|
||||||
internal static bool IsSdhci(SafeFileHandle fd)
|
internal static bool IsSdhci(SafeFileHandle fd)
|
||||||
{
|
{
|
||||||
SffdiskQueryDeviceProtocolData queryData1 = new SffdiskQueryDeviceProtocolData();
|
var queryData1 = new SffdiskQueryDeviceProtocolData();
|
||||||
queryData1.size = (ushort)Marshal.SizeOf(queryData1);
|
queryData1.size = (ushort) Marshal.SizeOf(queryData1);
|
||||||
Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskQueryDeviceProtocol, IntPtr.Zero, 0, ref queryData1,
|
Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskQueryDeviceProtocol, IntPtr.Zero, 0, ref queryData1,
|
||||||
queryData1.size, out _, IntPtr.Zero);
|
queryData1.size, out _, IntPtr.Zero);
|
||||||
return queryData1.protocolGuid.Equals(Consts.GuidSffProtocolSd);
|
return queryData1.protocolGuid.Equals(Consts.GuidSffProtocolSd) ||
|
||||||
|
queryData1.protocolGuid.Equals(Consts.GuidSffProtocolMmc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -495,13 +498,13 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
out bool sense,
|
out bool sense,
|
||||||
uint timeout = 0)
|
uint timeout = 0)
|
||||||
{
|
{
|
||||||
SffdiskDeviceCommandData commandData = new SffdiskDeviceCommandData();
|
var commandData = new SffdiskDeviceCommandData();
|
||||||
SdCmdDescriptor commandDescriptor = new SdCmdDescriptor();
|
var commandDescriptor = new SdCmdDescriptor();
|
||||||
commandData.size = (ushort)Marshal.SizeOf(commandData);
|
commandData.size = (ushort) Marshal.SizeOf(commandData);
|
||||||
commandData.command = SffdiskDcmd.DeviceCommand;
|
commandData.command = SffdiskDcmd.DeviceCommand;
|
||||||
commandData.protocolArgumentSize = (ushort)Marshal.SizeOf(commandDescriptor);
|
commandData.protocolArgumentSize = (ushort) Marshal.SizeOf(commandDescriptor);
|
||||||
commandData.deviceDataBufferSize = blockSize * blocks;
|
commandData.deviceDataBufferSize = blockSize * blocks;
|
||||||
commandDescriptor.commandCode = (byte)command;
|
commandDescriptor.commandCode = (byte) command;
|
||||||
commandDescriptor.cmdClass = isApplication ? SdCommandClass.AppCmd : SdCommandClass.Standard;
|
commandDescriptor.cmdClass = isApplication ? SdCommandClass.AppCmd : SdCommandClass.Standard;
|
||||||
commandDescriptor.transferDirection = write ? SdTransferDirection.Write : SdTransferDirection.Read;
|
commandDescriptor.transferDirection = write ? SdTransferDirection.Write : SdTransferDirection.Read;
|
||||||
commandDescriptor.transferType = flags.HasFlag(MmcFlags.CommandAdtc)
|
commandDescriptor.transferType = flags.HasFlag(MmcFlags.CommandAdtc)
|
||||||
@@ -509,36 +512,39 @@ namespace DiscImageChef.Devices.Windows
|
|||||||
: SdTransferType.CmdOnly;
|
: SdTransferType.CmdOnly;
|
||||||
commandDescriptor.responseType = 0;
|
commandDescriptor.responseType = 0;
|
||||||
|
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR1) || flags.HasFlag(MmcFlags.ResponseSpiR1))
|
if (flags.HasFlag(MmcFlags.ResponseR1) || flags.HasFlag(MmcFlags.ResponseSpiR1))
|
||||||
commandDescriptor.responseType = SdResponseType.R1;
|
commandDescriptor.responseType = SdResponseType.R1;
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR1B) || flags.HasFlag(MmcFlags.ResponseSpiR1B))
|
if (flags.HasFlag(MmcFlags.ResponseR1B) || flags.HasFlag(MmcFlags.ResponseSpiR1B))
|
||||||
commandDescriptor.responseType = SdResponseType.R1b;
|
commandDescriptor.responseType = SdResponseType.R1b;
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR2) || flags.HasFlag(MmcFlags.ResponseSpiR2))
|
if (flags.HasFlag(MmcFlags.ResponseR2) || flags.HasFlag(MmcFlags.ResponseSpiR2))
|
||||||
commandDescriptor.responseType = SdResponseType.R2;
|
commandDescriptor.responseType = SdResponseType.R2;
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR3) || flags.HasFlag(MmcFlags.ResponseSpiR3))
|
if (flags.HasFlag(MmcFlags.ResponseR3) || flags.HasFlag(MmcFlags.ResponseSpiR3))
|
||||||
commandDescriptor.responseType = SdResponseType.R3;
|
commandDescriptor.responseType = SdResponseType.R3;
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR4) || flags.HasFlag(MmcFlags.ResponseSpiR4))
|
if (flags.HasFlag(MmcFlags.ResponseR4) || flags.HasFlag(MmcFlags.ResponseSpiR4))
|
||||||
commandDescriptor.responseType = SdResponseType.R4;
|
commandDescriptor.responseType = SdResponseType.R4;
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR5) || flags.HasFlag(MmcFlags.ResponseSpiR5))
|
if (flags.HasFlag(MmcFlags.ResponseR5) || flags.HasFlag(MmcFlags.ResponseSpiR5))
|
||||||
commandDescriptor.responseType = SdResponseType.R5;
|
commandDescriptor.responseType = SdResponseType.R5;
|
||||||
if(flags.HasFlag(MmcFlags.ResponseR6)) commandDescriptor.responseType = SdResponseType.R6;
|
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];
|
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);
|
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.StructureToPtr(commandDescriptor, descriptorOffset, true);
|
||||||
Marshal.Copy(hBuf, commandB, 0, commandB.Length);
|
Marshal.Copy(hBuf, commandB, 0, commandB.Length);
|
||||||
Marshal.FreeHGlobal(hBuf);
|
Marshal.FreeHGlobal(hBuf);
|
||||||
|
|
||||||
int error = 0;
|
var error = 0;
|
||||||
DateTime start = DateTime.Now;
|
var start = DateTime.Now;
|
||||||
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB, (uint)commandB.Length,
|
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB,
|
||||||
commandB, (uint)commandB.Length, out _, IntPtr.Zero);
|
(uint) commandB.Length,
|
||||||
DateTime end = DateTime.Now;
|
commandB, (uint) commandB.Length, out _, IntPtr.Zero);
|
||||||
|
var end = DateTime.Now;
|
||||||
|
|
||||||
if(sense) error = Marshal.GetLastWin32Error();
|
if (sense) error = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
buffer = new byte[blockSize * blocks];
|
buffer = new byte[blockSize * blocks];
|
||||||
Buffer.BlockCopy(commandB, commandB.Length - buffer.Length, buffer, 0, buffer.Length);
|
Buffer.BlockCopy(commandB, commandB.Length - buffer.Length, buffer, 0, buffer.Length);
|
||||||
|
|||||||
Reference in New Issue
Block a user