2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-19 02:59:32 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : DiscInformation.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes MMC's GET DISC INFORMATION structures.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-19 02:59:32 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-19 02:59:32 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-10-19 02:59:32 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-10-19 02:59:32 +01:00
|
|
|
using System;
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-11-24 01:45:31 +00:00
|
|
|
using System.Text;
|
2015-10-19 02:59:32 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.SCSI.MMC
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// 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
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2017-12-22 02:04:18 +00:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
|
|
|
|
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
|
2015-10-19 02:59:32 +01:00
|
|
|
public static class DiscInformation
|
|
|
|
|
{
|
2015-11-24 00:40:33 +00:00
|
|
|
public struct StandardDiscInformation
|
2015-10-19 02:59:32 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// 32 + OPCTablesNumber*8
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 7 to 5
|
|
|
|
|
/// 000b
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DataType;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bit 4
|
|
|
|
|
/// If set, disc is erasable
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool Erasable;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 3 to 2
|
|
|
|
|
/// Status of last session
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte LastSessionStatus;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 1 to 0
|
|
|
|
|
/// Status of disc
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DiscStatus;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Number of logical track that contains LBA 0
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte FirstTrackNumber;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 9 (MSB) and byte 4 (LSB)
|
|
|
|
|
/// Number of sessions
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort Sessions;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 10 (MSB) and byte 5 (LSB)
|
|
|
|
|
/// Number of first track in last session
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort FirstTrackLastSession;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 11 (MSB) and byte 6 (LSB)
|
|
|
|
|
/// Number of last track in last session
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort LastTrackLastSession;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bit 7
|
|
|
|
|
/// If set, DiscIdentification is valid
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool DID_V;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bit 6
|
|
|
|
|
/// If set, DiscBarcode is valid
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool DBC_V;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bit 5
|
|
|
|
|
/// If set, disc is unrestricted
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool URU;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bit 4
|
|
|
|
|
/// If set DiscApplicationCode is valid
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool DAC_V;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bit 3
|
|
|
|
|
/// Reserved
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool Reserved;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bit 2
|
|
|
|
|
/// Copy of dirty bit from MRW status
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public bool Dbit;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 7, bits 1 to 0
|
|
|
|
|
/// Background format status
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte BGFormatStatus;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 8
|
|
|
|
|
/// Disc type code
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DiscType;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 12 to 15
|
|
|
|
|
/// Disc identification number from PMA
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint DiscIdentification;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 16 to 19
|
|
|
|
|
/// Last Session Lead-in Start Address (MSF for CD, LBA for others)
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint LastSessionLeadInStartLBA;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 20 to 23
|
|
|
|
|
/// Last Possible Lead-out Start Address (MSF for CD, LBA for others)
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint LastPossibleLeadOutStartLBA;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 24 to 31
|
|
|
|
|
/// Disc barcode
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ulong DiscBarcode;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 32
|
|
|
|
|
/// Disc application code
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DiscApplicationCode;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 33
|
|
|
|
|
/// How many OPC tables are
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte OPCTablesNumber;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 34 to end
|
|
|
|
|
/// OPC tables (8 bytes each)
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public OPCTable[] OPCTables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct OPCTable
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// kilobytes/sec this OPC table applies to
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort Speed;
|
2015-10-19 02:59:32 +01:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 2 to 7
|
|
|
|
|
/// OPC values
|
2015-10-19 02:59:32 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public byte[] OPCValues;
|
|
|
|
|
}
|
2015-11-24 00:40:33 +00:00
|
|
|
|
|
|
|
|
public struct TrackResourcesInformation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// 10
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 7 to 5
|
|
|
|
|
/// 001b
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DataType;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 4 to 0
|
|
|
|
|
/// Reserved
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 4 to 5
|
|
|
|
|
/// Maximum possible number of the tracks on the disc
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort MaxTracks;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 6 to 7
|
|
|
|
|
/// Number of the assigned tracks on the disc
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort AssignedTracks;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 8 to 9
|
|
|
|
|
/// Maximum possible number of appendable tracks on the disc
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort MaxAppendableTracks;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 10 to 11
|
|
|
|
|
/// Current number of appendable tracks on the disc
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort AppendableTracks;
|
2015-11-24 00:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct POWResourcesInformation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// 14
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 7 to 5
|
|
|
|
|
/// 010b
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte DataType;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 2, bits 4 to 0
|
|
|
|
|
/// Reserved
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 4 to 7
|
|
|
|
|
/// Remaining POW replacements
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint RemainingPOWReplacements;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 8 to 11
|
|
|
|
|
/// Remaining POW reallocation map entries
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint RemainingPOWReallocation;
|
2015-11-24 00:40:33 +00:00
|
|
|
/// <summary>
|
2017-12-23 18:31:38 +00:00
|
|
|
/// Bytes 12 to 15
|
|
|
|
|
/// Number of remaining POW updates
|
2015-11-24 00:40:33 +00:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint RemainingPOWUpdates;
|
2015-11-24 00:40:33 +00:00
|
|
|
}
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
public static StandardDiscInformation? Decode000b(byte[] response)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Length < 34) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if((response[2] & 0xE0) != 0) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
StandardDiscInformation decoded =
|
|
|
|
|
new StandardDiscInformation {DataLength = (ushort)((response[0] << 8) + response[1])};
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
if(decoded.DataLength + 2 != response.Length) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
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);
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
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]);
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
byte[] temp = new byte[8];
|
|
|
|
|
Array.Copy(response, 24, temp, 0, 8);
|
|
|
|
|
Array.Reverse(temp);
|
|
|
|
|
decoded.DiscBarcode = BitConverter.ToUInt64(temp, 0);
|
|
|
|
|
|
|
|
|
|
decoded.DiscApplicationCode = response[32];
|
2018-06-22 08:08:38 +01:00
|
|
|
decoded.OPCTablesNumber = response[33];
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
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++)
|
2015-11-24 01:45:31 +00:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
decoded.OPCTables[i].Speed = (ushort)((response[34 + i * 8 + 0] << 16) + response[34 + i * 8 + 1]);
|
2017-12-21 06:06:19 +00:00
|
|
|
decoded.OPCTables[i].OPCValues = new byte[6];
|
|
|
|
|
Array.Copy(response, 34 + i * 8 + 2, decoded.OPCTables[i].OPCValues, 0, 6);
|
2015-11-24 01:45:31 +00:00
|
|
|
}
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2015-11-24 01:45:31 +00:00
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Prettify000b(StandardDiscInformation? information)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!information.HasValue) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
StandardDiscInformation decoded = information.Value;
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.DataType != 0) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(decoded.DiscType)
|
2015-11-24 01:45:31 +00:00
|
|
|
{
|
|
|
|
|
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", decoded.DiscType).AppendLine();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(decoded.DiscStatus)
|
2015-11-24 01:45:31 +00:00
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
sb.AppendLine("Disc is empty");
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
sb.AppendLine("Disc is incomplete");
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
sb.AppendLine("Disc is finalized");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.Erasable) sb.AppendLine("Disc is erasable");
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(decoded.LastSessionStatus)
|
2015-11-24 01:45:31 +00:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(decoded.BGFormatStatus)
|
2015-11-24 01:45:31 +00:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.Dbit) sb.AppendLine("MRW is dirty");
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
sb.AppendFormat("First track on disc is track {0}", decoded.FirstTrackNumber).AppendLine();
|
|
|
|
|
sb.AppendFormat("Disc has {0} sessions", decoded.Sessions).AppendLine();
|
|
|
|
|
sb.AppendFormat("First track in last session is track {0}", decoded.FirstTrackLastSession).AppendLine();
|
|
|
|
|
sb.AppendFormat("Last track in last session is track {0}", decoded.LastTrackLastSession).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Last session Lead-In address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}",
|
|
|
|
|
decoded.LastSessionLeadInStartLBA, (decoded.LastSessionLeadInStartLBA & 0xFF0000) >> 16,
|
2018-06-22 08:08:38 +01:00
|
|
|
(decoded.LastSessionLeadInStartLBA & 0xFF00) >> 8,
|
|
|
|
|
decoded.LastSessionLeadInStartLBA & 0xFF)
|
2017-12-23 18:31:38 +00:00
|
|
|
.AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Last possible Lead-Out address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}",
|
|
|
|
|
decoded.LastPossibleLeadOutStartLBA, (decoded.LastPossibleLeadOutStartLBA & 0xFF0000) >> 16,
|
2018-06-22 08:08:38 +01:00
|
|
|
(decoded.LastPossibleLeadOutStartLBA & 0xFF00) >> 8,
|
2017-12-20 17:26:28 +00:00
|
|
|
decoded.LastPossibleLeadOutStartLBA & 0xFF).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
sb.AppendLine(decoded.URU ? "Disc is defined for unrestricted use" : "Disc is defined for restricted use");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
if(decoded.DID_V) sb.AppendFormat("Disc ID: {0:X6}", decoded.DiscIdentification & 0x00FFFFFF).AppendLine();
|
|
|
|
|
if(decoded.DBC_V) sb.AppendFormat("Disc barcode: {0:X16}", decoded.DiscBarcode).AppendLine();
|
|
|
|
|
if(decoded.DAC_V) sb.AppendFormat("Disc application code: {0}", decoded.DiscApplicationCode).AppendLine();
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(decoded.OPCTables == null) return sb.ToString();
|
|
|
|
|
|
|
|
|
|
foreach(OPCTable table in decoded.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();
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TrackResourcesInformation? Decode001b(byte[] response)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Length != 12) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if((response[2] & 0xE0) != 0x20) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
TrackResourcesInformation decoded =
|
|
|
|
|
new TrackResourcesInformation {DataLength = (ushort)((response[0] << 8) + response[1])};
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
if(decoded.DataLength + 2 != response.Length) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
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]);
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Prettify001b(TrackResourcesInformation? information)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!information.HasValue) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
TrackResourcesInformation decoded = information.Value;
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.DataType != 1) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("{0} maximum possible tracks on the disc", decoded.MaxTracks).AppendLine();
|
|
|
|
|
sb.AppendFormat("{0} assigned tracks on the disc", decoded.AssignedTracks).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("{0} maximum possible appendable tracks on the disc", decoded.AppendableTracks)
|
|
|
|
|
.AppendLine();
|
2015-11-24 01:45:31 +00:00
|
|
|
sb.AppendFormat("{0} current appendable tracks on the disc", decoded.MaxAppendableTracks).AppendLine();
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static POWResourcesInformation? Decode010b(byte[] response)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Length != 16) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if((response[2] & 0xE0) != 0x40) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
POWResourcesInformation decoded =
|
|
|
|
|
new POWResourcesInformation {DataLength = (ushort)((response[0] << 8) + response[1])};
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
if(decoded.DataLength + 2 != response.Length) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
decoded.DataType = (byte)((response[2] & 0xE0) >> 5);
|
2017-12-19 20:33:03 +00:00
|
|
|
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]);
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Prettify010b(POWResourcesInformation? information)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!information.HasValue) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
POWResourcesInformation decoded = information.Value;
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(decoded.DataType != 1) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("{0} remaining POW replacements", decoded.RemainingPOWReplacements).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("{0} remaining POW reallocation map entries", decoded.RemainingPOWReallocation)
|
|
|
|
|
.AppendLine();
|
2015-11-24 01:45:31 +00:00
|
|
|
sb.AppendFormat("{0} remaining POW updates", decoded.RemainingPOWUpdates).AppendLine();
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Prettify(byte[] response)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response == null) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(response.Length < 12) return null;
|
2015-11-24 01:45:31 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(response[2] & 0xE0)
|
2015-11-24 01:45:31 +00:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0x00: return Prettify000b(Decode000b(response));
|
|
|
|
|
case 0x20: return Prettify001b(Decode001b(response));
|
|
|
|
|
case 0x40: return Prettify010b(Decode010b(response));
|
2015-11-24 01:45:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-10-19 02:59:32 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|