Separated SCSI decoders by type.

This commit is contained in:
2015-10-19 02:59:32 +01:00
parent 45303f8a8d
commit b3d48cac37
17 changed files with 3475 additions and 2884 deletions

View File

@@ -1,3 +1,20 @@
2015-10-19 Natalia Portillo <claunia@claunia.com>
* SCSI/Enums.cs:
* SCSI/Inquiry.cs:
* SCSI/MMC/OPW.cs:
* SCSI/MMC/MMC.cs:
* SCSI/MMC/AACS.cs:
* SCSI/MMC/CPRM.cs:
* SCSI/MMC/Enums.cs:
* SCSI/MMC/Hybrid.cs:
* SCSI/VendorString.cs:
* SCSI/MMC/WriteProtect.cs:
* SCSI/MMC/DiscInformation.cs:
* SCSI/MMC/TrackInformation.cs:
* DiscImageChef.Decoders.csproj:
Separated SCSI decoders by type.
2015-10-19 Natalia Portillo <claunia@claunia.com>
* CD/TOC.cs:

View File

@@ -69,6 +69,16 @@
<Compile Include="CD\ATIP.cs" />
<Compile Include="CD\Enums.cs" />
<Compile Include="CD\CDTextOnLeadIn.cs" />
<Compile Include="SCSI\MMC\AACS.cs" />
<Compile Include="SCSI\MMC\CPRM.cs" />
<Compile Include="SCSI\MMC\Enums.cs" />
<Compile Include="SCSI\MMC\Hybrid.cs" />
<Compile Include="SCSI\MMC\WriteProtect.cs" />
<Compile Include="SCSI\MMC\DiscInformation.cs" />
<Compile Include="SCSI\MMC\TrackInformation.cs" />
<Compile Include="SCSI\MMC\OPW.cs" />
<Compile Include="SCSI\Enums.cs" />
<Compile Include="SCSI\VendorString.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -0,0 +1,258 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Enums.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
namespace DiscImageChef.Decoders.SCSI
{
enum SCSIPeripheralQualifiers : byte
{
/// <summary>
/// Peripheral qualifier: Device is connected and supported
/// </summary>
SCSIPQSupported = 0x00,
/// <summary>
/// Peripheral qualifier: Device is supported but not connected
/// </summary>
SCSIPQUnconnected = 0x01,
/// <summary>
/// Peripheral qualifier: Reserved value
/// </summary>
SCSIPQReserved = 0x02,
/// <summary>
/// Peripheral qualifier: Device is connected but unsupported
/// </summary>
SCSIPQUnsupported = 0x03,
/// <summary>
/// Peripheral qualifier: Vendor values: 0x04, 0x05, 0x06 and 0x07
/// </summary>
SCSIPQVendorMask = 0x04
}
public enum SCSIPeripheralDeviceTypes : byte
{
/// <summary>
/// Direct-access device
/// </summary>
SCSIPDTDirectAccess = 0x00,
/// <summary>
/// Sequential-access device
/// </summary>
SCSIPDTSequentialAccess = 0x01,
/// <summary>
/// Printer device
/// </summary>
SCSIPDTPrinterDevice = 0x02,
/// <summary>
/// Processor device
/// </summary>
SCSIPDTProcessorDevice = 0x03,
/// <summary>
/// Write-once device
/// </summary>
SCSIPDTWriteOnceDevice = 0x04,
/// <summary>
/// CD-ROM/DVD/etc device
/// </summary>
SCSIPDTMultiMediaDevice = 0x05,
/// <summary>
/// Scanner device
/// </summary>
SCSIPDTScannerDevice = 0x06,
/// <summary>
/// Optical memory device
/// </summary>
SCSIPDTOpticalDevice = 0x07,
/// <summary>
/// Medium change device
/// </summary>
SCSIPDTMediumChangerDevice = 0x08,
/// <summary>
/// Communications device
/// </summary>
SCSIPDTCommsDevice = 0x09,
/// <summary>
/// Graphics arts pre-press device (defined in ASC IT8)
/// </summary>
SCSIPDTPrePressDevice1 = 0x0A,
/// <summary>
/// Graphics arts pre-press device (defined in ASC IT8)
/// </summary>
SCSIPDTPrePressDevice2 = 0x0B,
/// <summary>
/// Array controller device
/// </summary>
SCSIPDTArrayControllerDevice = 0x0C,
/// <summary>
/// Enclosure services device
/// </summary>
SCSIPDTEnclosureServiceDevice = 0x0D,
/// <summary>
/// Simplified direct-access device
/// </summary>
SCSIPDTSimplifiedDevice = 0x0E,
/// <summary>
/// Optical card reader/writer device
/// </summary>
SCSIPDTOCRWDevice = 0x0F,
/// <summary>
/// Bridging Expanders
/// </summary>
SCSIPDTBridgingExpander = 0x10,
/// <summary>
/// Object-based Storage Device
/// </summary>
SCSIPDTObjectDevice = 0x11,
/// <summary>
/// Automation/Drive Interface
/// </summary>
SCSIPDTADCDevice = 0x12,
/// <summary>
/// Security Manager Device
/// </summary>
SCSISecurityManagerDevice = 0x13,
/// <summary>
/// Host managed zoned block device
/// </summary>
SCSIZonedBlockDEvice = 0x14,
/// <summary>
/// Well known logical unit
/// </summary>
SCSIPDTWellKnownDevice = 0x1E,
/// <summary>
/// Unknown or no device type
/// </summary>
SCSIPDTUnknownDevice = 0x1F
}
enum SCSIANSIVersions : byte
{
/// <summary>
/// Device does not claim conformance to any ANSI version
/// </summary>
SCSIANSINoVersion = 0x00,
/// <summary>
/// Device complies with ANSI X3.131:1986
/// </summary>
SCSIANSI1986Version = 0x01,
/// <summary>
/// Device complies with ANSI X3.131:1994
/// </summary>
SCSIANSI1994Version = 0x02,
/// <summary>
/// Device complies with ANSI X3.301:1997
/// </summary>
SCSIANSI1997Version = 0x03,
/// <summary>
/// Device complies with ANSI X3.351:2001
/// </summary>
SCSIANSI2001Version = 0x04,
/// <summary>
/// Device complies with ANSI X3.408:2005.
/// </summary>
SCSIANSI2005Version = 0x05,
/// <summary>
/// Device complies with SPC-4
/// </summary>
SCSIANSI2008Version = 0x06
}
enum SCSIECMAVersions : byte
{
/// <summary>
/// Device does not claim conformance to any ECMA version
/// </summary>
SCSIECMANoVersion = 0x00,
/// <summary>
/// Device complies with an obsolete ECMA standard
/// </summary>
SCSIECMAObsolete = 0x01
}
enum SCSIISOVersions : byte
{
/// <summary>
/// Device does not claim conformance to any ISO/IEC version
/// </summary>
SCSIISONoVersion = 0x00,
/// <summary>
/// Device complies with ISO/IEC 9316:1995
/// </summary>
SCSIISO1995Version = 0x02
}
enum SCSISPIClocking : byte
{
/// <summary>
/// Supports only ST
/// </summary>
SCSIClockingST = 0x00,
/// <summary>
/// Supports only DT
/// </summary>
SCSIClockingDT = 0x01,
/// <summary>
/// Reserved value
/// </summary>
SCSIClockingReserved = 0x02,
/// <summary>
/// Supports ST and DT
/// </summary>
SCSIClockingSTandDT = 0x03,
}
enum SCSITGPSValues : byte
{
/// <summary>
/// Assymetrical access not supported
/// </summary>
NotSupported = 0x00,
/// <summary>
/// Only implicit assymetrical access is supported
/// </summary>
OnlyImplicit = 0x01,
/// <summary>
/// Only explicit assymetrical access is supported
/// </summary>
OnlyExplicit = 0x02,
/// <summary>
/// Both implicit and explicit assymetrical access are supported
/// </summary>
Both = 0x03
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,514 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : AACS.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using System.Text;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class AACS
{
public struct AACSVolumeIdentifier
{
/// <summary>
/// Bytes 0 to 1
/// Data length
/// </summary>
public UInt16 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 UInt16 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 UInt16 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 UInt16 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 UInt16 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 UInt16 DataLength;
/// <summary>
/// Byte 2
/// Reserved
/// </summary>
public byte Reserved;
/// <summary>
/// Byte 3
/// Number of LBA extents the drive can store.
/// if(MaxLBAExtents == 0 && 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 UInt32 StartLBA;
/// <summary>
/// Bytes 12 to 15
/// Extent length
/// </summary>
public UInt32 LBACount;
}
public static AACSVolumeIdentifier? DecodeAACSVolumeIdentifier(byte[] AACSVIResponse)
{
if (AACSVIResponse == null)
return null;
AACSVolumeIdentifier decoded = new AACSVolumeIdentifier();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
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;
StringBuilder 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;
AACSMediaSerialNumber decoded = new AACSMediaSerialNumber();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
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;
StringBuilder 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;
AACSMediaIdentifier decoded = new AACSMediaIdentifier();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
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;
StringBuilder 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;
AACSMediaKeyBlock decoded = new AACSMediaKeyBlock();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
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;
StringBuilder 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;
AACSDataKeys decoded = new AACSDataKeys();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
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;
StringBuilder 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;
AACSLBAExtentsResponse decoded = new AACSLBAExtentsResponse();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSLBAExtsResponse, 0);
decoded.Reserved = AACSLBAExtsResponse[2];
decoded.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;
StringBuilder sb = new StringBuilder();
if (response.MaxLBAExtents == 0)
{
if (response.DataLength > 2)
sb.AppendLine("Drive can store 256 LBA Extents");
else
sb.AppendLine("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);
}
}
}

View File

@@ -0,0 +1,130 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : CPRM.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using System.Text;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class CPRM
{
public struct CPRMMediaKeyBlock
{
/// <summary>
/// Bytes 0 to 1
/// Data Length
/// </summary>
public UInt16 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 static CPRMMediaKeyBlock? DecodeCPRMMediaKeyBlock(byte[] CPRMMKBResponse)
{
if (CPRMMKBResponse == null)
return null;
CPRMMediaKeyBlock decoded = new CPRMMediaKeyBlock();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
decoded.MKBPackData = new byte[CPRMMKBResponse.Length - 4];
decoded.DataLength = BigEndianBitConverter.ToUInt16(CPRMMKBResponse, 0);
decoded.Reserved = CPRMMKBResponse[2];
decoded.TotalPacks = CPRMMKBResponse[3];
Array.Copy(CPRMMKBResponse, 4, decoded.MKBPackData, 0, CPRMMKBResponse.Length - 4);
return decoded;
}
public static string PrettifyCPRMMediaKeyBlock(CPRMMediaKeyBlock? CPRMMKBResponse)
{
if (CPRMMKBResponse == null)
return null;
CPRMMediaKeyBlock response = CPRMMKBResponse.Value;
StringBuilder 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();
sb.AppendFormat("CPRM Media Key Blocks in hex follows:");
sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.MKBPackData, 80));
return sb.ToString();
}
public static string PrettifyCPRMMediaKeyBlock(byte[] CPRMMKBResponse)
{
CPRMMediaKeyBlock? decoded = DecodeCPRMMediaKeyBlock(CPRMMKBResponse);
return PrettifyCPRMMediaKeyBlock(decoded);
}
}
}

