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

@@ -43,8 +43,9 @@ namespace DiscImageChef.Devices
buffer = new byte[512];
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.ReadBuffer};
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
out duration,
out bool sense);
Error = LastError != 0;
@@ -59,8 +60,8 @@ namespace DiscImageChef.Devices
buffer = new byte[512];
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.ReadBufferDma};
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.NoTransfer,
ref buffer, timeout, false, out duration, out bool sense);
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.NoTransfer,
ref buffer, timeout, false, out duration, out bool sense);
Error = LastError != 0;
DicConsole.DebugWriteLine("ATA Device", "READ BUFFER DMA took {0} ms.", duration);
@@ -68,29 +69,30 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
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)
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
byte count, uint timeout, out double duration)
{
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
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
};
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;
@@ -99,24 +101,25 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
{
buffer = count == 0 ? new byte[512 * 256] : new byte[512 * count];
AtaRegistersLba28 registers = new AtaRegistersLba28
{
Command = (byte)AtaCommands.ReadMultiple,
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)
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
LbaMid = (byte)((lba & 0xFF00) / 0x100),
LbaLow = (byte)((lba & 0xFF) / 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;
@@ -125,17 +128,18 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadNativeMaxAddress(out uint lba, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
public bool ReadNativeMaxAddress(out uint lba, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
out double duration)
{
lba = 0;
byte[] buffer = new byte[0];
byte[] buffer = new byte[0];
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.ReadNativeMaxAddress};
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;
@@ -144,7 +148,7 @@ namespace DiscImageChef.Devices
lba += (uint)(statusRegisters.DeviceHead & 0xF);
lba *= 0x1000000;
lba += (uint)(statusRegisters.LbaHigh << 16);
lba += (uint)(statusRegisters.LbaMid << 8);
lba += (uint)(statusRegisters.LbaMid << 8);
lba += statusRegisters.LbaLow;
}
@@ -153,30 +157,31 @@ namespace DiscImageChef.Devices
return sense;
}
public bool Read(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
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)
public bool Read(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
byte count, uint timeout, out double duration)
{
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
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
};
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;
@@ -185,30 +190,32 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, uint blockSize,
uint timeout, out double duration)
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)
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
{
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
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
};
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;
@@ -222,17 +229,18 @@ namespace DiscImageChef.Devices
byte[] buffer = new byte[0];
AtaRegistersLba28 registers = new AtaRegistersLba28
{
Command = (byte)AtaCommands.Seek,
Command = (byte)AtaCommands.Seek,
DeviceHead = (byte)((lba & 0xF000000) / 0x1000000),
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
LbaMid = (byte)((lba & 0xFF00) / 0x100),
LbaLow = (byte)((lba & 0xFF) / 0x1)
LbaHigh = (byte)((lba & 0xFF0000) / 0x10000),
LbaMid = (byte)((lba & 0xFF00) / 0x100),
LbaLow = (byte)((lba & 0xFF) / 0x1)
};
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;