mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Renamed project files and folders
This commit is contained in:
246
Aaru.Devices/Device/AtaCommands/Ata28.cs
Normal file
246
Aaru.Devices/Device/AtaCommands/Ata28.cs
Normal file
@@ -0,0 +1,246 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Ata28.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains 28-bit LBA ATA commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
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 {Command = (byte)AtaCommands.ReadBuffer};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool 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 {Command = (byte)AtaCommands.ReadBufferDma};
|
||||
|
||||
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);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
|
||||
uint timeout, out double duration) =>
|
||||
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)
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma,
|
||||
AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out bool 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)
|
||||
{
|
||||
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.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
|
||||
out duration,
|
||||
out bool 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 {Command = (byte)AtaCommands.ReadNativeMaxAddress};
|
||||
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
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 += (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) =>
|
||||
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)
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
|
||||
out duration,
|
||||
out bool 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) =>
|
||||
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
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
registers.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
|
||||
out duration,
|
||||
out bool 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
|
||||
{
|
||||
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.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SEEK took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
224
Aaru.Devices/Device/AtaCommands/Ata48.cs
Normal file
224
Aaru.Devices/Device/AtaCommands/Ata48.cs
Normal file
@@ -0,0 +1,224 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Ata48.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains 48-bit LBA ATA commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
public bool GetNativeMaxAddressExt(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
lba = 0;
|
||||
byte[] buffer = new byte[0];
|
||||
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,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if((statusRegisters.Status & 0x23) == 0)
|
||||
{
|
||||
lba = statusRegisters.LbaHigh;
|
||||
lba *= 0x100000000;
|
||||
lba += (ulong)(statusRegisters.LbaMid << 16);
|
||||
lba += statusRegisters.LbaLow;
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "GET NATIVE MAX ADDRESS EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
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,
|
||||
SectorCount = count,
|
||||
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,
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ DMA EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
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,
|
||||
SectorCount = count,
|
||||
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,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LOG EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
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,
|
||||
SectorCount = count,
|
||||
LbaLow = (ushort)((pageNumber & 0xFF) * 0x100),
|
||||
LbaHigh = (ushort)((pageNumber & 0xFF00) / 0x100)
|
||||
};
|
||||
|
||||
registers.LbaLow += logAddress;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma,
|
||||
AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LOG DMA EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
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,
|
||||
SectorCount = count,
|
||||
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,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadNativeMaxAddress(out ulong lba, out AtaErrorRegistersLba48 statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
lba = 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,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
if((statusRegisters.Status & 0x23) == 0)
|
||||
{
|
||||
lba = statusRegisters.LbaHigh;
|
||||
lba *= 0x100000000;
|
||||
lba += (ulong)(statusRegisters.LbaMid << 16);
|
||||
lba += statusRegisters.LbaLow;
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ NATIVE MAX ADDRESS EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
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,
|
||||
SectorCount = count,
|
||||
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,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ SECTORS EXT took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
268
Aaru.Devices/Device/AtaCommands/AtaCHS.cs
Normal file
268
Aaru.Devices/Device/AtaCommands/AtaCHS.cs
Normal file
@@ -0,0 +1,268 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : AtaCHS.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains ATA commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY DEVICE command to the device, using default device timeout
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
public bool AtaIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters) =>
|
||||
AtaIdentify(out buffer, out statusRegisters, Timeout);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY DEVICE command to the device, using default device timeout
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
/// <param name="duration">Duration.</param>
|
||||
public bool AtaIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, out double duration) =>
|
||||
AtaIdentify(out buffer, out statusRegisters, Timeout, out duration);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY DEVICE command to the device
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
public bool AtaIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, uint timeout) =>
|
||||
AtaIdentify(out buffer, out statusRegisters, timeout, out _);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY DEVICE command to the device
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
/// <param name="duration">Duration.</param>
|
||||
public bool AtaIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersChs registers = new AtaRegistersChs {Command = (byte)AtaCommands.IdentifyDevice};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "IDENTIFY DEVICE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder,
|
||||
byte head,
|
||||
byte sector, byte count, uint timeout,
|
||||
out double duration) =>
|
||||
ReadDma(out buffer, out statusRegisters, true, cylinder, head, sector, count, timeout, out duration);
|
||||
|
||||
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, bool retry, ushort cylinder,
|
||||
byte head, byte sector, byte count, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma,
|
||||
AtaTransferRegister.SectorCount,
|
||||
ref buffer, timeout, true, out duration, out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ DMA took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder,
|
||||
byte head, byte sector, byte count,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ MULTIPLE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool Read(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder, byte head,
|
||||
byte sector, byte count, uint timeout,
|
||||
out double duration) =>
|
||||
Read(out buffer, out statusRegisters, true, cylinder, head, sector, count, timeout, out duration);
|
||||
|
||||
public bool Read(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, bool retry, ushort cylinder,
|
||||
byte head, byte sector, byte count, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ SECTORS took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder,
|
||||
byte head,
|
||||
byte sector, uint blockSize, uint timeout,
|
||||
out double duration) =>
|
||||
ReadLong(out buffer, out statusRegisters, true, cylinder, head, sector, blockSize, timeout, out duration);
|
||||
|
||||
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, bool retry,
|
||||
ushort cylinder,
|
||||
byte head, byte sector, uint blockSize,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[blockSize];
|
||||
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
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.SectorCount, ref buffer, timeout, true,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "READ LONG took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool Seek(out AtaErrorRegistersChs statusRegisters, ushort cylinder, byte head, byte sector,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = (byte)AtaCommands.Seek,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, true, out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SEEK took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SetFeatures(out AtaErrorRegistersChs statusRegisters, AtaFeatures feature, uint timeout,
|
||||
out double duration) =>
|
||||
SetFeatures(out statusRegisters, feature, 0, 0, 0, 0, timeout, out duration);
|
||||
|
||||
public bool SetFeatures(out AtaErrorRegistersChs statusRegisters, AtaFeatures feature, ushort cylinder,
|
||||
byte head, byte sector, byte sectorCount,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = (byte)AtaCommands.SetFeatures,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
DeviceHead = (byte)(head & 0x0F),
|
||||
Sector = sector,
|
||||
SectorCount = sectorCount,
|
||||
Feature = (byte)feature
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, true, out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SET FEATURES took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
Aaru.Devices/Device/AtaCommands/Atapi.cs
Normal file
94
Aaru.Devices/Device/AtaCommands/Atapi.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Atapi.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains ATAPI commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY PACKET DEVICE command to the device, using default device timeout
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
public bool AtapiIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters) =>
|
||||
AtapiIdentify(out buffer, out statusRegisters, Timeout);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY PACKET DEVICE command to the device, using default device timeout
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
/// <param name="duration">Duration.</param>
|
||||
public bool AtapiIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, out double duration) =>
|
||||
AtapiIdentify(out buffer, out statusRegisters, Timeout, out duration);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY PACKET DEVICE command to the device
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
public bool AtapiIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, uint timeout) =>
|
||||
AtapiIdentify(out buffer, out statusRegisters, timeout, out _);
|
||||
|
||||
/// <summary>
|
||||
/// Sends the ATA IDENTIFY PACKET DEVICE command to the device
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the command failed and <paramref name="statusRegisters" /> contains the error registers.</returns>
|
||||
/// <param name="buffer">Buffer.</param>
|
||||
/// <param name="statusRegisters">Status registers.</param>
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
/// <param name="duration">Duration.</param>
|
||||
public bool AtapiIdentify(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersChs registers = new AtaRegistersChs {Command = (byte)AtaCommands.IdentifyPacketDevice};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "IDENTIFY PACKET DEVICE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
110
Aaru.Devices/Device/AtaCommands/Cfa.cs
Normal file
110
Aaru.Devices/Device/AtaCommands/Cfa.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Cfa.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains Compact Flash Association commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
public bool TranslateSector(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
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.DeviceHead += 0x40;
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CFA TRANSLATE SECTOR took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool TranslateSector(out byte[] buffer, out AtaErrorRegistersChs statusRegisters, ushort cylinder,
|
||||
byte head, byte sector, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersChs registers = new AtaRegistersChs
|
||||
{
|
||||
Command = (byte)AtaCommands.TranslateSector,
|
||||
CylinderHigh = (byte)((cylinder & 0xFF00) / 0x100),
|
||||
CylinderLow = (byte)((cylinder & 0xFF) / 0x1),
|
||||
Sector = sector,
|
||||
DeviceHead = (byte)(head & 0x0F)
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CFA TRANSLATE SECTOR took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool RequestExtendedErrorCode(out byte errorCode, out AtaErrorRegistersLba28 statusRegisters,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28 {Command = (byte)AtaCommands.RequestSense};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
errorCode = statusRegisters.Error;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CFA REQUEST EXTENDED ERROR CODE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
Aaru.Devices/Device/AtaCommands/MCPT.cs
Normal file
66
Aaru.Devices/Device/AtaCommands/MCPT.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : MCPT.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains Media Card Pass-Thru commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
public bool EnableMediaCardPassThrough(out AtaErrorRegistersChs statusRegisters, uint timeout,
|
||||
out double duration) =>
|
||||
CheckMediaCardType(1, out statusRegisters, timeout, out duration);
|
||||
|
||||
public bool DisableMediaCardPassThrough(out AtaErrorRegistersChs statusRegisters, uint timeout,
|
||||
out double duration) =>
|
||||
CheckMediaCardType(0, out statusRegisters, timeout, out duration);
|
||||
|
||||
public bool CheckMediaCardType(byte feature, out AtaErrorRegistersChs statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersChs registers =
|
||||
new AtaRegistersChs {Command = (byte)AtaCommands.CheckMediaCardType, Feature = feature};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "CHECK MEDIA CARD TYPE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
224
Aaru.Devices/Device/AtaCommands/Smart.cs
Normal file
224
Aaru.Devices/Device/AtaCommands/Smart.cs
Normal file
@@ -0,0 +1,224 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Smart.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : ATA commands.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains S.M.A.R.T. commands.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
{
|
||||
public partial class Device
|
||||
{
|
||||
public bool SmartDisable(out AtaErrorRegistersLba28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.Disable,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART DISABLE OPERATIONS took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartEnableAttributeAutosave(out AtaErrorRegistersLba28 statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.EnableDisableAttributeAutosave,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F,
|
||||
SectorCount = 0xF1
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART ENABLE ATTRIBUTE AUTOSAVE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartDisableAttributeAutosave(out AtaErrorRegistersLba28 statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.EnableDisableAttributeAutosave,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART DISABLE ATTRIBUTE AUTOSAVE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartEnable(out AtaErrorRegistersLba28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.Enable,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART ENABLE OPERATIONS took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartExecuteOffLineImmediate(out AtaErrorRegistersLba28 statusRegisters, byte subcommand,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ExecuteOfflineImmediate,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F,
|
||||
LbaLow = subcommand
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART EXECUTE OFF-LINE IMMEDIATE took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartReadData(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
|
||||
out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ReadData,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART READ DATA took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartReadLog(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, byte logAddress,
|
||||
uint timeout, out double duration)
|
||||
{
|
||||
buffer = new byte[512];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ReadLog,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F,
|
||||
LbaLow = logAddress
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART READ LOG took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
|
||||
public bool SmartReturnStatus(out AtaErrorRegistersLba28 statusRegisters, uint timeout, out double duration)
|
||||
{
|
||||
byte[] buffer = new byte[0];
|
||||
AtaRegistersLba28 registers = new AtaRegistersLba28
|
||||
{
|
||||
Command = (byte)AtaCommands.Smart,
|
||||
Feature = (byte)AtaSmartSubCommands.ReturnStatus,
|
||||
LbaHigh = 0xC2,
|
||||
LbaMid = 0x4F
|
||||
};
|
||||
|
||||
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
|
||||
AtaTransferRegister.NoTransfer, ref buffer, timeout, false,
|
||||
out duration,
|
||||
out bool sense);
|
||||
Error = LastError != 0;
|
||||
|
||||
DicConsole.DebugWriteLine("ATA Device", "SMART RETURN STATUS took {0} ms.", duration);
|
||||
|
||||
return sense;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user