View File

@@ -0,0 +1,198 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : DiscInformation.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class DiscInformation
{
public struct DiscInformationResponse
{
/// <summary>
/// Bytes 0 to 1
/// 32 + OPCTablesNumber*8
/// </summary>
public UInt16 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 byte Sessions;
/// <summary>
/// Byte 10 (MSB) and byte 5 (LSB)
/// Number of first track in last session
/// </summary>
public byte FirstTrackLastSession;
/// <summary>
/// Byte 11 (MSB) and byte 6 (LSB)
/// Number of last track in last session
/// </summary>
public byte 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 UInt32 DiscIdentification;
/// <summary>
/// Bytes 16 to 19
/// Last Session Lead-in Start Address (MSF for CD, LBA for others)
/// </summary>
public UInt32 LastSessionLeadInStartLBA;
/// <summary>
/// Bytes 20 to 23
/// Last Possible Lead-out Start Address (MSF for CD, LBA for others)
/// </summary>
public UInt32 LastPossibleLeadOutStartLBA;
/// <summary>
/// Bytes 24 to 31
/// Disc barcode
/// </summary>
public UInt64 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 UInt16 Speed;
/// <summary>
/// Bytes 2 to 7
/// OPC values
/// </summary>
public byte[] OPCValues;
}
}
}

