2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-19 02:28:40 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Spare.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:28:40 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:28:40 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes DVD spare area information.
|
2015-10-19 02:28:40 +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:28:40 +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:28:40 +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:28:40 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-10-19 02:28:40 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-12-02 06:49:36 +00:00
|
|
|
using System.Text;
|
2015-10-19 02:28:40 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.DVD
|
|
|
|
|
{
|
|
|
|
|
/// <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 Spare
|
|
|
|
|
{
|
|
|
|
|
public struct SpareAreaInformation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 0 to 1
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort DataLength;
|
2015-10-19 02:28:40 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 2
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Byte 3
|
|
|
|
|
/// Reserved
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 4 to 7
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint UnusedPrimaryBlocks;
|
2015-10-19 02:28:40 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 8 to 11
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint UnusedSupplementaryBlocks;
|
2015-10-19 02:28:40 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Bytes 12 to 15
|
|
|
|
|
/// Data length
|
|
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public uint AllocatedSupplementaryBlocks;
|
2015-10-19 02:28:40 +01:00
|
|
|
}
|
2015-12-02 06:49:36 +00:00
|
|
|
|
|
|
|
|
public static SpareAreaInformation? Decode(byte[] response)
|
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(response == null)
|
2015-12-02 06:49:36 +00:00
|
|
|
return null;
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(response.Length != 16)
|
2015-12-02 06:49:36 +00:00
|
|
|
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)
|
|
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if(sai == null)
|
2015-12-02 06:49:36 +00:00
|
|
|
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));
|
|
|
|
|
}
|
2015-10-19 02:28:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|