Move to file scoped namespaces.

This commit is contained in:
2022-03-06 13:29:37 +00:00
parent c7178d94c6
commit 3b6091c02c
119 changed files with 38048 additions and 38172 deletions

View File

@@ -35,395 +35,394 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Helpers;
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class AACS
{
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class AACS
public static AACSVolumeIdentifier? DecodeAACSVolumeIdentifier(byte[] AACSVIResponse)
{
public static AACSVolumeIdentifier? DecodeAACSVolumeIdentifier(byte[] AACSVIResponse)
if(AACSVIResponse == null)
return null;
var decoded = new AACSVolumeIdentifier();
decoded.VolumeIdentifier = new byte[AACSVIResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSVIResponse, 0);
decoded.Reserved1 = AACSVIResponse[2];
decoded.Reserved2 = AACSVIResponse[3];
Array.Copy(AACSVIResponse, 4, decoded.VolumeIdentifier, 0, AACSVIResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSVolumeIdentifier(AACSVolumeIdentifier? AACSVIResponse)
{
if(AACSVIResponse == null)
return null;
AACSVolumeIdentifier response = AACSVIResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Volume Identifier in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.VolumeIdentifier, 80));
return sb.ToString();
}
public static string PrettifyAACSVolumeIdentifier(byte[] AACSVIResponse)
{
AACSVolumeIdentifier? decoded = DecodeAACSVolumeIdentifier(AACSVIResponse);
return PrettifyAACSVolumeIdentifier(decoded);
}
public static AACSMediaSerialNumber? DecodeAACSMediaSerialNumber(byte[] AACSMSNResponse)
{
if(AACSMSNResponse == null)
return null;
var decoded = new AACSMediaSerialNumber();
decoded.MediaSerialNumber = new byte[AACSMSNResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMSNResponse, 0);
decoded.Reserved1 = AACSMSNResponse[2];
decoded.Reserved2 = AACSMSNResponse[3];
Array.Copy(AACSMSNResponse, 4, decoded.MediaSerialNumber, 0, AACSMSNResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSMediaSerialNumber(AACSMediaSerialNumber? AACSMSNResponse)
{
if(AACSMSNResponse == null)
return null;
AACSMediaSerialNumber response = AACSMSNResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Media Serial Number in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaSerialNumber, 80));
return sb.ToString();
}
public static string PrettifyAACSMediaSerialNumber(byte[] AACSMSNResponse)
{
AACSMediaSerialNumber? decoded = DecodeAACSMediaSerialNumber(AACSMSNResponse);
return PrettifyAACSMediaSerialNumber(decoded);
}
public static AACSMediaIdentifier? DecodeAACSMediaIdentifier(byte[] AACSMIResponse)
{
if(AACSMIResponse == null)
return null;
var decoded = new AACSMediaIdentifier();
decoded.MediaIdentifier = new byte[AACSMIResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMIResponse, 0);
decoded.Reserved1 = AACSMIResponse[2];
decoded.Reserved2 = AACSMIResponse[3];
Array.Copy(AACSMIResponse, 4, decoded.MediaIdentifier, 0, AACSMIResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSMediaIdentifier(AACSMediaIdentifier? AACSMIResponse)
{
if(AACSMIResponse == null)
return null;
AACSMediaIdentifier response = AACSMIResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Media Identifier in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaIdentifier, 80));
return sb.ToString();
}
public static string PrettifyAACSMediaIdentifier(byte[] AACSMIResponse)
{
AACSMediaIdentifier? decoded = DecodeAACSMediaIdentifier(AACSMIResponse);
return PrettifyAACSMediaIdentifier(decoded);
}
public static AACSMediaKeyBlock? DecodeAACSMediaKeyBlock(byte[] AACSMKBResponse)
{
if(AACSMKBResponse == null)
return null;
var decoded = new AACSMediaKeyBlock();
decoded.MediaKeyBlockPacks = new byte[AACSMKBResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMKBResponse, 0);
decoded.Reserved = AACSMKBResponse[2];
decoded.TotalPacks = AACSMKBResponse[3];
Array.Copy(AACSMKBResponse, 4, decoded.MediaKeyBlockPacks, 0, AACSMKBResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSMediaKeyBlock(AACSMediaKeyBlock? AACSMKBResponse)
{
if(AACSMKBResponse == null)
return null;
AACSMediaKeyBlock response = AACSMKBResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved != 0)
sb.AppendFormat("Reserved = 0x{0:X2}", response.Reserved).AppendLine();
#endif
sb.AppendFormat("Total number of media key blocks available to transfer {0}", response.TotalPacks).
AppendLine();
sb.AppendFormat("AACS Media Key Blocks in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaKeyBlockPacks, 80));
return sb.ToString();
}
public static string PrettifyAACSMediaKeyBlock(byte[] AACSMKBResponse)
{
AACSMediaKeyBlock? decoded = DecodeAACSMediaKeyBlock(AACSMKBResponse);
return PrettifyAACSMediaKeyBlock(decoded);
}
public static AACSDataKeys? DecodeAACSDataKeys(byte[] AACSDKResponse)
{
if(AACSDKResponse == null)
return null;
var decoded = new AACSDataKeys();
decoded.DataKeys = new byte[AACSDKResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSDKResponse, 0);
decoded.Reserved1 = AACSDKResponse[2];
decoded.Reserved2 = AACSDKResponse[3];
Array.Copy(AACSDKResponse, 4, decoded.DataKeys, 0, AACSDKResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSDataKeys(AACSDataKeys? AACSDKResponse)
{
if(AACSDKResponse == null)
return null;
AACSDataKeys response = AACSDKResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Data Keys in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.DataKeys, 80));
return sb.ToString();
}
public static string PrettifyAACSDataKeys(byte[] AACSDKResponse)
{
AACSDataKeys? decoded = DecodeAACSDataKeys(AACSDKResponse);
return PrettifyAACSDataKeys(decoded);
}
public static AACSLBAExtentsResponse? DecodeAACSLBAExtents(byte[] AACSLBAExtsResponse)
{
if(AACSLBAExtsResponse == null)
return null;
var decoded = new AACSLBAExtentsResponse
{
if(AACSVIResponse == null)
return null;
var decoded = new AACSVolumeIdentifier();
decoded.VolumeIdentifier = new byte[AACSVIResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSVIResponse, 0);
decoded.Reserved1 = AACSVIResponse[2];
decoded.Reserved2 = AACSVIResponse[3];
Array.Copy(AACSVIResponse, 4, decoded.VolumeIdentifier, 0, AACSVIResponse.Length - 4);
DataLength = BigEndianBitConverter.ToUInt16(AACSLBAExtsResponse, 0),
Reserved = AACSLBAExtsResponse[2],
MaxLBAExtents = AACSLBAExtsResponse[3]
};
if((AACSLBAExtsResponse.Length - 4) % 16 != 0)
return decoded;
}
public static string PrettifyAACSVolumeIdentifier(AACSVolumeIdentifier? AACSVIResponse)
decoded.Extents = new AACSLBAExtent[(AACSLBAExtsResponse.Length - 4) / 16];
for(int i = 0; i < (AACSLBAExtsResponse.Length - 4) / 16; i++)
{
if(AACSVIResponse == null)
return null;
AACSVolumeIdentifier response = AACSVIResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Volume Identifier in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.VolumeIdentifier, 80));
return sb.ToString();
decoded.Extents[i].Reserved = new byte[8];
Array.Copy(AACSLBAExtsResponse, 0 + (i * 16) + 4, decoded.Extents[i].Reserved, 0, 8);
decoded.Extents[i].StartLBA = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 8 + (i * 16) + 4);
decoded.Extents[i].LBACount = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 12 + (i * 16) + 4);
}
public static string PrettifyAACSVolumeIdentifier(byte[] AACSVIResponse)
{
AACSVolumeIdentifier? decoded = DecodeAACSVolumeIdentifier(AACSVIResponse);
return PrettifyAACSVolumeIdentifier(decoded);
}
public static AACSMediaSerialNumber? DecodeAACSMediaSerialNumber(byte[] AACSMSNResponse)
{
if(AACSMSNResponse == null)
return null;
var decoded = new AACSMediaSerialNumber();
decoded.MediaSerialNumber = new byte[AACSMSNResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMSNResponse, 0);
decoded.Reserved1 = AACSMSNResponse[2];
decoded.Reserved2 = AACSMSNResponse[3];
Array.Copy(AACSMSNResponse, 4, decoded.MediaSerialNumber, 0, AACSMSNResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSMediaSerialNumber(AACSMediaSerialNumber? AACSMSNResponse)
{
if(AACSMSNResponse == null)
return null;
AACSMediaSerialNumber response = AACSMSNResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Media Serial Number in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaSerialNumber, 80));
return sb.ToString();
}
public static string PrettifyAACSMediaSerialNumber(byte[] AACSMSNResponse)
{
AACSMediaSerialNumber? decoded = DecodeAACSMediaSerialNumber(AACSMSNResponse);
return PrettifyAACSMediaSerialNumber(decoded);
}
public static AACSMediaIdentifier? DecodeAACSMediaIdentifier(byte[] AACSMIResponse)
{
if(AACSMIResponse == null)
return null;
var decoded = new AACSMediaIdentifier();
decoded.MediaIdentifier = new byte[AACSMIResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMIResponse, 0);
decoded.Reserved1 = AACSMIResponse[2];
decoded.Reserved2 = AACSMIResponse[3];
Array.Copy(AACSMIResponse, 4, decoded.MediaIdentifier, 0, AACSMIResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSMediaIdentifier(AACSMediaIdentifier? AACSMIResponse)
{
if(AACSMIResponse == null)
return null;
AACSMediaIdentifier response = AACSMIResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Media Identifier in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaIdentifier, 80));
return sb.ToString();
}
public static string PrettifyAACSMediaIdentifier(byte[] AACSMIResponse)
{
AACSMediaIdentifier? decoded = DecodeAACSMediaIdentifier(AACSMIResponse);
return PrettifyAACSMediaIdentifier(decoded);
}
public static AACSMediaKeyBlock? DecodeAACSMediaKeyBlock(byte[] AACSMKBResponse)
{
if(AACSMKBResponse == null)
return null;
var decoded = new AACSMediaKeyBlock();
decoded.MediaKeyBlockPacks = new byte[AACSMKBResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSMKBResponse, 0);
decoded.Reserved = AACSMKBResponse[2];
decoded.TotalPacks = AACSMKBResponse[3];
Array.Copy(AACSMKBResponse, 4, decoded.MediaKeyBlockPacks, 0, AACSMKBResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSMediaKeyBlock(AACSMediaKeyBlock? AACSMKBResponse)
{
if(AACSMKBResponse == null)
return null;
AACSMediaKeyBlock response = AACSMKBResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved != 0)
sb.AppendFormat("Reserved = 0x{0:X2}", response.Reserved).AppendLine();
#endif
sb.AppendFormat("Total number of media key blocks available to transfer {0}", response.TotalPacks).
AppendLine();
sb.AppendFormat("AACS Media Key Blocks in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MediaKeyBlockPacks, 80));
return sb.ToString();
}
public static string PrettifyAACSMediaKeyBlock(byte[] AACSMKBResponse)
{
AACSMediaKeyBlock? decoded = DecodeAACSMediaKeyBlock(AACSMKBResponse);
return PrettifyAACSMediaKeyBlock(decoded);
}
public static AACSDataKeys? DecodeAACSDataKeys(byte[] AACSDKResponse)
{
if(AACSDKResponse == null)
return null;
var decoded = new AACSDataKeys();
decoded.DataKeys = new byte[AACSDKResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSDKResponse, 0);
decoded.Reserved1 = AACSDKResponse[2];
decoded.Reserved2 = AACSDKResponse[3];
Array.Copy(AACSDKResponse, 4, decoded.DataKeys, 0, AACSDKResponse.Length - 4);
return decoded;
}
public static string PrettifyAACSDataKeys(AACSDataKeys? AACSDKResponse)
{
if(AACSDKResponse == null)
return null;
AACSDataKeys response = AACSDKResponse.Value;
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
#endif
sb.AppendFormat("AACS Data Keys in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.DataKeys, 80));
return sb.ToString();
}
public static string PrettifyAACSDataKeys(byte[] AACSDKResponse)
{
AACSDataKeys? decoded = DecodeAACSDataKeys(AACSDKResponse);
return PrettifyAACSDataKeys(decoded);
}
public static AACSLBAExtentsResponse? DecodeAACSLBAExtents(byte[] AACSLBAExtsResponse)
{
if(AACSLBAExtsResponse == null)
return null;
var decoded = new AACSLBAExtentsResponse
{
DataLength = BigEndianBitConverter.ToUInt16(AACSLBAExtsResponse, 0),
Reserved = AACSLBAExtsResponse[2],
MaxLBAExtents = AACSLBAExtsResponse[3]
};
if((AACSLBAExtsResponse.Length - 4) % 16 != 0)
return decoded;
decoded.Extents = new AACSLBAExtent[(AACSLBAExtsResponse.Length - 4) / 16];
for(int i = 0; i < (AACSLBAExtsResponse.Length - 4) / 16; i++)
{
decoded.Extents[i].Reserved = new byte[8];
Array.Copy(AACSLBAExtsResponse, 0 + (i * 16) + 4, decoded.Extents[i].Reserved, 0, 8);
decoded.Extents[i].StartLBA = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 8 + (i * 16) + 4);
decoded.Extents[i].LBACount = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 12 + (i * 16) + 4);
}
return decoded;
}
public static string PrettifyAACSLBAExtents(AACSLBAExtentsResponse? AACSLBAExtsResponse)
{
if(AACSLBAExtsResponse == null)
return null;
AACSLBAExtentsResponse response = AACSLBAExtsResponse.Value;
var sb = new StringBuilder();
if(response.MaxLBAExtents == 0)
sb.AppendLine(response.DataLength > 2 ? "Drive can store 256 LBA Extents"
: "Drive cannot store LBA Extents");
else
sb.AppendFormat("Drive can store {0} LBA Extents", response.MaxLBAExtents).AppendLine();
for(int i = 0; i < response.Extents.Length; i++)
sb.AppendFormat("LBA Extent {0} starts at LBA {1} and goes for {2} sectors", i,
response.Extents[i].StartLBA, response.Extents[i].LBACount);
return sb.ToString();
}
public static string PrettifyAACSLBAExtents(byte[] AACSLBAExtsResponse)
{
AACSLBAExtentsResponse? decoded = DecodeAACSLBAExtents(AACSLBAExtsResponse);
return PrettifyAACSLBAExtents(decoded);
}
public struct AACSVolumeIdentifier
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS volume identifier data</summary>
public byte[] VolumeIdentifier;
}
public struct AACSMediaSerialNumber
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS media serial number</summary>
public byte[] MediaSerialNumber;
}
public struct AACSMediaIdentifier
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS media identifier data</summary>
public byte[] MediaIdentifier;
}
public struct AACSMediaKeyBlock
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved;
/// <summary>Byte 3 Number of MKB packs available to transfer</summary>
public byte TotalPacks;
/// <summary>Bytes 4 to end AACS media key block packs</summary>
public byte[] MediaKeyBlockPacks;
}
public struct AACSDataKeys
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS data keys</summary>
public byte[] DataKeys;
}
public struct AACSLBAExtentsResponse
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved;
/// <summary>
/// Byte 3 Number of LBA extents the drive can store. if(MaxLBAExtents == 0 &amp;&amp; DataLength > 2), 256
/// extents can be stored
/// </summary>
public byte MaxLBAExtents;
/// <summary>Bytes 4 to end LBA Extents</summary>
public AACSLBAExtent[] Extents;
}
public struct AACSLBAExtent
{
/// <summary>Bytes 0 to 7 Reserved</summary>
public byte[] Reserved;
/// <summary>Bytes 8 to 11 Start LBA of extent</summary>
public uint StartLBA;
/// <summary>Bytes 12 to 15 Extent length</summary>
public uint LBACount;
}
return decoded;
}
public static string PrettifyAACSLBAExtents(AACSLBAExtentsResponse? AACSLBAExtsResponse)
{
if(AACSLBAExtsResponse == null)
return null;
AACSLBAExtentsResponse response = AACSLBAExtsResponse.Value;
var sb = new StringBuilder();
if(response.MaxLBAExtents == 0)
sb.AppendLine(response.DataLength > 2 ? "Drive can store 256 LBA Extents"
: "Drive cannot store LBA Extents");
else
sb.AppendFormat("Drive can store {0} LBA Extents", response.MaxLBAExtents).AppendLine();
for(int i = 0; i < response.Extents.Length; i++)
sb.AppendFormat("LBA Extent {0} starts at LBA {1} and goes for {2} sectors", i,
response.Extents[i].StartLBA, response.Extents[i].LBACount);
return sb.ToString();
}
public static string PrettifyAACSLBAExtents(byte[] AACSLBAExtsResponse)
{
AACSLBAExtentsResponse? decoded = DecodeAACSLBAExtents(AACSLBAExtsResponse);
return PrettifyAACSLBAExtents(decoded);
}
public struct AACSVolumeIdentifier
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS volume identifier data</summary>
public byte[] VolumeIdentifier;
}
public struct AACSMediaSerialNumber
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS media serial number</summary>
public byte[] MediaSerialNumber;
}
public struct AACSMediaIdentifier
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS media identifier data</summary>
public byte[] MediaIdentifier;
}
public struct AACSMediaKeyBlock
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved;
/// <summary>Byte 3 Number of MKB packs available to transfer</summary>
public byte TotalPacks;
/// <summary>Bytes 4 to end AACS media key block packs</summary>
public byte[] MediaKeyBlockPacks;
}
public struct AACSDataKeys
{
/// <summary>Bytes 0 to 1 Data length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to end AACS data keys</summary>
public byte[] DataKeys;
}
public struct AACSLBAExtentsResponse
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved;
/// <summary>
/// Byte 3 Number of LBA extents the drive can store. if(MaxLBAExtents == 0 &amp;&amp; DataLength > 2), 256
/// extents can be stored
/// </summary>
public byte MaxLBAExtents;
/// <summary>Bytes 4 to end LBA Extents</summary>
public AACSLBAExtent[] Extents;
}
public struct AACSLBAExtent
{
/// <summary>Bytes 0 to 7 Reserved</summary>
public byte[] Reserved;
/// <summary>Bytes 8 to 11 Start LBA of extent</summary>
public uint StartLBA;
/// <summary>Bytes 12 to 15 Extent length</summary>
public uint LBACount;
}
}

