2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-01-13 05:04:45 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Adaptec.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Adaptec vendor commands.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Contains vendor commands for Adaptec ACB-4000A and
|
|
|
|
|
// ACB-4070 ST-506 to SCSI controllers.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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
|
2016-01-13 05:04:45 +00:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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/>.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2016-01-13 05:04:45 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2016-01-13 05:04:45 +00:00
|
|
|
using System;
|
2025-08-17 05:50:25 +01:00
|
|
|
using Aaru.Logging;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2023-10-05 01:05:23 +01:00
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Devices;
|
|
|
|
|
|
2022-03-26 18:31:04 +00:00
|
|
|
public partial class Device
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Gets the underlying drive cylinder, head and index bytes for the specified SCSI LBA.</summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="lba">SCSI Logical Block Address.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecTranslate(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint lba, uint timeout,
|
2022-03-06 13:29:38 +00:00
|
|
|
out double duration) =>
|
|
|
|
|
AdaptecTranslate(out buffer, out senseBuffer, false, lba, timeout, out duration);
|
|
|
|
|
|
|
|
|
|
/// <summary>Gets the underlying drive cylinder, head and index bytes for the specified SCSI LBA.</summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="drive1">If set to <c>true</c> request the data from drive 1.</param>
|
|
|
|
|
/// <param name="lba">SCSI Logical Block Address.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecTranslate(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, bool drive1, uint lba,
|
|
|
|
|
uint timeout, out double duration)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
buffer = new byte[8];
|
2025-08-22 15:56:59 +01:00
|
|
|
Span<byte> cdb = CdbBuffer[..6];
|
|
|
|
|
cdb.Clear();
|
2025-08-22 19:57:09 +01:00
|
|
|
senseBuffer = SenseBuffer;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecTranslate;
|
|
|
|
|
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
|
|
|
|
cdb[2] = (byte)((lba & 0xFF00) >> 8);
|
|
|
|
|
cdb[3] = (byte)(lba & 0xFF);
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(drive1) cdb[1] += 0x20;
|
|
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
Error = LastError != 0;
|
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(SCSI_MODULE_NAME, Localization.ADAPTEC_TRANSLATE_took_0_ms, duration);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Sets the error threshold</summary>
|
|
|
|
|
/// <returns><c>true</c>, if set error threshold was adapteced, <c>false</c> otherwise.</returns>
|
|
|
|
|
/// <param name="threshold">Threshold. 0 to disable error reporting.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecSetErrorThreshold(byte threshold, out ReadOnlySpan<byte> senseBuffer, uint timeout,
|
|
|
|
|
out double duration) =>
|
2022-03-06 13:29:38 +00:00
|
|
|
AdaptecSetErrorThreshold(threshold, out senseBuffer, false, timeout, out duration);
|
|
|
|
|
|
|
|
|
|
/// <summary>Sets the error threshold</summary>
|
|
|
|
|
/// <returns><c>true</c>, if set error threshold was adapteced, <c>false</c> otherwise.</returns>
|
|
|
|
|
/// <param name="threshold">Threshold. 0 to disable error reporting.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="drive1">If set to <c>true</c> set the threshold from drive 1.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecSetErrorThreshold(byte threshold, out ReadOnlySpan<byte> senseBuffer, bool drive1, uint timeout,
|
2022-03-06 13:29:38 +00:00
|
|
|
out double duration)
|
|
|
|
|
{
|
2025-08-17 05:50:25 +01:00
|
|
|
byte[] buffer = new byte[1];
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer[0] = threshold;
|
2025-08-22 15:56:59 +01:00
|
|
|
Span<byte> cdb = CdbBuffer[..6];
|
|
|
|
|
cdb.Clear();
|
2025-08-22 19:57:09 +01:00
|
|
|
senseBuffer = SenseBuffer;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecSetErrorThreshold;
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(drive1) cdb[1] += 0x20;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cdb[4] = 1;
|
|
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.Out, out duration, out bool sense);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
Error = LastError != 0;
|
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(SCSI_MODULE_NAME, Localization.ADAPTEC_SET_ERROR_THRESHOLD_took_0_ms, duration);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Requests the usage, seek and error counters, and resets them</summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecReadUsageCounter(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout,
|
|
|
|
|
out double duration) =>
|
2022-03-06 13:29:38 +00:00
|
|
|
AdaptecReadUsageCounter(out buffer, out senseBuffer, false, timeout, out duration);
|
|
|
|
|
|
|
|
|
|
/// <summary>Requests the usage, seek and error counters, and resets them</summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="drive1">If set to <c>true</c> get the counters from drive 1.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecReadUsageCounter(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, bool drive1,
|
|
|
|
|
uint timeout, out double duration)
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[9];
|
2025-08-22 15:56:59 +01:00
|
|
|
Span<byte> cdb = CdbBuffer[..6];
|
|
|
|
|
cdb.Clear();
|
2025-08-22 19:57:09 +01:00
|
|
|
senseBuffer = SenseBuffer;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecTranslate;
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(drive1) cdb[1] += 0x20;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[4] = (byte)buffer.Length;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(SCSI_MODULE_NAME, Localization.ADAPTEC_READ_RESET_USAGE_COUNTER_took_0_ms, duration);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Fills the Adaptec controller RAM with 1K bytes of data</summary>
|
|
|
|
|
/// <param name="buffer">Data to fill the buffer with.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecWriteBuffer(byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout, out double duration)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2025-08-17 05:50:25 +01:00
|
|
|
byte[] oneKBuffer = new byte[1024];
|
2022-03-06 13:29:38 +00:00
|
|
|
Array.Copy(buffer, 0, oneKBuffer, 0, buffer.Length < 1024 ? buffer.Length : 1024);
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2025-08-22 15:56:59 +01:00
|
|
|
Span<byte> cdb = CdbBuffer[..6];
|
|
|
|
|
cdb.Clear();
|
2025-08-22 19:57:09 +01:00
|
|
|
senseBuffer = SenseBuffer;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecWriteBuffer;
|
|
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
LastError = SendScsiCommand(cdb, ref oneKBuffer, timeout, ScsiDirection.Out, out duration, out bool sense);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
Error = LastError != 0;
|
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(SCSI_MODULE_NAME, Localization.ADAPTEC_WRITE_DATA_BUFFER_took_0_ms, duration);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Reads 1K bytes of data from the Adaptec controller RAM</summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2025-08-22 19:57:09 +01:00
|
|
|
public bool AdaptecReadBuffer(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout,
|
|
|
|
|
out double duration)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
buffer = new byte[1024];
|
2025-08-22 15:56:59 +01:00
|
|
|
Span<byte> cdb = CdbBuffer[..6];
|
|
|
|
|
cdb.Clear();
|
2025-08-22 19:57:09 +01:00
|
|
|
senseBuffer = SenseBuffer;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecReadBuffer;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2025-08-22 19:57:09 +01:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(SCSI_MODULE_NAME, Localization.ADAPTEC_READ_DATA_BUFFER_took_0_ms, duration);
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
2016-01-13 05:04:45 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|