Files
Aaru/SCSI/Modes/07.cs

132 lines
5.2 KiB
C#
Raw Normal View History

2017-12-21 02:03:21 +00:00
// /***************************************************************************
2020-02-27 12:31:23 +00:00
// Aaru Data Preservation Suite
2017-12-21 02:03:21 +00:00
// ----------------------------------------------------------------------------
//
// Filename : 07.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGE 07h: Verify error recovery page.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:39 +00:00
// Copyright © 2011-2022 Natalia Portillo
2017-12-21 02:03:21 +00:00
// ****************************************************************************/
using System.Diagnostics.CodeAnalysis;
2017-12-21 02:03:21 +00:00
using System.Text;
2020-02-27 00:33:24 +00:00
namespace Aaru.Decoders.SCSI
2017-12-21 02:03:21 +00:00
{
2019-11-25 00:54:38 +00:00
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
2017-12-21 02:03:21 +00:00
public static partial class Modes
{
#region Mode Page 0x07: Verify error recovery page
2019-11-25 00:54:38 +00:00
/// <summary>Disconnect-reconnect page Page code 0x07 12 bytes in SCSI-2, SBC-1, SBC-2</summary>
2017-12-21 02:03:21 +00:00
public struct ModePage_07
{
2019-11-25 00:54:38 +00:00
/// <summary>Parameters can be saved</summary>
2017-12-21 02:03:21 +00:00
public bool PS;
2019-11-25 00:54:38 +00:00
/// <summary>Enable early recovery</summary>
2017-12-21 02:03:21 +00:00
public bool EER;
2019-11-25 00:54:38 +00:00
/// <summary>Post error reporting</summary>
2017-12-21 02:03:21 +00:00
public bool PER;
2019-11-25 00:54:38 +00:00
/// <summary>Disable transfer on error</summary>
2017-12-21 02:03:21 +00:00
public bool DTE;
2019-11-25 00:54:38 +00:00
/// <summary>Disable correction</summary>
2017-12-21 02:03:21 +00:00
public bool DCR;
2019-11-25 00:54:38 +00:00
/// <summary>How many times to retry a verify operation</summary>
2017-12-21 02:03:21 +00:00
public byte VerifyRetryCount;
2019-11-25 00:54:38 +00:00
/// <summary>How many bits of largest data burst error is maximum to apply error correction on it</summary>
2017-12-21 02:03:21 +00:00
public byte CorrectionSpan;
2019-11-25 00:54:38 +00:00
/// <summary>Maximum time in ms to use in data error recovery procedures</summary>
2017-12-21 02:03:21 +00:00
public ushort RecoveryTimeLimit;
}
public static ModePage_07? DecodeModePage_07(byte[] pageResponse)
{
2019-11-25 00:54:38 +00:00
if((pageResponse?[0] & 0x40) == 0x40)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if((pageResponse?[0] & 0x3F) != 0x07)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if(pageResponse[1] + 2 != pageResponse.Length)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if(pageResponse.Length < 12)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
var decoded = new ModePage_07();
2017-12-21 02:03:21 +00:00
2018-06-22 08:08:38 +01:00
decoded.PS |= (pageResponse[0] & 0x80) == 0x80;
2017-12-21 02:03:21 +00:00
decoded.EER |= (pageResponse[2] & 0x08) == 0x08;
decoded.PER |= (pageResponse[2] & 0x04) == 0x04;
decoded.DTE |= (pageResponse[2] & 0x02) == 0x02;
decoded.DCR |= (pageResponse[2] & 0x01) == 0x01;
2018-06-22 08:08:38 +01:00
decoded.VerifyRetryCount = pageResponse[3];
decoded.CorrectionSpan = pageResponse[4];
2017-12-21 02:03:21 +00:00
decoded.RecoveryTimeLimit = (ushort)((pageResponse[10] << 8) + pageResponse[11]);
return decoded;
}
2018-12-31 13:17:27 +00:00
public static string PrettifyModePage_07(byte[] pageResponse) =>
PrettifyModePage_07(DecodeModePage_07(pageResponse));
2017-12-21 02:03:21 +00:00
public static string PrettifyModePage_07(ModePage_07? modePage)
{
2019-11-25 00:54:38 +00:00
if(!modePage.HasValue)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
ModePage_07 page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
sb.AppendLine("SCSI Verify error recovery page:");
2019-11-25 00:54:38 +00:00
if(page.PS)
sb.AppendLine("\tParameters can be saved");
if(page.EER)
sb.AppendLine("\tDrive will use the most expedient form of error recovery first");
if(page.PER)
sb.AppendLine("\tDrive shall report recovered errors");
if(page.DTE)
sb.AppendLine("\tTransfer will be terminated upon error detection");
if(page.DCR)
sb.AppendLine("\tError correction is disabled");
2017-12-21 02:03:21 +00:00
if(page.VerifyRetryCount > 0)
sb.AppendFormat("\tDrive will repeat verify operations {0} times", page.VerifyRetryCount).AppendLine();
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
if(page.RecoveryTimeLimit > 0)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("\tDrive will employ a maximum of {0} ms to recover data", page.RecoveryTimeLimit).
AppendLine();
2017-12-21 02:03:21 +00:00
return sb.ToString();
}
#endregion Mode Page 0x07: Verify error recovery page
}
}