mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: All refactor in DiscImageChef.Devices.
This commit is contained in:
@@ -41,14 +41,12 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.ReadBuffer};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadBuffer;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ BUFFER took {0} ms.", duration);
|
||||
@@ -60,13 +58,11 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.ReadBufferDma};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadBufferDma;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.NoTransfer,
|
||||
ref buffer, timeout, false, out duration, out sense);
|
||||
ref buffer, timeout, false, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ BUFFER DMA took {0} ms.", duration);
|
||||
@@ -83,22 +79,21 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
|
||||
byte count, uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 256];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
SectorCount = count,
|
||||
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
|
||||
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
|
||||
LbaMid = (byte)((lba & 0xFF00) / 0x100),
|
||||
LbaLow = (byte)((lba & 0xFF) / 0x1),
|
||||
Command = retry ? (byte)AtaCommands.ReadDmaRetry : (byte)AtaCommands.ReadDma
|
||||
};
|
||||
|
||||
if(retry) registers.Command = (byte)AtaCommands.ReadDmaRetry;
|
||||
else registers.Command = (byte)AtaCommands.ReadDma;
|
||||
registers.SectorCount = count;
|
||||
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
|
||||
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
|
||||
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
|
||||
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out sense);
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ DMA took {0} ms.", duration);
|
||||
@@ -109,22 +104,22 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 256];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadMultiple,
|
||||
SectorCount = count,
|
||||
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
|
||||
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
|
||||
LbaMid = (byte)((lba & 0xFF00) / 0x100),
|
||||
LbaLow = (byte)((lba & 0xFF) / 0x1)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadMultiple;
|
||||
registers.SectorCount = count;
|
||||
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
|
||||
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
|
||||
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
|
||||
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE took {0} ms.", duration);
|
||||
@@ -137,15 +132,13 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
lba = 0;
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.ReadNativeMaxAddress};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadNativeMaxAddress;
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if((statusRegisters.Status & 0x23) == 0)
|
||||
@@ -171,23 +164,22 @@ namespace DiscImageChef.Devices
|
||||
public bool Read(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
|
||||
byte count, uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 256];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
SectorCount = count,
|
||||
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
|
||||
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
|
||||
LbaMid = (byte)((lba & 0xFF00) / 0x100),
|
||||
LbaLow = (byte)((lba & 0xFF) / 0x1),
|
||||
Command = retry ? (byte)AtaCommands.ReadRetry : (byte)AtaCommands.Read
|
||||
};
|
||||
|
||||
if(retry) registers.Command = (byte)AtaCommands.ReadRetry;
|
||||
else registers.Command = (byte)AtaCommands.Read;
|
||||
registers.SectorCount = count;
|
||||
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
|
||||
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
|
||||
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
|
||||
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ SECTORS took {0} ms.", duration);
|
||||
@@ -205,21 +197,21 @@ namespace DiscImageChef.Devices
|
||||
uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[blockSize];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
SectorCount = 1,
|
||||
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
|
||||
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
|
||||
LbaMid = (byte)((lba & 0xFF00) / 0x100),
|
||||
LbaLow = (byte)((lba & 0xFF) / 0x1),
|
||||
Command = retry ? (byte)AtaCommands.ReadLongRetry : (byte)AtaCommands.ReadLong
|
||||
};
|
||||
|
||||
if(retry) registers.Command = (byte)AtaCommands.ReadLongRetry;
|
||||
else registers.Command = (byte)AtaCommands.ReadLong;
|
||||
registers.SectorCount = 1;
|
||||
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
|
||||
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
|
||||
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
|
||||
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LONG took {0} ms.", duration);
|
||||
@@ -230,19 +222,20 @@ namespace DiscImageChef.Devices
|
||||
public bool Seek(out AtaErrorRegistersLba28 statusRegisters, uint lba, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Seek,
|
||||
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
|
||||
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
|
||||
LbaMid = (byte)((lba & 0xFF00) / 0x100),
|
||||
LbaLow = (byte)((lba & 0xFF) / 0x1)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Seek;
|
||||
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
|
||||
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
|
||||
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
|
||||
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SEEK took {0} ms.", duration);
|
||||
|
||||
@@ -41,16 +41,14 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
lba = 0;
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba48 registers =
|
||||
new AtaRegistersLba48 {Command = (byte)AtaCommands.NativeMaxAddress, Feature = 0x0000};
|
||||
|
||||
registers.Command = (byte)AtaCommands.NativeMaxAddress;
|
||||
registers.Feature = 0x0000;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if((statusRegisters.Status & 0x23) == 0)
|
||||
@@ -69,20 +67,20 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 65536];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadDmaExt,
|
||||
SectorCount = count,
|
||||
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
|
||||
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
|
||||
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadDmaExt;
|
||||
registers.SectorCount = count;
|
||||
registers.LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000);
|
||||
registers.LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000);
|
||||
registers.LbaLow = (ushort)((lba & 0xFFFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out sense);
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ DMA EXT took {0} ms.", duration);
|
||||
@@ -94,18 +92,19 @@ namespace DiscImageChef.Devices
|
||||
ushort pageNumber, ushort count, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadLogExt,
|
||||
SectorCount = count,
|
||||
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
|
||||
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadLogExt;
|
||||
registers.SectorCount = count;
|
||||
registers.LbaLow = (ushort)((pageNumber & 0xFF) * 0x100);
|
||||
registers.LbaLow += logAddress;
|
||||
registers.LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100);
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LOG EXT took {0} ms.", duration);
|
||||
@@ -117,17 +116,18 @@ namespace DiscImageChef.Devices
|
||||
ushort pageNumber, ushort count, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadLogDmaExt,
|
||||
SectorCount = count,
|
||||
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
|
||||
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadLogDmaExt;
|
||||
registers.SectorCount = count;
|
||||
registers.LbaLow = (ushort)((pageNumber & 0xFF) * 0x100);
|
||||
registers.LbaLow += logAddress;
|
||||
registers.LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100);
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out sense);
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LOG DMA EXT took {0} ms.", duration);
|
||||
@@ -138,21 +138,21 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 65536];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadMultipleExt,
|
||||
SectorCount = count,
|
||||
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
|
||||
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
|
||||
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadMultipleExt;
|
||||
registers.SectorCount = count;
|
||||
registers.LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000);
|
||||
registers.LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000);
|
||||
registers.LbaLow = (ushort)((lba & 0xFFFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE EXT took {0} ms.", duration);
|
||||
@@ -165,15 +165,13 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
lba = 0;
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48 {Command = (byte)AtaCommands.ReadNativeMaxAddressExt};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadNativeMaxAddressExt;
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if((statusRegisters.Status & 0x23) == 0)
|
||||
@@ -192,21 +190,21 @@ namespace DiscImageChef.Devices
|
||||
public bool Read(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 65536];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
|
||||
AtaRegistersLba48 registers = new AtaRegistersLba48
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadExt,
|
||||
SectorCount = count,
|
||||
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
|
||||
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
|
||||
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadExt;
|
||||
registers.SectorCount = count;
|
||||
registers.LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000);
|
||||
registers.LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000);
|
||||
registers.LbaLow = (ushort)((lba & 0xFFFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ SECTORS EXT took {0} ms.", duration);
|
||||
|
||||
@@ -69,8 +69,7 @@ namespace DiscImageChef.Devices
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
public bool AtaIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, uint timeout)
|
||||
{
|
||||
double duration;
|
||||
return AtaIdentify(out buffer, out statusRegisters, timeout, out duration);
|
||||
return AtaIdentify(out buffer, out statusRegisters, timeout, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,14 +84,12 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
AtaRegistersChs registers = new AtaRegistersChs {Command = (byte)AtaCommands.IdentifyDevice};
|
||||
|
||||
registers.Command = (byte)AtaCommands.IdentifyDevice;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "IDENTIFY DEVICE took {0} ms.", duration);
|
||||
@@ -109,21 +106,20 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, bool retry, ushort cylinder,
|
||||
byte head, byte sector, byte count, uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 256];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
SectorCount = count,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector,
|
||||
Command = retry ? (byte)AtaCommands.ReadDmaRetry : (byte)AtaCommands.ReadDma
|
||||
};
|
||||
|
||||
if(retry) registers.Command = (byte)AtaCommands.ReadDmaRetry;
|
||||
else registers.Command = (byte)AtaCommands.ReadDma;
|
||||
registers.SectorCount = count;
|
||||
registers.CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100);
|
||||
registers.CylinderLow = (byte)((cylinder & 0xFF) / 0x1);
|
||||
registers.DeviceHead = (byte)(head & 0x0F);
|
||||
registers.Sector = sector;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out sense);
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ DMA took {0} ms.", duration);
|
||||
@@ -134,21 +130,21 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder,
|
||||
byte head, byte sector, byte count, uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 256];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = (byte)AtaCommands.ReadMultiple,
|
||||
SectorCount = count,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.ReadMultiple;
|
||||
registers.SectorCount = count;
|
||||
registers.CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100);
|
||||
registers.CylinderLow = (byte)((cylinder & 0xFF) / 0x1);
|
||||
registers.DeviceHead = (byte)(head & 0x0F);
|
||||
registers.Sector = sector;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE took {0} ms.", duration);
|
||||
@@ -165,22 +161,21 @@ namespace DiscImageChef.Devices
|
||||
public bool Read(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, bool retry, ushort cylinder,
|
||||
byte head, byte sector, byte count, uint timeout, out double duration)
|
||||
{
|
||||
if(count == 0) buffer = new byte[512 * 256];
|
||||
else buffer = new byte[512 * count];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = retry ? (byte)AtaCommands.ReadRetry : (byte)AtaCommands.Read,
|
||||
SectorCount = count,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector
|
||||
};
|
||||
|
||||
if(retry) registers.Command = (byte)AtaCommands.ReadRetry;
|
||||
else registers.Command = (byte)AtaCommands.Read;
|
||||
registers.SectorCount = count;
|
||||
registers.CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100);
|
||||
registers.CylinderLow = (byte)((cylinder & 0xFF) / 0x1);
|
||||
registers.DeviceHead = (byte)(head & 0x0F);
|
||||
registers.Sector = sector;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ SECTORS took {0} ms.", duration);
|
||||
@@ -199,20 +194,20 @@ namespace DiscImageChef.Devices
|
||||
byte head, byte sector, uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[blockSize];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = retry ? (byte)AtaCommands.ReadLongRetry : (byte)AtaCommands.ReadLong,
|
||||
SectorCount = 1,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector
|
||||
};
|
||||
|
||||
if(retry) registers.Command = (byte)AtaCommands.ReadLongRetry;
|
||||
else registers.Command = (byte)AtaCommands.ReadLong;
|
||||
registers.SectorCount = 1;
|
||||
registers.CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100);
|
||||
registers.CylinderLow = (byte)((cylinder & 0xFF) / 0x1);
|
||||
registers.DeviceHead = (byte)(head & 0x0F);
|
||||
registers.Sector = sector;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LONG took {0} ms.", duration);
|
||||
@@ -224,18 +219,19 @@ namespace DiscImageChef.Devices
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = (byte)AtaCommands.Seek,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Seek;
|
||||
registers.CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100);
|
||||
registers.CylinderLow = (byte)((cylinder & 0xFF) / 0x1);
|
||||
registers.DeviceHead = (byte)(head & 0x0F);
|
||||
registers.Sector = sector;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, true, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SEEK took {0} ms.", duration);
|
||||
|
||||
@@ -69,8 +69,7 @@ namespace DiscImageChef.Devices
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
public bool AtapiIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, uint timeout)
|
||||
{
|
||||
double duration;
|
||||
return AtapiIdentify(out buffer, out statusRegisters, timeout, out duration);
|
||||
return AtapiIdentify(out buffer, out statusRegisters, timeout, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,14 +84,12 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
AtaRegistersChs registers = new AtaRegistersChs {Command = (byte)AtaCommands.IdentifyPacketDevice};
|
||||
|
||||
registers.Command = (byte)AtaCommands.IdentifyPacketDevice;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "IDENTIFY PACKET DEVICE took {0} ms.", duration);
|
||||
|
||||
@@ -41,19 +41,20 @@ namespace DiscImageChef.Devices
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.TranslateSector,
|
||||
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
|
||||
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
|
||||
LbaMid = (byte)((lba & 0xFF00) / 0x100),
|
||||
LbaLow = (byte)((lba & 0xFF) / 0x1)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.TranslateSector;
|
||||
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
|
||||
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
|
||||
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
|
||||
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CFA TRANSLATE SECTOR took {0} ms.", duration);
|
||||
@@ -65,18 +66,19 @@ namespace DiscImageChef.Devices
|
||||
byte head, byte sector, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = (byte)AtaCommands.TranslateSector,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
Sector = sector,
|
||||
DeviceHead = (byte)(head & 0x0F)
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.TranslateSector;
|
||||
registers.CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100);
|
||||
registers.CylinderLow = (byte)((cylinder & 0xFF) / 0x1);
|
||||
registers.Sector = sector;
|
||||
registers.DeviceHead = (byte)(head & 0x0F);
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CFA TRANSLATE SECTOR took {0} ms.", duration);
|
||||
@@ -88,14 +90,12 @@ namespace DiscImageChef.Devices
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.RequestSense};
|
||||
|
||||
registers.Command = (byte)AtaCommands.RequestSense;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
errorCode = statusRegisters.Error;
|
||||
|
||||
@@ -53,15 +53,13 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersChs registers = new AtaRegistersChs();
|
||||
bool sense;
|
||||
AtaRegistersChs registers =
|
||||
new AtaRegistersChs {Command = (byte)AtaCommands.CheckMediaCardType, Feature = feature};
|
||||
|
||||
registers.Command = (byte)AtaCommands.CheckMediaCardType;
|
||||
registers.Feature = feature;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CHECK MEDIA CARD TYPE took {0} ms.", duration);
|
||||
|
||||
@@ -40,17 +40,18 @@ namespace DiscImageChef.Devices
|
||||
public bool SmartDisable(out AtaErrorRegistersLba28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.Disable,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.Disable;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART DISABLE OPERATIONS took {0} ms.", duration);
|
||||
@@ -62,18 +63,19 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.EnableDisableAttributeAutosave,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F,
|
||||
SectorCount = 0xF1
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.EnableDisableAttributeAutosave;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
registers.SectorCount = 0xF1;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART ENABLE ATTRIBUTE AUTOSAVE took {0} ms.", duration);
|
||||
@@ -85,17 +87,18 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.EnableDisableAttributeAutosave,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.EnableDisableAttributeAutosave;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART DISABLE ATTRIBUTE AUTOSAVE took {0} ms.", duration);
|
||||
@@ -106,17 +109,18 @@ namespace DiscImageChef.Devices
|
||||
public bool SmartEnable(out AtaErrorRegistersLba28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.Enable,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.Enable;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART ENABLE OPERATIONS took {0} ms.", duration);
|
||||
@@ -128,18 +132,19 @@ namespace DiscImageChef.Devices
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ExecuteOfflineImmediate,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F,
|
||||
LbaLow = subcommand
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.ExecuteOfflineImmediate;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
registers.LbaLow = subcommand;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART EXECUTE OFF-LINE IMMEDIATE took {0} ms.", duration);
|
||||
@@ -151,17 +156,18 @@ namespace DiscImageChef.Devices
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ReadData,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.ReadData;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART READ DATA took {0} ms.", duration);
|
||||
@@ -173,18 +179,19 @@ namespace DiscImageChef.Devices
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ReadLog,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F,
|
||||
LbaLow = logAddress
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.ReadLog;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
registers.LbaLow = logAddress;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART READ LOG took {0} ms.", duration);
|
||||
@@ -195,17 +202,18 @@ namespace DiscImageChef.Devices
|
||||
public bool SmartReturnStatus(out AtaErrorRegistersLba28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28();
|
||||
bool sense;
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ReturnStatus,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
registers.Command = (byte)AtaCommands.Smart;
|
||||
registers.Feature = (byte)AtaSmartSubCommands.ReturnStatus;
|
||||
registers.LbaHigh = 0xC2;
|
||||
registers.LbaMid = 0x4F;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART RETURN STATUS took {0} ms.", duration);
|
||||
|
||||
@@ -31,10 +31,12 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public partial class Device
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -125,16 +125,12 @@ namespace DiscImageChef.Devices
|
||||
Type = DeviceType.Unknown;
|
||||
ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
||||
|
||||
AtaErrorRegistersChs errorRegisters;
|
||||
|
||||
byte[] ataBuf;
|
||||
byte[] senseBuf;
|
||||
byte[] inqBuf = null;
|
||||
|
||||
if(Error) throw new SystemException($"Error {LastError} trying device.");
|
||||
|
||||
bool scsiSense = true;
|
||||
string ntDevicePath;
|
||||
|
||||
// Windows is answering SCSI INQUIRY for all device types so it needs to be detected first
|
||||
switch(PlatformId) {
|
||||
@@ -163,19 +159,21 @@ namespace DiscImageChef.Devices
|
||||
|
||||
if(!hasError && error == 0)
|
||||
{
|
||||
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor();
|
||||
descriptor.Version = BitConverter.ToUInt32(descriptorB, 0);
|
||||
descriptor.Size = BitConverter.ToUInt32(descriptorB, 4);
|
||||
descriptor.DeviceType = descriptorB[8];
|
||||
descriptor.DeviceTypeModifier = descriptorB[9];
|
||||
descriptor.RemovableMedia = descriptorB[10] > 0;
|
||||
descriptor.CommandQueueing = descriptorB[11] > 0;
|
||||
descriptor.VendorIdOffset = BitConverter.ToInt32(descriptorB, 12);
|
||||
descriptor.ProductIdOffset = BitConverter.ToInt32(descriptorB, 16);
|
||||
descriptor.ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20);
|
||||
descriptor.SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24);
|
||||
descriptor.BusType = (StorageBusType)BitConverter.ToUInt32(descriptorB, 28);
|
||||
descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32);
|
||||
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor
|
||||
{
|
||||
Version = BitConverter.ToUInt32(descriptorB, 0),
|
||||
Size = BitConverter.ToUInt32(descriptorB, 4),
|
||||
DeviceType = descriptorB[8],
|
||||
DeviceTypeModifier = descriptorB[9],
|
||||
RemovableMedia = descriptorB[10] > 0,
|
||||
CommandQueueing = descriptorB[11] > 0,
|
||||
VendorIdOffset = BitConverter.ToInt32(descriptorB, 12),
|
||||
ProductIdOffset = BitConverter.ToInt32(descriptorB, 16),
|
||||
ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20),
|
||||
SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24),
|
||||
BusType = (StorageBusType)BitConverter.ToUInt32(descriptorB, 28),
|
||||
RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32)
|
||||
};
|
||||
descriptor.RawDeviceProperties = new byte[descriptor.RawPropertiesLength];
|
||||
Array.Copy(descriptorB, 36, descriptor.RawDeviceProperties, 0, descriptor.RawPropertiesLength);
|
||||
|
||||
@@ -216,36 +214,35 @@ namespace DiscImageChef.Devices
|
||||
|
||||
switch(Type) {
|
||||
case DeviceType.SCSI:
|
||||
case DeviceType.ATAPI: scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
|
||||
case DeviceType.ATAPI: scsiSense = ScsiInquiry(out inqBuf, out _);
|
||||
break;
|
||||
case DeviceType.ATA:
|
||||
bool atapiSense = AtapiIdentify(out ataBuf, out errorRegisters);
|
||||
bool atapiSense = AtapiIdentify(out ataBuf, out _);
|
||||
|
||||
if(!atapiSense)
|
||||
{
|
||||
Type = DeviceType.ATAPI;
|
||||
Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf);
|
||||
|
||||
if(ataid.HasValue) scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
|
||||
if(ataid.HasValue) scsiSense = ScsiInquiry(out inqBuf, out _);
|
||||
}
|
||||
else Manufacturer = "ATA";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ntDevicePath = Windows.Command.GetDevicePath((SafeFileHandle)FileHandle);
|
||||
string ntDevicePath = Windows.Command.GetDevicePath((SafeFileHandle)FileHandle);
|
||||
DicConsole.DebugWriteLine("Windows devices", "NT device path: {0}", ntDevicePath);
|
||||
Marshal.FreeHGlobal(descriptorPtr);
|
||||
|
||||
if(Windows.Command.IsSdhci((SafeFileHandle)FileHandle))
|
||||
{
|
||||
byte[] sdBuffer = new byte[16];
|
||||
bool sense;
|
||||
|
||||
LastError = Windows.Command.SendMmcCommand((SafeFileHandle)FileHandle, MmcCommands.SendCsd, false, false,
|
||||
MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 |
|
||||
MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer,
|
||||
out uint[] response, out double duration, out sense, 0);
|
||||
out _, out _, out bool sense);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
@@ -257,8 +254,8 @@ namespace DiscImageChef.Devices
|
||||
|
||||
LastError = Windows.Command.SendMmcCommand((SafeFileHandle)FileHandle, MmcCommands.SendCid, false, false,
|
||||
MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 |
|
||||
MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, out response,
|
||||
out duration, out sense, 0);
|
||||
MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, out _,
|
||||
out _, out sense);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
@@ -272,7 +269,7 @@ namespace DiscImageChef.Devices
|
||||
(MmcCommands)SecureDigitalCommands.SendScr, false, true,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 |
|
||||
MmcFlags.CommandAdtc, 0, 8, 1, ref sdBuffer,
|
||||
out response, out duration, out sense, 0);
|
||||
out _, out _, out sense);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
@@ -289,7 +286,7 @@ namespace DiscImageChef.Devices
|
||||
.SendOperatingCondition, false, true,
|
||||
MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 |
|
||||
MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer,
|
||||
out response, out duration, out sense, 0);
|
||||
out _, out _, out sense);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
@@ -305,7 +302,7 @@ namespace DiscImageChef.Devices
|
||||
true,
|
||||
MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 |
|
||||
MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer,
|
||||
out response, out duration, out sense, 0);
|
||||
out _, out _, out sense);
|
||||
|
||||
if(!sense)
|
||||
{
|
||||
@@ -319,7 +316,7 @@ namespace DiscImageChef.Devices
|
||||
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
|
||||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
|
||||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
|
||||
scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
|
||||
scsiSense = ScsiInquiry(out inqBuf, out _);
|
||||
// MultiMediaCard and SecureDigital go here
|
||||
else if(devicePath.StartsWith("/dev/mmcblk", StringComparison.Ordinal))
|
||||
{
|
||||
@@ -346,7 +343,7 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
|
||||
default: scsiSense = ScsiInquiry(out inqBuf, out _);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -397,21 +394,17 @@ namespace DiscImageChef.Devices
|
||||
!File.Exists(resolvedLink + "/idProduct") ||
|
||||
!File.Exists(resolvedLink + "/idVendor")) continue;
|
||||
|
||||
FileStream usbFs;
|
||||
StreamReader usbSr;
|
||||
string usbTemp;
|
||||
|
||||
usbFs = new FileStream(resolvedLink + "/descriptors",
|
||||
System.IO.FileMode.Open,
|
||||
System.IO.FileAccess.Read);
|
||||
FileStream usbFs = new FileStream(resolvedLink + "/descriptors",
|
||||
System.IO.FileMode.Open,
|
||||
System.IO.FileAccess.Read);
|
||||
byte[] usbBuf = new byte[65536];
|
||||
int usbCount = usbFs.Read(usbBuf, 0, 65536);
|
||||
UsbDescriptors = new byte[usbCount];
|
||||
Array.Copy(usbBuf, 0, UsbDescriptors, 0, usbCount);
|
||||
usbFs.Close();
|
||||
|
||||
usbSr = new StreamReader(resolvedLink + "/idProduct");
|
||||
usbTemp = usbSr.ReadToEnd();
|
||||
StreamReader usbSr = new StreamReader(resolvedLink + "/idProduct");
|
||||
string usbTemp = usbSr.ReadToEnd();
|
||||
ushort.TryParse(usbTemp, NumberStyles.HexNumber,
|
||||
CultureInfo.InvariantCulture, out usbProduct);
|
||||
usbSr.Close();
|
||||
@@ -500,11 +493,8 @@ namespace DiscImageChef.Devices
|
||||
!File.Exists(resolvedLink + "/vendor") ||
|
||||
!File.Exists(resolvedLink + "/guid")) continue;
|
||||
|
||||
StreamReader fwSr;
|
||||
string fwTemp;
|
||||
|
||||
fwSr = new StreamReader(resolvedLink + "/model");
|
||||
fwTemp = fwSr.ReadToEnd();
|
||||
StreamReader fwSr = new StreamReader(resolvedLink + "/model");
|
||||
string fwTemp = fwSr.ReadToEnd();
|
||||
uint.TryParse(fwTemp, NumberStyles.HexNumber,
|
||||
CultureInfo.InvariantCulture, out firewireModel);
|
||||
fwSr.Close();
|
||||
@@ -576,11 +566,9 @@ namespace DiscImageChef.Devices
|
||||
if(!File.Exists(possibleDir + "/card_type") ||
|
||||
!File.Exists(possibleDir + "/cis")) continue;
|
||||
|
||||
FileStream cisFs;
|
||||
|
||||
cisFs = new FileStream(possibleDir + "/cis",
|
||||
System.IO.FileMode.Open,
|
||||
System.IO.FileAccess.Read);
|
||||
FileStream cisFs = new FileStream(possibleDir + "/cis",
|
||||
System.IO.FileMode.Open,
|
||||
System.IO.FileAccess.Read);
|
||||
byte[] cisBuf = new byte[65536];
|
||||
int cisCount = cisFs.Read(cisBuf, 0, 65536);
|
||||
Cis = new byte[cisCount];
|
||||
@@ -602,7 +590,7 @@ namespace DiscImageChef.Devices
|
||||
Inquiry.SCSIInquiry? inquiry = Inquiry.Decode(inqBuf);
|
||||
|
||||
Type = DeviceType.SCSI;
|
||||
bool serialSense = ScsiInquiry(out inqBuf, out senseBuf, 0x80);
|
||||
bool serialSense = ScsiInquiry(out inqBuf, out _, 0x80);
|
||||
if(!serialSense) Serial = EVPD.DecodePage80(inqBuf);
|
||||
|
||||
if(inquiry.HasValue)
|
||||
@@ -618,7 +606,7 @@ namespace DiscImageChef.Devices
|
||||
ScsiType = (PeripheralDeviceTypes)inquiry.Value.PeripheralDeviceType;
|
||||
}
|
||||
|
||||
bool atapiSense = AtapiIdentify(out ataBuf, out errorRegisters);
|
||||
bool atapiSense = AtapiIdentify(out ataBuf, out _);
|
||||
|
||||
if(!atapiSense)
|
||||
{
|
||||
@@ -636,7 +624,7 @@ namespace DiscImageChef.Devices
|
||||
|
||||
if(scsiSense && (IsUsb || IsFireWire) || Manufacturer == "ATA")
|
||||
{
|
||||
bool ataSense = AtaIdentify(out ataBuf, out errorRegisters);
|
||||
bool ataSense = AtaIdentify(out ataBuf, out _);
|
||||
if(!ataSense)
|
||||
{
|
||||
Type = DeviceType.ATA;
|
||||
@@ -680,7 +668,7 @@ namespace DiscImageChef.Devices
|
||||
if(string.IsNullOrEmpty(Manufacturer)) Manufacturer = UsbManufacturerString;
|
||||
if(string.IsNullOrEmpty(Model)) Model = UsbProductString;
|
||||
if(string.IsNullOrEmpty(Serial)) Serial = UsbSerialString;
|
||||
else foreach(char c in Serial.Where(c => char.IsControl(c))) Serial = UsbSerialString;
|
||||
else foreach(char c in Serial.Where(char.IsControl)) Serial = UsbSerialString;
|
||||
}
|
||||
|
||||
if(!IsFireWire) return;
|
||||
@@ -688,7 +676,7 @@ namespace DiscImageChef.Devices
|
||||
if(string.IsNullOrEmpty(Manufacturer)) Manufacturer = FireWireVendorName;
|
||||
if(string.IsNullOrEmpty(Model)) Model = FireWireModelName;
|
||||
if(string.IsNullOrEmpty(Serial)) Serial = $"{firewireGuid:X16}";
|
||||
else foreach(char c in Serial.Where(c => char.IsControl(c))) Serial = $"{firewireGuid:X16}";
|
||||
else foreach(char c in Serial.Where(char.IsControl)) Serial = $"{firewireGuid:X16}";
|
||||
}
|
||||
|
||||
static int ConvertFromHexAscii(string file, out byte[] outBuf)
|
||||
|
||||
@@ -39,11 +39,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadCsd(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[16];
|
||||
bool sense;
|
||||
|
||||
LastError = SendMmcCommand(MmcCommands.SendCsd, false, false,
|
||||
MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | MmcFlags.CommandAc, 0, 16, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("MMC Device", "SEND_CSD took {0} ms.", duration);
|
||||
@@ -54,11 +53,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadCid(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[16];
|
||||
bool sense;
|
||||
|
||||
LastError = SendMmcCommand(MmcCommands.SendCid, false, false,
|
||||
MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | MmcFlags.CommandAc, 0, 16, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("MMC Device", "SEND_CID took {0} ms.", duration);
|
||||
@@ -69,11 +67,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadOcr(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[4];
|
||||
bool sense;
|
||||
|
||||
LastError = SendMmcCommand(MmcCommands.SendOpCond, false, true,
|
||||
MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | MmcFlags.CommandBcr, 0, 4, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SecureDigital Device", "SEND_OP_COND took {0} ms.", duration);
|
||||
@@ -84,11 +81,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadExtendedCsd(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
bool sense;
|
||||
|
||||
LastError = SendMmcCommand(MmcCommands.SendExtCsd, false, false,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.CommandAdtc, 0, 512, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("MMC Device", "SEND_EXT_CSD took {0} ms.", duration);
|
||||
@@ -99,11 +95,10 @@ namespace DiscImageChef.Devices
|
||||
public bool SetBlockLength(uint length, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
LastError = SendMmcCommand(MmcCommands.SetBlocklen, false, false,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.CommandAc, length, 0,
|
||||
0, ref buffer, out response, out duration, out sense, timeout);
|
||||
0, ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("MMC Device", "SET_BLOCKLEN took {0} ms.", duration);
|
||||
@@ -115,18 +110,15 @@ namespace DiscImageChef.Devices
|
||||
bool byteAddressed, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[transferLength * blockSize];
|
||||
bool sense;
|
||||
uint address;
|
||||
if(byteAddressed) address = lba * blockSize;
|
||||
else address = lba;
|
||||
|
||||
MmcCommands command;
|
||||
if(transferLength > 1) command = MmcCommands.ReadMultipleBlock;
|
||||
else command = MmcCommands.ReadSingleBlock;
|
||||
MmcCommands command = transferLength > 1 ? MmcCommands.ReadMultipleBlock : MmcCommands.ReadSingleBlock;
|
||||
|
||||
LastError = SendMmcCommand(command, false, false,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.CommandAdtc, address,
|
||||
blockSize, transferLength, ref buffer, out response, out duration, out sense,
|
||||
blockSize, transferLength, ref buffer, out response, out duration, out bool sense,
|
||||
timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
@@ -135,7 +127,7 @@ namespace DiscImageChef.Devices
|
||||
byte[] foo = new byte[0];
|
||||
SendMmcCommand(MmcCommands.StopTransmission, false, false,
|
||||
MmcFlags.ResponseR1B | MmcFlags.ResponseSpiR1B | MmcFlags.CommandAc, 0, 0, 0, ref foo,
|
||||
out uint[] responseStop, out double stopDuration, out bool stopSense, timeout);
|
||||
out _, out double stopDuration, out bool _, timeout);
|
||||
duration += stopDuration;
|
||||
DicConsole.DebugWriteLine("MMC Device", "READ_MULTIPLE_BLOCK took {0} ms.", duration);
|
||||
}
|
||||
@@ -147,11 +139,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadStatus(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[4];
|
||||
bool sense = false;
|
||||
|
||||
LastError = SendMmcCommand(MmcCommands.SendStatus, false, true,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.CommandAc, 0, 4, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SecureDigital Device", "SEND_STATUS took {0} ms.", duration);
|
||||
|
||||
@@ -39,11 +39,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadSdStatus(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[64];
|
||||
bool sense = false;
|
||||
|
||||
LastError = SendMmcCommand((MmcCommands)SecureDigitalCommands.SendStatus, false, true,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.CommandAdtc, 0, 64, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SecureDigital Device", "SD_STATUS took {0} ms.", duration);
|
||||
@@ -54,11 +53,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadSdocr(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[4];
|
||||
bool sense = false;
|
||||
|
||||
LastError = SendMmcCommand((MmcCommands)SecureDigitalCommands.SendOperatingCondition, false, true,
|
||||
MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | MmcFlags.CommandBcr, 0, 4, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SecureDigital Device", "SD_SEND_OP_COND took {0} ms.", duration);
|
||||
@@ -69,11 +67,10 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadScr(out byte[] buffer, out uint[] response, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[8];
|
||||
bool sense = false;
|
||||
|
||||
LastError = SendMmcCommand((MmcCommands)SecureDigitalCommands.SendScr, false, true,
|
||||
MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | MmcFlags.CommandAdtc, 0, 8, 1,
|
||||
ref buffer, out response, out duration, out sense, timeout);
|
||||
ref buffer, out response, out duration, out bool sense, timeout);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SecureDigital Device", "SEND_SCR took {0} ms.", duration);
|
||||
|
||||
@@ -67,7 +67,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.AdaptecTranslate;
|
||||
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
||||
@@ -76,7 +75,7 @@ namespace DiscImageChef.Devices
|
||||
if(drive1) cdb[1] += 0x20;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC TRANSLATE took {0} ms.", duration);
|
||||
@@ -113,14 +112,13 @@ namespace DiscImageChef.Devices
|
||||
buffer[0] = threshold;
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.AdaptecSetErrorThreshold;
|
||||
if(drive1) cdb[1] += 0x20;
|
||||
cdb[4] = 1;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC SET ERROR THRESHOLD took {0} ms.", duration);
|
||||
@@ -155,14 +153,13 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[9];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.AdaptecTranslate;
|
||||
if(drive1) cdb[1] += 0x20;
|
||||
cdb[4] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC READ/RESET USAGE COUNTER took {0} ms.", duration);
|
||||
@@ -180,17 +177,15 @@ namespace DiscImageChef.Devices
|
||||
public bool AdaptecWriteBuffer(byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
||||
{
|
||||
byte[] oneKBuffer = new byte[1024];
|
||||
if(buffer.Length < 1024) Array.Copy(buffer, 0, oneKBuffer, 0, buffer.Length);
|
||||
else Array.Copy(buffer, 0, oneKBuffer, 0, 1024);
|
||||
Array.Copy(buffer, 0, oneKBuffer, 0, buffer.Length < 1024 ? buffer.Length : 1024);
|
||||
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.AdaptecWriteBuffer;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref oneKBuffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC WRITE DATA BUFFER took {0} ms.", duration);
|
||||
@@ -210,12 +205,11 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[1024];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.AdaptecReadBuffer;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC READ DATA BUFFER took {0} ms.", duration);
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[3];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ArchiveRequestBlockAddress;
|
||||
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
||||
@@ -59,7 +58,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = 3;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ARCHIVE CORP. REQUEST BLOCK ADDRESS took {0} ms.", duration);
|
||||
@@ -93,7 +92,6 @@ namespace DiscImageChef.Devices
|
||||
byte[] buffer = new byte[0];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ArchiveSeekBlock;
|
||||
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
||||
@@ -102,7 +100,7 @@ namespace DiscImageChef.Devices
|
||||
if(immediate) cdb[1] += 0x01;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "ARCHIVE CORP. SEEK BLOCK took {0} ms.", duration);
|
||||
|
||||
@@ -30,10 +30,12 @@
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using DiscImageChef.Console;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public partial class Device
|
||||
{
|
||||
/// <summary>
|
||||
@@ -70,13 +72,12 @@ namespace DiscImageChef.Devices
|
||||
byte[] buffer = new byte[0];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.CertanceParkUnpark;
|
||||
if(park) cdb[4] = 1;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "CERTANCE PARK UNPARK took {0} ms.", duration);
|
||||
|
||||
@@ -48,7 +48,6 @@ namespace DiscImageChef.Devices
|
||||
bool displayLen = false;
|
||||
bool halfMsg = false;
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(firstHalf))
|
||||
{
|
||||
@@ -67,10 +66,7 @@ namespace DiscImageChef.Devices
|
||||
displayLen = true;
|
||||
else if(!ArrayHelpers.ArrayIsNullOrWhiteSpace(firstHalfBytes) &&
|
||||
ArrayHelpers.ArrayIsNullOrWhiteSpace(secondHalfBytes))
|
||||
{
|
||||
displayLen = false;
|
||||
halfMsg = true;
|
||||
}
|
||||
|
||||
buffer[0] = (byte)((byte)mode << 5);
|
||||
if(displayLen) buffer[0] += 0x10;
|
||||
@@ -85,7 +81,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[6] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "FUJITSU DISPLAY took {0} ms.", duration);
|
||||
|
||||
@@ -52,7 +52,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
buffer = new byte[2064 * transferLength];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.HlDtStVendor;
|
||||
cdb[1] = 0x48;
|
||||
@@ -67,7 +66,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[11] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "HL-DT-ST READ DVD (RAW) took {0} ms.", duration);
|
||||
|
||||
@@ -75,7 +75,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadLong;
|
||||
if(relAddr) cdb[1] += 0x01;
|
||||
@@ -88,11 +87,10 @@ namespace DiscImageChef.Devices
|
||||
if(pba) cdb[9] += 0x80;
|
||||
if(sectorCount) cdb[9] += 0x40;
|
||||
|
||||
if(sectorCount) buffer = new byte[blockBytes * transferLen];
|
||||
else buffer = new byte[transferLen];
|
||||
buffer = sectorCount ? new byte[blockBytes * transferLen] : new byte[transferLen];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "HP READ LONG took {0} ms.", duration);
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.KreonCommand;
|
||||
cdb[1] = 0x08;
|
||||
@@ -57,7 +56,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[3] = 0x01;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "KREON DEPRECATED UNLOCK took {0} ms.", duration);
|
||||
@@ -114,7 +113,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.KreonCommand;
|
||||
cdb[1] = 0x08;
|
||||
@@ -123,7 +121,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = (byte)state;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "KREON SET LOCK STATE took {0} ms.", duration);
|
||||
@@ -145,7 +143,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[26];
|
||||
bool sense;
|
||||
features = 0;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.KreonCommand;
|
||||
@@ -154,7 +151,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[3] = 0x10;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "KREON GET FEATURE LIST took {0} ms.", duration);
|
||||
@@ -222,7 +219,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[2048];
|
||||
byte[] cdb = new byte[12];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.KreonSsCommand;
|
||||
cdb[1] = 0x00;
|
||||
@@ -238,7 +234,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[11] = 0xC0;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "KREON EXTRACT SS took {0} ms.", duration);
|
||||
|
||||
@@ -83,7 +83,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
buffer = new byte[8];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.GetConfiguration;
|
||||
cdb[1] = (byte)((byte)rt & 0x03);
|
||||
@@ -94,7 +93,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = 0;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -134,7 +133,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
buffer = new byte[8];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadDiscStructure;
|
||||
cdb[1] = (byte)((byte)mediaType & 0x0F);
|
||||
@@ -149,7 +147,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[10] = (byte)((agid & 0x03) << 6);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -297,11 +295,8 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
byte[] tmpBuffer;
|
||||
bool sense;
|
||||
|
||||
if((format & 0x0F) == 5) tmpBuffer = new byte[32768];
|
||||
else tmpBuffer = new byte[1024];
|
||||
byte[] tmpBuffer = (format & 0x0F) == 5 ? new byte[32768] : new byte[1024];
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadTocPmaAtip;
|
||||
if(msf) cdb[1] = 0x02;
|
||||
@@ -311,7 +306,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[8] = (byte)(tmpBuffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
uint strctLength = (uint)((tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
|
||||
@@ -364,7 +359,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
byte[] tmpBuffer = new byte[804];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadDiscInformation;
|
||||
cdb[1] = (byte)dataType;
|
||||
@@ -372,7 +366,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[8] = (byte)(tmpBuffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
uint strctLength = (uint)((tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
|
||||
@@ -411,7 +405,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCd;
|
||||
cdb[1] = (byte)((byte)expectedSectorType << 2);
|
||||
@@ -434,7 +427,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[blockSize * transferLength];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ CD took {0} ms.", duration);
|
||||
@@ -468,7 +461,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCdMsf;
|
||||
cdb[1] = (byte)((byte)expectedSectorType << 2);
|
||||
@@ -491,7 +483,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[blockSize * transferLength];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ CD MSF took {0} ms.", duration);
|
||||
@@ -515,14 +507,13 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PreventAllowMediumRemoval;
|
||||
if(prevent) cdb[4] += 0x01;
|
||||
if(persistent) cdb[4] += 0x02;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PREVENT ALLOW MEDIUM REMOVAL took {0} ms.", duration);
|
||||
@@ -556,7 +547,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.StartStopUnit;
|
||||
if(immediate) cdb[1] += 0x01;
|
||||
@@ -573,7 +563,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] += (byte)((powerConditions & 0x0F) << 4);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "START STOP UNIT took {0} ms.", duration);
|
||||
|
||||
@@ -51,7 +51,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.NecReadCdDa;
|
||||
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
|
||||
@@ -64,7 +63,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[2352 * transferLength];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ CD-DA took {0} ms.", duration);
|
||||
|
||||
@@ -54,7 +54,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCdDa;
|
||||
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
|
||||
@@ -69,7 +68,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[blockSize * transferLength];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PIONEER READ CD-DA took {0} ms.", duration);
|
||||
@@ -94,7 +93,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCdDaMsf;
|
||||
cdb[3] = (byte)((startMsf & 0xFF0000) >> 16);
|
||||
@@ -109,7 +107,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[blockSize * transferLength];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PIONEER READ CD-DA MSF took {0} ms.", duration);
|
||||
@@ -134,7 +132,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCdXa;
|
||||
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
|
||||
@@ -162,7 +159,7 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PIONEER READ CD-XA took {0} ms.", duration);
|
||||
|
||||
@@ -92,7 +92,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlasmonReadSectorLocation;
|
||||
cdb[2] = (byte)((address & 0xFF000000) >> 24);
|
||||
@@ -104,7 +103,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLASMON READ SECTOR LOCATION took {0} ms.", duration);
|
||||
|
||||
@@ -55,7 +55,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCdDa;
|
||||
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
|
||||
@@ -71,7 +70,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[blockSize * transferLength];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ CD-DA took {0} ms.", duration);
|
||||
@@ -95,7 +94,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
buffer = new byte[2064 * transferLength];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadBuffer;
|
||||
cdb[1] = 0x02;
|
||||
@@ -107,7 +105,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[5] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "Plextor READ DVD (RAW) took {0} ms.", duration);
|
||||
@@ -128,13 +126,12 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[256];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorReadEeprom;
|
||||
cdb[8] = 1;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR READ EEPROM took {0} ms.", duration);
|
||||
@@ -155,13 +152,12 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[512];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorReadEeprom;
|
||||
cdb[8] = 2;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR READ EEPROM took {0} ms.", duration);
|
||||
@@ -185,7 +181,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[blockSize];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorReadEeprom;
|
||||
cdb[1] = 1;
|
||||
@@ -194,7 +189,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = (byte)(blockSize & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR READ EEPROM took {0} ms.", duration);
|
||||
@@ -218,7 +213,6 @@ namespace DiscImageChef.Devices
|
||||
byte[] buf = new byte[10];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
selected = 0;
|
||||
max = 0;
|
||||
@@ -228,7 +222,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = (byte)buf.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buf, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR POWEREC GET SPEEDS took {0} ms.", duration);
|
||||
@@ -258,7 +252,6 @@ namespace DiscImageChef.Devices
|
||||
byte[] buf = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
enabled = false;
|
||||
speed = 0;
|
||||
@@ -268,7 +261,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = (byte)buf.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buf, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR POWEREC GET SPEEDS took {0} ms.", duration);
|
||||
@@ -295,7 +288,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -304,7 +296,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[10] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SILENT MODE took {0} ms.", duration);
|
||||
@@ -325,7 +317,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -333,7 +324,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[10] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET GIGAREC took {0} ms.", duration);
|
||||
@@ -356,7 +347,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -367,7 +357,7 @@ namespace DiscImageChef.Devices
|
||||
else cdb[3] = 0x02;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET VARIREC took {0} ms.", duration);
|
||||
@@ -388,14 +378,13 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[2] = (byte)PlextorSubCommands.SecuRec;
|
||||
cdb[10] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SECUREC took {0} ms.", duration);
|
||||
@@ -416,7 +405,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -424,7 +412,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[10] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SPEEDREAD took {0} ms.", duration);
|
||||
@@ -445,7 +433,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -453,7 +440,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET SINGLE-SESSION / HIDE CD-R took {0} ms.", duration);
|
||||
@@ -476,7 +463,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -487,7 +473,7 @@ namespace DiscImageChef.Devices
|
||||
else cdb[3] = (byte)PlextorSubCommands.BitSetR;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET BOOK BITSETTING took {0} ms.", duration);
|
||||
@@ -509,7 +495,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[8];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PlextorExtend;
|
||||
cdb[1] = (byte)PlextorSubCommands.GetMode;
|
||||
@@ -517,7 +502,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[10] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR GET TEST WRITE DVD+ took {0} ms.", duration);
|
||||
|
||||
@@ -69,7 +69,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read6;
|
||||
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
||||
@@ -81,7 +80,7 @@ namespace DiscImageChef.Devices
|
||||
else buffer = new byte[transferLength * blockSize];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ (6) took {0} ms.", duration);
|
||||
@@ -112,7 +111,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read10;
|
||||
cdb[1] = (byte)((rdprotect & 0x07) << 5);
|
||||
@@ -131,7 +129,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[transferLength * blockSize];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ (10) took {0} ms.", duration);
|
||||
@@ -163,7 +161,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read12;
|
||||
cdb[1] = (byte)((rdprotect & 0x07) << 5);
|
||||
@@ -185,7 +182,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[transferLength * blockSize];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ (12) took {0} ms.", duration);
|
||||
@@ -216,7 +213,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[16];
|
||||
bool sense;
|
||||
byte[] lbaBytes = BitConverter.GetBytes(lba);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read16;
|
||||
@@ -242,7 +238,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[transferLength * blockSize];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ (16) took {0} ms.", duration);
|
||||
@@ -267,7 +263,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadLong;
|
||||
if(correct) cdb[1] += 0x02;
|
||||
@@ -282,7 +277,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[transferBytes];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ LONG (10) took {0} ms.", duration);
|
||||
@@ -306,7 +301,6 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[16];
|
||||
bool sense;
|
||||
byte[] lbaBytes = BitConverter.GetBytes(lba);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ServiceActionIn;
|
||||
@@ -326,7 +320,7 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[transferBytes];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ LONG (16) took {0} ms.", duration);
|
||||
@@ -346,7 +340,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Seek6;
|
||||
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
||||
@@ -354,7 +347,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[3] = (byte)(lba & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "SEEK (6) took {0} ms.", duration);
|
||||
@@ -374,7 +367,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Seek10;
|
||||
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
|
||||
@@ -383,7 +375,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[5] = (byte)(lba & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "SEEK (10) took {0} ms.", duration);
|
||||
|
||||
@@ -57,7 +57,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[256];
|
||||
byte[] cdb = new byte[16];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadAttribute;
|
||||
cdb[1] = (byte)((byte)action & 0x1F);
|
||||
@@ -75,7 +74,7 @@ namespace DiscImageChef.Devices
|
||||
if(cache) cdb[14] += 0x01;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
|
||||
@@ -31,11 +31,13 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using DiscImageChef.Console;
|
||||
using PlatformID = DiscImageChef.Interop.PlatformID;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public partial class Device
|
||||
{
|
||||
/// <summary>
|
||||
@@ -70,8 +72,7 @@ namespace DiscImageChef.Devices
|
||||
/// <param name="timeout">Timeout in seconds.</param>
|
||||
public bool ScsiInquiry(out byte[] buffer, out byte[] senseBuffer, uint timeout)
|
||||
{
|
||||
double duration;
|
||||
return ScsiInquiry(out buffer, out senseBuffer, timeout, out duration);
|
||||
return ScsiInquiry(out buffer, out senseBuffer, timeout, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,10 +88,9 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[36];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = {(byte)ScsiCommands.Inquiry, 0, 0, 0, 36, 0};
|
||||
bool sense;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -145,8 +145,7 @@ namespace DiscImageChef.Devices
|
||||
/// <param name="page">The Extended Vital Product Data</param>
|
||||
public bool ScsiInquiry(out byte[] buffer, out byte[] senseBuffer, byte page, uint timeout)
|
||||
{
|
||||
double duration;
|
||||
return ScsiInquiry(out buffer, out senseBuffer, page, timeout, out duration);
|
||||
return ScsiInquiry(out buffer, out senseBuffer, page, timeout, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -163,10 +162,9 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[36];
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = {(byte)ScsiCommands.Inquiry, 1, page, 0, 36, 0};
|
||||
bool sense;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -200,11 +198,10 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = {(byte)ScsiCommands.TestUnitReady, 0, 0, 0, 0, 0};
|
||||
bool sense;
|
||||
byte[] buffer = new byte[0];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "TEST UNIT READY took {0} ms.", duration);
|
||||
@@ -262,7 +259,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
buffer = new byte[255];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ModeSense;
|
||||
if(dbd) cdb[1] = 0x08;
|
||||
@@ -273,7 +269,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[5] = 0;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -349,7 +345,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
buffer = new byte[4096];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ModeSense10;
|
||||
if(llbaa) cdb[1] |= 0x10;
|
||||
@@ -362,7 +357,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = 0;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -437,14 +432,13 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
bool sense;
|
||||
byte[] buffer = new byte[0];
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.PreventAllowMediumRemoval;
|
||||
cdb[4] = (byte)((byte)preventMode & 0x03);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "PREVENT ALLOW MEDIUM REMOVAL took {0} ms.", duration);
|
||||
@@ -482,7 +476,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
buffer = new byte[8];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadCapacity;
|
||||
|
||||
@@ -498,7 +491,7 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ CAPACITY took {0} ms.", duration);
|
||||
@@ -535,7 +528,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[16];
|
||||
buffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ServiceActionIn;
|
||||
cdb[1] = (byte)ScsiServiceActions.ReadCapacity16;
|
||||
@@ -560,7 +552,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[13] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ CAPACITY(16) took {0} ms.", duration);
|
||||
@@ -581,7 +573,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[12];
|
||||
buffer = new byte[4];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadSerialNumber;
|
||||
cdb[1] = 0x01;
|
||||
@@ -591,7 +582,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[9] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -748,7 +739,6 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
|
||||
byte[] cdb = new byte[6];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ModeSelect;
|
||||
if(pageFormat) cdb[1] += 0x10;
|
||||
@@ -756,7 +746,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = (byte)buffer.Length;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "MODE SELECT(6) took {0} ms.", duration);
|
||||
@@ -793,7 +783,6 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
|
||||
byte[] cdb = new byte[10];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ModeSelect10;
|
||||
if(pageFormat) cdb[1] += 0x10;
|
||||
@@ -802,7 +791,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[8] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "MODE SELECT(10) took {0} ms.", duration);
|
||||
@@ -817,10 +806,8 @@ namespace DiscImageChef.Devices
|
||||
|
||||
public bool RequestSense(bool descriptor, out byte[] buffer, uint timeout, out double duration)
|
||||
{
|
||||
byte[] senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
buffer = new byte[252];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.RequestSense;
|
||||
if(descriptor) cdb[1] = 0x01;
|
||||
@@ -829,8 +816,8 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = (byte)buffer.Length;
|
||||
cdb[5] = 0;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out _, timeout, ScsiDirection.In, out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "REQUEST SENSE took {0} ms.", duration);
|
||||
|
||||
@@ -79,7 +79,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.LoadUnload;
|
||||
if(immediate) cdb[1] = 0x01;
|
||||
@@ -89,7 +88,7 @@ namespace DiscImageChef.Devices
|
||||
if(hold) cdb[4] += 0x08;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "LOAD UNLOAD (6) took {0} ms.", duration);
|
||||
@@ -167,7 +166,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[10];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Locate;
|
||||
if(immediate) cdb[1] += 0x01;
|
||||
@@ -180,7 +178,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[8] = partition;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "LOCATE (10) took {0} ms.", duration);
|
||||
@@ -263,7 +261,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[16];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
byte[] idBytes = BitConverter.GetBytes(identifier);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Locate16;
|
||||
@@ -283,7 +280,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[11] = idBytes[0];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "LOCATE (16) took {0} ms.", duration);
|
||||
@@ -335,11 +332,9 @@ namespace DiscImageChef.Devices
|
||||
public bool Read6(out byte[] buffer, out byte[] senseBuffer, bool sili, bool fixedLen, uint transferLen,
|
||||
uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
if(fixedLen) buffer = new byte[blockSize * transferLen];
|
||||
else buffer = new byte[transferLen];
|
||||
buffer = fixedLen ? new byte[blockSize * transferLen] : new byte[transferLen];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read6;
|
||||
if(fixedLen) cdb[1] += 0x01;
|
||||
@@ -349,7 +344,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = (byte)(transferLen & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ (6) took {0} ms.", duration);
|
||||
@@ -445,11 +440,9 @@ namespace DiscImageChef.Devices
|
||||
public bool Read16(out byte[] buffer, out byte[] senseBuffer, bool sili, bool fixedLen, byte partition,
|
||||
ulong objectId, uint transferLen, uint objectSize, uint timeout, out double duration)
|
||||
{
|
||||
if(fixedLen) buffer = new byte[objectSize * transferLen];
|
||||
else buffer = new byte[transferLen];
|
||||
buffer = fixedLen ? new byte[objectSize * transferLen] : new byte[transferLen];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
byte[] idBytes = BitConverter.GetBytes(objectId);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read16;
|
||||
@@ -469,7 +462,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[14] = (byte)(transferLen & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ (16) took {0} ms.", duration);
|
||||
@@ -489,12 +482,11 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[6];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadBlockLimits;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ BLOCK LIMITS took {0} ms.", duration);
|
||||
@@ -580,7 +572,6 @@ namespace DiscImageChef.Devices
|
||||
|
||||
byte[] cdb = new byte[10];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadPosition;
|
||||
cdb[1] = (byte)((byte)responseForm & 0x1F);
|
||||
@@ -591,7 +582,7 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ POSITION took {0} ms.", duration);
|
||||
@@ -647,11 +638,9 @@ namespace DiscImageChef.Devices
|
||||
public bool ReadReverse6(out byte[] buffer, out byte[] senseBuffer, bool byteOrder, bool sili, bool fixedLen,
|
||||
uint transferLen, uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
if(fixedLen) buffer = new byte[blockSize * transferLen];
|
||||
else buffer = new byte[transferLen];
|
||||
buffer = fixedLen ? new byte[blockSize * transferLen] : new byte[transferLen];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReadReverse;
|
||||
if(fixedLen) cdb[1] += 0x01;
|
||||
@@ -662,7 +651,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = (byte)(transferLen & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ REVERSE (6) took {0} ms.", duration);
|
||||
@@ -760,11 +749,9 @@ namespace DiscImageChef.Devices
|
||||
byte partition, ulong objectId, uint transferLen, uint objectSize, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
if(fixedLen) buffer = new byte[objectSize * transferLen];
|
||||
else buffer = new byte[transferLen];
|
||||
buffer = fixedLen ? new byte[objectSize * transferLen] : new byte[transferLen];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
byte[] idBytes = BitConverter.GetBytes(objectId);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Read16;
|
||||
@@ -785,7 +772,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[14] = (byte)(transferLen & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "READ REVERSE (16) took {0} ms.", duration);
|
||||
@@ -840,11 +827,9 @@ namespace DiscImageChef.Devices
|
||||
public bool RecoverBufferedData(out byte[] buffer, out byte[] senseBuffer, bool sili, bool fixedLen,
|
||||
uint transferLen, uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
if(fixedLen) buffer = new byte[blockSize * transferLen];
|
||||
else buffer = new byte[transferLen];
|
||||
buffer = fixedLen ? new byte[blockSize * transferLen] : new byte[transferLen];
|
||||
byte[] cdb = new byte[6];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.RecoverBufferedData;
|
||||
if(fixedLen) cdb[1] += 0x01;
|
||||
@@ -854,7 +839,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = (byte)(transferLen & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "RECOVER BUFFERED DATA took {0} ms.", duration);
|
||||
@@ -903,7 +888,6 @@ namespace DiscImageChef.Devices
|
||||
buffer = new byte[256];
|
||||
byte[] cdb = new byte[10];
|
||||
senseBuffer = new byte[32];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.ReportDensitySupport;
|
||||
if(currentMedia) cdb[1] += 0x01;
|
||||
@@ -912,7 +896,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[8] = (byte)(buffer.Length & 0xFF);
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if(sense) return true;
|
||||
@@ -955,13 +939,12 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Rewind;
|
||||
if(immediate) cdb[1] += 0x01;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "REWIND took {0} ms.", duration);
|
||||
@@ -982,13 +965,12 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.TrackSelect;
|
||||
cdb[5] = track;
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "TRACK SELECT took {0} ms.", duration);
|
||||
@@ -1001,7 +983,6 @@ namespace DiscImageChef.Devices
|
||||
senseBuffer = new byte[32];
|
||||
byte[] cdb = new byte[6];
|
||||
byte[] buffer = new byte[0];
|
||||
bool sense;
|
||||
byte[] countB = BitConverter.GetBytes(count);
|
||||
|
||||
cdb[0] = (byte)ScsiCommands.Space;
|
||||
@@ -1011,7 +992,7 @@ namespace DiscImageChef.Devices
|
||||
cdb[4] = countB[0];
|
||||
|
||||
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
|
||||
out sense);
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("SCSI Device", "SPACE took {0} ms.", duration);
|
||||
|
||||
@@ -97,8 +97,7 @@ namespace DiscImageChef.Devices
|
||||
if(readLong) cdb[5] += 0x40;
|
||||
|
||||
if(!inhibitDma && !readLong)
|
||||
if(transferLength == 0) buffer = new byte[256 * blockSize];
|
||||
else buffer = new byte[transferLength * blockSize];
|
||||
buffer = transferLength == 0 ? new byte[256 * blockSize] : new byte[transferLength * blockSize];
|
||||
else if(readLong)
|
||||
{
|
||||
buffer = new byte[blockSize];
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
// ReSharper disable MemberCanBeInternal
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
@@ -39,6 +40,7 @@ using static DiscImageChef.Devices.FreeBSD.Extern;
|
||||
|
||||
namespace DiscImageChef.Devices.FreeBSD
|
||||
{
|
||||
[SuppressMessage("ReSharper", "BitwiseOperatorOnEnumWithoutFlags")]
|
||||
static class Command
|
||||
{
|
||||
const int CAM_MAX_CDBLEN = 16;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains structures necessary for directly interfacing devices under
|
||||
// Contains [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] structures necessary for directly interfacing devices under
|
||||
// FreeBSD.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
@@ -32,15 +32,18 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using lun_id_t = System.UInt32;
|
||||
using path_id_t = System.UInt32;
|
||||
using target_id_t = System.UInt32;
|
||||
#pragma warning disable 649
|
||||
#pragma warning disable 169
|
||||
|
||||
namespace DiscImageChef.Devices.FreeBSD
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct AtaCmd
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct AtaCmd
|
||||
{
|
||||
public CamAtaIoFlags flags;
|
||||
public byte command;
|
||||
@@ -59,7 +62,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct AtaRes
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct AtaRes
|
||||
{
|
||||
public CamAtaIoFlags flags;
|
||||
public byte status;
|
||||
@@ -76,14 +79,14 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CamPinfo
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CamPinfo
|
||||
{
|
||||
public uint priority;
|
||||
public uint generation;
|
||||
public int index;
|
||||
}
|
||||
|
||||
struct ListEntry
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct ListEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// LIST_ENTRY(ccb_hdr)=le->*le_next
|
||||
@@ -95,7 +98,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
public IntPtr LePrev;
|
||||
}
|
||||
|
||||
struct SlistEntry
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct SlistEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// SLIST_ENTRY(ccb_hdr)=sle->*sle_next
|
||||
@@ -103,7 +106,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
public IntPtr SleNext;
|
||||
}
|
||||
|
||||
struct TailqEntry
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct TailqEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// TAILQ_ENTRY(ccb_hdr)=tqe->*tqe_next
|
||||
@@ -115,7 +118,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
public IntPtr TqePrev;
|
||||
}
|
||||
|
||||
struct StailqEntry
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct StailqEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// STAILQ_ENTRY(ccb_hdr)=stqe->*stqe_next
|
||||
@@ -124,7 +127,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
struct CamqEntry
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CamqEntry
|
||||
{
|
||||
[FieldOffset(0)] public ListEntry le;
|
||||
[FieldOffset(0)] public SlistEntry sle;
|
||||
@@ -133,7 +136,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct Timeval
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct Timeval
|
||||
{
|
||||
public long tv_sec;
|
||||
/// <summary>long</summary>
|
||||
@@ -141,7 +144,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbQosArea
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbQosArea
|
||||
{
|
||||
public Timeval etime;
|
||||
public UIntPtr sim_data;
|
||||
@@ -149,7 +152,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbHdr
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbHdr
|
||||
{
|
||||
public CamPinfo pinfo;
|
||||
public CamqEntry xpt_links;
|
||||
@@ -173,7 +176,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct ScsiSenseData
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct ScsiSenseData
|
||||
{
|
||||
const int SSD_FULL_SIZE = 252;
|
||||
public byte error_code;
|
||||
@@ -184,7 +187,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
/// SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO function codes.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbScsiio
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbScsiio
|
||||
{
|
||||
public CcbHdr ccb_h;
|
||||
/// <summary>Ptr for next CCB for action</summary>
|
||||
@@ -230,7 +233,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
/// SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO function codes.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbScsiio64
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbScsiio64
|
||||
{
|
||||
public CcbHdr ccb_h;
|
||||
/// <summary>Ptr for next CCB for action</summary>
|
||||
@@ -277,7 +280,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
/// ATA I/O Request CCB used for the XPT_ATA_IO function code.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbAtaio
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbAtaio
|
||||
{
|
||||
public CcbHdr ccb_h;
|
||||
/// <summary>Ptr for next CCB for action</summary>
|
||||
@@ -299,7 +302,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct NvmeCommand
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct NvmeCommand
|
||||
{
|
||||
ushort opc_fuse_rsvd1;
|
||||
/// <summary>
|
||||
@@ -370,7 +373,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct NvmeStatus
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct NvmeStatus
|
||||
{
|
||||
ushort status;
|
||||
|
||||
@@ -406,7 +409,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct NvmeCompletion
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct NvmeCompletion
|
||||
{
|
||||
/// <summary>
|
||||
/// command-specific
|
||||
@@ -440,7 +443,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
/// NVMe I/O Request CCB used for the XPT_NVME_IO and XPT_NVME_ADMIN function codes.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbNvmeio
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbNvmeio
|
||||
{
|
||||
public CcbHdr ccb_h;
|
||||
/// <summary>Ptr for next CCB for action</summary>
|
||||
@@ -460,7 +463,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct PeriphMatchPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct PeriphMatchPattern
|
||||
{
|
||||
const int DEV_IDLEN = 16;
|
||||
|
||||
@@ -473,14 +476,14 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct DeviceIdMatchPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct DeviceIdMatchPattern
|
||||
{
|
||||
public byte id_len;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public byte[] id;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct ScsiStaticInquiryPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct ScsiStaticInquiryPattern
|
||||
{
|
||||
const int SID_VENDOR_SIZE = 8;
|
||||
const int SID_PRODUCT_SIZE = 16;
|
||||
@@ -493,14 +496,14 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
struct DeviceMatchPatternData
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct DeviceMatchPatternData
|
||||
{
|
||||
[FieldOffset(0)] public ScsiStaticInquiryPattern inq_pat;
|
||||
[FieldOffset(0)] public DeviceIdMatchPattern devid_pat;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct DeviceMatchPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct DeviceMatchPattern
|
||||
{
|
||||
public path_id_t path_id;
|
||||
public target_id_t target_id;
|
||||
@@ -510,7 +513,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct BusMatchPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct BusMatchPattern
|
||||
{
|
||||
const int DEV_IDLEN = 16;
|
||||
|
||||
@@ -522,7 +525,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
struct MatchPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct MatchPattern
|
||||
{
|
||||
[FieldOffset(0)] public PeriphMatchPattern periph_pattern;
|
||||
[FieldOffset(0)] public DeviceMatchPattern device_pattern;
|
||||
@@ -530,14 +533,14 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct DevMatchPattern
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct DevMatchPattern
|
||||
{
|
||||
public DevMatchType type;
|
||||
public MatchPattern pattern;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct PeriphMatchResult
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct PeriphMatchResult
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] periph_name;
|
||||
public uint unit_number;
|
||||
@@ -547,7 +550,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct MmcCid
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct MmcCid
|
||||
{
|
||||
public uint mid;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] pnm;
|
||||
@@ -560,7 +563,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct MmcParams
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct MmcParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Card model
|
||||
@@ -606,7 +609,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct DeviceMatchResult
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct DeviceMatchResult
|
||||
{
|
||||
public path_id_t path_id;
|
||||
public target_id_t target_id;
|
||||
@@ -619,7 +622,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct BusMatchResult
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct BusMatchResult
|
||||
{
|
||||
public path_id_t path_id;
|
||||
const int DEV_IDLEN = 16;
|
||||
@@ -629,7 +632,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
struct MatchResult
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct MatchResult
|
||||
{
|
||||
[FieldOffset(0)] public PeriphMatchResult periph_result;
|
||||
[FieldOffset(0)] public DeviceMatchResult device_result;
|
||||
@@ -637,14 +640,14 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct DevMatchResult
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct DevMatchResult
|
||||
{
|
||||
public DevMatchType type;
|
||||
public MatchResult result;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbDmCookie
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbDmCookie
|
||||
{
|
||||
public IntPtr bus;
|
||||
public IntPtr target;
|
||||
@@ -654,7 +657,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbDevPosition
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbDevPosition
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public CamGenerations[] generations;
|
||||
DevPosType position_type;
|
||||
@@ -662,7 +665,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbDevMatch
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbDevMatch
|
||||
{
|
||||
public CcbHdr ccb_h;
|
||||
CcbDevMatchStatus status;
|
||||
@@ -685,6 +688,8 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
public CcbDevPosition pos;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "BuiltInTypeReferenceStyle")]
|
||||
struct CamDevice
|
||||
{
|
||||
const int MAXPATHLEN = 1024;
|
||||
@@ -769,7 +774,7 @@ namespace DiscImageChef.Devices.FreeBSD
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct CcbGetdev
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] struct CcbGetdev
|
||||
{
|
||||
public CcbHdr ccb_h;
|
||||
public CamProto protocol;
|
||||
|
||||
@@ -92,8 +92,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
|
||||
sense |= (ioHdr.info & SgInfo.OkMask) != SgInfo.Ok;
|
||||
|
||||
if(ioHdr.duration > 0) duration = ioHdr.duration;
|
||||
else duration = (end - start).TotalMilliseconds;
|
||||
duration = ioHdr.duration > 0 ? ioHdr.duration : (end - start).TotalMilliseconds;
|
||||
|
||||
Marshal.FreeHGlobal(ioHdr.dxferp);
|
||||
Marshal.FreeHGlobal(ioHdr.cmdp);
|
||||
@@ -162,8 +161,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
cdb[13] = registers.DeviceHead;
|
||||
cdb[14] = registers.Command;
|
||||
|
||||
byte[] senseBuffer;
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout,
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out byte[] senseBuffer, timeout,
|
||||
AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
|
||||
if(senseBuffer.Length < 22 || senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C) return error;
|
||||
@@ -224,8 +222,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
cdb[13] = registers.DeviceHead;
|
||||
cdb[14] = registers.Command;
|
||||
|
||||
byte[] senseBuffer;
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout,
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out byte[] senseBuffer, timeout,
|
||||
AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
|
||||
if(senseBuffer.Length < 22 || senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C) return error;
|
||||
@@ -292,8 +289,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
cdb[13] = registers.DeviceHead;
|
||||
cdb[14] = registers.Command;
|
||||
|
||||
byte[] senseBuffer;
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout,
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out byte[] senseBuffer, timeout,
|
||||
AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
|
||||
if(senseBuffer.Length < 22 || senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C) return error;
|
||||
|
||||
@@ -46,9 +46,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
DeviceInfo[] devices = new DeviceInfo[sysdevs.Length];
|
||||
bool hasUdev;
|
||||
|
||||
StreamReader sr;
|
||||
IntPtr udev = IntPtr.Zero;
|
||||
IntPtr udevDev;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -59,13 +57,12 @@ namespace DiscImageChef.Devices.Linux
|
||||
|
||||
for(int i = 0; i < sysdevs.Length; i++)
|
||||
{
|
||||
devices[i] = new DeviceInfo();
|
||||
devices[i].Path = "/dev/" + Path.GetFileName(sysdevs[i]);
|
||||
devices[i] = new DeviceInfo {Path = "/dev/" + Path.GetFileName(sysdevs[i])};
|
||||
|
||||
if(hasUdev)
|
||||
{
|
||||
udevDev = Extern.udev_device_new_from_subsystem_sysname(udev, "block",
|
||||
Path.GetFileName(sysdevs[i]));
|
||||
IntPtr udevDev = Extern.udev_device_new_from_subsystem_sysname(udev, "block",
|
||||
Path.GetFileName(sysdevs[i]));
|
||||
devices[i].Vendor = Extern.udev_device_get_property_value(udevDev, "ID_VENDOR");
|
||||
devices[i].Model = Extern.udev_device_get_property_value(udevDev, "ID_MODEL");
|
||||
if(!string.IsNullOrEmpty(devices[i].Model)) devices[i].Model = devices[i].Model.Replace('_', ' ');
|
||||
@@ -75,10 +72,11 @@ namespace DiscImageChef.Devices.Linux
|
||||
devices[i].Bus = Extern.udev_device_get_property_value(udevDev, "ID_BUS");
|
||||
}
|
||||
|
||||
StreamReader sr;
|
||||
if(File.Exists(Path.Combine(sysdevs[i], "device/vendor")) && string.IsNullOrEmpty(devices[i].Vendor))
|
||||
{
|
||||
sr = new StreamReader(Path.Combine(sysdevs[i], "device/vendor"), Encoding.ASCII);
|
||||
devices[i].Vendor = sr.ReadLine().Trim();
|
||||
devices[i].Vendor = sr.ReadLine()?.Trim();
|
||||
}
|
||||
else if(devices[i].Path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
|
||||
devices[i].Vendor = "Linux";
|
||||
@@ -87,7 +85,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
(string.IsNullOrEmpty(devices[i].Model) || devices[i].Bus == "ata"))
|
||||
{
|
||||
sr = new StreamReader(Path.Combine(sysdevs[i], "device/model"), Encoding.ASCII);
|
||||
devices[i].Model = sr.ReadLine().Trim();
|
||||
devices[i].Model = sr.ReadLine()?.Trim();
|
||||
}
|
||||
else if(devices[i].Path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
|
||||
devices[i].Model = "Linux";
|
||||
@@ -95,7 +93,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
if(File.Exists(Path.Combine(sysdevs[i], "device/serial")) && string.IsNullOrEmpty(devices[i].Serial))
|
||||
{
|
||||
sr = new StreamReader(Path.Combine(sysdevs[i], "device/serial"), Encoding.ASCII);
|
||||
devices[i].Serial = sr.ReadLine().Trim();
|
||||
devices[i].Serial = sr.ReadLine()?.Trim();
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(devices[i].Vendor) || devices[i].Vendor == "ATA")
|
||||
|
||||
@@ -32,11 +32,13 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DiscImageChef.Devices.Linux
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct SgIoHdrT
|
||||
{
|
||||
/// <summary>
|
||||
@@ -67,6 +69,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct MmcIocCmd
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
@@ -39,6 +40,7 @@ using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
|
||||
static class Command
|
||||
{
|
||||
/// <summary>
|
||||
@@ -63,19 +65,23 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if(buffer == null) return -1;
|
||||
|
||||
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);
|
||||
ScsiPassThroughDirectAndSenseBuffer sptdSb = new ScsiPassThroughDirectAndSenseBuffer
|
||||
{
|
||||
SenseBuf = new byte[32],
|
||||
sptd = new ScsiPassThroughDirect
|
||||
{
|
||||
Cdb = new byte[16],
|
||||
CdbLength = (byte)cdb.Length,
|
||||
SenseInfoLength = 32,
|
||||
DataIn = direction,
|
||||
DataTransferLength = (uint)buffer.Length,
|
||||
TimeOutValue = timeout,
|
||||
DataBuffer = Marshal.AllocHGlobal(buffer.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);
|
||||
Array.Copy(cdb, sptdSb.sptd.Cdb, cdb.Length);
|
||||
|
||||
uint k = 0;
|
||||
int error = 0;
|
||||
@@ -454,8 +460,6 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if(buffer == null) return -1;
|
||||
|
||||
uint offsetForBuffer = (uint)(Marshal.SizeOf(typeof(AtaPassThroughDirect)) + Marshal.SizeOf(typeof(uint)));
|
||||
|
||||
IdePassThroughDirect iptd = new IdePassThroughDirect
|
||||
{
|
||||
CurrentTaskFile = new AtaTaskFile
|
||||
@@ -504,10 +508,9 @@ namespace DiscImageChef.Devices.Windows
|
||||
return error;
|
||||
}
|
||||
|
||||
internal static uint GetDeviceNumber(SafeFileHandle deviceHandle)
|
||||
static uint GetDeviceNumber(SafeFileHandle deviceHandle)
|
||||
{
|
||||
StorageDeviceNumber sdn = new StorageDeviceNumber();
|
||||
sdn.deviceNumber = -1;
|
||||
StorageDeviceNumber 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,
|
||||
@@ -533,11 +536,9 @@ namespace DiscImageChef.Devices.Windows
|
||||
DeviceInterfaceData spdid = new DeviceInterfaceData();
|
||||
spdid.cbSize = Marshal.SizeOf(spdid);
|
||||
|
||||
byte[] buffer;
|
||||
|
||||
while(true)
|
||||
{
|
||||
buffer = new byte[2048];
|
||||
byte[] buffer = new byte[2048];
|
||||
|
||||
if(!Extern.SetupDiEnumDeviceInterfaces(hDevInfo, IntPtr.Zero, ref Consts.GuidDevinterfaceDisk, index,
|
||||
ref spdid)) break;
|
||||
@@ -595,9 +596,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
SffdiskQueryDeviceProtocolData queryData1 = new SffdiskQueryDeviceProtocolData();
|
||||
queryData1.size = (ushort)Marshal.SizeOf(queryData1);
|
||||
uint bytesReturned;
|
||||
Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskQueryDeviceProtocol, IntPtr.Zero, 0, ref queryData1,
|
||||
queryData1.size, out bytesReturned, IntPtr.Zero);
|
||||
queryData1.size, out _, IntPtr.Zero);
|
||||
return queryData1.protocolGuid.Equals(Consts.GuidSffProtocolSd);
|
||||
}
|
||||
|
||||
@@ -660,12 +660,11 @@ namespace DiscImageChef.Devices.Windows
|
||||
Marshal.Copy(hBuf, commandB, 0, commandB.Length);
|
||||
Marshal.FreeHGlobal(hBuf);
|
||||
|
||||
uint bytesReturned;
|
||||
int error = 0;
|
||||
DateTime start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB,
|
||||
(uint)commandB.Length, commandB, (uint)commandB.Length,
|
||||
out bytesReturned, IntPtr.Zero);
|
||||
out _, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
|
||||
if(sense) error = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
@@ -403,6 +404,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
Max = 3
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
enum StorageBusType
|
||||
{
|
||||
Unknown = 0,
|
||||
@@ -471,6 +473,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
MultiBlockNoCmd12
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
enum SdResponseType : uint
|
||||
{
|
||||
Unspecified,
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -42,16 +43,17 @@ namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
static class ListDevices
|
||||
{
|
||||
internal static string HexStringToString(string hex)
|
||||
static string HexStringToString(string hex)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
const string hextable = "0123456789abcdef";
|
||||
const string HEXTABLE = "0123456789abcdef";
|
||||
|
||||
for(int i = 0; i < hex.Length / 2; i++) result.Append((char)(16 * hextable.IndexOf(hex[2 * i]) + hextable.IndexOf(hex[2 * i + 1])));
|
||||
for(int i = 0; i < hex.Length / 2; i++) result.Append((char)(16 * HEXTABLE.IndexOf(hex[2 * i]) + HEXTABLE.IndexOf(hex[2 * i + 1])));
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "RedundantCatchClause")]
|
||||
internal static DeviceInfo[] GetList()
|
||||
{
|
||||
List<string> deviceIDs = new List<string>();
|
||||
@@ -74,7 +76,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
deviceIDs.AddRange(from ManagementObject drive in objCol select (string)drive["Drive"]);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch(Exception)
|
||||
{
|
||||
#if DEBUG
|
||||
throw;
|
||||
@@ -94,10 +96,12 @@ namespace DiscImageChef.Devices.Windows
|
||||
FileMode.OpenExisting, 0, IntPtr.Zero);
|
||||
if(fd.IsInvalid) continue;
|
||||
|
||||
StoragePropertyQuery query = new StoragePropertyQuery();
|
||||
query.PropertyId = StoragePropertyId.Device;
|
||||
query.QueryType = StorageQueryType.Standard;
|
||||
query.AdditionalParameters = new byte[1];
|
||||
StoragePropertyQuery query = new StoragePropertyQuery
|
||||
{
|
||||
PropertyId = StoragePropertyId.Device,
|
||||
QueryType = StorageQueryType.Standard,
|
||||
AdditionalParameters = new byte[1]
|
||||
};
|
||||
|
||||
//StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor();
|
||||
//descriptor.RawDeviceProperties = new byte[16384];
|
||||
@@ -118,19 +122,21 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
if(hasError && error != 0) continue;
|
||||
|
||||
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor();
|
||||
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.ToInt32(descriptorB, 12);
|
||||
descriptor.ProductIdOffset = BitConverter.ToInt32(descriptorB, 16);
|
||||
descriptor.ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20);
|
||||
descriptor.SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24);
|
||||
descriptor.BusType = (StorageBusType)BitConverter.ToUInt32(descriptorB, 28);
|
||||
descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32);
|
||||
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor
|
||||
{
|
||||
Version = BitConverter.ToUInt32(descriptorB, 0),
|
||||
Size = BitConverter.ToUInt32(descriptorB, 4),
|
||||
DeviceType = descriptorB[8],
|
||||
DeviceTypeModifier = descriptorB[9],
|
||||
RemovableMedia = BitConverter.ToBoolean(descriptorB, 10),
|
||||
CommandQueueing = BitConverter.ToBoolean(descriptorB, 11),
|
||||
VendorIdOffset = BitConverter.ToInt32(descriptorB, 12),
|
||||
ProductIdOffset = BitConverter.ToInt32(descriptorB, 16),
|
||||
ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20),
|
||||
SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24),
|
||||
BusType = (StorageBusType)BitConverter.ToUInt32(descriptorB, 28),
|
||||
RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32)
|
||||
};
|
||||
|
||||
DeviceInfo info = new DeviceInfo {Path = physId, Bus = descriptor.BusType.ToString()};
|
||||
|
||||
|
||||
@@ -32,11 +32,13 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct ScsiPassThroughDirect
|
||||
{
|
||||
public ushort Length;
|
||||
@@ -62,6 +64,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct AtaPassThroughDirect
|
||||
{
|
||||
/// <summary>
|
||||
@@ -115,6 +118,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct AtaPassThroughDirectWithBuffer
|
||||
{
|
||||
public AtaPassThroughDirect aptd;
|
||||
@@ -123,6 +127,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct AtaTaskFile
|
||||
{
|
||||
// Fields for commands sent
|
||||
@@ -151,6 +156,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct StorageDescriptorHeader
|
||||
{
|
||||
public uint Version;
|
||||
@@ -193,6 +199,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct StorageDeviceNumber
|
||||
{
|
||||
public int deviceType;
|
||||
@@ -201,6 +208,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct DeviceInfoData
|
||||
{
|
||||
public int cbSize;
|
||||
@@ -210,6 +218,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct DeviceInterfaceData
|
||||
{
|
||||
public int cbSize;
|
||||
@@ -219,6 +228,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct UsbSetupPacket
|
||||
{
|
||||
public byte bmRequest;
|
||||
@@ -229,6 +239,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct UsbDescriptorRequest
|
||||
{
|
||||
public int ConnectionIndex;
|
||||
@@ -237,6 +248,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct SffdiskQueryDeviceProtocolData
|
||||
{
|
||||
public ushort size;
|
||||
@@ -245,6 +257,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
struct SffdiskDeviceCommandData
|
||||
{
|
||||
public ushort size;
|
||||
|
||||
@@ -28,18 +28,20 @@
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// Copyright © 2007 Fort Hood TX, herethen, Public Domain
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
// Copyright "Fort Hood TX", internal domain, 2007
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
partial class Usb
|
||||
// TODO: Even after cleaning, refactoring and xml-documenting, this code needs some love
|
||||
static partial class Usb
|
||||
{
|
||||
#region "API Region"
|
||||
// ********************** Constants ************************
|
||||
@@ -276,6 +278,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
// UCHAR bNumConfigurations;
|
||||
//} USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR ;
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
internal struct UsbDeviceDescriptor
|
||||
{
|
||||
internal byte bLength;
|
||||
@@ -487,7 +490,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
//
|
||||
// Return a list of USB Host Controllers
|
||||
//
|
||||
static internal ReadOnlyCollection<UsbController> GetHostControllers()
|
||||
static IEnumerable<UsbController> GetHostControllers()
|
||||
{
|
||||
List<UsbController> hostList = new List<UsbController>();
|
||||
Guid hostGuid = new Guid(GUID_DEVINTERFACE_HUBCONTROLLER);
|
||||
@@ -503,8 +506,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
UsbController host = new UsbController();
|
||||
host.ControllerIndex = i;
|
||||
UsbController host = new UsbController {ControllerIndex = i};
|
||||
|
||||
// create a Device Interface Data structure
|
||||
SpDeviceInterfaceData dia = new SpDeviceInterfaceData();
|
||||
@@ -519,13 +521,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
da.cbSize = Marshal.SizeOf(da);
|
||||
|
||||
// build a Device Interface Detail Data structure
|
||||
SpDeviceInterfaceDetailData didd = new SpDeviceInterfaceDetailData();
|
||||
didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)
|
||||
SpDeviceInterfaceDetailData didd =
|
||||
new SpDeviceInterfaceDetailData {cbSize = 4 + Marshal.SystemDefaultCharSize};
|
||||
// trust me :)
|
||||
|
||||
// now we can get some more detailed information
|
||||
int nRequiredSize = 0;
|
||||
int nBytes = BUFFER_SIZE;
|
||||
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
|
||||
const int N_BYTES = BUFFER_SIZE;
|
||||
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, N_BYTES, ref nRequiredSize, ref da))
|
||||
{
|
||||
host.ControllerDevicePath = didd.DevicePath;
|
||||
|
||||
@@ -554,7 +557,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
//
|
||||
// The USB Host Controller Class
|
||||
//
|
||||
internal class UsbController
|
||||
class UsbController
|
||||
{
|
||||
internal int ControllerIndex;
|
||||
internal string ControllerDriverKeyName, ControllerDevicePath, ControllerDeviceDesc;
|
||||
@@ -569,50 +572,35 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// Return the index of the instance
|
||||
internal int Index
|
||||
{
|
||||
get { return ControllerIndex; }
|
||||
}
|
||||
internal int Index => ControllerIndex;
|
||||
|
||||
// Return the Device Path, such as "\\?\pci#ven_10de&dev_005a&subsys_815a1043&rev_a2#3&267a616a&0&58#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"
|
||||
internal string DevicePath
|
||||
{
|
||||
get { return ControllerDevicePath; }
|
||||
}
|
||||
internal string DevicePath => ControllerDevicePath;
|
||||
|
||||
// The DriverKeyName may be useful as a search key
|
||||
internal string DriverKeyName
|
||||
{
|
||||
get { return ControllerDriverKeyName; }
|
||||
}
|
||||
internal string DriverKeyName => ControllerDriverKeyName;
|
||||
|
||||
// Return the Friendly Name, such as "VIA USB Enhanced Host Controller"
|
||||
internal string Name
|
||||
{
|
||||
get { return ControllerDeviceDesc; }
|
||||
}
|
||||
internal string Name => ControllerDeviceDesc;
|
||||
|
||||
// Return Root Hub for this Controller
|
||||
internal UsbHub GetRootHub()
|
||||
{
|
||||
IntPtr h, h2;
|
||||
UsbHub root = new UsbHub();
|
||||
root.HubIsRootHub = true;
|
||||
root.HubDeviceDesc = "Root Hub";
|
||||
UsbHub root = new UsbHub {HubIsRootHub = true, HubDeviceDesc = "Root Hub"};
|
||||
|
||||
// Open a handle to the Host Controller
|
||||
h = CreateFile(ControllerDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0,
|
||||
IntPtr.Zero);
|
||||
if(h.ToInt32() == INVALID_HANDLE_VALUE) return root;
|
||||
|
||||
int nBytesReturned;
|
||||
UsbRootHubName hubName = new UsbRootHubName();
|
||||
int nBytes = Marshal.SizeOf(hubName);
|
||||
IntPtr ptrHubName = Marshal.AllocHGlobal(nBytes);
|
||||
|
||||
// get the Hub Name
|
||||
if(DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes,
|
||||
out nBytesReturned, IntPtr.Zero))
|
||||
out _, IntPtr.Zero))
|
||||
{
|
||||
hubName = (UsbRootHubName)Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName));
|
||||
root.HubDevicePath = @"\\.\" + hubName.RootHubName;
|
||||
@@ -625,15 +613,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
IntPtr.Zero);
|
||||
if(h2.ToInt32() != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
UsbNodeInformation nodeInfo = new UsbNodeInformation();
|
||||
nodeInfo.NodeType = (int)UsbHubNode.UsbHub;
|
||||
UsbNodeInformation nodeInfo = new UsbNodeInformation {NodeType = (int)UsbHubNode.UsbHub};
|
||||
nBytes = Marshal.SizeOf(nodeInfo);
|
||||
IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes);
|
||||
Marshal.StructureToPtr(nodeInfo, ptrNodeInfo, true);
|
||||
|
||||
// get the Hub Information
|
||||
if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes,
|
||||
out nBytesReturned, IntPtr.Zero))
|
||||
out _, IntPtr.Zero))
|
||||
{
|
||||
nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo,
|
||||
typeof(UsbNodeInformation));
|
||||
@@ -676,64 +663,34 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// return Port Count
|
||||
internal int PortCount
|
||||
{
|
||||
get { return HubPortCount; }
|
||||
}
|
||||
internal int PortCount => HubPortCount;
|
||||
|
||||
// return the Device Path, such as "\\?\pci#ven_10de&dev_005a&subsys_815a1043&rev_a2#3&267a616a&0&58#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"
|
||||
internal string DevicePath
|
||||
{
|
||||
get { return HubDevicePath; }
|
||||
}
|
||||
internal string DevicePath => HubDevicePath;
|
||||
|
||||
// The DriverKey may be useful as a search key
|
||||
internal string DriverKey
|
||||
{
|
||||
get { return HubDriverKey; }
|
||||
}
|
||||
internal string DriverKey => HubDriverKey;
|
||||
|
||||
// return the Friendly Name, such as "VIA USB Enhanced Host Controller"
|
||||
internal string Name
|
||||
{
|
||||
get { return HubDeviceDesc; }
|
||||
}
|
||||
internal string Name => HubDeviceDesc;
|
||||
|
||||
// the device path of this device
|
||||
internal string InstanceId
|
||||
{
|
||||
get { return HubInstanceId; }
|
||||
}
|
||||
internal string InstanceId => HubInstanceId;
|
||||
|
||||
// is is this a self-powered hub?
|
||||
internal bool IsBusPowered
|
||||
{
|
||||
get { return HubIsBusPowered; }
|
||||
}
|
||||
internal bool IsBusPowered => HubIsBusPowered;
|
||||
|
||||
// is this a root hub?
|
||||
internal bool IsRootHub
|
||||
{
|
||||
get { return HubIsRootHub; }
|
||||
}
|
||||
internal bool IsRootHub => HubIsRootHub;
|
||||
|
||||
internal string Manufacturer
|
||||
{
|
||||
get { return HubManufacturer; }
|
||||
}
|
||||
internal string Manufacturer => HubManufacturer;
|
||||
|
||||
internal string Product
|
||||
{
|
||||
get { return HubProduct; }
|
||||
}
|
||||
internal string Product => HubProduct;
|
||||
|
||||
internal string SerialNumber
|
||||
{
|
||||
get { return HubSerialNumber; }
|
||||
}
|
||||
internal string SerialNumber => HubSerialNumber;
|
||||
|
||||
// return a list of the down stream ports
|
||||
internal ReadOnlyCollection<UsbPort> GetPorts()
|
||||
internal IEnumerable<UsbPort> GetPorts()
|
||||
{
|
||||
List<UsbPort> portList = new List<UsbPort>();
|
||||
|
||||
@@ -750,13 +707,12 @@ namespace DiscImageChef.Devices.Windows
|
||||
// BTW: Ports are numbered starting at 1
|
||||
for(int i = 1; i <= HubPortCount; i++)
|
||||
{
|
||||
int nBytesReturned;
|
||||
UsbNodeConnectionInformationEx nodeConnection = new UsbNodeConnectionInformationEx();
|
||||
nodeConnection.ConnectionIndex = i;
|
||||
UsbNodeConnectionInformationEx nodeConnection =
|
||||
new UsbNodeConnectionInformationEx {ConnectionIndex = i};
|
||||
Marshal.StructureToPtr(nodeConnection, ptrNodeConnection, true);
|
||||
|
||||
if(!DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, ptrNodeConnection, nBytes,
|
||||
ptrNodeConnection, nBytes, out nBytesReturned, IntPtr.Zero)) continue;
|
||||
ptrNodeConnection, nBytes, out _, IntPtr.Zero)) continue;
|
||||
|
||||
nodeConnection =
|
||||
(UsbNodeConnectionInformationEx)Marshal.PtrToStructure(ptrNodeConnection,
|
||||
@@ -765,17 +721,17 @@ namespace DiscImageChef.Devices.Windows
|
||||
));
|
||||
|
||||
// load up the USBPort class
|
||||
UsbPort port = new UsbPort();
|
||||
port.PortPortNumber = i;
|
||||
port.PortHubDevicePath = HubDevicePath;
|
||||
UsbConnectionStatus status = (UsbConnectionStatus)nodeConnection.ConnectionStatus;
|
||||
port.PortStatus = status.ToString();
|
||||
UsbDeviceSpeed speed = (UsbDeviceSpeed)nodeConnection.Speed;
|
||||
port.PortSpeed = speed.ToString();
|
||||
port.PortIsDeviceConnected =
|
||||
nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected;
|
||||
port.PortIsHub = Convert.ToBoolean(nodeConnection.DeviceIsHub);
|
||||
port.PortDeviceDescriptor = nodeConnection.DeviceDescriptor;
|
||||
UsbPort port = new UsbPort
|
||||
{
|
||||
PortPortNumber = i,
|
||||
PortHubDevicePath = HubDevicePath,
|
||||
PortStatus = ((UsbConnectionStatus)nodeConnection.ConnectionStatus).ToString(),
|
||||
PortSpeed = ((UsbDeviceSpeed)nodeConnection.Speed).ToString(),
|
||||
PortIsDeviceConnected =
|
||||
nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected,
|
||||
PortIsHub = Convert.ToBoolean(nodeConnection.DeviceIsHub),
|
||||
PortDeviceDescriptor = nodeConnection.DeviceDescriptor
|
||||
};
|
||||
|
||||
// add it to the list
|
||||
portList.Add(port);
|
||||
@@ -810,53 +766,36 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// return Port Index of the Hub
|
||||
internal int PortNumber
|
||||
{
|
||||
get { return PortPortNumber; }
|
||||
}
|
||||
internal int PortNumber => PortPortNumber;
|
||||
|
||||
// return the Device Path of the Hub
|
||||
internal string HubDevicePath
|
||||
{
|
||||
get { return PortHubDevicePath; }
|
||||
}
|
||||
internal string HubDevicePath => PortHubDevicePath;
|
||||
|
||||
// the status (see USB_CONNECTION_STATUS above)
|
||||
internal string Status
|
||||
{
|
||||
get { return PortStatus; }
|
||||
}
|
||||
internal string Status => PortStatus;
|
||||
|
||||
// the speed of the connection (see USB_DEVICE_SPEED above)
|
||||
internal string Speed
|
||||
{
|
||||
get { return PortSpeed; }
|
||||
}
|
||||
internal string Speed => PortSpeed;
|
||||
|
||||
// is this a downstream external hub?
|
||||
internal bool IsHub
|
||||
{
|
||||
get { return PortIsHub; }
|
||||
}
|
||||
internal bool IsHub => PortIsHub;
|
||||
|
||||
// is anybody home?
|
||||
internal bool IsDeviceConnected
|
||||
{
|
||||
get { return PortIsDeviceConnected; }
|
||||
}
|
||||
internal bool IsDeviceConnected => PortIsDeviceConnected;
|
||||
|
||||
// return a down stream external hub
|
||||
internal UsbDevice GetDevice()
|
||||
{
|
||||
if(!PortIsDeviceConnected) return null;
|
||||
|
||||
UsbDevice device = new UsbDevice();
|
||||
|
||||
// Copy over some values from the Port class
|
||||
// Ya know, I've given some thought about making Device a derived class...
|
||||
device.DevicePortNumber = PortPortNumber;
|
||||
device.DeviceHubDevicePath = PortHubDevicePath;
|
||||
device.DeviceDescriptor = PortDeviceDescriptor;
|
||||
UsbDevice device = new UsbDevice
|
||||
{
|
||||
DevicePortNumber = PortPortNumber,
|
||||
DeviceHubDevicePath = PortHubDevicePath,
|
||||
DeviceDescriptor = PortDeviceDescriptor
|
||||
};
|
||||
|
||||
// Open a handle to the Hub device
|
||||
IntPtr h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0,
|
||||
@@ -875,12 +814,17 @@ namespace DiscImageChef.Devices.Windows
|
||||
if(PortDeviceDescriptor.iManufacturer > 0)
|
||||
{
|
||||
// build a request for string descriptor
|
||||
UsbDescriptorRequest request = new UsbDescriptorRequest();
|
||||
request.ConnectionIndex = PortPortNumber;
|
||||
request.SetupPacket.wValue =
|
||||
(short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iManufacturer);
|
||||
UsbDescriptorRequest request = new UsbDescriptorRequest
|
||||
{
|
||||
ConnectionIndex = PortPortNumber,
|
||||
SetupPacket =
|
||||
{
|
||||
// Language Code
|
||||
wIndex = 0x409,
|
||||
wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iManufacturer)
|
||||
}
|
||||
};
|
||||
request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request));
|
||||
request.SetupPacket.wIndex = 0x409; // Language Code
|
||||
// Geez, I wish C# had a Marshal.MemSet() method
|
||||
IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString);
|
||||
Marshal.StructureToPtr(request, ptrRequest, true);
|
||||
@@ -904,12 +848,17 @@ namespace DiscImageChef.Devices.Windows
|
||||
if(PortDeviceDescriptor.iProduct > 0)
|
||||
{
|
||||
// build a request for string descriptor
|
||||
UsbDescriptorRequest request = new UsbDescriptorRequest();
|
||||
request.ConnectionIndex = PortPortNumber;
|
||||
request.SetupPacket.wValue =
|
||||
(short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iProduct);
|
||||
UsbDescriptorRequest request = new UsbDescriptorRequest
|
||||
{
|
||||
ConnectionIndex = PortPortNumber,
|
||||
SetupPacket =
|
||||
{
|
||||
// Language Code
|
||||
wIndex = 0x409,
|
||||
wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iProduct)
|
||||
}
|
||||
};
|
||||
request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request));
|
||||
request.SetupPacket.wIndex = 0x409; // Language Code
|
||||
// Geez, I wish C# had a Marshal.MemSet() method
|
||||
IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString);
|
||||
Marshal.StructureToPtr(request, ptrRequest, true);
|
||||
@@ -930,12 +879,17 @@ namespace DiscImageChef.Devices.Windows
|
||||
if(PortDeviceDescriptor.iSerialNumber > 0)
|
||||
{
|
||||
// build a request for string descriptor
|
||||
UsbDescriptorRequest request = new UsbDescriptorRequest();
|
||||
request.ConnectionIndex = PortPortNumber;
|
||||
request.SetupPacket.wValue =
|
||||
(short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iSerialNumber);
|
||||
UsbDescriptorRequest request = new UsbDescriptorRequest
|
||||
{
|
||||
ConnectionIndex = PortPortNumber,
|
||||
SetupPacket =
|
||||
{
|
||||
// Language Code
|
||||
wIndex = 0x409,
|
||||
wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iSerialNumber)
|
||||
}
|
||||
};
|
||||
request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request));
|
||||
request.SetupPacket.wIndex = 0x409; // Language Code
|
||||
// Geez, I wish C# had a Marshal.MemSet() method
|
||||
IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString);
|
||||
Marshal.StructureToPtr(request, ptrRequest, true);
|
||||
@@ -955,11 +909,12 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// build a request for configuration descriptor
|
||||
UsbDescriptorRequest dcrRequest = new UsbDescriptorRequest();
|
||||
dcrRequest.ConnectionIndex = PortPortNumber;
|
||||
dcrRequest.SetupPacket.wValue = USB_CONFIGURATION_DESCRIPTOR_TYPE << 8;
|
||||
UsbDescriptorRequest dcrRequest = new UsbDescriptorRequest
|
||||
{
|
||||
ConnectionIndex = PortPortNumber,
|
||||
SetupPacket = {wIndex = 0, wValue = USB_CONFIGURATION_DESCRIPTOR_TYPE << 8}
|
||||
};
|
||||
dcrRequest.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(dcrRequest));
|
||||
dcrRequest.SetupPacket.wIndex = 0;
|
||||
// Geez, I wish C# had a Marshal.MemSet() method
|
||||
IntPtr dcrPtrRequest = Marshal.StringToHGlobalAuto(nullString);
|
||||
Marshal.StructureToPtr(dcrRequest, dcrPtrRequest, true);
|
||||
@@ -975,8 +930,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
Marshal.FreeHGlobal(dcrPtrRequest);
|
||||
|
||||
// Get the Driver Key Name (usefull in locating a device)
|
||||
UsbNodeConnectionDriverkeyName driverKey = new UsbNodeConnectionDriverkeyName();
|
||||
driverKey.ConnectionIndex = PortPortNumber;
|
||||
UsbNodeConnectionDriverkeyName driverKey =
|
||||
new UsbNodeConnectionDriverkeyName {ConnectionIndex = PortPortNumber};
|
||||
nBytes = Marshal.SizeOf(driverKey);
|
||||
IntPtr ptrDriverKey = Marshal.AllocHGlobal(nBytes);
|
||||
Marshal.StructureToPtr(driverKey, ptrDriverKey, true);
|
||||
@@ -1015,16 +970,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
IntPtr.Zero);
|
||||
if(h.ToInt32() == INVALID_HANDLE_VALUE) return hub;
|
||||
// Get the DevicePath for downstream hub
|
||||
int nBytesReturned;
|
||||
UsbNodeConnectionName nodeName = new UsbNodeConnectionName();
|
||||
nodeName.ConnectionIndex = PortPortNumber;
|
||||
UsbNodeConnectionName nodeName = new UsbNodeConnectionName {ConnectionIndex = PortPortNumber};
|
||||
int nBytes = Marshal.SizeOf(nodeName);
|
||||
IntPtr ptrNodeName = Marshal.AllocHGlobal(nBytes);
|
||||
Marshal.StructureToPtr(nodeName, ptrNodeName, true);
|
||||
|
||||
// Use an IOCTL call to request the Node Name
|
||||
if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes,
|
||||
out nBytesReturned, IntPtr.Zero))
|
||||
out _, IntPtr.Zero))
|
||||
{
|
||||
nodeName = (UsbNodeConnectionName)Marshal.PtrToStructure(ptrNodeName,
|
||||
typeof(UsbNodeConnectionName));
|
||||
@@ -1036,15 +989,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
IntPtr.Zero);
|
||||
if(h2.ToInt32() != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
UsbNodeInformation nodeInfo = new UsbNodeInformation();
|
||||
nodeInfo.NodeType = (int)UsbHubNode.UsbHub;
|
||||
UsbNodeInformation nodeInfo = new UsbNodeInformation {NodeType = (int)UsbHubNode.UsbHub};
|
||||
nBytes = Marshal.SizeOf(nodeInfo);
|
||||
IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes);
|
||||
Marshal.StructureToPtr(nodeInfo, ptrNodeInfo, true);
|
||||
|
||||
// get the Hub Information
|
||||
if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes,
|
||||
out nBytesReturned, IntPtr.Zero))
|
||||
out _, IntPtr.Zero))
|
||||
{
|
||||
nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo,
|
||||
typeof(UsbNodeInformation));
|
||||
@@ -1096,54 +1048,27 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// return Port Index of the Hub
|
||||
internal int PortNumber
|
||||
{
|
||||
get { return DevicePortNumber; }
|
||||
}
|
||||
internal int PortNumber => DevicePortNumber;
|
||||
|
||||
// return the Device Path of the Hub (the parent device)
|
||||
internal string HubDevicePath
|
||||
{
|
||||
get { return DeviceHubDevicePath; }
|
||||
}
|
||||
internal string HubDevicePath => DeviceHubDevicePath;
|
||||
|
||||
// useful as a search key
|
||||
internal string DriverKey
|
||||
{
|
||||
get { return DeviceDriverKey; }
|
||||
}
|
||||
internal string DriverKey => DeviceDriverKey;
|
||||
|
||||
// the device path of this device
|
||||
internal string InstanceId
|
||||
{
|
||||
get { return DeviceInstanceId; }
|
||||
}
|
||||
internal string InstanceId => DeviceInstanceId;
|
||||
|
||||
// the friendly name
|
||||
internal string Name
|
||||
{
|
||||
get { return DeviceName; }
|
||||
}
|
||||
internal string Name => DeviceName;
|
||||
|
||||
internal string Manufacturer
|
||||
{
|
||||
get { return DeviceManufacturer; }
|
||||
}
|
||||
internal string Manufacturer => DeviceManufacturer;
|
||||
|
||||
internal string Product
|
||||
{
|
||||
get { return DeviceProduct; }
|
||||
}
|
||||
internal string Product => DeviceProduct;
|
||||
|
||||
internal string SerialNumber
|
||||
{
|
||||
get { return DeviceSerialNumber; }
|
||||
}
|
||||
internal string SerialNumber => DeviceSerialNumber;
|
||||
|
||||
internal byte[] BinaryDescriptors
|
||||
{
|
||||
get { return BinaryDeviceDescriptors; }
|
||||
}
|
||||
internal byte[] BinaryDescriptors => BinaryDeviceDescriptors;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1152,15 +1077,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
static string GetDescriptionByKeyName(string driverKeyName)
|
||||
{
|
||||
string ans = "";
|
||||
string devEnum = REGSTR_KEY_USB;
|
||||
const string DEV_ENUM = REGSTR_KEY_USB;
|
||||
|
||||
// Use the "enumerator form" of the SetupDiGetClassDevs API
|
||||
// to generate a list of all USB devices
|
||||
IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
|
||||
IntPtr h = SetupDiGetClassDevs(0, DEV_ENUM, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
|
||||
if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans;
|
||||
|
||||
IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE);
|
||||
string keyName;
|
||||
|
||||
bool success;
|
||||
int i = 0;
|
||||
@@ -1176,7 +1100,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
int requiredSize = 0;
|
||||
int regType = REG_SZ;
|
||||
keyName = "";
|
||||
string keyName = "";
|
||||
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE,
|
||||
ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
@@ -1206,15 +1130,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
static string GetInstanceIdByKeyName(string driverKeyName)
|
||||
{
|
||||
string ans = "";
|
||||
string devEnum = REGSTR_KEY_USB;
|
||||
const string DEV_ENUM = REGSTR_KEY_USB;
|
||||
|
||||
// Use the "enumerator form" of the SetupDiGetClassDevs API
|
||||
// to generate a list of all USB devices
|
||||
IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
|
||||
IntPtr h = SetupDiGetClassDevs(0, DEV_ENUM, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
|
||||
if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans;
|
||||
|
||||
IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE);
|
||||
string keyName;
|
||||
|
||||
bool success;
|
||||
int i = 0;
|
||||
@@ -1231,16 +1154,16 @@ namespace DiscImageChef.Devices.Windows
|
||||
int requiredSize = 0;
|
||||
int regType = REG_SZ;
|
||||
|
||||
keyName = "";
|
||||
string keyName = "";
|
||||
if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE,
|
||||
ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf);
|
||||
|
||||
// is it a match?
|
||||
if(keyName == driverKeyName)
|
||||
{
|
||||
int nBytes = BUFFER_SIZE;
|
||||
StringBuilder sb = new StringBuilder(nBytes);
|
||||
SetupDiGetDeviceInstanceId(h, ref da, sb, nBytes, out requiredSize);
|
||||
const int N_BYTES = BUFFER_SIZE;
|
||||
StringBuilder sb = new StringBuilder(N_BYTES);
|
||||
SetupDiGetDeviceInstanceId(h, ref da, sb, N_BYTES, out requiredSize);
|
||||
ans = sb.ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -28,25 +28,26 @@
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2018 Natalia Portillo
|
||||
// Copyright © 2007 Fort Hood TX, herethen, Public Domain
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Copyright "Fort Hood TX", internal domain, 2007
|
||||
namespace DiscImageChef.Devices.Windows
|
||||
{
|
||||
//
|
||||
// A place for "higher level" related functions
|
||||
// You might not want to keep these in the USB class... your choice
|
||||
//
|
||||
partial class Usb
|
||||
// TODO: Even after cleaning, refactoring and xml-documenting, this code needs some love
|
||||
static partial class Usb
|
||||
{
|
||||
//
|
||||
// Get a list of all connected devices
|
||||
//
|
||||
static internal List<UsbDevice> GetConnectedDevices()
|
||||
internal static List<UsbDevice> GetConnectedDevices()
|
||||
{
|
||||
List<UsbDevice> devList = new List<UsbDevice>();
|
||||
|
||||
@@ -56,7 +57,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// private routine for enumerating a hub
|
||||
static void ListHub(UsbHub hub, List<UsbDevice> devList)
|
||||
static void ListHub(UsbHub hub, ICollection<UsbDevice> devList)
|
||||
{
|
||||
foreach(UsbPort port in hub.GetPorts())
|
||||
if(port.IsHub) ListHub(port.GetHub(), devList);
|
||||
@@ -66,7 +67,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
//
|
||||
// Find a device based upon it's DriverKeyName
|
||||
//
|
||||
static internal UsbDevice FindDeviceByDriverKeyName(string driverKeyName)
|
||||
internal static UsbDevice FindDeviceByDriverKeyName(string driverKeyName)
|
||||
{
|
||||
UsbDevice foundDevice = null;
|
||||
|
||||
@@ -99,7 +100,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
//
|
||||
// Find a device based upon it's Instance ID
|
||||
//
|
||||
static internal UsbDevice FindDeviceByInstanceId(string instanceId)
|
||||
static UsbDevice FindDeviceByInstanceId(string instanceId)
|
||||
{
|
||||
UsbDevice foundDevice = null;
|
||||
|
||||
@@ -167,38 +168,28 @@ namespace DiscImageChef.Devices.Windows
|
||||
//
|
||||
// Find a device based upon a Drive Letter
|
||||
//
|
||||
static internal UsbDevice FindDriveLetter(string driveLetter, string deviceGuid)
|
||||
internal static UsbDevice FindDriveLetter(string driveLetter, string deviceGuid)
|
||||
{
|
||||
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;
|
||||
|
||||
return FindDeviceNumber(devNum, deviceGuid);
|
||||
return devNum < 0 ? null : FindDeviceNumber(devNum, deviceGuid);
|
||||
}
|
||||
|
||||
static internal UsbDevice FindDrivePath(string drivePath, string deviceGuid)
|
||||
internal static UsbDevice FindDrivePath(string drivePath, string deviceGuid)
|
||||
{
|
||||
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;
|
||||
|
||||
return FindDeviceNumber(devNum, deviceGuid);
|
||||
return devNum < 0 ? null : FindDeviceNumber(devNum, deviceGuid);
|
||||
}
|
||||
|
||||
//
|
||||
// Find a device based upon a Drive Letter
|
||||
//
|
||||
static internal UsbDevice FindDeviceNumber(int devNum, string deviceGuid)
|
||||
static UsbDevice FindDeviceNumber(int devNum, string deviceGuid)
|
||||
{
|
||||
UsbDevice foundDevice = null;
|
||||
string instanceId = "";
|
||||
@@ -227,23 +218,22 @@ namespace DiscImageChef.Devices.Windows
|
||||
da.cbSize = Marshal.SizeOf(da);
|
||||
|
||||
// build a Device Interface Detail Data structure
|
||||
SpDeviceInterfaceDetailData didd = new SpDeviceInterfaceDetailData();
|
||||
didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)
|
||||
SpDeviceInterfaceDetailData didd =
|
||||
new SpDeviceInterfaceDetailData {cbSize = 4 + Marshal.SystemDefaultCharSize}; // trust me :)
|
||||
|
||||
// now we can get some more detailed information
|
||||
int nRequiredSize = 0;
|
||||
int nBytes = BUFFER_SIZE;
|
||||
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
|
||||
const int N_BYTES = BUFFER_SIZE;
|
||||
if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, N_BYTES, ref nRequiredSize, ref da))
|
||||
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
|
||||
IntPtr ptrPrevious;
|
||||
CM_Get_Parent(out ptrPrevious, da.DevInst, 0);
|
||||
CM_Get_Parent(out IntPtr ptrPrevious, da.DevInst, 0);
|
||||
|
||||
// Now we get the InstanceID of the USB level device
|
||||
IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(nBytes);
|
||||
CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, nBytes, 0);
|
||||
IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(N_BYTES);
|
||||
CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, N_BYTES, 0);
|
||||
instanceId = Marshal.PtrToStringAuto(ptrInstanceBuf);
|
||||
|
||||
Marshal.FreeHGlobal(ptrInstanceBuf);
|
||||
@@ -271,12 +261,11 @@ namespace DiscImageChef.Devices.Windows
|
||||
IntPtr h = CreateFile(devicePath.TrimEnd('\\'), 0, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
|
||||
if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans;
|
||||
|
||||
int requiredSize;
|
||||
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,
|
||||
if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out _,
|
||||
IntPtr.Zero))
|
||||
{
|
||||
sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber));
|
||||
|
||||
Reference in New Issue
Block a user