REFACTOR: Fixed MOST name inconsistencies.

This commit is contained in:
2017-12-20 17:15:26 +00:00
parent 542520f5cd
commit a4650c61aa
428 changed files with 16205 additions and 16320 deletions

View File

@@ -63,43 +63,43 @@ namespace DiscImageChef.Devices.Windows
if(buffer == null) return -1;
ScsiPassThroughDirectAndSenseBuffer sptd_sb = new ScsiPassThroughDirectAndSenseBuffer();
sptd_sb.sptd = new ScsiPassThroughDirect();
sptd_sb.SenseBuf = new byte[32];
sptd_sb.sptd.Cdb = new byte[16];
Array.Copy(cdb, sptd_sb.sptd.Cdb, cdb.Length);
sptd_sb.sptd.Length = (ushort)Marshal.SizeOf(sptd_sb.sptd);
sptd_sb.sptd.CdbLength = (byte)cdb.Length;
sptd_sb.sptd.SenseInfoLength = (byte)sptd_sb.SenseBuf.Length;
sptd_sb.sptd.DataIn = direction;
sptd_sb.sptd.DataTransferLength = (uint)buffer.Length;
sptd_sb.sptd.TimeOutValue = timeout;
sptd_sb.sptd.DataBuffer = Marshal.AllocHGlobal(buffer.Length);
sptd_sb.sptd.SenseInfoOffset = (uint)Marshal.SizeOf(sptd_sb.sptd);
ScsiPassThroughDirectAndSenseBuffer sptdSb = new ScsiPassThroughDirectAndSenseBuffer();
sptdSb.sptd = new ScsiPassThroughDirect();
sptdSb.SenseBuf = new byte[32];
sptdSb.sptd.Cdb = new byte[16];
Array.Copy(cdb, sptdSb.sptd.Cdb, cdb.Length);
sptdSb.sptd.Length = (ushort)Marshal.SizeOf(sptdSb.sptd);
sptdSb.sptd.CdbLength = (byte)cdb.Length;
sptdSb.sptd.SenseInfoLength = (byte)sptdSb.SenseBuf.Length;
sptdSb.sptd.DataIn = direction;
sptdSb.sptd.DataTransferLength = (uint)buffer.Length;
sptdSb.sptd.TimeOutValue = timeout;
sptdSb.sptd.DataBuffer = Marshal.AllocHGlobal(buffer.Length);
sptdSb.sptd.SenseInfoOffset = (uint)Marshal.SizeOf(sptdSb.sptd);
uint k = 0;
int error = 0;
Marshal.Copy(buffer, 0, sptd_sb.sptd.DataBuffer, buffer.Length);
Marshal.Copy(buffer, 0, sptdSb.sptd.DataBuffer, buffer.Length);
DateTime start = DateTime.Now;
bool hasError = !Extern.DeviceIoControlScsi(fd, WindowsIoctl.IOCTL_SCSI_PASS_THROUGH_DIRECT, ref sptd_sb,
(uint)Marshal.SizeOf(sptd_sb), ref sptd_sb,
(uint)Marshal.SizeOf(sptd_sb), ref k, IntPtr.Zero);
bool 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;
if(hasError) error = Marshal.GetLastWin32Error();
Marshal.Copy(sptd_sb.sptd.DataBuffer, buffer, 0, buffer.Length);
Marshal.Copy(sptdSb.sptd.DataBuffer, buffer, 0, buffer.Length);
sense |= sptd_sb.sptd.ScsiStatus != 0;
sense |= sptdSb.sptd.ScsiStatus != 0;
senseBuffer = new byte[32];
Array.Copy(sptd_sb.SenseBuf, senseBuffer, 32);
Array.Copy(sptdSb.SenseBuf, senseBuffer, 32);
duration = (end - start).TotalMilliseconds;
Marshal.FreeHGlobal(sptd_sb.sptd.DataBuffer);
Marshal.FreeHGlobal(sptdSb.sptd.DataBuffer);
return error;
}
@@ -116,7 +116,7 @@ namespace DiscImageChef.Devices.Windows
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
AtaPassThroughDirectWithBuffer aptd_buf = new AtaPassThroughDirectWithBuffer
AtaPassThroughDirectWithBuffer aptdBuf = new AtaPassThroughDirectWithBuffer
{
aptd = new AtaPassThroughDirect
{
@@ -140,49 +140,49 @@ namespace DiscImageChef.Devices.Windows
};
if(protocol == AtaProtocol.PioIn || protocol == AtaProtocol.UDmaIn || protocol == AtaProtocol.Dma)
aptd_buf.aptd.AtaFlags = AtaFlags.DataIn;
aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
else if(protocol == AtaProtocol.PioOut || protocol == AtaProtocol.UDmaOut)
aptd_buf.aptd.AtaFlags = AtaFlags.DataOut;
aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
switch(protocol)
{
case AtaProtocol.Dma:
case AtaProtocol.DmaQueued:
case AtaProtocol.FPDma:
case AtaProtocol.FpDma:
case AtaProtocol.UDmaIn:
case AtaProtocol.UDmaOut:
aptd_buf.aptd.AtaFlags |= AtaFlags.DMA;
aptdBuf.aptd.AtaFlags |= AtaFlags.Dma;
break;
}
// Unknown if needed
aptd_buf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
uint k = 0;
int error = 0;
Array.Copy(buffer, 0, aptd_buf.dataBuffer, 0, buffer.Length);
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
DateTime start = DateTime.Now;
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IOCTL_ATA_PASS_THROUGH, ref aptd_buf,
(uint)Marshal.SizeOf(aptd_buf), ref aptd_buf,
(uint)Marshal.SizeOf(aptd_buf), ref k, IntPtr.Zero);
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;
if(sense) error = Marshal.GetLastWin32Error();
Array.Copy(aptd_buf.dataBuffer, 0, buffer, 0, buffer.Length);
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
duration = (end - start).TotalMilliseconds;
errorRegisters.command = aptd_buf.aptd.CurrentTaskFile.Command;
errorRegisters.cylinderHigh = aptd_buf.aptd.CurrentTaskFile.CylinderHigh;
errorRegisters.cylinderLow = aptd_buf.aptd.CurrentTaskFile.CylinderLow;
errorRegisters.deviceHead = aptd_buf.aptd.CurrentTaskFile.DeviceHead;
errorRegisters.error = aptd_buf.aptd.CurrentTaskFile.Error;
errorRegisters.sector = aptd_buf.aptd.CurrentTaskFile.SectorNumber;
errorRegisters.sectorCount = aptd_buf.aptd.CurrentTaskFile.SectorCount;
errorRegisters.status = aptd_buf.aptd.CurrentTaskFile.Status;
errorRegisters.command = aptdBuf.aptd.CurrentTaskFile.Command;
errorRegisters.cylinderHigh = aptdBuf.aptd.CurrentTaskFile.CylinderHigh;
errorRegisters.cylinderLow = aptdBuf.aptd.CurrentTaskFile.CylinderLow;
errorRegisters.deviceHead = aptdBuf.aptd.CurrentTaskFile.DeviceHead;
errorRegisters.error = aptdBuf.aptd.CurrentTaskFile.Error;
errorRegisters.sector = aptdBuf.aptd.CurrentTaskFile.SectorNumber;
errorRegisters.sectorCount = aptdBuf.aptd.CurrentTaskFile.SectorCount;
errorRegisters.status = aptdBuf.aptd.CurrentTaskFile.Status;
sense = errorRegisters.error != 0 || (errorRegisters.status & 0xA5) != 0;
@@ -201,7 +201,7 @@ namespace DiscImageChef.Devices.Windows
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
AtaPassThroughDirectWithBuffer aptd_buf = new AtaPassThroughDirectWithBuffer
AtaPassThroughDirectWithBuffer aptdBuf = new AtaPassThroughDirectWithBuffer
{
aptd = new AtaPassThroughDirect
{
@@ -225,49 +225,49 @@ namespace DiscImageChef.Devices.Windows
};
if(protocol == AtaProtocol.PioIn || protocol == AtaProtocol.UDmaIn || protocol == AtaProtocol.Dma)
aptd_buf.aptd.AtaFlags = AtaFlags.DataIn;
aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
else if(protocol == AtaProtocol.PioOut || protocol == AtaProtocol.UDmaOut)
aptd_buf.aptd.AtaFlags = AtaFlags.DataOut;
aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
switch(protocol)
{
case AtaProtocol.Dma:
case AtaProtocol.DmaQueued:
case AtaProtocol.FPDma:
case AtaProtocol.FpDma:
case AtaProtocol.UDmaIn:
case AtaProtocol.UDmaOut:
aptd_buf.aptd.AtaFlags |= AtaFlags.DMA;
aptdBuf.aptd.AtaFlags |= AtaFlags.Dma;
break;
}
// Unknown if needed
aptd_buf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
uint k = 0;
int error = 0;
Array.Copy(buffer, 0, aptd_buf.dataBuffer, 0, buffer.Length);
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
DateTime start = DateTime.Now;
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IOCTL_ATA_PASS_THROUGH, ref aptd_buf,
(uint)Marshal.SizeOf(aptd_buf), ref aptd_buf,
(uint)Marshal.SizeOf(aptd_buf), ref k, IntPtr.Zero);
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;
if(sense) error = Marshal.GetLastWin32Error();
Array.Copy(aptd_buf.dataBuffer, 0, buffer, 0, buffer.Length);
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
duration = (end - start).TotalMilliseconds;
errorRegisters.command = aptd_buf.aptd.CurrentTaskFile.Command;
errorRegisters.lbaHigh = aptd_buf.aptd.CurrentTaskFile.CylinderHigh;
errorRegisters.lbaMid = aptd_buf.aptd.CurrentTaskFile.CylinderLow;
errorRegisters.deviceHead = aptd_buf.aptd.CurrentTaskFile.DeviceHead;
errorRegisters.error = aptd_buf.aptd.CurrentTaskFile.Error;
errorRegisters.lbaLow = aptd_buf.aptd.CurrentTaskFile.SectorNumber;
errorRegisters.sectorCount = aptd_buf.aptd.CurrentTaskFile.SectorCount;
errorRegisters.status = aptd_buf.aptd.CurrentTaskFile.Status;
errorRegisters.command = aptdBuf.aptd.CurrentTaskFile.Command;
errorRegisters.lbaHigh = aptdBuf.aptd.CurrentTaskFile.CylinderHigh;
errorRegisters.lbaMid = aptdBuf.aptd.CurrentTaskFile.CylinderLow;
errorRegisters.deviceHead = aptdBuf.aptd.CurrentTaskFile.DeviceHead;
errorRegisters.error = aptdBuf.aptd.CurrentTaskFile.Error;
errorRegisters.lbaLow = aptdBuf.aptd.CurrentTaskFile.SectorNumber;
errorRegisters.sectorCount = aptdBuf.aptd.CurrentTaskFile.SectorCount;
errorRegisters.status = aptdBuf.aptd.CurrentTaskFile.Status;
sense = errorRegisters.error != 0 || (errorRegisters.status & 0xA5) != 0;
@@ -286,7 +286,7 @@ namespace DiscImageChef.Devices.Windows
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
AtaPassThroughDirectWithBuffer aptd_buf = new AtaPassThroughDirectWithBuffer
AtaPassThroughDirectWithBuffer aptdBuf = new AtaPassThroughDirectWithBuffer
{
aptd = new AtaPassThroughDirect
{
@@ -318,53 +318,53 @@ namespace DiscImageChef.Devices.Windows
};
if(protocol == AtaProtocol.PioIn || protocol == AtaProtocol.UDmaIn || protocol == AtaProtocol.Dma)
aptd_buf.aptd.AtaFlags = AtaFlags.DataIn;
aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
else if(protocol == AtaProtocol.PioOut || protocol == AtaProtocol.UDmaOut)
aptd_buf.aptd.AtaFlags = AtaFlags.DataOut;
aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
switch(protocol)
{
case AtaProtocol.Dma:
case AtaProtocol.DmaQueued:
case AtaProtocol.FPDma:
case AtaProtocol.FpDma:
case AtaProtocol.UDmaIn:
case AtaProtocol.UDmaOut:
aptd_buf.aptd.AtaFlags |= AtaFlags.DMA;
aptdBuf.aptd.AtaFlags |= AtaFlags.Dma;
break;
}
// Unknown if needed
aptd_buf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
aptdBuf.aptd.AtaFlags |= AtaFlags.DrdyRequired;
uint k = 0;
int error = 0;
Array.Copy(buffer, 0, aptd_buf.dataBuffer, 0, buffer.Length);
Array.Copy(buffer, 0, aptdBuf.dataBuffer, 0, buffer.Length);
DateTime start = DateTime.Now;
sense = !Extern.DeviceIoControlAta(fd, WindowsIoctl.IOCTL_ATA_PASS_THROUGH, ref aptd_buf,
(uint)Marshal.SizeOf(aptd_buf), ref aptd_buf,
(uint)Marshal.SizeOf(aptd_buf), ref k, IntPtr.Zero);
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;
if(sense) error = Marshal.GetLastWin32Error();
Array.Copy(aptd_buf.dataBuffer, 0, buffer, 0, buffer.Length);
Array.Copy(aptdBuf.dataBuffer, 0, buffer, 0, buffer.Length);
duration = (end - start).TotalMilliseconds;
errorRegisters.sectorCount = (ushort)((aptd_buf.aptd.PreviousTaskFile.SectorCount << 8) +
aptd_buf.aptd.CurrentTaskFile.SectorCount);
errorRegisters.lbaLow = (ushort)((aptd_buf.aptd.PreviousTaskFile.SectorNumber << 8) +
aptd_buf.aptd.CurrentTaskFile.SectorNumber);
errorRegisters.lbaMid = (ushort)((aptd_buf.aptd.PreviousTaskFile.CylinderLow << 8) +
aptd_buf.aptd.CurrentTaskFile.CylinderLow);
errorRegisters.lbaHigh = (ushort)((aptd_buf.aptd.PreviousTaskFile.CylinderHigh << 8) +
aptd_buf.aptd.CurrentTaskFile.CylinderHigh);
errorRegisters.command = aptd_buf.aptd.CurrentTaskFile.Command;
errorRegisters.deviceHead = aptd_buf.aptd.CurrentTaskFile.DeviceHead;
errorRegisters.error = aptd_buf.aptd.CurrentTaskFile.Error;
errorRegisters.status = aptd_buf.aptd.CurrentTaskFile.Status;
errorRegisters.sectorCount = (ushort)((aptdBuf.aptd.PreviousTaskFile.SectorCount << 8) +
aptdBuf.aptd.CurrentTaskFile.SectorCount);
errorRegisters.lbaLow = (ushort)((aptdBuf.aptd.PreviousTaskFile.SectorNumber << 8) +
aptdBuf.aptd.CurrentTaskFile.SectorNumber);
errorRegisters.lbaMid = (ushort)((aptdBuf.aptd.PreviousTaskFile.CylinderLow << 8) +
aptdBuf.aptd.CurrentTaskFile.CylinderLow);
errorRegisters.lbaHigh = (ushort)((aptdBuf.aptd.PreviousTaskFile.CylinderHigh << 8) +
aptdBuf.aptd.CurrentTaskFile.CylinderHigh);
errorRegisters.command = aptdBuf.aptd.CurrentTaskFile.Command;
errorRegisters.deviceHead = aptdBuf.aptd.CurrentTaskFile.DeviceHead;
errorRegisters.error = aptdBuf.aptd.CurrentTaskFile.Error;
errorRegisters.status = aptdBuf.aptd.CurrentTaskFile.Status;
sense = errorRegisters.error != 0 || (errorRegisters.status & 0xA5) != 0;
@@ -403,7 +403,7 @@ namespace DiscImageChef.Devices.Windows
Array.Copy(buffer, 0, iptd.DataBuffer, 0, buffer.Length);
DateTime start = DateTime.Now;
sense = !Extern.DeviceIoControlIde(fd, WindowsIoctl.IOCTL_IDE_PASS_THROUGH, ref iptd,
sense = !Extern.DeviceIoControlIde(fd, WindowsIoctl.IoctlIdePassThrough, ref iptd,
(uint)Marshal.SizeOf(iptd), ref iptd, (uint)Marshal.SizeOf(iptd), ref k,
IntPtr.Zero);
DateTime end = DateTime.Now;
@@ -463,7 +463,7 @@ namespace DiscImageChef.Devices.Windows
Array.Copy(buffer, 0, iptd.DataBuffer, 0, buffer.Length);
DateTime start = DateTime.Now;
sense = !Extern.DeviceIoControlIde(fd, WindowsIoctl.IOCTL_IDE_PASS_THROUGH, ref iptd,
sense = !Extern.DeviceIoControlIde(fd, WindowsIoctl.IoctlIdePassThrough, ref iptd,
(uint)Marshal.SizeOf(iptd), ref iptd, (uint)Marshal.SizeOf(iptd), ref k,
IntPtr.Zero);
DateTime end = DateTime.Now;
@@ -494,7 +494,7 @@ namespace DiscImageChef.Devices.Windows
StorageDeviceNumber sdn = new StorageDeviceNumber();
sdn.deviceNumber = -1;
uint k = 0;
if(!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IOCTL_STORAGE_GET_DEVICE_NUMBER,
if(!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IoctlStorageGetDeviceNumber,
IntPtr.Zero, 0, ref sdn, (uint)Marshal.SizeOf(sdn), ref k,
IntPtr.Zero)) { return uint.MaxValue; }
@@ -507,7 +507,7 @@ namespace DiscImageChef.Devices.Windows
if(devNumber == uint.MaxValue) return null;
SafeFileHandle hDevInfo = Extern.SetupDiGetClassDevs(ref Consts.GUID_DEVINTERFACE_DISK, IntPtr.Zero,
SafeFileHandle hDevInfo = Extern.SetupDiGetClassDevs(ref Consts.GuidDevinterfaceDisk, IntPtr.Zero,
IntPtr.Zero,
DeviceGetClassFlags.Present |
DeviceGetClassFlags.DeviceInterface);
@@ -524,7 +524,7 @@ namespace DiscImageChef.Devices.Windows
{
buffer = new byte[2048];
if(!Extern.SetupDiEnumDeviceInterfaces(hDevInfo, IntPtr.Zero, ref Consts.GUID_DEVINTERFACE_DISK, index,
if(!Extern.SetupDiEnumDeviceInterfaces(hDevInfo, IntPtr.Zero, ref Consts.GuidDevinterfaceDisk, index,
ref spdid)) break;
uint size = 0;
@@ -581,9 +581,9 @@ namespace DiscImageChef.Devices.Windows
SffdiskQueryDeviceProtocolData queryData1 = new SffdiskQueryDeviceProtocolData();
queryData1.size = (ushort)Marshal.SizeOf(queryData1);
uint bytesReturned;
Extern.DeviceIoControl(fd, WindowsIoctl.IOCTL_SFFDISK_QUERY_DEVICE_PROTOCOL, IntPtr.Zero, 0, ref queryData1,
Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskQueryDeviceProtocol, IntPtr.Zero, 0, ref queryData1,
queryData1.size, out bytesReturned, IntPtr.Zero);
return queryData1.protocolGuid.Equals(Consts.GUID_SFF_PROTOCOL_SD);
return queryData1.protocolGuid.Equals(Consts.GuidSffProtocolSd);
}
/// <summary>
@@ -617,46 +617,46 @@ namespace DiscImageChef.Devices.Windows
commandDescriptor.commandCode = (byte)command;
commandDescriptor.cmdClass = isApplication ? SdCommandClass.AppCmd : SdCommandClass.Standard;
commandDescriptor.transferDirection = write ? SdTransferDirection.Write : SdTransferDirection.Read;
commandDescriptor.transferType = flags.HasFlag(MmcFlags.CommandADTC)
commandDescriptor.transferType = flags.HasFlag(MmcFlags.CommandAdtc)
? SdTransferType.SingleBlock
: SdTransferType.CmdOnly;
commandDescriptor.responseType = 0;
if(flags.HasFlag(MmcFlags.Response_R1) || flags.HasFlag(MmcFlags.ResponseSPI_R1))
if(flags.HasFlag(MmcFlags.ResponseR1) || flags.HasFlag(MmcFlags.ResponseSpiR1))
commandDescriptor.responseType = SdResponseType.R1;
if(flags.HasFlag(MmcFlags.Response_R1b) || flags.HasFlag(MmcFlags.ResponseSPI_R1b))
if(flags.HasFlag(MmcFlags.ResponseR1B) || flags.HasFlag(MmcFlags.ResponseSpiR1B))
commandDescriptor.responseType = SdResponseType.R1b;
if(flags.HasFlag(MmcFlags.Response_R2) || flags.HasFlag(MmcFlags.ResponseSPI_R2))
if(flags.HasFlag(MmcFlags.ResponseR2) || flags.HasFlag(MmcFlags.ResponseSpiR2))
commandDescriptor.responseType = SdResponseType.R2;
if(flags.HasFlag(MmcFlags.Response_R3) || flags.HasFlag(MmcFlags.ResponseSPI_R3))
if(flags.HasFlag(MmcFlags.ResponseR3) || flags.HasFlag(MmcFlags.ResponseSpiR3))
commandDescriptor.responseType = SdResponseType.R3;
if(flags.HasFlag(MmcFlags.Response_R4) || flags.HasFlag(MmcFlags.ResponseSPI_R4))
if(flags.HasFlag(MmcFlags.ResponseR4) || flags.HasFlag(MmcFlags.ResponseSpiR4))
commandDescriptor.responseType = SdResponseType.R4;
if(flags.HasFlag(MmcFlags.Response_R5) || flags.HasFlag(MmcFlags.ResponseSPI_R5))
if(flags.HasFlag(MmcFlags.ResponseR5) || flags.HasFlag(MmcFlags.ResponseSpiR5))
commandDescriptor.responseType = SdResponseType.R5;
if(flags.HasFlag(MmcFlags.Response_R6)) commandDescriptor.responseType = SdResponseType.R6;
if(flags.HasFlag(MmcFlags.ResponseR6)) commandDescriptor.responseType = SdResponseType.R6;
byte[] command_b = new byte[commandData.size + commandData.protocolArgumentSize +
byte[] commandB = new byte[commandData.size + commandData.protocolArgumentSize +
commandData.deviceDataBufferSize];
IntPtr hBuf = Marshal.AllocHGlobal(command_b.Length);
IntPtr hBuf = Marshal.AllocHGlobal(commandB.Length);
Marshal.StructureToPtr(commandData, hBuf, true);
IntPtr descriptorOffset = new IntPtr(hBuf.ToInt32() + commandData.size);
Marshal.StructureToPtr(commandDescriptor, descriptorOffset, true);
Marshal.Copy(hBuf, command_b, 0, command_b.Length);
Marshal.Copy(hBuf, commandB, 0, commandB.Length);
Marshal.FreeHGlobal(hBuf);
uint bytesReturned;
int error = 0;
DateTime start = DateTime.Now;
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IOCTL_SFFDISK_DEVICE_COMMAND, command_b,
(uint)command_b.Length, command_b, (uint)command_b.Length,
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB,
(uint)commandB.Length, commandB, (uint)commandB.Length,
out bytesReturned, IntPtr.Zero);
DateTime end = DateTime.Now;
if(sense) error = Marshal.GetLastWin32Error();
buffer = new byte[blockSize * blocks];
Buffer.BlockCopy(command_b, command_b.Length - buffer.Length, buffer, 0, buffer.Length);
Buffer.BlockCopy(commandB, commandB.Length - buffer.Length, buffer, 0, buffer.Length);
response = new uint[4];
duration = (end - start).TotalMilliseconds;

View File

@@ -213,11 +213,11 @@ namespace DiscImageChef.Devices.Windows
/// <summary>
/// FILE_READ_EA
/// </summary>
ReadEA = 0x0008,
ReadEa = 0x0008,
/// <summary>
/// FILE_WRITE_EA
/// </summary>
WriteEA = 0x0010,
WriteEa = 0x0010,
/// <summary>
/// FILE_EXECUTE
/// </summary>
@@ -326,25 +326,25 @@ namespace DiscImageChef.Devices.Windows
enum WindowsIoctl : uint
{
IOCTL_ATA_PASS_THROUGH = 0x4D02C,
IOCTL_ATA_PASS_THROUGH_DIRECT = 0x4D030,
IoctlAtaPassThrough = 0x4D02C,
IoctlAtaPassThroughDirect = 0x4D030,
/// <summary>
/// ScsiPassThrough
/// </summary>
IOCTL_SCSI_PASS_THROUGH = 0x4D004,
IoctlScsiPassThrough = 0x4D004,
/// <summary>
/// ScsiPassThroughDirect
/// </summary>
IOCTL_SCSI_PASS_THROUGH_DIRECT = 0x4D014,
IoctlScsiPassThroughDirect = 0x4D014,
/// <summary>
/// ScsiGetAddress
/// </summary>
IOCTL_SCSI_GET_ADDRESS = 0x41018,
IOCTL_STORAGE_QUERY_PROPERTY = 0x2D1400,
IOCTL_IDE_PASS_THROUGH = 0x4D028,
IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080,
IOCTL_SFFDISK_QUERY_DEVICE_PROTOCOL = 0x71E80,
IOCTL_SFFDISK_DEVICE_COMMAND = 0x79E84,
IoctlScsiGetAddress = 0x41018,
IoctlStorageQueryProperty = 0x2D1400,
IoctlIdePassThrough = 0x4D028,
IoctlStorageGetDeviceNumber = 0x2D1080,
IoctlSffdiskQueryDeviceProtocol = 0x71E80,
IoctlSffdiskDeviceCommand = 0x79E84,
}
[Flags]
@@ -369,7 +369,7 @@ namespace DiscImageChef.Devices.Windows
/// <summary>
/// ATA_FLAGS_USE_DMA
/// </summary>
DMA = 0x10,
Dma = 0x10,
/// <summary>
/// ATA_FLAGS_NO_MULTIPLE
/// </summary>
@@ -389,7 +389,7 @@ namespace DiscImageChef.Devices.Windows
Trim = 8,
WriteAggregation = 9,
Telemetry = 10,
LBProvisioning = 11,
LbProvisioning = 11,
Power = 12,
Copyoffload = 13,
Resiliency = 14
@@ -495,8 +495,8 @@ namespace DiscImageChef.Devices.Windows
static class Consts
{
public static Guid GUID_SFF_PROTOCOL_SD = new Guid("AD7536A8-D055-4C40-AA4D-96312DDB6B38");
public static Guid GUID_DEVINTERFACE_DISK =
public static Guid GuidSffProtocolSd = new Guid("AD7536A8-D055-4C40-AA4D-96312DDB6B38");
public static Guid GuidDevinterfaceDisk =
new Guid(0x53F56307, 0xB6BF, 0x11D0, 0x94, 0xF2, 0x00, 0xA0, 0xC9, 0x1E, 0xFB, 0x8B);
}
}

View File

@@ -49,51 +49,51 @@ namespace DiscImageChef.Devices.Windows
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,
internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
uint nInBufferSize,
ref ScsiPassThroughDirectAndSenseBuffer OutBuffer,
ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
uint nOutBufferSize, ref uint pBytesReturned,
IntPtr Overlapped);
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 AtaPassThroughDirectWithBuffer inBuffer, uint nInBufferSize,
ref AtaPassThroughDirectWithBuffer 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,
internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
IntPtr inBuffer, uint nInBufferSize,
ref StorageDeviceNumber outBuffer,
uint nOutBufferSize, ref uint pBytesReturned,
IntPtr Overlapped);
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);
internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, 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,

View File

@@ -43,7 +43,7 @@ namespace DiscImageChef.Devices.Windows
{
internal static DeviceInfo[] GetList()
{
List<string> DeviceIDs = new List<string>();
List<string> deviceIDs = new List<string>();
try
{
@@ -51,17 +51,17 @@ namespace DiscImageChef.Devices.Windows
new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
ManagementObjectCollection objCol = mgmtObjSearcher.Get();
foreach(ManagementObject drive in objCol) DeviceIDs.Add((string)drive["DeviceID"]);
foreach(ManagementObject drive in objCol) deviceIDs.Add((string)drive["DeviceID"]);
mgmtObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_TapeDrive");
objCol = mgmtObjSearcher.Get();
foreach(ManagementObject drive in objCol) DeviceIDs.Add((string)drive["DeviceID"]);
foreach(ManagementObject drive in objCol) deviceIDs.Add((string)drive["DeviceID"]);
mgmtObjSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_CDROMDrive");
objCol = mgmtObjSearcher.Get();
foreach(ManagementObject drive in objCol) DeviceIDs.Add((string)drive["Drive"]);
foreach(ManagementObject drive in objCol) deviceIDs.Add((string)drive["Drive"]);
}
catch(Exception ex)
{
@@ -72,9 +72,9 @@ namespace DiscImageChef.Devices.Windows
#endif
}
List<DeviceInfo> dev_list = new List<DeviceInfo>();
List<DeviceInfo> devList = new List<DeviceInfo>();
foreach(string devId in DeviceIDs)
foreach(string devId in deviceIDs)
{
string physId = devId;
// TODO: This can be done better
@@ -92,56 +92,56 @@ namespace DiscImageChef.Devices.Windows
//descriptor.RawDeviceProperties = new byte[16384];
IntPtr descriptorPtr = Marshal.AllocHGlobal(1000);
byte[] descriptor_b = new byte[1000];
byte[] descriptorB = new byte[1000];
uint returned = 0;
int error = 0;
bool hasError = !Extern.DeviceIoControlStorageQuery(fd, WindowsIoctl.IOCTL_STORAGE_QUERY_PROPERTY,
bool hasError = !Extern.DeviceIoControlStorageQuery(fd, WindowsIoctl.IoctlStorageQueryProperty,
ref query, (uint)Marshal.SizeOf(query),
descriptorPtr, 1000, ref returned, IntPtr.Zero);
if(hasError) error = Marshal.GetLastWin32Error();
Marshal.Copy(descriptorPtr, descriptor_b, 0, 1000);
Marshal.Copy(descriptorPtr, descriptorB, 0, 1000);
if(hasError && error != 0) continue;
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor();
descriptor.Version = BitConverter.ToUInt32(descriptor_b, 0);
descriptor.Size = BitConverter.ToUInt32(descriptor_b, 4);
descriptor.DeviceType = descriptor_b[8];
descriptor.DeviceTypeModifier = descriptor_b[9];
descriptor.RemovableMedia = BitConverter.ToBoolean(descriptor_b, 10);
descriptor.CommandQueueing = BitConverter.ToBoolean(descriptor_b, 11);
descriptor.VendorIdOffset = BitConverter.ToUInt32(descriptor_b, 12);
descriptor.ProductIdOffset = BitConverter.ToUInt32(descriptor_b, 16);
descriptor.ProductRevisionOffset = BitConverter.ToUInt32(descriptor_b, 20);
descriptor.SerialNumberOffset = BitConverter.ToUInt32(descriptor_b, 24);
descriptor.BusType = (StorageBusType)BitConverter.ToUInt32(descriptor_b, 28);
descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptor_b, 32);
descriptor.Version = BitConverter.ToUInt32(descriptorB, 0);
descriptor.Size = BitConverter.ToUInt32(descriptorB, 4);
descriptor.DeviceType = descriptorB[8];
descriptor.DeviceTypeModifier = descriptorB[9];
descriptor.RemovableMedia = BitConverter.ToBoolean(descriptorB, 10);
descriptor.CommandQueueing = BitConverter.ToBoolean(descriptorB, 11);
descriptor.VendorIdOffset = BitConverter.ToUInt32(descriptorB, 12);
descriptor.ProductIdOffset = BitConverter.ToUInt32(descriptorB, 16);
descriptor.ProductRevisionOffset = BitConverter.ToUInt32(descriptorB, 20);
descriptor.SerialNumberOffset = BitConverter.ToUInt32(descriptorB, 24);
descriptor.BusType = (StorageBusType)BitConverter.ToUInt32(descriptorB, 28);
descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32);
DeviceInfo info = new DeviceInfo {path = physId, bus = descriptor.BusType.ToString()};
DeviceInfo info = new DeviceInfo {Path = physId, Bus = descriptor.BusType.ToString()};
if(descriptor.VendorIdOffset > 0)
info.vendor =
StringHandlers.CToString(descriptor_b, Encoding.ASCII, start: (int)descriptor.VendorIdOffset);
info.Vendor =
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: (int)descriptor.VendorIdOffset);
if(descriptor.ProductIdOffset > 0)
info.model =
StringHandlers.CToString(descriptor_b, Encoding.ASCII, start: (int)descriptor.ProductIdOffset);
info.Model =
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: (int)descriptor.ProductIdOffset);
// TODO: Get serial number of SCSI and USB devices, probably also FireWire (untested)
if(descriptor.SerialNumberOffset > 0)
info.serial =
StringHandlers.CToString(descriptor_b, Encoding.ASCII,
info.Serial =
StringHandlers.CToString(descriptorB, Encoding.ASCII,
start: (int)descriptor.SerialNumberOffset);
if(string.IsNullOrEmpty(info.vendor) || info.vendor == "ATA")
if(string.IsNullOrEmpty(info.Vendor) || info.Vendor == "ATA")
{
string[] pieces = info.model.Split(' ');
string[] pieces = info.Model.Split(' ');
if(pieces.Length > 1)
{
info.vendor = pieces[0];
info.model = info.model.Substring(pieces[0].Length + 1);
info.Vendor = pieces[0];
info.Model = info.Model.Substring(pieces[0].Length + 1);
}
}
@@ -157,15 +157,15 @@ namespace DiscImageChef.Devices.Windows
case StorageBusType.iSCSI:
case StorageBusType.SAS:
case StorageBusType.SATA:
info.supported = true;
info.Supported = true;
break;
}
Marshal.FreeHGlobal(descriptorPtr);
dev_list.Add(info);
devList.Add(info);
}
DeviceInfo[] devices = dev_list.ToArray();
DeviceInfo[] devices = devList.ToArray();
return devices;
}