View File

@@ -35,82 +35,81 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Helpers;
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class CPRM
{
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class CPRM
public static CPRMMediaKeyBlock? DecodeCPRMMediaKeyBlock(byte[] CPRMMKBResponse)
{
public static CPRMMediaKeyBlock? DecodeCPRMMediaKeyBlock(byte[] CPRMMKBResponse)
if(CPRMMKBResponse == null)
return null;
var decoded = new CPRMMediaKeyBlock
{
if(CPRMMKBResponse == null)
return null;
MKBPackData = new byte[CPRMMKBResponse.Length - 4],
DataLength = BigEndianBitConverter.ToUInt16(CPRMMKBResponse, 0),
Reserved = CPRMMKBResponse[2],
TotalPacks = CPRMMKBResponse[3]
};
var decoded = new CPRMMediaKeyBlock
{
MKBPackData = new byte[CPRMMKBResponse.Length - 4],
DataLength = BigEndianBitConverter.ToUInt16(CPRMMKBResponse, 0),
Reserved = CPRMMKBResponse[2],
TotalPacks = CPRMMKBResponse[3]
};
Array.Copy(CPRMMKBResponse, 4, decoded.MKBPackData, 0, CPRMMKBResponse.Length - 4);
Array.Copy(CPRMMKBResponse, 4, decoded.MKBPackData, 0, CPRMMKBResponse.Length - 4);
return decoded;
}
return decoded;
}
public static string PrettifyCPRMMediaKeyBlock(CPRMMediaKeyBlock? CPRMMKBResponse)
{
if(CPRMMKBResponse == null)
return null;
public static string PrettifyCPRMMediaKeyBlock(CPRMMediaKeyBlock? CPRMMKBResponse)
{
if(CPRMMKBResponse == null)
return null;
CPRMMediaKeyBlock response = CPRMMKBResponse.Value;
CPRMMediaKeyBlock response = CPRMMKBResponse.Value;
var sb = new StringBuilder();
var sb = new StringBuilder();
#if DEBUG
if(response.Reserved != 0)
sb.AppendFormat("Reserved = 0x{0:X2}", response.Reserved).AppendLine();
#endif
sb.AppendFormat("Total number of CPRM Media Key Blocks available to transfer: {0}", response.TotalPacks).
AppendLine();
#if DEBUG
if(response.Reserved != 0)
sb.AppendFormat("Reserved = 0x{0:X2}", response.Reserved).AppendLine();
#endif
sb.AppendFormat("Total number of CPRM Media Key Blocks available to transfer: {0}", response.TotalPacks).
AppendLine();
sb.AppendFormat("CPRM Media Key Blocks in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MKBPackData, 80));
sb.AppendFormat("CPRM Media Key Blocks in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MKBPackData, 80));
return sb.ToString();
}
return sb.ToString();
}
public static string PrettifyCPRMMediaKeyBlock(byte[] CPRMMKBResponse)
{
CPRMMediaKeyBlock? decoded = DecodeCPRMMediaKeyBlock(CPRMMKBResponse);
public static string PrettifyCPRMMediaKeyBlock(byte[] CPRMMKBResponse)
{
CPRMMediaKeyBlock? decoded = DecodeCPRMMediaKeyBlock(CPRMMKBResponse);
return PrettifyCPRMMediaKeyBlock(decoded);
}
return PrettifyCPRMMediaKeyBlock(decoded);
}
public struct CPRMMediaKeyBlock
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved;
/// <summary>Byte 3 Number of MKB packs available to transfer</summary>
public byte TotalPacks;
/// <summary>Byte 4 MKB Packs</summary>
public byte[] MKBPackData;
}
public struct CPRMMediaKeyBlock
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved;
/// <summary>Byte 3 Number of MKB packs available to transfer</summary>
public byte TotalPacks;
/// <summary>Byte 4 MKB Packs</summary>
public byte[] MKBPackData;
}
}

