Code cleanup.

This commit is contained in:
2018-06-22 08:08:38 +01:00
parent 82f474c7e3
commit 88da8fc019
581 changed files with 22423 additions and 20839 deletions

View File

@@ -37,7 +37,7 @@ namespace DiscImageChef.Devices
{
public partial class Device
{
public bool GetNativeMaxAddressExt(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
public bool GetNativeMaxAddressExt(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
out double duration)
{
lba = 0;
@@ -45,14 +45,15 @@ namespace DiscImageChef.Devices
AtaRegistersLba48 registers =
new AtaRegistersLba48 {Command = (byte)AtaCommands.NativeMaxAddress, Feature = 0x0000};
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
out duration,
out bool sense);
Error = LastError != 0;
if((statusRegisters.Status & 0x23) == 0)
{
lba = statusRegisters.LbaHigh;
lba = statusRegisters.LbaHigh;
lba *= 0x100000000;
lba += (ulong)(statusRegisters.LbaMid << 16);
lba += statusRegisters.LbaLow;
@@ -63,22 +64,23 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
uint timeout, out double duration)
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
uint timeout, out double duration)
{
buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
AtaRegistersLba48 registers = new AtaRegistersLba48
{
Command = (byte)AtaCommands.ReadDmaExt,
Command = (byte)AtaCommands.ReadDmaExt,
SectorCount = count,
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
};
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma,
AtaTransferRegister.SectorCount,
ref buffer, timeout, true, out duration, out bool sense);
Error = LastError != 0;
@@ -87,22 +89,24 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadLog(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, byte logAddress,
ushort pageNumber, ushort count, uint timeout, out double duration)
public bool ReadLog(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, byte logAddress,
ushort pageNumber, ushort count, uint timeout,
out double duration)
{
buffer = new byte[512 * count];
AtaRegistersLba48 registers = new AtaRegistersLba48
{
Command = (byte)AtaCommands.ReadLogExt,
Command = (byte)AtaCommands.ReadLogExt,
SectorCount = count,
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
};
registers.LbaLow += logAddress;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
out duration,
out bool sense);
Error = LastError != 0;
@@ -111,21 +115,23 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadLogDma(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, byte logAddress,
ushort pageNumber, ushort count, uint timeout, out double duration)
public bool ReadLogDma(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, byte logAddress,
ushort pageNumber, ushort count, uint timeout,
out double duration)
{
buffer = new byte[512 * count];
AtaRegistersLba48 registers = new AtaRegistersLba48
{
Command = (byte)AtaCommands.ReadLogDmaExt,
Command = (byte)AtaCommands.ReadLogDmaExt,
SectorCount = count,
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
};
registers.LbaLow += logAddress;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma,
AtaTransferRegister.SectorCount,
ref buffer, timeout, true, out duration, out bool sense);
Error = LastError != 0;
@@ -134,23 +140,25 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
uint timeout, out double duration)
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba,
ushort count,
uint timeout, out double duration)
{
buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
AtaRegistersLba48 registers = new AtaRegistersLba48
{
Command = (byte)AtaCommands.ReadMultipleExt,
Command = (byte)AtaCommands.ReadMultipleExt,
SectorCount = count,
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
};
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
out duration,
out bool sense);
Error = LastError != 0;
@@ -159,23 +167,24 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadNativeMaxAddress(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
public bool ReadNativeMaxAddress(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
out double duration)
{
lba = 0;
byte[] buffer = new byte[0];
byte[] buffer = new byte[0];
AtaRegistersLba48 registers = new AtaRegistersLba48 {Command = (byte)AtaCommands.ReadNativeMaxAddressExt};
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
out duration,
out bool sense);
Error = LastError != 0;
if((statusRegisters.Status & 0x23) == 0)
{
lba = statusRegisters.LbaHigh;
lba = statusRegisters.LbaHigh;
lba *= 0x100000000;
lba += (ulong)(statusRegisters.LbaMid << 16);
lba += statusRegisters.LbaLow;
@@ -186,23 +195,24 @@ namespace DiscImageChef.Devices
return sense;
}
public bool Read(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
uint timeout, out double duration)
public bool Read(out byte[] buffer, out AtaErrorRegistersLba48 statusRegisters, ulong lba, ushort count,
uint timeout, out double duration)
{
buffer = count == 0 ? new byte[512 * 65536] : new byte[512 * count];
AtaRegistersLba48 registers = new AtaRegistersLba48
{
Command = (byte)AtaCommands.ReadExt,
Command = (byte)AtaCommands.ReadExt,
SectorCount = count,
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
LbaHigh = (ushort)((lba & 0xFFFF00000000) / 0x100000000),
LbaMid = (ushort)((lba & 0xFFFF0000) / 0x10000),
LbaLow = (ushort)((lba & 0xFFFF) / 0x1)
};
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
out duration,
out bool sense);
Error = LastError != 0;