View File

@@ -219,7 +219,7 @@ namespace DiscImageChef.Devices.Windows
}
[StructLayout(LayoutKind.Sequential)]
struct USB_SETUP_PACKET
struct UsbSetupPacket
{
public byte bmRequest;
public byte bRequest;
@@ -229,10 +229,10 @@ namespace DiscImageChef.Devices.Windows
}
[StructLayout(LayoutKind.Sequential)]
struct USB_DESCRIPTOR_REQUEST
struct UsbDescriptorRequest
{
public int ConnectionIndex;
public USB_SETUP_PACKET SetupPacket;
public UsbSetupPacket SetupPacket;
//public byte[] Data;
}

File diff suppressed because it is too large Load Diff

View File

@@ -46,63 +46,63 @@ namespace DiscImageChef.Devices.Windows
//
// Get a list of all connected devices
//
static internal List<USBDevice> GetConnectedDevices()
static internal List<UsbDevice> GetConnectedDevices()
{
List<USBDevice> DevList = new List<USBDevice>();
List<UsbDevice> devList = new List<UsbDevice>();
foreach(USBController Controller in GetHostControllers()) { ListHub(Controller.GetRootHub(), DevList); }
foreach(UsbController controller in GetHostControllers()) { ListHub(controller.GetRootHub(), devList); }
return DevList;
return devList;
}
// private routine for enumerating a hub
static void ListHub(USBHub Hub, List<USBDevice> DevList)
static void ListHub(UsbHub hub, List<UsbDevice> devList)
{
foreach(USBPort Port in Hub.GetPorts())
foreach(UsbPort port in hub.GetPorts())
{
if(Port.IsHub)
if(port.IsHub)
{
// recursive
ListHub(Port.GetHub(), DevList);
ListHub(port.GetHub(), devList);
}
else { if(Port.IsDeviceConnected) { DevList.Add(Port.GetDevice()); } }
else { if(port.IsDeviceConnected) { devList.Add(port.GetDevice()); } }
}
}
//
// Find a device based upon it's DriverKeyName
//
static internal USBDevice FindDeviceByDriverKeyName(string DriverKeyName)
static internal UsbDevice FindDeviceByDriverKeyName(string driverKeyName)
{
USBDevice FoundDevice = null;
UsbDevice foundDevice = null;
foreach(USBController Controller in GetHostControllers())
foreach(UsbController controller in GetHostControllers())
{
SearchHubDriverKeyName(Controller.GetRootHub(), ref FoundDevice, DriverKeyName);
if(FoundDevice != null) break;
SearchHubDriverKeyName(controller.GetRootHub(), ref foundDevice, driverKeyName);
if(foundDevice != null) break;
}
return FoundDevice;
return foundDevice;
}
// private routine for enumerating a hub
static void SearchHubDriverKeyName(USBHub Hub, ref USBDevice FoundDevice, string DriverKeyName)
static void SearchHubDriverKeyName(UsbHub hub, ref UsbDevice foundDevice, string driverKeyName)
{
foreach(USBPort Port in Hub.GetPorts())
foreach(UsbPort port in hub.GetPorts())
{
if(Port.IsHub)
if(port.IsHub)
{
// recursive
SearchHubDriverKeyName(Port.GetHub(), ref FoundDevice, DriverKeyName);
SearchHubDriverKeyName(port.GetHub(), ref foundDevice, driverKeyName);
}
else
{
if(Port.IsDeviceConnected)
if(port.IsDeviceConnected)
{
USBDevice Device = Port.GetDevice();
if(Device.DeviceDriverKey == DriverKeyName)
UsbDevice device = port.GetDevice();
if(device.DeviceDriverKey == driverKeyName)
{
FoundDevice = Device;
foundDevice = device;
break;
}
}
@@ -113,37 +113,37 @@ namespace DiscImageChef.Devices.Windows
//
// Find a device based upon it's Instance ID
//
static internal USBDevice FindDeviceByInstanceID(string InstanceID)
static internal UsbDevice FindDeviceByInstanceId(string instanceId)
{
USBDevice FoundDevice = null;
UsbDevice foundDevice = null;
foreach(USBController Controller in GetHostControllers())
foreach(UsbController controller in GetHostControllers())
{
SearchHubInstanceID(Controller.GetRootHub(), ref FoundDevice, InstanceID);
if(FoundDevice != null) break;
SearchHubInstanceId(controller.GetRootHub(), ref foundDevice, instanceId);
if(foundDevice != null) break;
}
return FoundDevice;
return foundDevice;
}
// private routine for enumerating a hub
static void SearchHubInstanceID(USBHub Hub, ref USBDevice FoundDevice, string InstanceID)
static void SearchHubInstanceId(UsbHub hub, ref UsbDevice foundDevice, string instanceId)
{
foreach(USBPort Port in Hub.GetPorts())
foreach(UsbPort port in hub.GetPorts())
{
if(Port.IsHub)
if(port.IsHub)
{
// recursive
SearchHubInstanceID(Port.GetHub(), ref FoundDevice, InstanceID);
SearchHubInstanceId(port.GetHub(), ref foundDevice, instanceId);
}
else
{
if(Port.IsDeviceConnected)
if(port.IsDeviceConnected)
{
USBDevice Device = Port.GetDevice();
if(Device.InstanceID == InstanceID)
UsbDevice device = port.GetDevice();
if(device.InstanceId == instanceId)
{
FoundDevice = Device;
foundDevice = device;
break;
}
}
@@ -152,9 +152,9 @@ namespace DiscImageChef.Devices.Windows
}
const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
internal const string GUID_DEVINTERFACE_DISK = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
internal const string GUID_DEVINTERFACE_CDROM = "53f56308-b6bf-11d0-94f2-00a0c91efb8b";
internal const string GUID_DEVINTERFACE_FLOPPY = "53f56311-b6bf-11d0-94f2-00a0c91efb8b";
internal const string GuidDevinterfaceDisk = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
internal const string GuidDevinterfaceCdrom = "53f56308-b6bf-11d0-94f2-00a0c91efb8b";
internal const string GuidDevinterfaceFloppy = "53f56311-b6bf-11d0-94f2-00a0c91efb8b";
//typedef struct _STORAGE_DEVICE_NUMBER {
// DEVICE_TYPE DeviceType;
@@ -162,7 +162,7 @@ namespace DiscImageChef.Devices.Windows
// ULONG PartitionNumber;
//} STORAGE_DEVICE_NUMBER, *PSTORAGE_DEVICE_NUMBER;
[StructLayout(LayoutKind.Sequential)]
struct STORAGE_DEVICE_NUMBER
struct StorageDeviceNumber
{
internal int DeviceType;
internal int DeviceNumber;
@@ -184,72 +184,72 @@ namespace DiscImageChef.Devices.Windows
// IN ULONG ulFlags
//);
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
static extern int CM_Get_Device_ID(IntPtr dnDevInst, IntPtr Buffer, int BufferLen, int ulFlags);
static extern int CM_Get_Device_ID(IntPtr dnDevInst, IntPtr buffer, int bufferLen, int ulFlags);
//
// Find a device based upon a Drive Letter
//
static internal USBDevice FindDriveLetter(string DriveLetter, string deviceGuid)
static internal UsbDevice FindDriveLetter(string driveLetter, string deviceGuid)
{
USBDevice FoundDevice = null;
string InstanceID = "";
UsbDevice foundDevice = null;
string instanceId = "";
// We start by getting the unique DeviceNumber of the given
// DriveLetter. We'll use this later to find a matching
// DevicePath "symbolic name"
int DevNum = GetDeviceNumber(@"\\.\" + DriveLetter.TrimEnd('\\'));
if(DevNum < 0) { return null; }
int devNum = GetDeviceNumber(@"\\.\" + driveLetter.TrimEnd('\\'));
if(devNum < 0) { return null; }
return FindDeviceNumber(DevNum, deviceGuid);
return FindDeviceNumber(devNum, deviceGuid);
}
static internal USBDevice FindDrivePath(string DrivePath, string deviceGuid)
static internal UsbDevice FindDrivePath(string drivePath, string deviceGuid)
{
USBDevice FoundDevice = null;
string InstanceID = "";
UsbDevice foundDevice = null;
string instanceId = "";
// We start by getting the unique DeviceNumber of the given
// DriveLetter. We'll use this later to find a matching
// DevicePath "symbolic name"
int DevNum = GetDeviceNumber(DrivePath);
if(DevNum < 0) { return null; }
int devNum = GetDeviceNumber(drivePath);
if(devNum < 0) { return null; }
return FindDeviceNumber(DevNum, deviceGuid);
return FindDeviceNumber(devNum, deviceGuid);
}
//
// Find a device based upon a Drive Letter
//
static internal USBDevice FindDeviceNumber(int DevNum, string deviceGuid)
static internal UsbDevice FindDeviceNumber(int devNum, string deviceGuid)
{
USBDevice FoundDevice = null;
string InstanceID = "";
UsbDevice foundDevice = null;
string instanceId = "";
Guid DiskGUID = new Guid(deviceGuid);
Guid diskGuid = new Guid(deviceGuid);
// We start at the "root" of the device tree and look for all
// devices that match the interface GUID of a disk
IntPtr h = SetupDiGetClassDevs(ref DiskGUID, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
IntPtr h = SetupDiGetClassDevs(ref diskGuid, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(h.ToInt32() != INVALID_HANDLE_VALUE)
{
bool Success = true;
bool success = true;
int i = 0;
do
{
// create a Device Interface Data structure
SP_DEVICE_INTERFACE_DATA dia = new SP_DEVICE_INTERFACE_DATA();
SpDeviceInterfaceData dia = new SpDeviceInterfaceData();
dia.cbSize = Marshal.SizeOf(dia);
// start the enumeration
Success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref DiskGUID, i, ref dia);
if(Success)
success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref diskGuid, i, ref dia);
if(success)
{
// build a DevInfo Data structure
SP_DEVINFO_DATA da = new SP_DEVINFO_DATA();
SpDevinfoData da = new SpDevinfoData();
da.cbSize = Marshal.SizeOf(da);
// build a Device Interface Detail Data structure
SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA();
SpDeviceInterfaceDetailData didd = new SpDeviceInterfaceDetailData();
didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)
// now we can get some more detailed information
@@ -260,7 +260,7 @@ namespace DiscImageChef.Devices.Windows
// Now that we have a DevicePath... we can use it to
// generate another DeviceNumber to see if it matches
// the one we're looking for.
if(GetDeviceNumber(didd.DevicePath) == DevNum)
if(GetDeviceNumber(didd.DevicePath) == devNum)
{
// current InstanceID is at the "USBSTOR" level, so we
// need up "move up" one level to get to the "USB" level
@@ -270,46 +270,46 @@ namespace DiscImageChef.Devices.Windows
// Now we get the InstanceID of the USB level device
IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(nBytes);
CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, nBytes, 0);
InstanceID = Marshal.PtrToStringAuto(ptrInstanceBuf);
instanceId = Marshal.PtrToStringAuto(ptrInstanceBuf);
Marshal.FreeHGlobal(ptrInstanceBuf);
System.Console.WriteLine("InstanceId: {0}", InstanceID);
System.Console.WriteLine("InstanceId: {0}", instanceId);
//break;
}
}
}
i++;
}
while(Success);
while(success);
SetupDiDestroyDeviceInfoList(h);
}
// Did we find an InterfaceID of a USB device?
if(InstanceID.StartsWith("USB\\")) { FoundDevice = FindDeviceByInstanceID(InstanceID); }
return FoundDevice;
if(instanceId.StartsWith("USB\\")) { foundDevice = FindDeviceByInstanceId(instanceId); }
return foundDevice;
}
// return a unique device number for the given device path
private static int GetDeviceNumber(string DevicePath)
private static int GetDeviceNumber(string devicePath)
{
int ans = -1;
IntPtr h = CreateFile(DevicePath.TrimEnd('\\'), 0, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
IntPtr h = CreateFile(devicePath.TrimEnd('\\'), 0, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if(h.ToInt32() != INVALID_HANDLE_VALUE)
{
int requiredSize;
STORAGE_DEVICE_NUMBER Sdn = new STORAGE_DEVICE_NUMBER();
int nBytes = Marshal.SizeOf(Sdn);
StorageDeviceNumber sdn = new StorageDeviceNumber();
int nBytes = Marshal.SizeOf(sdn);
IntPtr ptrSdn = Marshal.AllocHGlobal(nBytes);
if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out requiredSize,
IntPtr.Zero))
{
Sdn = (STORAGE_DEVICE_NUMBER)Marshal.PtrToStructure(ptrSdn, typeof(STORAGE_DEVICE_NUMBER));
sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber));
// just my way of combining the relevant parts of the
// STORAGE_DEVICE_NUMBER into a single number
ans = (Sdn.DeviceType << 8) + Sdn.DeviceNumber;
ans = (sdn.DeviceType << 8) + sdn.DeviceNumber;
}
Marshal.FreeHGlobal(ptrSdn);
CloseHandle(h);