View File

@@ -34,433 +34,432 @@ using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class DiscInformation
{
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class DiscInformation
public static StandardDiscInformation? Decode000b(byte[] response)
{
public static StandardDiscInformation? Decode000b(byte[] response)
{
if(response.Length < 32)
return null;
if((response[2] & 0xE0) != 0)
return null;
var decoded = new StandardDiscInformation
{
DataLength = (ushort)((response[0] << 8) + response[1])
};
if(decoded.DataLength + 2 != response.Length)
return null;
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
decoded.Erasable |= (response[2] & 0x10) == 0x10;
decoded.LastSessionStatus = (byte)((response[2] & 0x0C) >> 2);
decoded.DiscStatus = (byte)(response[2] & 0x03);
decoded.FirstTrackNumber = response[3];
decoded.Sessions = (ushort)((response[9] << 8) + response[4]);
decoded.FirstTrackLastSession = (ushort)((response[10] << 8) + response[5]);
decoded.LastTrackLastSession = (ushort)((response[11] << 8) + response[6]);
decoded.DID_V |= (response[7] & 0x80) == 0x80;
decoded.DBC_V |= (response[7] & 0x40) == 0x40;
decoded.URU |= (response[7] & 0x20) == 0x20;
decoded.DAC_V |= (response[7] & 0x10) == 0x10;
decoded.Reserved |= (response[7] & 0x08) == 0x08;
decoded.Dbit |= (response[7] & 0x04) == 0x04;
decoded.BGFormatStatus = (byte)(response[7] & 0x03);
decoded.DiscIdentification =
(uint)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]);
decoded.LastSessionLeadInStartLBA =
(uint)((response[16] << 24) + (response[17] << 16) + (response[18] << 8) + response[19]);
decoded.LastPossibleLeadOutStartLBA =
(uint)((response[20] << 24) + (response[21] << 16) + (response[22] << 8) + response[23]);
byte[] temp = new byte[8];
Array.Copy(response, 24, temp, 0, 8);
Array.Reverse(temp);
decoded.DiscBarcode = BitConverter.ToUInt64(temp, 0);
if(response.Length < 34)
return null;
decoded.DiscApplicationCode = response[32];
decoded.OPCTablesNumber = response[33];
if(decoded.OPCTablesNumber <= 0 ||
response.Length != (decoded.OPCTablesNumber * 8) + 34)
return decoded;
decoded.OPCTables = new OPCTable[decoded.OPCTablesNumber];
for(int i = 0; i < decoded.OPCTablesNumber; i++)
{
decoded.OPCTables[i].Speed = (ushort)((response[34 + (i * 8) + 0] << 16) + response[34 + (i * 8) + 1]);
decoded.OPCTables[i].OPCValues = new byte[6];
Array.Copy(response, 34 + (i * 8) + 2, decoded.OPCTables[i].OPCValues, 0, 6);
}
return decoded;
}
public static string Prettify000b(StandardDiscInformation? information)
{
if(information?.DataType != 0)
return null;
var sb = new StringBuilder();
switch(information.Value.DiscType)
{
case 0x00:
sb.AppendLine("Disc type declared as CD-DA or CD-ROM");
break;
case 0x10:
sb.AppendLine("Disc type declared as CD-i");
break;
case 0x20:
sb.AppendLine("Disc type declared as CD-ROM XA");
break;
case 0xFF:
sb.AppendLine("Disc type is undefined");
break;
default:
sb.AppendFormat("Unknown disc type {0:X2}h", information.Value.DiscType).AppendLine();
break;
}
switch(information.Value.DiscStatus)
{
case 0:
sb.AppendLine("Disc is empty");
break;
case 1:
sb.AppendLine("Disc is incomplete");
break;
case 2:
sb.AppendLine("Disc is finalized");
break;
}
if(information.Value.Erasable)
sb.AppendLine("Disc is erasable");
switch(information.Value.LastSessionStatus)
{
case 0:
sb.AppendLine("Last session is empty");
break;
case 1:
sb.AppendLine("Last session is incomplete");
break;
case 2:
sb.AppendLine("Last session is damaged");
break;
case 3:
sb.AppendLine("Last session is complete");
break;
}
switch(information.Value.BGFormatStatus)
{
case 1:
sb.AppendLine("Media was being formatted in the background but it is stopped and incomplete");
break;
case 2:
sb.AppendLine("Media is currently being formatted in the background");
break;
case 3:
sb.AppendLine("Media background formatting has completed");
break;
}
if(information.Value.Dbit)
sb.AppendLine("MRW is dirty");
sb.AppendFormat("First track on disc is track {0}", information.Value.FirstTrackNumber).AppendLine();
sb.AppendFormat("Disc has {0} sessions", information.Value.Sessions).AppendLine();
sb.AppendFormat("First track in last session is track {0}", information.Value.FirstTrackLastSession).
AppendLine();
sb.AppendFormat("Last track in last session is track {0}", information.Value.LastTrackLastSession).
AppendLine();
sb.AppendFormat("Last session Lead-In address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}",
information.Value.LastSessionLeadInStartLBA,
(information.Value.LastSessionLeadInStartLBA & 0xFF0000) >> 16,
(information.Value.LastSessionLeadInStartLBA & 0xFF00) >> 8,
information.Value.LastSessionLeadInStartLBA & 0xFF).AppendLine();
sb.AppendFormat("Last possible Lead-Out address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}",
information.Value.LastPossibleLeadOutStartLBA,
(information.Value.LastPossibleLeadOutStartLBA & 0xFF0000) >> 16,
(information.Value.LastPossibleLeadOutStartLBA & 0xFF00) >> 8,
information.Value.LastPossibleLeadOutStartLBA & 0xFF).AppendLine();
sb.AppendLine(information.Value.URU ? "Disc is defined for unrestricted use"
: "Disc is defined for restricted use");
if(information.Value.DID_V)
sb.AppendFormat("Disc ID: {0:X6}", information.Value.DiscIdentification & 0x00FFFFFF).AppendLine();
if(information.Value.DBC_V)
sb.AppendFormat("Disc barcode: {0:X16}", information.Value.DiscBarcode).AppendLine();
if(information.Value.DAC_V)
sb.AppendFormat("Disc application code: {0}", information.Value.DiscApplicationCode).AppendLine();
if(information.Value.OPCTables == null)
return sb.ToString();
foreach(OPCTable table in information.Value.OPCTables)
sb.AppendFormat("OPC values for {0}Kbit/sec.: {1}, {2}, {3}, {4}, {5}, {6}", table.Speed,
table.OPCValues[0], table.OPCValues[1], table.OPCValues[2], table.OPCValues[3],
table.OPCValues[4], table.OPCValues[5]).AppendLine();
return sb.ToString();
}
public static TrackResourcesInformation? Decode001b(byte[] response)
{
if(response.Length != 12)
return null;
if((response[2] & 0xE0) != 0x20)
return null;
var decoded = new TrackResourcesInformation
{
DataLength = (ushort)((response[0] << 8) + response[1])
};
if(decoded.DataLength + 2 != response.Length)
return null;
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
decoded.MaxTracks = (ushort)((response[4] << 8) + response[5]);
decoded.AssignedTracks = (ushort)((response[6] << 8) + response[7]);
decoded.MaxAppendableTracks = (ushort)((response[8] << 8) + response[9]);
decoded.AppendableTracks = (ushort)((response[10] << 8) + response[11]);
return decoded;
}
public static string Prettify001b(TrackResourcesInformation? information)
{
if(information?.DataType != 1)
return null;
var sb = new StringBuilder();
sb.AppendFormat("{0} maximum possible tracks on the disc", information.Value.MaxTracks).AppendLine();
sb.AppendFormat("{0} assigned tracks on the disc", information.Value.AssignedTracks).AppendLine();
sb.AppendFormat("{0} maximum possible appendable tracks on the disc", information.Value.AppendableTracks).
AppendLine();
sb.AppendFormat("{0} current appendable tracks on the disc", information.Value.MaxAppendableTracks).
AppendLine();
return sb.ToString();
}
public static POWResourcesInformation? Decode010b(byte[] response)
{
if(response.Length != 16)
return null;
if((response[2] & 0xE0) != 0x40)
return null;
var decoded = new POWResourcesInformation
{
DataLength = (ushort)((response[0] << 8) + response[1])
};
if(decoded.DataLength + 2 != response.Length)
return null;
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
decoded.RemainingPOWReplacements =
(ushort)((response[4] << 24) + (response[5] << 16) + (response[6] << 8) + response[7]);
decoded.RemainingPOWReallocation =
(ushort)((response[8] << 24) + (response[9] << 16) + (response[10] << 8) + response[11]);
decoded.RemainingPOWUpdates =
(ushort)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]);
return decoded;
}
public static string Prettify010b(POWResourcesInformation? information)
{
if(information?.DataType != 1)
return null;
var sb = new StringBuilder();
sb.AppendFormat("{0} remaining POW replacements", information.Value.RemainingPOWReplacements).AppendLine();
sb.AppendFormat("{0} remaining POW reallocation map entries", information.Value.RemainingPOWReallocation).
AppendLine();
sb.AppendFormat("{0} remaining POW updates", information.Value.RemainingPOWUpdates).AppendLine();
return sb.ToString();
}
public static string Prettify(byte[] response)
{
if(response == null)
return null;
if(response.Length < 12)
return null;
switch(response[2] & 0xE0)
{
case 0x00: return Prettify000b(Decode000b(response));
case 0x20: return Prettify001b(Decode001b(response));
case 0x40: return Prettify010b(Decode010b(response));
}
if(response.Length < 32)
return null;
if((response[2] & 0xE0) != 0)
return null;
var decoded = new StandardDiscInformation
{
DataLength = (ushort)((response[0] << 8) + response[1])
};
if(decoded.DataLength + 2 != response.Length)
return null;
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
decoded.Erasable |= (response[2] & 0x10) == 0x10;
decoded.LastSessionStatus = (byte)((response[2] & 0x0C) >> 2);
decoded.DiscStatus = (byte)(response[2] & 0x03);
decoded.FirstTrackNumber = response[3];
decoded.Sessions = (ushort)((response[9] << 8) + response[4]);
decoded.FirstTrackLastSession = (ushort)((response[10] << 8) + response[5]);
decoded.LastTrackLastSession = (ushort)((response[11] << 8) + response[6]);
decoded.DID_V |= (response[7] & 0x80) == 0x80;
decoded.DBC_V |= (response[7] & 0x40) == 0x40;
decoded.URU |= (response[7] & 0x20) == 0x20;
decoded.DAC_V |= (response[7] & 0x10) == 0x10;
decoded.Reserved |= (response[7] & 0x08) == 0x08;
decoded.Dbit |= (response[7] & 0x04) == 0x04;
decoded.BGFormatStatus = (byte)(response[7] & 0x03);
decoded.DiscIdentification =
(uint)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]);
decoded.LastSessionLeadInStartLBA =
(uint)((response[16] << 24) + (response[17] << 16) + (response[18] << 8) + response[19]);
decoded.LastPossibleLeadOutStartLBA =
(uint)((response[20] << 24) + (response[21] << 16) + (response[22] << 8) + response[23]);
byte[] temp = new byte[8];
Array.Copy(response, 24, temp, 0, 8);
Array.Reverse(temp);
decoded.DiscBarcode = BitConverter.ToUInt64(temp, 0);
if(response.Length < 34)
return null;
decoded.DiscApplicationCode = response[32];
decoded.OPCTablesNumber = response[33];
if(decoded.OPCTablesNumber <= 0 ||
response.Length != (decoded.OPCTablesNumber * 8) + 34)
return decoded;
decoded.OPCTables = new OPCTable[decoded.OPCTablesNumber];
for(int i = 0; i < decoded.OPCTablesNumber; i++)
{
decoded.OPCTables[i].Speed = (ushort)((response[34 + (i * 8) + 0] << 16) + response[34 + (i * 8) + 1]);
decoded.OPCTables[i].OPCValues = new byte[6];
Array.Copy(response, 34 + (i * 8) + 2, decoded.OPCTables[i].OPCValues, 0, 6);
}
public struct StandardDiscInformation
return decoded;
}
public static string Prettify000b(StandardDiscInformation? information)
{
if(information?.DataType != 0)
return null;
var sb = new StringBuilder();
switch(information.Value.DiscType)
{
/// <summary>Bytes 0 to 1 32 + OPCTablesNumber*8</summary>
public ushort DataLength;
/// <summary>Byte 2, bits 7 to 5 000b</summary>
public byte DataType;
/// <summary>Byte 2, bit 4 If set, disc is erasable</summary>
public bool Erasable;
/// <summary>Byte 2, bits 3 to 2 Status of last session</summary>
public byte LastSessionStatus;
/// <summary>Byte 2, bits 1 to 0 Status of disc</summary>
public byte DiscStatus;
/// <summary>Byte 3 Number of logical track that contains LBA 0</summary>
public byte FirstTrackNumber;
/// <summary>Byte 9 (MSB) and byte 4 (LSB) Number of sessions</summary>
public ushort Sessions;
/// <summary>Byte 10 (MSB) and byte 5 (LSB) Number of first track in last session</summary>
public ushort FirstTrackLastSession;
/// <summary>Byte 11 (MSB) and byte 6 (LSB) Number of last track in last session</summary>
public ushort LastTrackLastSession;
/// <summary>Byte 7, bit 7 If set, DiscIdentification is valid</summary>
public bool DID_V;
/// <summary>Byte 7, bit 6 If set, DiscBarcode is valid</summary>
public bool DBC_V;
/// <summary>Byte 7, bit 5 If set, disc is unrestricted</summary>
public bool URU;
/// <summary>Byte 7, bit 4 If set DiscApplicationCode is valid</summary>
public bool DAC_V;
/// <summary>Byte 7, bit 3 Reserved</summary>
public bool Reserved;
/// <summary>Byte 7, bit 2 Copy of dirty bit from MRW status</summary>
public bool Dbit;
/// <summary>Byte 7, bits 1 to 0 Background format status</summary>
public byte BGFormatStatus;
/// <summary>Byte 8 Disc type code</summary>
public byte DiscType;
/// <summary>Bytes 12 to 15 Disc identification number from PMA</summary>
public uint DiscIdentification;
/// <summary>Bytes 16 to 19 Last Session Lead-in Start Address (MSF for CD, LBA for others)</summary>
public uint LastSessionLeadInStartLBA;
/// <summary>Bytes 20 to 23 Last Possible Lead-out Start Address (MSF for CD, LBA for others)</summary>
public uint LastPossibleLeadOutStartLBA;
/// <summary>Bytes 24 to 31 Disc barcode</summary>
public ulong DiscBarcode;
/// <summary>Byte 32 Disc application code</summary>
public byte DiscApplicationCode;
/// <summary>Byte 33 How many OPC tables are</summary>
public byte OPCTablesNumber;
/// <summary>Bytes 34 to end OPC tables (8 bytes each)</summary>
public OPCTable[] OPCTables;
case 0x00:
sb.AppendLine("Disc type declared as CD-DA or CD-ROM");
break;
case 0x10:
sb.AppendLine("Disc type declared as CD-i");
break;
case 0x20:
sb.AppendLine("Disc type declared as CD-ROM XA");
break;
case 0xFF:
sb.AppendLine("Disc type is undefined");
break;
default:
sb.AppendFormat("Unknown disc type {0:X2}h", information.Value.DiscType).AppendLine();
break;
}
public struct OPCTable
switch(information.Value.DiscStatus)
{
/// <summary>Bytes 0 to 1 kilobytes/sec this OPC table applies to</summary>
public ushort Speed;
/// <summary>Bytes 2 to 7 OPC values</summary>
public byte[] OPCValues;
case 0:
sb.AppendLine("Disc is empty");
break;
case 1:
sb.AppendLine("Disc is incomplete");
break;
case 2:
sb.AppendLine("Disc is finalized");
break;
}
public struct TrackResourcesInformation
if(information.Value.Erasable)
sb.AppendLine("Disc is erasable");
switch(information.Value.LastSessionStatus)
{
/// <summary>Bytes 0 to 1 10</summary>
public ushort DataLength;
/// <summary>Byte 2, bits 7 to 5 001b</summary>
public byte DataType;
/// <summary>Byte 2, bits 4 to 0 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to 5 Maximum possible number of the tracks on the disc</summary>
public ushort MaxTracks;
/// <summary>Bytes 6 to 7 Number of the assigned tracks on the disc</summary>
public ushort AssignedTracks;
/// <summary>Bytes 8 to 9 Maximum possible number of appendable tracks on the disc</summary>
public ushort MaxAppendableTracks;
/// <summary>Bytes 10 to 11 Current number of appendable tracks on the disc</summary>
public ushort AppendableTracks;
case 0:
sb.AppendLine("Last session is empty");
break;
case 1:
sb.AppendLine("Last session is incomplete");
break;
case 2:
sb.AppendLine("Last session is damaged");
break;
case 3:
sb.AppendLine("Last session is complete");
break;
}
public struct POWResourcesInformation
switch(information.Value.BGFormatStatus)
{
/// <summary>Bytes 0 to 1 14</summary>
public ushort DataLength;
/// <summary>Byte 2, bits 7 to 5 010b</summary>
public byte DataType;
/// <summary>Byte 2, bits 4 to 0 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to 7 Remaining POW replacements</summary>
public uint RemainingPOWReplacements;
/// <summary>Bytes 8 to 11 Remaining POW reallocation map entries</summary>
public uint RemainingPOWReallocation;
/// <summary>Bytes 12 to 15 Number of remaining POW updates</summary>
public uint RemainingPOWUpdates;
case 1:
sb.AppendLine("Media was being formatted in the background but it is stopped and incomplete");
break;
case 2:
sb.AppendLine("Media is currently being formatted in the background");
break;
case 3:
sb.AppendLine("Media background formatting has completed");
break;
}
if(information.Value.Dbit)
sb.AppendLine("MRW is dirty");
sb.AppendFormat("First track on disc is track {0}", information.Value.FirstTrackNumber).AppendLine();
sb.AppendFormat("Disc has {0} sessions", information.Value.Sessions).AppendLine();
sb.AppendFormat("First track in last session is track {0}", information.Value.FirstTrackLastSession).
AppendLine();
sb.AppendFormat("Last track in last session is track {0}", information.Value.LastTrackLastSession).
AppendLine();
sb.AppendFormat("Last session Lead-In address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}",
information.Value.LastSessionLeadInStartLBA,
(information.Value.LastSessionLeadInStartLBA & 0xFF0000) >> 16,
(information.Value.LastSessionLeadInStartLBA & 0xFF00) >> 8,
information.Value.LastSessionLeadInStartLBA & 0xFF).AppendLine();
sb.AppendFormat("Last possible Lead-Out address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}",
information.Value.LastPossibleLeadOutStartLBA,
(information.Value.LastPossibleLeadOutStartLBA & 0xFF0000) >> 16,
(information.Value.LastPossibleLeadOutStartLBA & 0xFF00) >> 8,
information.Value.LastPossibleLeadOutStartLBA & 0xFF).AppendLine();
sb.AppendLine(information.Value.URU ? "Disc is defined for unrestricted use"
: "Disc is defined for restricted use");
if(information.Value.DID_V)
sb.AppendFormat("Disc ID: {0:X6}", information.Value.DiscIdentification & 0x00FFFFFF).AppendLine();
if(information.Value.DBC_V)
sb.AppendFormat("Disc barcode: {0:X16}", information.Value.DiscBarcode).AppendLine();
if(information.Value.DAC_V)
sb.AppendFormat("Disc application code: {0}", information.Value.DiscApplicationCode).AppendLine();
if(information.Value.OPCTables == null)
return sb.ToString();
foreach(OPCTable table in information.Value.OPCTables)
sb.AppendFormat("OPC values for {0}Kbit/sec.: {1}, {2}, {3}, {4}, {5}, {6}", table.Speed,
table.OPCValues[0], table.OPCValues[1], table.OPCValues[2], table.OPCValues[3],
table.OPCValues[4], table.OPCValues[5]).AppendLine();
return sb.ToString();
}
public static TrackResourcesInformation? Decode001b(byte[] response)
{
if(response.Length != 12)
return null;
if((response[2] & 0xE0) != 0x20)
return null;
var decoded = new TrackResourcesInformation
{
DataLength = (ushort)((response[0] << 8) + response[1])
};
if(decoded.DataLength + 2 != response.Length)
return null;
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
decoded.MaxTracks = (ushort)((response[4] << 8) + response[5]);
decoded.AssignedTracks = (ushort)((response[6] << 8) + response[7]);
decoded.MaxAppendableTracks = (ushort)((response[8] << 8) + response[9]);
decoded.AppendableTracks = (ushort)((response[10] << 8) + response[11]);
return decoded;
}
public static string Prettify001b(TrackResourcesInformation? information)
{
if(information?.DataType != 1)
return null;
var sb = new StringBuilder();
sb.AppendFormat("{0} maximum possible tracks on the disc", information.Value.MaxTracks).AppendLine();
sb.AppendFormat("{0} assigned tracks on the disc", information.Value.AssignedTracks).AppendLine();
sb.AppendFormat("{0} maximum possible appendable tracks on the disc", information.Value.AppendableTracks).
AppendLine();
sb.AppendFormat("{0} current appendable tracks on the disc", information.Value.MaxAppendableTracks).
AppendLine();
return sb.ToString();
}
public static POWResourcesInformation? Decode010b(byte[] response)
{
if(response.Length != 16)
return null;
if((response[2] & 0xE0) != 0x40)
return null;
var decoded = new POWResourcesInformation
{
DataLength = (ushort)((response[0] << 8) + response[1])
};
if(decoded.DataLength + 2 != response.Length)
return null;
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
decoded.RemainingPOWReplacements =
(ushort)((response[4] << 24) + (response[5] << 16) + (response[6] << 8) + response[7]);
decoded.RemainingPOWReallocation =
(ushort)((response[8] << 24) + (response[9] << 16) + (response[10] << 8) + response[11]);
decoded.RemainingPOWUpdates =
(ushort)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]);
return decoded;
}
public static string Prettify010b(POWResourcesInformation? information)
{
if(information?.DataType != 1)
return null;
var sb = new StringBuilder();
sb.AppendFormat("{0} remaining POW replacements", information.Value.RemainingPOWReplacements).AppendLine();
sb.AppendFormat("{0} remaining POW reallocation map entries", information.Value.RemainingPOWReallocation).
AppendLine();
sb.AppendFormat("{0} remaining POW updates", information.Value.RemainingPOWUpdates).AppendLine();
return sb.ToString();
}
public static string Prettify(byte[] response)
{
if(response == null)
return null;
if(response.Length < 12)
return null;
switch(response[2] & 0xE0)
{
case 0x00: return Prettify000b(Decode000b(response));
case 0x20: return Prettify001b(Decode001b(response));
case 0x40: return Prettify010b(Decode010b(response));
}
return null;
}
public struct StandardDiscInformation
{
/// <summary>Bytes 0 to 1 32 + OPCTablesNumber*8</summary>
public ushort DataLength;
/// <summary>Byte 2, bits 7 to 5 000b</summary>
public byte DataType;
/// <summary>Byte 2, bit 4 If set, disc is erasable</summary>
public bool Erasable;
/// <summary>Byte 2, bits 3 to 2 Status of last session</summary>
public byte LastSessionStatus;
/// <summary>Byte 2, bits 1 to 0 Status of disc</summary>
public byte DiscStatus;
/// <summary>Byte 3 Number of logical track that contains LBA 0</summary>
public byte FirstTrackNumber;
/// <summary>Byte 9 (MSB) and byte 4 (LSB) Number of sessions</summary>
public ushort Sessions;
/// <summary>Byte 10 (MSB) and byte 5 (LSB) Number of first track in last session</summary>
public ushort FirstTrackLastSession;
/// <summary>Byte 11 (MSB) and byte 6 (LSB) Number of last track in last session</summary>
public ushort LastTrackLastSession;
/// <summary>Byte 7, bit 7 If set, DiscIdentification is valid</summary>
public bool DID_V;
/// <summary>Byte 7, bit 6 If set, DiscBarcode is valid</summary>
public bool DBC_V;
/// <summary>Byte 7, bit 5 If set, disc is unrestricted</summary>
public bool URU;
/// <summary>Byte 7, bit 4 If set DiscApplicationCode is valid</summary>
public bool DAC_V;
/// <summary>Byte 7, bit 3 Reserved</summary>
public bool Reserved;
/// <summary>Byte 7, bit 2 Copy of dirty bit from MRW status</summary>
public bool Dbit;
/// <summary>Byte 7, bits 1 to 0 Background format status</summary>
public byte BGFormatStatus;
/// <summary>Byte 8 Disc type code</summary>
public byte DiscType;
/// <summary>Bytes 12 to 15 Disc identification number from PMA</summary>
public uint DiscIdentification;
/// <summary>Bytes 16 to 19 Last Session Lead-in Start Address (MSF for CD, LBA for others)</summary>
public uint LastSessionLeadInStartLBA;
/// <summary>Bytes 20 to 23 Last Possible Lead-out Start Address (MSF for CD, LBA for others)</summary>
public uint LastPossibleLeadOutStartLBA;
/// <summary>Bytes 24 to 31 Disc barcode</summary>
public ulong DiscBarcode;
/// <summary>Byte 32 Disc application code</summary>
public byte DiscApplicationCode;
/// <summary>Byte 33 How many OPC tables are</summary>
public byte OPCTablesNumber;
/// <summary>Bytes 34 to end OPC tables (8 bytes each)</summary>
public OPCTable[] OPCTables;
}
public struct OPCTable
{
/// <summary>Bytes 0 to 1 kilobytes/sec this OPC table applies to</summary>
public ushort Speed;
/// <summary>Bytes 2 to 7 OPC values</summary>
public byte[] OPCValues;
}
public struct TrackResourcesInformation
{
/// <summary>Bytes 0 to 1 10</summary>
public ushort DataLength;
/// <summary>Byte 2, bits 7 to 5 001b</summary>
public byte DataType;
/// <summary>Byte 2, bits 4 to 0 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to 5 Maximum possible number of the tracks on the disc</summary>
public ushort MaxTracks;
/// <summary>Bytes 6 to 7 Number of the assigned tracks on the disc</summary>
public ushort AssignedTracks;
/// <summary>Bytes 8 to 9 Maximum possible number of appendable tracks on the disc</summary>
public ushort MaxAppendableTracks;
/// <summary>Bytes 10 to 11 Current number of appendable tracks on the disc</summary>
public ushort AppendableTracks;
}
public struct POWResourcesInformation
{
/// <summary>Bytes 0 to 1 14</summary>
public ushort DataLength;
/// <summary>Byte 2, bits 7 to 5 010b</summary>
public byte DataType;
/// <summary>Byte 2, bits 4 to 0 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Bytes 4 to 7 Remaining POW replacements</summary>
public uint RemainingPOWReplacements;
/// <summary>Bytes 8 to 11 Remaining POW reallocation map entries</summary>
public uint RemainingPOWReallocation;
/// <summary>Bytes 12 to 15 Number of remaining POW updates</summary>
public uint RemainingPOWUpdates;
}
}

