Files
Aaru/SCSI/Modes/0F.cs

204 lines
7.5 KiB
C#
Raw Normal View History

2017-12-21 02:03:21 +00:00
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : 0F.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGE 0Fh: Data compression 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;
namespace DiscImageChef.Decoders.SCSI
{
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 0x0F: Data compression page
2019-11-25 00:54:38 +00:00
/// <summary>Data compression page Page code 0x0F 16 bytes in SSC-1, SSC-2, SSC-3</summary>
2017-12-21 02:03:21 +00:00
public struct ModePage_0F
{
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>Data compression enabled</summary>
2017-12-21 02:03:21 +00:00
public bool DCE;
2019-11-25 00:54:38 +00:00
/// <summary>Data compression capable</summary>
2017-12-21 02:03:21 +00:00
public bool DCC;
2019-11-25 00:54:38 +00:00
/// <summary>Data decompression enabled</summary>
2017-12-21 02:03:21 +00:00
public bool DDE;
2019-11-25 00:54:38 +00:00
/// <summary>Report exception on decompression</summary>
2017-12-21 02:03:21 +00:00
public byte RED;
2019-11-25 00:54:38 +00:00
/// <summary>Compression algorithm</summary>
2017-12-21 02:03:21 +00:00
public uint CompressionAlgo;
2019-11-25 00:54:38 +00:00
/// <summary>Decompression algorithm</summary>
2017-12-21 02:03:21 +00:00
public uint DecompressionAlgo;
}
public static ModePage_0F? DecodeModePage_0F(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) != 0x0F)
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 < 16)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
var decoded = new ModePage_0F();
2017-12-21 02:03:21 +00:00
decoded.PS |= (pageResponse[0] & 0x80) == 0x80;
decoded.DCE |= (pageResponse[2] & 0x80) == 0x80;
decoded.DCC |= (pageResponse[2] & 0x40) == 0x40;
decoded.DDE |= (pageResponse[3] & 0x80) == 0x80;
2018-06-22 08:08:38 +01:00
decoded.RED = (byte)((pageResponse[3] & 0x60) >> 5);
2017-12-21 02:03:21 +00:00
decoded.CompressionAlgo = (uint)((pageResponse[4] << 24) + (pageResponse[5] << 16) +
2018-06-22 08:08:38 +01:00
(pageResponse[6] << 8) + pageResponse[7]);
2019-11-25 00:54:38 +00:00
2018-06-22 08:08:38 +01:00
decoded.DecompressionAlgo = (uint)((pageResponse[8] << 24) + (pageResponse[9] << 16) +
(pageResponse[10] << 8) + pageResponse[11]);
2017-12-21 02:03:21 +00:00
return decoded;
}
2018-12-31 13:17:27 +00:00
public static string PrettifyModePage_0F(byte[] pageResponse) =>
PrettifyModePage_0F(DecodeModePage_0F(pageResponse));
2017-12-21 02:03:21 +00:00
public static string PrettifyModePage_0F(ModePage_0F? 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_0F page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
sb.AppendLine("SCSI Data compression 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.DCC)
{
sb.AppendLine("\tDrive supports data compression");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
if(page.DCE)
{
sb.Append("\tData compression is enabled with ");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
switch(page.CompressionAlgo)
{
case 3:
sb.AppendLine("IBM ALDC with 512 byte buffer");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 4:
sb.AppendLine("IBM ALDC with 1024 byte buffer");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 5:
sb.AppendLine("IBM ALDC with 2048 byte buffer");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 0x10:
sb.AppendLine("IBM IDRC");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 0x20:
sb.AppendLine("DCLZ");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 0xFF:
sb.AppendLine("an unregistered compression algorithm");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
default:
sb.AppendFormat("an unknown algorithm coded {0}", page.CompressionAlgo).AppendLine();
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
}
}
if(page.DDE)
{
sb.AppendLine("\tData decompression is enabled");
2019-11-25 00:54:38 +00:00
if(page.DecompressionAlgo == 0)
sb.AppendLine("\tLast data read was uncompressed");
2017-12-21 02:03:21 +00:00
else
{
sb.Append("\tLast data read was compressed with ");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
switch(page.CompressionAlgo)
{
case 3:
sb.AppendLine("IBM ALDC with 512 byte buffer");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 4:
sb.AppendLine("IBM ALDC with 1024 byte buffer");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 5:
sb.AppendLine("IBM ALDC with 2048 byte buffer");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 0x10:
sb.AppendLine("IBM IDRC");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 0x20:
sb.AppendLine("DCLZ");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 0xFF:
sb.AppendLine("an unregistered compression algorithm");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
default:
sb.AppendFormat("an unknown algorithm coded {0}", page.CompressionAlgo).AppendLine();
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
}
}
}
sb.AppendFormat("\tReport exception on compression is set to {0}", page.RED).AppendLine();
}
2019-11-25 00:54:38 +00:00
else
sb.AppendLine("\tDrive does not support data compression");
2017-12-21 02:03:21 +00:00
return sb.ToString();
}
#endregion Mode Page 0x0F: Data compression page
}
}