mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
* DiscImageChef.Devices/Device/AtaCommands/Cfa.cs:
* DiscImageChef.Devices/Device/AtaCommands/MCPT.cs: * DiscImageChef.Devices/Device/AtaCommands/Ata28.cs: * DiscImageChef.Devices/Device/AtaCommands/Ata48.cs: * DiscImageChef.Devices/Device/AtaCommands/Smart.cs: * DiscImageChef.Devices/Device/AtaCommands/AtaCHS.cs: * DiscImageChef.Devices/DiscImageChef.Devices.csproj: Implemented ATA commands. * DiscImageChef.Devices/Device/ScsiCommands/SPC.cs: Make MODE SENSE (6) buffer big enought. * DiscImageChef.Devices/Enums.cs: Added new command found in ACS-3 rev. 6
This commit is contained in:
@@ -43,6 +43,215 @@ namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
public bool ReadBuffer(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
|
||||
bool sense;
|
||||
|
||||
registers.command = (byte)AtaCommands.ReadBuffer;
|
||||
|
||||
lastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn, AtaTransferRegister.NoTransfer,
|
||||
ref buffer, timeout, false, out duration, out sense);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ BUFFER took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadBufferDma(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
|
||||
bool sense;
|
||||
|
||||
registers.command = (byte)AtaCommands.ReadBufferDma;
|
||||
|
||||
lastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.NoTransfer,
|
||||
ref buffer, timeout, false, out duration, out sense);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ BUFFER DMA took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, byte count, uint timeout, out double duration)
|
||||
{
|
||||
return ReadDma(out buffer, out statusRegisters, true, lba, count, timeout, out duration);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ DMA took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadNativeMaxAddress(out uint lba, out AtaErrorRegistersLBA28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
lba = 0;
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
|
||||
bool sense;
|
||||
|
||||
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);
|
||||
error = lastError != 0;
|
||||
|
||||
if ((statusRegisters.status & 0x23) == 0)
|
||||
{
|
||||
lba += (uint)(statusRegisters.deviceHead & 0xF);
|
||||
lba *= 0x1000000;
|
||||
lba += (uint)(statusRegisters.lbaHigh << 16);
|
||||
lba += (uint)(statusRegisters.lbaMid << 8);
|
||||
lba += statusRegisters.lbaLow;
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ NATIVE MAX ADDRESS took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool Read(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, byte count, uint timeout, out double duration)
|
||||
{
|
||||
return Read(out buffer, out statusRegisters, true, lba, count, timeout, out duration);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ SECTORS took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
|
||||
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
return ReadLong(out buffer, out statusRegisters, true, lba, blockSize, timeout, out duration);
|
||||
}
|
||||
|
||||
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, bool retry, uint lba, uint blockSize, uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[blockSize];
|
||||
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
|
||||
bool sense;
|
||||
|
||||
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);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LONG took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool Seek(out AtaErrorRegistersLBA28 statusRegisters, uint lba, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
|
||||
bool sense;
|
||||
|
||||
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.PioIn, AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out sense);
|
||||
error = lastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SEEK took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user