Files
Aaru/SCSI/Modes/1B.cs

122 lines
4.6 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 : 1B.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGE 1Bh: Removable Block Access Capabilities 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")]
2017-12-21 02:03:21 +00:00
public static partial class Modes
{
#region Mode Page 0x1B: Removable Block Access Capabilities page
2019-11-25 00:54:38 +00:00
/// <summary>Removable Block Access Capabilities page Page code 0x1B 12 bytes in INF-8070</summary>
2017-12-21 02:03:21 +00:00
public struct ModePage_1B
{
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>Supports reporting progress of format</summary>
2017-12-21 02:03:21 +00:00
public bool SRFP;
2019-11-25 00:54:38 +00:00
/// <summary>Non-CD Optical Device</summary>
2017-12-21 02:03:21 +00:00
public bool NCD;
2019-11-25 00:54:38 +00:00
/// <summary>Phase change dual device supporting a CD and a Non-CD Optical devices</summary>
2017-12-21 02:03:21 +00:00
public bool SML;
2019-11-25 00:54:38 +00:00
/// <summary>Total number of LUNs</summary>
2017-12-21 02:03:21 +00:00
public byte TLUN;
2019-11-25 00:54:38 +00:00
/// <summary>System Floppy Type device</summary>
2017-12-21 02:03:21 +00:00
public bool SFLP;
}
public static ModePage_1B? DecodeModePage_1B(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) != 0x1B)
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_1B();
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.SFLP |= (pageResponse[2] & 0x80) == 0x80;
decoded.SRFP |= (pageResponse[2] & 0x40) == 0x40;
2018-06-22 08:08:38 +01:00
decoded.NCD |= (pageResponse[3] & 0x80) == 0x80;
decoded.SML |= (pageResponse[3] & 0x40) == 0x40;
2017-12-21 02:03:21 +00:00
decoded.TLUN = (byte)(pageResponse[3] & 0x07);
return decoded;
}
2018-12-31 13:17:27 +00:00
public static string PrettifyModePage_1B(byte[] pageResponse) =>
PrettifyModePage_1B(DecodeModePage_1B(pageResponse));
2017-12-21 02:03:21 +00:00
public static string PrettifyModePage_1B(ModePage_1B? 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_1B page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
sb.AppendLine("SCSI Removable Block Access Capabilities page:");
2019-11-25 00:54:38 +00:00
if(page.PS)
sb.AppendLine("\tParameters can be saved");
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if(page.SFLP)
sb.AppendLine("\tDrive can be used as a system floppy device");
if(page.SRFP)
sb.AppendLine("\tDrive supports reporting progress of format");
if(page.NCD)
sb.AppendLine("\tDrive is a Non-CD Optical Device");
if(page.SML)
sb.AppendLine("\tDevice is a dual device supporting CD and Non-CD Optical");
if(page.TLUN > 0)
sb.AppendFormat("\tDrive supports {0} LUNs", page.TLUN).AppendLine();
2017-12-21 02:03:21 +00:00
return sb.ToString();
}
#endregion Mode Page 0x1B: Removable Block Access Capabilities page
}
}