Files
Aaru/SCSI/Modes/12_13_14.cs

110 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 : 12_13_14.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGEs 12h, 13h, 14h: Medium partition page (2-4).
//
// --[ 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 Pages 0x12, 0x13, 0x14: Medium partition page (2-4)
/// <summary>Medium partition page (2-4) Page codes 0x12, 0x13 and 0x14</summary>
public struct ModePage_12_13_14
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>Array of partition sizes in units defined in mode page 11</summary>
public ushort[] PartitionSizes;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static ModePage_12_13_14? DecodeModePage_12_13_14(byte[] pageResponse)
{
if(pageResponse == null)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
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) != 0x12 &&
(pageResponse[0] & 0x3F) != 0x13 &&
(pageResponse[0] & 0x3F) != 0x14)
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 < 2)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
var decoded = new ModePage_12_13_14();
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.PartitionSizes = new ushort[(pageResponse.Length - 2) / 2];
2017-12-21 02:03:21 +00:00
for(int i = 2; i < pageResponse.Length; i += 2)
2022-03-06 13:29:37 +00:00
{
decoded.PartitionSizes[(i - 2) / 2] = (ushort)(pageResponse[i] << 8);
decoded.PartitionSizes[(i - 2) / 2] += pageResponse[i + 1];
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_12_13_14(byte[] pageResponse) =>
PrettifyModePage_12_13_14(DecodeModePage_12_13_14(pageResponse));
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static string PrettifyModePage_12_13_14(ModePage_12_13_14? modePage)
{
if(!modePage.HasValue)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
ModePage_12_13_14 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 medium partition page (extra):");
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
sb.AppendFormat("\tMedium has defined {0} partitions", page.PartitionSizes.Length).AppendLine();
2017-12-21 02:03:21 +00:00
for(int i = 0; i < page.PartitionSizes.Length; i++)
2022-03-06 13:29:37 +00:00
sb.AppendFormat("\tPartition {0} is {1} units long", i, page.PartitionSizes[i]).AppendLine();
return sb.ToString();
2017-12-21 02:03:21 +00:00
}
2022-03-06 13:29:37 +00:00
#endregion Mode Pages 0x12, 0x13, 0x14: Medium partition page (2-4)
2017-12-21 02:03:21 +00:00
}