View File

@@ -32,46 +32,45 @@
using System.Diagnostics.CodeAnalysis;
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum FormatLayerTypeCodes : ushort
{
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum FormatLayerTypeCodes : ushort
{
CDLayer = 0x0008, DVDLayer = 0x0010, BDLayer = 0x0040,
HDDVDLayer = 0x0050
}
CDLayer = 0x0008, DVDLayer = 0x0010, BDLayer = 0x0040,
HDDVDLayer = 0x0050
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum SessionStatusCodes : byte
{
Empty = 0x00, Incomplete = 0x01, ReservedOrDamaged = 0x02,
Complete = 0x03
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum SessionStatusCodes : byte
{
Empty = 0x00, Incomplete = 0x01, ReservedOrDamaged = 0x02,
Complete = 0x03
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum DiscStatusCodes : byte
{
Empty = 0x00, Incomplete = 0x01, Finalized = 0x02,
Others = 0x03
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum DiscStatusCodes : byte
{
Empty = 0x00, Incomplete = 0x01, Finalized = 0x02,
Others = 0x03
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum BGFormatStatusCodes : byte
{
NoFormattable = 0x00, IncompleteBackgroundFormat = 0x01, BackgroundFormatInProgress = 0x02,
FormatComplete = 0x03
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum BGFormatStatusCodes : byte
{
NoFormattable = 0x00, IncompleteBackgroundFormat = 0x01, BackgroundFormatInProgress = 0x02,
FormatComplete = 0x03
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum DiscTypeCodes : byte
{
/// <summary>Also valid for CD-DA, DVD and BD</summary>
CDROM = 0x00, CDi = 0x10, CDROMXA = 0x20, Undefined = 0xFF
}
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum DiscTypeCodes : byte
{
/// <summary>Also valid for CD-DA, DVD and BD</summary>
CDROM = 0x00, CDi = 0x10, CDROMXA = 0x20, Undefined = 0xFF
}
public enum LayerJumpRecordingStatus : byte
{
Incremental = 0, Unspecified = 1, Manual = 2,
RegularInterval = 3
}
public enum LayerJumpRecordingStatus : byte
{
Incremental = 0, Unspecified = 1, Manual = 2,
RegularInterval = 3
}

File diff suppressed because it is too large Load Diff

View File

@@ -34,163 +34,162 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Helpers;
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class Hybrid
{
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class Hybrid
public static RecognizedFormatLayers? DecodeFormatLayers(byte[] FormatLayersResponse)
{
public static RecognizedFormatLayers? DecodeFormatLayers(byte[] FormatLayersResponse)
if(FormatLayersResponse == null)
return null;
if(FormatLayersResponse.Length < 8)
return null;
var decoded = new RecognizedFormatLayers
{
if(FormatLayersResponse == null)
return null;
DataLength = BigEndianBitConverter.ToUInt16(FormatLayersResponse, 0),
Reserved1 = FormatLayersResponse[2],
Reserved2 = FormatLayersResponse[3],
NumberOfLayers = FormatLayersResponse[4],
Reserved3 = (byte)((FormatLayersResponse[5] & 0xC0) >> 6),
DefaultFormatLayer = (byte)((FormatLayersResponse[5] & 0x30) >> 4),
Reserved4 = (byte)((FormatLayersResponse[5] & 0x0C) >> 2),
OnlineFormatLayer = (byte)(FormatLayersResponse[5] & 0x03),
FormatLayers = new ushort[(FormatLayersResponse.Length - 6) / 2]
};
if(FormatLayersResponse.Length < 8)
return null;
for(int i = 0; i < (FormatLayersResponse.Length - 6) / 2; i++)
decoded.FormatLayers[i] = BigEndianBitConverter.ToUInt16(FormatLayersResponse, (i * 2) + 6);
var decoded = new RecognizedFormatLayers
return decoded;
}
public static string PrettifyFormatLayers(RecognizedFormatLayers? FormatLayersResponse)
{
if(FormatLayersResponse == null)
return null;
RecognizedFormatLayers response = FormatLayersResponse.Value;
var sb = new StringBuilder();
sb.AppendFormat("{0} format layers recognized", response.NumberOfLayers);
for(int i = 0; i < response.FormatLayers.Length; i++)
switch(response.FormatLayers[i])
{
DataLength = BigEndianBitConverter.ToUInt16(FormatLayersResponse, 0),
Reserved1 = FormatLayersResponse[2],
Reserved2 = FormatLayersResponse[3],
NumberOfLayers = FormatLayersResponse[4],
Reserved3 = (byte)((FormatLayersResponse[5] & 0xC0) >> 6),
DefaultFormatLayer = (byte)((FormatLayersResponse[5] & 0x30) >> 4),
Reserved4 = (byte)((FormatLayersResponse[5] & 0x0C) >> 2),
OnlineFormatLayer = (byte)(FormatLayersResponse[5] & 0x03),
FormatLayers = new ushort[(FormatLayersResponse.Length - 6) / 2]
};
for(int i = 0; i < (FormatLayersResponse.Length - 6) / 2; i++)
decoded.FormatLayers[i] = BigEndianBitConverter.ToUInt16(FormatLayersResponse, (i * 2) + 6);
return decoded;
}
public static string PrettifyFormatLayers(RecognizedFormatLayers? FormatLayersResponse)
{
if(FormatLayersResponse == null)
return null;
RecognizedFormatLayers response = FormatLayersResponse.Value;
var sb = new StringBuilder();
sb.AppendFormat("{0} format layers recognized", response.NumberOfLayers);
for(int i = 0; i < response.FormatLayers.Length; i++)
switch(response.FormatLayers[i])
case (ushort)FormatLayerTypeCodes.BDLayer:
{
case (ushort)FormatLayerTypeCodes.BDLayer:
{
sb.AppendFormat("Layer {0} is of type Blu-ray", i).AppendLine();
sb.AppendFormat("Layer {0} is of type Blu-ray", i).AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
case (ushort)FormatLayerTypeCodes.CDLayer:
{
sb.AppendFormat("Layer {0} is of type CD", i).AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
case (ushort)FormatLayerTypeCodes.DVDLayer:
{
sb.AppendFormat("Layer {0} is of type DVD", i).AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
case (ushort)FormatLayerTypeCodes.HDDVDLayer:
{
sb.AppendFormat("Layer {0} is of type HD DVD", i).AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
default:
{
sb.AppendFormat("Layer {0} is of unknown type 0x{1:X4}", i, response.FormatLayers[i]).
AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
break;
}
return sb.ToString();
}
case (ushort)FormatLayerTypeCodes.CDLayer:
{
sb.AppendFormat("Layer {0} is of type CD", i).AppendLine();
public static string PrettifyFormatLayers(byte[] FormatLayersResponse)
{
RecognizedFormatLayers? decoded = DecodeFormatLayers(FormatLayersResponse);
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
return PrettifyFormatLayers(decoded);
}
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
public struct RecognizedFormatLayers
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Byte 4 Number of format layers in hybrid disc identified by drive</summary>
public byte NumberOfLayers;
/// <summary>Byte 5, bits 7 to 6 Reserved</summary>
public byte Reserved3;
/// <summary>Byte 5, bits 5 to 4 Layer no. used when disc is inserted</summary>
public byte DefaultFormatLayer;
/// <summary>Byte 5, bits 3 to 2 Reserved</summary>
public byte Reserved4;
/// <summary>Byte 5, bits 1 to 0 Layer no. currently in use</summary>
public byte OnlineFormatLayer;
/// <summary>Bytes 6 to end Recognized format layers</summary>
public ushort[] FormatLayers;
}
break;
}
case (ushort)FormatLayerTypeCodes.DVDLayer:
{
sb.AppendFormat("Layer {0} is of type DVD", i).AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
case (ushort)FormatLayerTypeCodes.HDDVDLayer:
{
sb.AppendFormat("Layer {0} is of type HD DVD", i).AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
default:
{
sb.AppendFormat("Layer {0} is of unknown type 0x{1:X4}", i, response.FormatLayers[i]).
AppendLine();
if(response.DefaultFormatLayer == i)
sb.AppendLine("This is the default layer.");
if(response.OnlineFormatLayer == i)
sb.AppendLine("This is the layer actually in use.");
break;
}
}
return sb.ToString();
}
public static string PrettifyFormatLayers(byte[] FormatLayersResponse)
{
RecognizedFormatLayers? decoded = DecodeFormatLayers(FormatLayersResponse);
return PrettifyFormatLayers(decoded);
}
public struct RecognizedFormatLayers
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Byte 4 Number of format layers in hybrid disc identified by drive</summary>
public byte NumberOfLayers;
/// <summary>Byte 5, bits 7 to 6 Reserved</summary>
public byte Reserved3;
/// <summary>Byte 5, bits 5 to 4 Layer no. used when disc is inserted</summary>
public byte DefaultFormatLayer;
/// <summary>Byte 5, bits 3 to 2 Reserved</summary>
public byte Reserved4;
/// <summary>Byte 5, bits 1 to 0 Layer no. currently in use</summary>
public byte OnlineFormatLayer;
/// <summary>Bytes 6 to end Recognized format layers</summary>
public ushort[] FormatLayers;
}
}

View File

@@ -26,85 +26,84 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
public class TrackInformation
{
public class TrackInformation
public bool Blank;
public bool Copy;
public bool Damage;
public ushort DataLength;
public byte DataMode;
public uint FixedPacketSize;
public bool FP;
public uint FreeBlocks;
public uint LastLayerJumpAddress;
public uint LastRecordedAddress;
public LayerJumpRecordingStatus LayerJumpRecordingStatus;
public ushort LogicalTrackNumber;
public uint LogicalTrackSize;
public uint LogicalTrackStartAddress;
public bool LraV;
public uint NextLayerJumpAddress;
public uint NextWritableAddress;
public bool NwaV;
public bool Packet;
public uint ReadCompatibilityLba;
public bool RT;
public ushort SessionNumber;
public byte TrackMode;
public static TrackInformation Decode(byte[] response)
{
public bool Blank;
public bool Copy;
public bool Damage;
public ushort DataLength;
public byte DataMode;
public uint FixedPacketSize;
public bool FP;
public uint FreeBlocks;
public uint LastLayerJumpAddress;
public uint LastRecordedAddress;
public LayerJumpRecordingStatus LayerJumpRecordingStatus;
public ushort LogicalTrackNumber;
public uint LogicalTrackSize;
public uint LogicalTrackStartAddress;
public bool LraV;
public uint NextLayerJumpAddress;
public uint NextWritableAddress;
public bool NwaV;
public bool Packet;
public uint ReadCompatibilityLba;
public bool RT;
public ushort SessionNumber;
public byte TrackMode;
if(response.Length < 32)
return null;
public static TrackInformation Decode(byte[] response)
var decoded = new TrackInformation
{
if(response.Length < 32)
return null;
var decoded = new TrackInformation
{
DataLength = (ushort)((response[0] << 8) + response[1]),
LogicalTrackNumber = response[2],
SessionNumber = response[3],
LayerJumpRecordingStatus = (LayerJumpRecordingStatus)(response[5] >> 6),
Damage = (response[5] & 0x20) == 0x20,
Copy = (response[5] & 0x10) == 0x10,
TrackMode = (byte)(response[5] & 0xF),
RT = (response[6] & 0x80) == 0x80,
Blank = (response[6] & 0x40) == 0x40,
Packet = (response[6] & 0x20) == 0x20,
FP = (response[6] & 0x10) == 0x10,
DataMode = (byte)(response[6] & 0xF),
LraV = (response[7] & 0x02) == 0x02,
NwaV = (response[7] & 0x01) == 0x01,
LogicalTrackStartAddress =
(uint)((response[8] << 24) + (response[9] << 16) + (response[10] << 8) + response[11]),
NextWritableAddress =
(uint)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]),
FreeBlocks = (uint)((response[16] << 24) + (response[17] << 16) + (response[18] << 8) + response[19]),
FixedPacketSize =
(uint)((response[20] << 24) + (response[21] << 16) + (response[22] << 8) + response[23]),
LogicalTrackSize =
(uint)((response[24] << 24) + (response[25] << 16) + (response[26] << 8) + response[27]),
LastRecordedAddress =
(uint)((response[28] << 24) + (response[29] << 16) + (response[30] << 8) + response[31])
};
if(response.Length < 48)
return decoded;
decoded.LogicalTrackNumber += (ushort)(response[32] << 8);
decoded.SessionNumber += (ushort)(response[33] << 8);
decoded.ReadCompatibilityLba =
(uint)((response[36] << 24) + (response[37] << 16) + (response[38] << 8) + response[39]);
decoded.NextLayerJumpAddress =
(uint)((response[40] << 24) + (response[41] << 16) + (response[42] << 8) + response[43]);
decoded.LastLayerJumpAddress =
(uint)((response[44] << 24) + (response[45] << 16) + (response[46] << 8) + response[47]);
DataLength = (ushort)((response[0] << 8) + response[1]),
LogicalTrackNumber = response[2],
SessionNumber = response[3],
LayerJumpRecordingStatus = (LayerJumpRecordingStatus)(response[5] >> 6),
Damage = (response[5] & 0x20) == 0x20,
Copy = (response[5] & 0x10) == 0x10,
TrackMode = (byte)(response[5] & 0xF),
RT = (response[6] & 0x80) == 0x80,
Blank = (response[6] & 0x40) == 0x40,
Packet = (response[6] & 0x20) == 0x20,
FP = (response[6] & 0x10) == 0x10,
DataMode = (byte)(response[6] & 0xF),
LraV = (response[7] & 0x02) == 0x02,
NwaV = (response[7] & 0x01) == 0x01,
LogicalTrackStartAddress =
(uint)((response[8] << 24) + (response[9] << 16) + (response[10] << 8) + response[11]),
NextWritableAddress =
(uint)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]),
FreeBlocks = (uint)((response[16] << 24) + (response[17] << 16) + (response[18] << 8) + response[19]),
FixedPacketSize =
(uint)((response[20] << 24) + (response[21] << 16) + (response[22] << 8) + response[23]),
LogicalTrackSize =
(uint)((response[24] << 24) + (response[25] << 16) + (response[26] << 8) + response[27]),
LastRecordedAddress =
(uint)((response[28] << 24) + (response[29] << 16) + (response[30] << 8) + response[31])
};
if(response.Length < 48)
return decoded;
}
decoded.LogicalTrackNumber += (ushort)(response[32] << 8);
decoded.SessionNumber += (ushort)(response[33] << 8);
decoded.ReadCompatibilityLba =
(uint)((response[36] << 24) + (response[37] << 16) + (response[38] << 8) + response[39]);
decoded.NextLayerJumpAddress =
(uint)((response[40] << 24) + (response[41] << 16) + (response[42] << 8) + response[43]);
decoded.LastLayerJumpAddress =
(uint)((response[44] << 24) + (response[45] << 16) + (response[46] << 8) + response[47]);
return decoded;
}
}

View File

@@ -35,123 +35,122 @@ using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Helpers;
namespace Aaru.Decoders.SCSI.MMC
namespace Aaru.Decoders.SCSI.MMC;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class WriteProtect
{
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
// T10/1048-D revision 10a
// T10/1228-D revision 7.0c
// T10/1228-D revision 11a
// T10/1363-D revision 10g
// T10/1545-D revision 1d
// T10/1545-D revision 5
// T10/1545-D revision 5a
// T10/1675-D revision 2c
// T10/1675-D revision 4
// T10/1836-D revision 2g
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static class WriteProtect
public static WriteProtectionStatus? DecodeWriteProtectionStatus(byte[] WPSResponse)
{
public static WriteProtectionStatus? DecodeWriteProtectionStatus(byte[] WPSResponse)
if(WPSResponse == null)
return null;
var decoded = new WriteProtectionStatus
{
if(WPSResponse == null)
return null;
DataLength = BigEndianBitConverter.ToUInt16(WPSResponse, 0),
Reserved1 = WPSResponse[2],
Reserved2 = WPSResponse[3],
Reserved3 = (byte)((WPSResponse[4] & 0xF0) >> 4),
MSWI = Convert.ToBoolean(WPSResponse[4] & 0x08),
CWP = Convert.ToBoolean(WPSResponse[4] & 0x04),
PWP = Convert.ToBoolean(WPSResponse[4] & 0x02),
SWPP = Convert.ToBoolean(WPSResponse[4] & 0x01),
Reserved4 = WPSResponse[5],
Reserved5 = WPSResponse[6],
Reserved6 = WPSResponse[7]
};
var decoded = new WriteProtectionStatus
{
DataLength = BigEndianBitConverter.ToUInt16(WPSResponse, 0),
Reserved1 = WPSResponse[2],
Reserved2 = WPSResponse[3],
Reserved3 = (byte)((WPSResponse[4] & 0xF0) >> 4),
MSWI = Convert.ToBoolean(WPSResponse[4] & 0x08),
CWP = Convert.ToBoolean(WPSResponse[4] & 0x04),
PWP = Convert.ToBoolean(WPSResponse[4] & 0x02),
SWPP = Convert.ToBoolean(WPSResponse[4] & 0x01),
Reserved4 = WPSResponse[5],
Reserved5 = WPSResponse[6],
Reserved6 = WPSResponse[7]
};
return decoded;
}
return decoded;
}
public static string PrettifyWriteProtectionStatus(WriteProtectionStatus? WPSResponse)
{
if(WPSResponse == null)
return null;
public static string PrettifyWriteProtectionStatus(WriteProtectionStatus? WPSResponse)
{
if(WPSResponse == null)
return null;
WriteProtectionStatus response = WPSResponse.Value;
WriteProtectionStatus response = WPSResponse.Value;
var sb = new StringBuilder();
var sb = new StringBuilder();
if(response.MSWI)
sb.AppendLine("Writing inhibited by media specific reason");
if(response.MSWI)
sb.AppendLine("Writing inhibited by media specific reason");
if(response.CWP)
sb.AppendLine("Cartridge sets write protection");
if(response.CWP)
sb.AppendLine("Cartridge sets write protection");
if(response.PWP)
sb.AppendLine("Media surface sets write protection");
if(response.PWP)
sb.AppendLine("Media surface sets write protection");
if(response.SWPP)
sb.AppendLine("Software write protection is set until power down");
if(response.SWPP)
sb.AppendLine("Software write protection is set until power down");
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
#if DEBUG
if(response.Reserved1 != 0)
sb.AppendFormat("Reserved1 = 0x{0:X2}", response.Reserved1).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
if(response.Reserved2 != 0)
sb.AppendFormat("Reserved2 = 0x{0:X2}", response.Reserved2).AppendLine();
if(response.Reserved3 != 0)
sb.AppendFormat("Reserved3 = 0x{0:X2}", response.Reserved3).AppendLine();
if(response.Reserved3 != 0)
sb.AppendFormat("Reserved3 = 0x{0:X2}", response.Reserved3).AppendLine();
if(response.Reserved4 != 0)
sb.AppendFormat("Reserved4 = 0x{0:X2}", response.Reserved4).AppendLine();
if(response.Reserved4 != 0)
sb.AppendFormat("Reserved4 = 0x{0:X2}", response.Reserved4).AppendLine();
if(response.Reserved5 != 0)
sb.AppendFormat("Reserved5 = 0x{0:X2}", response.Reserved5).AppendLine();
if(response.Reserved5 != 0)
sb.AppendFormat("Reserved5 = 0x{0:X2}", response.Reserved5).AppendLine();
if(response.Reserved6 != 0)
sb.AppendFormat("Reserved6 = 0x{0:X2}", response.Reserved6).AppendLine();
#endif
if(response.Reserved6 != 0)
sb.AppendFormat("Reserved6 = 0x{0:X2}", response.Reserved6).AppendLine();
#endif
return sb.ToString();
}
return sb.ToString();
}
public static string PrettifyWriteProtectionStatus(byte[] WPSResponse)
{
WriteProtectionStatus? decoded = DecodeWriteProtectionStatus(WPSResponse);
public static string PrettifyWriteProtectionStatus(byte[] WPSResponse)
{
WriteProtectionStatus? decoded = DecodeWriteProtectionStatus(WPSResponse);
return PrettifyWriteProtectionStatus(decoded);
}
return PrettifyWriteProtectionStatus(decoded);
}
public struct WriteProtectionStatus
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Byte 4, bits 7 to 4 Reserved</summary>
public byte Reserved3;
/// <summary>Byte 4, bit 3 Writing inhibited by media specific reason</summary>
public bool MSWI;
/// <summary>Byte 4, bit 2 Cartridge sets write protection</summary>
public bool CWP;
/// <summary>Byte 4, bit 1 Media surface sets write protection</summary>
public bool PWP;
/// <summary>Byte 4, bit 0 Software write protection until power down</summary>
public bool SWPP;
/// <summary>Byte 5 Reserved</summary>
public byte Reserved4;
/// <summary>Byte 6 Reserved</summary>
public byte Reserved5;
/// <summary>Byte 7 Reserved</summary>
public byte Reserved6;
}
public struct WriteProtectionStatus
{
/// <summary>Bytes 0 to 1 Data Length</summary>
public ushort DataLength;
/// <summary>Byte 2 Reserved</summary>
public byte Reserved1;
/// <summary>Byte 3 Reserved</summary>
public byte Reserved2;
/// <summary>Byte 4, bits 7 to 4 Reserved</summary>
public byte Reserved3;
/// <summary>Byte 4, bit 3 Writing inhibited by media specific reason</summary>
public bool MSWI;
/// <summary>Byte 4, bit 2 Cartridge sets write protection</summary>
public bool CWP;
/// <summary>Byte 4, bit 1 Media surface sets write protection</summary>
public bool PWP;
/// <summary>Byte 4, bit 0 Software write protection until power down</summary>
public bool SWPP;
/// <summary>Byte 5 Reserved</summary>
public byte Reserved4;
/// <summary>Byte 6 Reserved</summary>
public byte Reserved5;
/// <summary>Byte 7 Reserved</summary>
public byte Reserved6;
}
}