View File

@@ -0,0 +1,85 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Enums.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
namespace DiscImageChef.Decoders.SCSI.MMC
{
public enum FormatLayerTypeCodes : ushort
{
CDLayer = 0x0008,
DVDLayer = 0x0010,
BDLayer = 0x0040,
HDDVDLayer = 0x0050
}
public enum SessionStatusCodes : byte
{
Empty = 0x00,
Incomplete = 0x01,
ReservedOrDamaged = 0x02,
Complete = 0x03
}
public enum DiscStatusCodes : byte
{
Empty = 0x00,
Incomplete = 0x01,
Finalized = 0x02,
Others = 0x03
}
public enum BGFormatStatusCodes : byte
{
NoFormattable = 0x00,
IncompleteBackgroundFormat = 0x01,
BackgroundFormatInProgress = 0x02,
FormatComplete = 0x03
}
public enum DiscTypeCodes : byte
{
/// <summary>
/// Also valid for CD-DA, DVD and BD
/// </summary>
CDROM = 0x00,
CDi = 0x10,
CDROMXA = 0x20,
Undefined = 0xFF
}
}

View File

@@ -0,0 +1,213 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Hybrid.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using System.Text;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class Hybrid
{
public struct RecognizedFormatLayers
{
/// <summary>
/// Bytes 0 to 1
/// Data Length
/// </summary>
public UInt16 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 UInt16[] FormatLayers;
}
public static RecognizedFormatLayers? DecodeFormatLayers(byte[] FormatLayersResponse)
{
if (FormatLayersResponse == null)
return null;
if (FormatLayersResponse.Length < 8)
return null;
RecognizedFormatLayers decoded = new RecognizedFormatLayers();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
decoded.DataLength = BigEndianBitConverter.ToUInt16(FormatLayersResponse, 0);
decoded.Reserved1 = FormatLayersResponse[2];
decoded.Reserved2 = FormatLayersResponse[3];
decoded.NumberOfLayers = FormatLayersResponse[4];
decoded.Reserved3 = (byte)((FormatLayersResponse[5] & 0xC0) >> 6);
decoded.DefaultFormatLayer = (byte)((FormatLayersResponse[5] & 0x30) >> 4);
decoded.Reserved4 = (byte)((FormatLayersResponse[5] & 0x0C) >> 2);
decoded.OnlineFormatLayer = (byte)(FormatLayersResponse[5] & 0x03);
decoded.FormatLayers = new UInt16[(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;
StringBuilder 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 (UInt16)FormatLayerTypeCodes.BDLayer:
{
sb.AppendFormat("Layer {0} is of type Blu-ray", 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 (UInt16)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 (UInt16)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 (UInt16)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);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : OPW.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class OPW
{
public struct OPWInformation
{
/// <summary>
/// Bytes 0 to 1
/// Data length, always 14
/// </summary>
public UInt16 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 5
/// Remaining POW Replacements
/// </summary>
public UInt32 RemainingReplacements;
/// <summary>
/// Bytes 6 to 7
/// Remaining POW Reallocation Map Entries
/// </summary>
public UInt32 RemainingReallocationEntries;
/// <summary>
/// Bytes 8 to 9
/// Number of Remaining POW Updates
/// </summary>
public UInt32 RemainingUpdates;
}
}
}

View File

@@ -0,0 +1,104 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : TrackInformation.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class TrackInformation
{
public struct TrackInformationResponse
{
/// <summary>
/// Bytes 0 to 1
/// Data length, always 10
/// </summary>
public UInt16 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 tracks on the disc
/// </summary>
public UInt16 MaxTracks;
/// <summary>
/// Bytes 6 to 7
/// Number of assigned tracks on the disc
/// </summary>
public UInt16 AssignedTracks;
/// <summary>
/// Bytes 8 to 9
/// Maximum possible number of appendable tracks on the disc
/// </summary>
public UInt16 MaxAppendable;
/// <summary>
/// Bytes 10 to 11
/// Current number of appendable tracks on the disc
/// </summary>
public UInt16 CurrentAppendable;
}
}
}

View File

@@ -0,0 +1,186 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : WriteProtect.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using System.Text;
namespace DiscImageChef.Decoders.SCSI.MMC
{
/// <summary>
/// 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
/// </summary>
public static class WriteProtect
{
public struct WriteProtectionStatus
{
/// <summary>
/// Bytes 0 to 1
/// Data Length
/// </summary>
public UInt16 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 static WriteProtectionStatus? DecodeWriteProtectionStatus(byte[] WPSResponse)
{
if (WPSResponse == null)
return null;
WriteProtectionStatus decoded = new WriteProtectionStatus();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
decoded.DataLength = BigEndianBitConverter.ToUInt16(WPSResponse, 0);
decoded.Reserved1 = WPSResponse[2];
decoded.Reserved2 = WPSResponse[3];
decoded.Reserved3 = (byte)((WPSResponse[4] & 0xF0) >> 4);
decoded.MSWI = Convert.ToBoolean(WPSResponse[4] & 0x08);
decoded.CWP = Convert.ToBoolean(WPSResponse[4] & 0x04);
decoded.PWP = Convert.ToBoolean(WPSResponse[4] & 0x02);
decoded.SWPP = Convert.ToBoolean(WPSResponse[4] & 0x01);
decoded.Reserved4 = WPSResponse[5];
decoded.Reserved5 = WPSResponse[6];
decoded.Reserved6 = WPSResponse[7];
return decoded;
}
public static string PrettifyWriteProtectionStatus(WriteProtectionStatus? WPSResponse)
{
if (WPSResponse == null)
return null;
WriteProtectionStatus response = WPSResponse.Value;
StringBuilder sb = new StringBuilder();
if (response.MSWI)
sb.AppendLine("Writing inhibited by media specific reason");
if (response.CWP)
sb.AppendLine("Cartridge 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 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.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.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
return sb.ToString();
}
public static string PrettifyWriteProtectionStatus(byte[] WPSResponse)
{
WriteProtectionStatus? decoded = DecodeWriteProtectionStatus(WPSResponse);
return PrettifyWriteProtectionStatus(decoded);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,9 @@
2015-10-19 Natalia Portillo <claunia@claunia.com>
* Commands/Decode.cs:
* Commands/DeviceInfo.cs:
Separated SCSI decoders by type.
2015-10-19 Natalia Portillo <claunia@claunia.com>
* Commands/Decode.cs:

View File

@@ -82,7 +82,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("SCSI INQUIRY command response:");
DicConsole.WriteLine("================================================================================");
DicConsole.WriteLine(Decoders.SCSI.PrettifySCSIInquiry(inquiry));
DicConsole.WriteLine(Decoders.SCSI.Inquiry.PrettifySCSIInquiry(inquiry));
DicConsole.WriteLine("================================================================================");
}
break;

View File

@@ -81,7 +81,7 @@ namespace DiscImageChef.Commands
else
DicConsole.WriteLine("SCSI OK");
DicConsole.WriteLine(Decoders.SCSI.PrettifySCSIInquiry(inqBuf));
DicConsole.WriteLine(Decoders.SCSI.Inquiry.PrettifySCSIInquiry(inqBuf));
Structs.AtaErrorRegistersCHS errorRegisters;