diff --git a/DiscImageChef.Decoders/ChangeLog b/DiscImageChef.Decoders/ChangeLog index 489ab985a..39d70d330 100644 --- a/DiscImageChef.Decoders/ChangeLog +++ b/DiscImageChef.Decoders/ChangeLog @@ -1,3 +1,8 @@ +2015-12-02 Natalia Portillo + + * DVD/Spare.cs: + Implemented decoding DVD-RAM Spare Area Information. + 2015-12-02 Natalia Portillo * DVD/Cartridge.cs: diff --git a/DiscImageChef.Decoders/DVD/Spare.cs b/DiscImageChef.Decoders/DVD/Spare.cs index 7bf1cc51d..a0fe3b860 100644 --- a/DiscImageChef.Decoders/DVD/Spare.cs +++ b/DiscImageChef.Decoders/DVD/Spare.cs @@ -36,6 +36,7 @@ // ****************************************************************************/ // //$Id$ using System; +using System.Text; namespace DiscImageChef.Decoders.DVD { @@ -53,7 +54,6 @@ namespace DiscImageChef.Decoders.DVD /// T10/1675-D revision 2c /// T10/1675-D revision 4 /// T10/1836-D revision 2g - /// ECMA 365 /// public static class Spare { @@ -90,6 +90,46 @@ namespace DiscImageChef.Decoders.DVD /// public UInt32 AllocatedSupplementaryBlocks; } + + public static SpareAreaInformation? Decode(byte[] response) + { + if (response == null) + return null; + + if (response.Length != 16) + return null; + + SpareAreaInformation sai = new SpareAreaInformation(); + + sai.DataLength = (ushort)((response[0] << 8) + response[1]); + sai.Reserved1 = response[2]; + sai.Reserved2 = response[3]; + sai.UnusedPrimaryBlocks = (uint)((response[4] << 24) + (response[5] << 16) + (response[6] << 8) + response[7]); + sai.UnusedSupplementaryBlocks = (uint)((response[8] << 24) + (response[9] << 16) + (response[10] << 8) + response[11]); + sai.AllocatedSupplementaryBlocks = (uint)((response[12] << 24) + (response[13] << 16) + (response[14] << 8) + response[15]); + + return sai; + } + + public static string Prettify(SpareAreaInformation? sai) + { + if (sai == null) + return null; + + SpareAreaInformation decoded = sai.Value; + StringBuilder sb = new StringBuilder(); + + sb.AppendFormat("{0} unused primary spare blocks", decoded.UnusedPrimaryBlocks).AppendLine(); + sb.AppendFormat("{0} unused supplementary spare blocks", decoded.UnusedSupplementaryBlocks).AppendLine(); + sb.AppendFormat("{0} allocated supplementary spare blocks", decoded.AllocatedSupplementaryBlocks).AppendLine(); + + return sb.ToString(); + } + + public static string Prettify(byte[] response) + { + return Prettify(Decode(response)); + } } } diff --git a/DiscImageChef/ChangeLog b/DiscImageChef/ChangeLog index 1b1fee224..254dcf33d 100644 --- a/DiscImageChef/ChangeLog +++ b/DiscImageChef/ChangeLog @@ -1,3 +1,8 @@ +2015-12-02 Natalia Portillo + + * Commands/MediaInfo.cs: + Implemented decoding DVD-RAM Spare Area Information. + 2015-12-02 Natalia Portillo * Commands/MediaInfo.cs: diff --git a/DiscImageChef/Commands/MediaInfo.cs b/DiscImageChef/Commands/MediaInfo.cs index 7a4c27bff..aca272751 100644 --- a/DiscImageChef/Commands/MediaInfo.cs +++ b/DiscImageChef/Commands/MediaInfo.cs @@ -431,7 +431,10 @@ namespace DiscImageChef.Commands if(sense) DicConsole.ErrorWriteLine("READ DISC STRUCTURE: SAI\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); else + { doWriteFile(outputPrefix, "_readdiscstructure_dvdram_spare.bin", "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Spare Area Information:\n{0}", Decoders.DVD.Spare.Prettify(cmdBuf)); + } sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.DVD, 0, 0, MmcDiscStructureFormat.DVDRAM_RecordingType, 0, dev.Timeout, out duration); if(sense) DicConsole.ErrorWriteLine("READ DISC STRUCTURE: Recording Type\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf));