Files
Aaru/SCSI/Modes/0B.cs

115 lines
4.4 KiB
C#
Raw Normal View History

2017-12-21 02:03:21 +00:00
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : 0B.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGE 0Bh: Medium types supported 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/>.
//
// ----------------------------------------------------------------------------
2020-01-03 17:51:28 +00:00
// Copyright © 2011-2020 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 0x0B: Medium types supported page
2019-11-25 00:54:38 +00:00
/// <summary>Disconnect-reconnect page Page code 0x0B 8 bytes in SCSI-2</summary>
2017-12-21 02:03:21 +00:00
public struct ModePage_0B
{
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;
public MediumTypes MediumType1;
public MediumTypes MediumType2;
public MediumTypes MediumType3;
public MediumTypes MediumType4;
}
public static ModePage_0B? DecodeModePage_0B(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) != 0x0B)
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 < 8)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
var decoded = new ModePage_0B();
2017-12-21 02:03:21 +00:00
2018-06-22 08:08:38 +01:00
decoded.PS |= (pageResponse[0] & 0x80) == 0x80;
decoded.MediumType1 = (MediumTypes)pageResponse[4];
decoded.MediumType2 = (MediumTypes)pageResponse[5];
decoded.MediumType3 = (MediumTypes)pageResponse[6];
decoded.MediumType4 = (MediumTypes)pageResponse[7];
2017-12-21 02:03:21 +00:00
return decoded;
}
2018-12-31 13:17:27 +00:00
public static string PrettifyModePage_0B(byte[] pageResponse) =>
PrettifyModePage_0B(DecodeModePage_0B(pageResponse));
2017-12-21 02:03:21 +00:00
public static string PrettifyModePage_0B(ModePage_0B? 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_0B page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
sb.AppendLine("SCSI Medium types supported 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
if(page.MediumType1 != MediumTypes.Default)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("Supported medium type one: {0}", GetMediumTypeDescription(page.MediumType1)).
AppendLine();
2017-12-21 02:03:21 +00:00
if(page.MediumType2 != MediumTypes.Default)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("Supported medium type two: {0}", GetMediumTypeDescription(page.MediumType2)).
AppendLine();
2017-12-21 02:03:21 +00:00
if(page.MediumType3 != MediumTypes.Default)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("Supported medium type three: {0}", GetMediumTypeDescription(page.MediumType3)).
AppendLine();
2017-12-21 02:03:21 +00:00
if(page.MediumType4 != MediumTypes.Default)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("Supported medium type four: {0}", GetMediumTypeDescription(page.MediumType4)).
AppendLine();
2017-12-21 02:03:21 +00:00
return sb.ToString();
}
#endregion Mode Page 0x0B: Medium types supported page
}
}