Files
Aaru/SCSI/Modes/00_SFF.cs

116 lines
4.0 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 : 00_SFF.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGE 00h: Drive Operation Mode 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;
namespace Aaru.Decoders.SCSI;
2022-03-06 13:29:37 +00:00
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Modes
2017-12-21 02:03:21 +00:00
{
2022-03-06 13:29:37 +00:00
#region Mode Page 0x00: Drive Operation Mode page
/// <summary>Drive Operation Mode page Page code 0x00 4 bytes in INF-8070</summary>
public struct ModePage_00_SFF
2017-12-21 02:03:21 +00:00
{
2022-03-06 13:29:37 +00:00
/// <summary>Parameters can be saved</summary>
public bool PS;
/// <summary>Select LUN Mode</summary>
public bool SLM;
/// <summary>Select LUN for rewritable</summary>
public bool SLR;
/// <summary>Disable verify for WRITE</summary>
public bool DVW;
/// <summary>Disable deferred error</summary>
public bool DDE;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static ModePage_00_SFF? DecodeModePage_00_SFF(byte[] pageResponse)
{
if((pageResponse?[0] & 0x40) == 0x40)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if((pageResponse?[0] & 0x3F) != 0x00)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(pageResponse[1] + 2 != pageResponse.Length)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(pageResponse.Length < 4)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
var decoded = new ModePage_00_SFF();
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
decoded.PS |= (pageResponse[0] & 0x80) == 0x80;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
decoded.SLM |= (pageResponse[2] & 0x80) == 0x80;
decoded.SLR |= (pageResponse[2] & 0x40) == 0x40;
decoded.DVW |= (pageResponse[2] & 0x20) == 0x20;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
decoded.DDE |= (pageResponse[3] & 0x10) == 0x10;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
return decoded;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static string PrettifyModePage_00_SFF(byte[] pageResponse) =>
PrettifyModePage_00_SFF(DecodeModePage_00_SFF(pageResponse));
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static string PrettifyModePage_00_SFF(ModePage_00_SFF? modePage)
{
if(!modePage.HasValue)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
ModePage_00_SFF page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
sb.AppendLine("SCSI Drive Operation Mode page:");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(page.PS)
sb.AppendLine("\tParameters can be saved");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(page.DVW)
sb.AppendLine("\tVerifying after writing is disabled");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(page.DDE)
sb.AppendLine("\tDrive will abort when a writing error is detected");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
if(!page.SLM)
return sb.ToString();
2022-03-06 13:29:37 +00:00
sb.Append("\tDrive has two LUNs with rewritable being ");
sb.AppendLine(page.SLR ? "LUN 1" : "LUN 0");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
return sb.ToString();
2017-12-21 02:03:21 +00:00
}
2022-03-06 13:29:37 +00:00
#endregion Mode Page 0x00: Drive Operation Mode page
2017-12-21 02:03:21 +00:00
}