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 : 08.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Device structures decoders.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Decodes SCSI MODE PAGE 08h: Caching 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
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2017-12-22 02:04:18 +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 0x08: Caching page
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Disconnect-reconnect page Page code 0x08 12 bytes in SCSI-2 20 bytes in SBC-1, SBC-2, SBC-3</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public struct ModePage_08
|
|
|
|
|
|
{
|
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><c>true</c> if write cache is enabled</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool WCE;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Multiplication factor</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool MF;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary><c>true</c> if read cache is enabled</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool RCD;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Advices on reading-cache retention priority</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public byte DemandReadRetentionPrio;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Advices on writing-cache retention priority</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public byte WriteRetentionPriority;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>If requested read blocks are more than this, no pre-fetch is done</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public ushort DisablePreFetch;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Minimum pre-fetch</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public ushort MinimumPreFetch;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Maximum pre-fetch</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public ushort MaximumPreFetch;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Upper limit on maximum pre-fetch value</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public ushort MaximumPreFetchCeiling;
|
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Manual cache controlling</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool IC;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Abort pre-fetch</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool ABPF;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Caching analysis permitted</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool CAP;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Pre-fetch over discontinuities</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool Disc;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary><see cref="CacheSegmentSize" /> is to be used to control caching segmentation</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool Size;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Force sequential write</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool FSW;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Logical block cache segment size</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool LBCSS;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>Disable read-ahead</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public bool DRA;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>How many segments should the cache be divided upon</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public byte CacheSegments;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>How many bytes should the cache be divided upon</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public ushort CacheSegmentSize;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
/// <summary>How many bytes should be used as a buffer when all other cached data cannot be evicted</summary>
|
2017-12-21 02:03:21 +00:00
|
|
|
|
public uint NonCacheSegmentSize;
|
|
|
|
|
|
|
|
|
|
|
|
public bool NV_DIS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ModePage_08? DecodeModePage_08(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) != 0x08)
|
|
|
|
|
|
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_08();
|
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.WCE |= (pageResponse[2] & 0x04) == 0x04;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.MF |= (pageResponse[2] & 0x02) == 0x02;
|
2017-12-21 02:03:21 +00:00
|
|
|
|
decoded.RCD |= (pageResponse[2] & 0x01) == 0x01;
|
|
|
|
|
|
|
|
|
|
|
|
decoded.DemandReadRetentionPrio = (byte)((pageResponse[3] & 0xF0) >> 4);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.WriteRetentionPriority = (byte)(pageResponse[3] & 0x0F);
|
|
|
|
|
|
decoded.DisablePreFetch = (ushort)((pageResponse[4] << 8) + pageResponse[5]);
|
|
|
|
|
|
decoded.MinimumPreFetch = (ushort)((pageResponse[6] << 8) + pageResponse[7]);
|
|
|
|
|
|
decoded.MaximumPreFetch = (ushort)((pageResponse[8] << 8) + pageResponse[9]);
|
|
|
|
|
|
decoded.MaximumPreFetchCeiling = (ushort)((pageResponse[10] << 8) + pageResponse[11]);
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(pageResponse.Length < 20)
|
|
|
|
|
|
return decoded;
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.IC |= (pageResponse[2] & 0x80) == 0x80;
|
2017-12-21 02:03:21 +00:00
|
|
|
|
decoded.ABPF |= (pageResponse[2] & 0x40) == 0x40;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.CAP |= (pageResponse[2] & 0x20) == 0x20;
|
2017-12-21 02:03:21 +00:00
|
|
|
|
decoded.Disc |= (pageResponse[2] & 0x10) == 0x10;
|
|
|
|
|
|
decoded.Size |= (pageResponse[2] & 0x08) == 0x08;
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.FSW |= (pageResponse[12] & 0x80) == 0x80;
|
2017-12-21 02:03:21 +00:00
|
|
|
|
decoded.LBCSS |= (pageResponse[12] & 0x40) == 0x40;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.DRA |= (pageResponse[12] & 0x20) == 0x20;
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
decoded.CacheSegments = pageResponse[13];
|
2020-10-17 04:06:30 +01:00
|
|
|
|
decoded.CacheSegmentSize = (ushort)((pageResponse[14] << 8) + pageResponse[15]);
|
2017-12-21 02:03:21 +00:00
|
|
|
|
decoded.NonCacheSegmentSize = (uint)((pageResponse[17] << 16) + (pageResponse[18] << 8) + pageResponse[19]);
|
|
|
|
|
|
|
|
|
|
|
|
decoded.NV_DIS |= (pageResponse[12] & 0x01) == 0x01;
|
|
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public static string PrettifyModePage_08(byte[] pageResponse) =>
|
|
|
|
|
|
PrettifyModePage_08(DecodeModePage_08(pageResponse));
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
public static string PrettifyModePage_08(ModePage_08? 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_08 page = modePage.Value;
|
|
|
|
|
|
var sb = new StringBuilder();
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("SCSI Caching mode page:");
|
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(page.PS)
|
|
|
|
|
|
sb.AppendLine("\tParameters can be saved");
|
|
|
|
|
|
|
|
|
|
|
|
if(page.RCD)
|
|
|
|
|
|
sb.AppendLine("\tRead-cache is enabled");
|
|
|
|
|
|
|
|
|
|
|
|
if(page.WCE)
|
|
|
|
|
|
sb.AppendLine("\tWrite-cache is enabled");
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
switch(page.DemandReadRetentionPrio)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
sb.AppendLine("\tDrive does not distinguish between cached read data");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
sb.AppendLine("\tData put by READ commands should be evicted from cache sooner than data put in read cache by other means");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 0xF:
|
|
|
|
|
|
sb.AppendLine("\tData put by READ commands should not be evicted if there is data cached by other means that can be evicted");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.AppendFormat("\tUnknown demand read retention priority value {0}", page.DemandReadRetentionPrio).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(page.WriteRetentionPriority)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
sb.AppendLine("\tDrive does not distinguish between cached write data");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
sb.AppendLine("\tData put by WRITE commands should be evicted from cache sooner than data put in write cache by other means");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 0xF:
|
|
|
|
|
|
sb.AppendLine("\tData put by WRITE commands should not be evicted if there is data cached by other means that can be evicted");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.AppendFormat("\tUnknown demand write retention priority value {0}",
|
|
|
|
|
|
page.DemandReadRetentionPrio).AppendLine();
|
|
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(page.DRA)
|
|
|
|
|
|
sb.AppendLine("\tRead-ahead is disabled");
|
2017-12-21 02:03:21 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(page.MF)
|
|
|
|
|
|
sb.AppendLine("\tPre-fetch values indicate a block multiplier");
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(page.DisablePreFetch == 0)
|
|
|
|
|
|
sb.AppendLine("\tNo pre-fetch will be done");
|
2017-12-21 02:03:21 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("\tPre-fetch will be done for READ commands of {0} blocks or less",
|
|
|
|
|
|
page.DisablePreFetch).AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
if(page.MinimumPreFetch > 0)
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.AppendFormat("At least {0} blocks will be always pre-fetched", page.MinimumPreFetch).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
if(page.MaximumPreFetch > 0)
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.AppendFormat("\tA maximum of {0} blocks will be pre-fetched", page.MaximumPreFetch).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
if(page.MaximumPreFetchCeiling > 0)
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.
|
|
|
|
|
|
AppendFormat("\tA maximum of {0} blocks will be pre-fetched even if it is commanded to pre-fetch more",
|
2018-06-22 08:08:38 +01:00
|
|
|
|
page.MaximumPreFetchCeiling).AppendLine();
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
if(page.IC)
|
|
|
|
|
|
sb.AppendLine("\tDevice should use number of cache segments or cache segment size for caching");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
|
|
if(page.ABPF)
|
|
|
|
|
|
sb.AppendLine("\tPre-fetch should be aborted upong receiving a new command");
|
|
|
|
|
|
|
|
|
|
|
|
if(page.CAP)
|
|
|
|
|
|
sb.AppendLine("\tCaching analysis is permitted");
|
|
|
|
|
|
|
2017-12-21 02:03:21 +00:00
|
|
|
|
if(page.Disc)
|
|
|
|
|
|
sb.AppendLine("\tPre-fetch can continue across discontinuities (such as cylinders or tracks)");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(page.FSW)
|
|
|
|
|
|
sb.AppendLine("\tDrive should not reorder the sequence of write commands to be faster");
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
if(page.Size)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(page.CacheSegmentSize > 0)
|
|
|
|
|
|
if(page.LBCSS)
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.AppendFormat("\tDrive cache segments should be {0} blocks long", page.CacheSegmentSize).
|
|
|
|
|
|
AppendLine();
|
2017-12-21 02:03:21 +00:00
|
|
|
|
else
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.AppendFormat("\tDrive cache segments should be {0} bytes long", page.CacheSegmentSize).
|
|
|
|
|
|
AppendLine();
|
2017-12-21 02:03:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(page.CacheSegments > 0)
|
|
|
|
|
|
sb.AppendFormat("\tDrive should have {0} cache segments", page.CacheSegments).AppendLine();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(page.NonCacheSegmentSize > 0)
|
2019-11-25 00:54:38 +00:00
|
|
|
|
sb.
|
|
|
|
|
|
AppendFormat("\tDrive shall allocate {0} bytes to buffer even when all cached data cannot be evicted",
|
2018-06-22 08:08:38 +01:00
|
|
|
|
page.NonCacheSegmentSize).AppendLine();
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(page.NV_DIS)
|
|
|
|
|
|
sb.AppendLine("\tNon-Volatile cache is disabled");
|
2017-12-21 02:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion Mode Page 0x08: Caching page
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|