2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:23 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-01-15 07:00:43 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : BlockLimits.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-01-15 07:00:43 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2016-01-15 07:00:43 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2018-12-29 15:26:00 +00:00
|
|
|
// Decodes SCSI SSC block limits structures.
|
2016-01-15 07:00:43 +00:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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
|
2016-01-15 07:00:43 +00:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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.
|
2016-01-15 07:00:43 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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/>.
|
2016-01-15 07:00:43 +00:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:08 +00:00
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-01-15 07:00:43 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2016-01-15 07:00:43 +00:00
|
|
|
using System;
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-01-15 07:00:43 +00:00
|
|
|
using System.Text;
|
2022-11-27 13:33:47 +00:00
|
|
|
using Aaru.Localization;
|
2016-01-15 07:00:43 +00:00
|
|
|
|
2022-11-15 15:58:41 +00:00
|
|
|
namespace Aaru.Decoders.SCSI.SSC;
|
|
|
|
|
|
2023-10-03 23:09:28 +01:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
2022-03-06 13:29:37 +00:00
|
|
|
public static class BlockLimits
|
2016-01-15 07:00:43 +00:00
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
public static BlockLimitsData? Decode(byte[] response)
|
2016-01-15 07:00:43 +00:00
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
if(response?.Length != 6)
|
|
|
|
|
return null;
|
2016-01-15 07:00:43 +00:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
return new BlockLimitsData
|
2016-01-15 07:00:43 +00:00
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
granularity = (byte)(response[0] & 0x1F),
|
|
|
|
|
maxBlockLen = (uint)((response[1] << 16) + (response[2] << 8) + response[3]),
|
|
|
|
|
minBlockLen = (ushort)((response[4] << 8) + response[5])
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-01-15 07:00:43 +00:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
public static string Prettify(BlockLimitsData? decoded)
|
|
|
|
|
{
|
|
|
|
|
if(decoded == null)
|
|
|
|
|
return null;
|
2016-01-15 07:00:43 +00:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
var sb = new StringBuilder();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
if(decoded.Value.maxBlockLen == decoded.Value.minBlockLen)
|
2022-11-27 13:33:47 +00:00
|
|
|
sb.AppendFormat(Core.Device_block_size_is_fixed_at_0_bytes, decoded.Value.minBlockLen).AppendLine();
|
2022-03-06 13:29:37 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(decoded.Value.maxBlockLen > 0)
|
2022-11-27 13:33:47 +00:00
|
|
|
sb.AppendFormat(Core.Device_maximum_block_size_is_0_bytes, decoded.Value.maxBlockLen).AppendLine();
|
2022-03-06 13:29:37 +00:00
|
|
|
else
|
2022-11-27 13:33:47 +00:00
|
|
|
sb.AppendLine(Core.Device_does_not_specify_a_maximum_block_size);
|
2016-01-15 07:00:43 +00:00
|
|
|
|
2022-11-27 13:33:47 +00:00
|
|
|
sb.AppendFormat(Core.Device_minimum_block_size_is_0_bytes, decoded.Value.minBlockLen).AppendLine();
|
2016-01-15 07:00:43 +00:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
if(decoded.Value.granularity > 0)
|
2023-10-03 23:09:28 +01:00
|
|
|
{
|
2022-11-27 13:33:47 +00:00
|
|
|
sb.AppendFormat(Core.Device_needs_a_block_size_granularity_of_pow_0_1_bytes, decoded.Value.granularity,
|
|
|
|
|
Math.Pow(2, decoded.Value.granularity)).AppendLine();
|
2023-10-03 23:09:28 +01:00
|
|
|
}
|
2016-01-15 07:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
public static string Prettify(byte[] response) => Prettify(Decode(response));
|
|
|
|
|
|
2023-10-03 23:09:28 +01:00
|
|
|
#region Nested type: BlockLimitsData
|
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
public struct BlockLimitsData
|
|
|
|
|
{
|
|
|
|
|
/// <summary>All blocks size must be multiple of 2^<cref name="granularity" /></summary>
|
|
|
|
|
public byte granularity;
|
|
|
|
|
/// <summary>Maximum block length in bytes</summary>
|
|
|
|
|
public uint maxBlockLen;
|
|
|
|
|
/// <summary>Minimum block length in bytes</summary>
|
|
|
|
|
public ushort minBlockLen;
|
2016-01-15 07:00:43 +00:00
|
|
|
}
|
2023-10-03 23:09:28 +01:00
|
|
|
|
|
|
|
|
#endregion
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|