2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-15 01:54:13 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : UDF.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-09-15 01:54:40 +01:00
|
|
|
|
// Component : Universal Disk Format plugin.
|
2016-09-15 01:54:13 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-09-15 01:54:40 +01:00
|
|
|
|
// Identifies the Universal Disk Format and shows information.
|
2016-09-15 01:54:13 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2016-09-15 01:54:13 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2016-09-15 01:54:13 +01:00
|
|
|
|
using System;
|
2020-07-20 07:47:12 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Linq;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.Console;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2016-09-15 01:54:13 +01:00
|
|
|
|
{
|
2016-09-15 01:54:40 +01:00
|
|
|
|
// TODO: Detect bootable
|
2021-08-17 14:25:12 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
/// <summary>Implements detection of the Universal Disk Format filesystem</summary>
|
2020-07-20 07:47:12 +01:00
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed class UDF : IFilesystem
|
2016-09-15 01:54:13 +01:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
readonly byte[] _magic =
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
0x2A, 0x4F, 0x53, 0x54, 0x41, 0x20, 0x55, 0x44, 0x46, 0x20, 0x43, 0x6F, 0x6D, 0x70, 0x6C, 0x69, 0x61, 0x6E,
|
|
|
|
|
|
0x74, 0x00, 0x00, 0x00, 0x00
|
2017-12-24 02:37:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
public string Name => "Universal Disk Format";
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public Guid Id => new("83976FEC-A91B-464B-9293-56C719461BAB");
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-15 01:54:40 +01:00
|
|
|
|
{
|
|
|
|
|
|
// UDF needs at least that
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.End - partition.Start < 256)
|
|
|
|
|
|
return false;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
// UDF needs at least that
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
var anchor = new AnchorVolumeDescriptorPointer();
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
// All positions where anchor may reside, with the ratio between 512 and 2048bps
|
|
|
|
|
|
ulong[][] positions =
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
2021-06-03 13:56:40 +01:00
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
256, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
512, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End - 256, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
1024, 4
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
2048, 4
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End - 1024, 4
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End - 4, 4
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool anchorFound = false;
|
2021-06-03 13:56:40 +01:00
|
|
|
|
uint ratio = 1;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
foreach(ulong[] position in positions.Where(position => position[0] + partition.Start + position[1] <=
|
2021-06-03 23:33:40 +01:00
|
|
|
|
partition.End && position[0] < partition.End))
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(position[0], (uint)position[1], out sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
anchor = Marshal.ByteArrayToStructureLittleEndian<AnchorVolumeDescriptorPointer>(sector);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagIdentifier = {0}", anchor.tag.tagIdentifier);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorVersion = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.tag.descriptorVersion);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagChecksum = 0x{0:X2}", anchor.tag.tagChecksum);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.reserved = {0}", anchor.tag.reserved);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagSerialNumber = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.tag.tagSerialNumber);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrc = 0x{0:X4}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.tag.descriptorCrc);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrcLength = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.tag.descriptorCrcLength);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagLocation = {0}", anchor.tag.tagLocation);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.length = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.mainVolumeDescriptorSequenceExtent.length);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.location = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.mainVolumeDescriptorSequenceExtent.location);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.length = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.reserveVolumeDescriptorSequenceExtent.length);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.location = {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
anchor.reserveVolumeDescriptorSequenceExtent.location);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2020-07-20 04:34:16 +01:00
|
|
|
|
if(anchor.tag.tagIdentifier != TagIdentifier.AnchorVolumeDescriptorPointer ||
|
2021-06-03 13:56:40 +01:00
|
|
|
|
anchor.tag.tagLocation != position[0] / position[1] ||
|
|
|
|
|
|
(anchor.mainVolumeDescriptorSequenceExtent.location * position[1]) + partition.Start >=
|
|
|
|
|
|
partition.End)
|
2020-02-29 18:03:35 +00:00
|
|
|
|
continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
|
|
|
|
|
anchorFound = true;
|
2021-06-03 13:56:40 +01:00
|
|
|
|
ratio = (uint)position[1];
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(!anchorFound)
|
|
|
|
|
|
return false;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
ulong count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while(count < 256)
|
|
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ErrorNumber errno =
|
2021-06-03 13:56:40 +01:00
|
|
|
|
imagePlugin.
|
|
|
|
|
|
ReadSectors(partition.Start + (anchor.mainVolumeDescriptorSequenceExtent.location * ratio) + (count * ratio),
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ratio, out sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
var tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0);
|
|
|
|
|
|
uint location = BitConverter.ToUInt32(sector, 0x0C);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
if(location == (partition.Start / ratio) + anchor.mainVolumeDescriptorSequenceExtent.location + count)
|
2016-09-15 01:54:40 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(tagId == TagIdentifier.TerminatingDescriptor)
|
|
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
if(tagId == TagIdentifier.LogicalVolumeDescriptor)
|
|
|
|
|
|
{
|
2019-03-01 00:28:55 +00:00
|
|
|
|
LogicalVolumeDescriptor lvd =
|
2019-03-01 07:35:22 +00:00
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeDescriptor>(sector);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
return _magic.SequenceEqual(lvd.domainIdentifier.identifier);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
else
|
|
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
2016-09-15 01:54:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding encoding)
|
2016-09-15 01:54:40 +01:00
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
information = "";
|
|
|
|
|
|
ErrorNumber errno;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
// UDF is always UTF-8
|
2017-12-26 08:01:40 +00:00
|
|
|
|
Encoding = Encoding.UTF8;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine("Universal Disk Format");
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var anchor = new AnchorVolumeDescriptorPointer();
|
|
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
// All positions where anchor may reside, with the ratio between 512 and 2048bps
|
|
|
|
|
|
ulong[][] positions =
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
2021-06-03 13:56:40 +01:00
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
256, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
512, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End - 256, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End, 1
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
1024, 4
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
2048, 4
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End - 1024, 4
|
|
|
|
|
|
},
|
|
|
|
|
|
new ulong[]
|
|
|
|
|
|
{
|
|
|
|
|
|
partition.End - 4, 4
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
};
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
uint ratio = 1;
|
|
|
|
|
|
|
|
|
|
|
|
foreach(ulong[] position in positions)
|
2016-09-15 01:54:40 +01:00
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
errno = imagePlugin.ReadSectors(position[0], (uint)position[1], out sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
anchor = Marshal.ByteArrayToStructureLittleEndian<AnchorVolumeDescriptorPointer>(sector);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
if(anchor.tag.tagIdentifier != TagIdentifier.AnchorVolumeDescriptorPointer ||
|
|
|
|
|
|
anchor.tag.tagLocation != position[0] / position[1] ||
|
|
|
|
|
|
anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start >= partition.End)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
ratio = (uint)position[1];
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ulong count = 0;
|
|
|
|
|
|
|
2021-08-17 14:40:50 +01:00
|
|
|
|
var pvd = new PrimaryVolumeDescriptor();
|
|
|
|
|
|
var lvd = new LogicalVolumeDescriptor();
|
|
|
|
|
|
LogicalVolumeIntegrityDescriptor lvid;
|
|
|
|
|
|
var lvidiu = new LogicalVolumeIntegrityDescriptorImplementationUse();
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
while(count < 256)
|
|
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
errno =
|
2021-06-03 13:56:40 +01:00
|
|
|
|
imagePlugin.
|
|
|
|
|
|
ReadSectors(partition.Start + (anchor.mainVolumeDescriptorSequenceExtent.location * ratio) + (count * ratio),
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ratio, out sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
continue;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
var tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0);
|
|
|
|
|
|
uint location = BitConverter.ToUInt32(sector, 0x0C);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2021-06-03 13:56:40 +01:00
|
|
|
|
if(location == (partition.Start / ratio) + anchor.mainVolumeDescriptorSequenceExtent.location + count)
|
2016-09-15 01:54:40 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(tagId == TagIdentifier.TerminatingDescriptor)
|
|
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
switch(tagId)
|
|
|
|
|
|
{
|
2017-12-21 04:43:29 +00:00
|
|
|
|
case TagIdentifier.LogicalVolumeDescriptor:
|
2019-03-01 07:35:22 +00:00
|
|
|
|
lvd = Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeDescriptor>(sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case TagIdentifier.PrimaryVolumeDescriptor:
|
2019-03-01 07:35:22 +00:00
|
|
|
|
pvd = Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
else
|
|
|
|
|
|
break;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
errno = imagePlugin.ReadSectors(lvd.integritySequenceExtent.location * ratio, ratio, out sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
lvid = Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeIntegrityDescriptor>(sector);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(lvid.tag.tagIdentifier == TagIdentifier.LogicalVolumeIntegrityDescriptor &&
|
2018-06-22 08:08:38 +01:00
|
|
|
|
lvid.tag.tagLocation == lvd.integritySequenceExtent.location)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
lvidiu =
|
2019-03-01 07:35:22 +00:00
|
|
|
|
Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeIntegrityDescriptorImplementationUse>(sector,
|
2020-11-11 04:19:18 +00:00
|
|
|
|
(int)((lvid.numberOfPartitions * 8) + 80),
|
|
|
|
|
|
System.Runtime.InteropServices.Marshal.SizeOf(lvidiu));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
else
|
|
|
|
|
|
lvid = new LogicalVolumeIntegrityDescriptor();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Volume is number {0} of {1}", pvd.volumeSequenceNumber,
|
|
|
|
|
|
pvd.maximumVolumeSequenceNumber).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume set identifier: {0}",
|
|
|
|
|
|
StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier)).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Volume name: {0}", StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2016-09-15 01:54:40 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume uses {0} bytes per block", lvd.logicalBlockSize).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-01-13 16:01:28 -07:00
|
|
|
|
sbInformation.AppendFormat("Volume was last written in {0}", EcmaToDateTime(lvid.recordingDateTime)).
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2016-09-15 01:54:40 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume contains {0} partitions", lvid.numberOfPartitions).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Volume contains {0} files and {1} directories", lvidiu.files, lvidiu.directories).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume conforms to {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding.GetString(lvd.domainIdentifier.identifier).TrimEnd('\u0000')).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume was last written by: {0}",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000')).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be read",
|
2017-12-21 17:58:51 +00:00
|
|
|
|
Convert.ToInt32($"{(lvidiu.minimumReadUDF & 0xFF00) >> 8}", 10),
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Convert.ToInt32($"{lvidiu.minimumReadUDF & 0xFF}", 10)).AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be written to",
|
2017-12-24 02:37:41 +00:00
|
|
|
|
Convert.ToInt32($"{(lvidiu.minimumWriteUDF & 0xFF00) >> 8}", 10),
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Convert.ToInt32($"{lvidiu.minimumWriteUDF & 0xFF}", 10)).AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume cannot be written by any UDF version higher than {0}.{1:X2}",
|
2017-12-24 02:37:41 +00:00
|
|
|
|
Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10),
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10)).AppendLine();
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
Type =
|
|
|
|
|
|
$"UDF v{Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10)}.{Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10):X2}",
|
2020-07-20 04:34:16 +01:00
|
|
|
|
ApplicationIdentifier = Encoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000'),
|
|
|
|
|
|
ClusterSize = lvd.logicalBlockSize,
|
|
|
|
|
|
ModificationDate = EcmaToDateTime(lvid.recordingDateTime),
|
|
|
|
|
|
ModificationDateSpecified = true,
|
|
|
|
|
|
Files = lvidiu.files,
|
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
|
VolumeName = StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier),
|
|
|
|
|
|
VolumeSetIdentifier = StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier),
|
2021-03-01 19:32:50 +00:00
|
|
|
|
VolumeSerial = StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier),
|
2020-07-20 04:34:16 +01:00
|
|
|
|
SystemIdentifier = Encoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000')
|
2017-12-22 08:43:22 +00:00
|
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-03-01 19:32:50 +00:00
|
|
|
|
XmlFsType.Clusters = (partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize /
|
2019-04-23 01:38:33 +01:00
|
|
|
|
XmlFsType.ClusterSize;
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
|
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
static DateTime EcmaToDateTime(Timestamp timestamp) => DateHandlers.EcmaToDateTime(timestamp.typeAndZone,
|
2020-11-11 04:19:18 +00:00
|
|
|
|
timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second,
|
|
|
|
|
|
timestamp.centiseconds, timestamp.hundredsMicroseconds, timestamp.microseconds);
|
2016-09-15 01:54:40 +01:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
|
enum EntityFlags : byte
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Dirty = 0x01, Protected = 0x02
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct EntityIdentifier
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Entity flags</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly EntityFlags flags;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Structure identifier</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 23)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] identifier;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Structure data</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] identifierSuffix;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct Timestamp
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort typeAndZone;
|
|
|
|
|
|
public readonly short year;
|
|
|
|
|
|
public readonly byte month;
|
|
|
|
|
|
public readonly byte day;
|
|
|
|
|
|
public readonly byte hour;
|
|
|
|
|
|
public readonly byte minute;
|
|
|
|
|
|
public readonly byte second;
|
|
|
|
|
|
public readonly byte centiseconds;
|
|
|
|
|
|
public readonly byte hundredsMicroseconds;
|
|
|
|
|
|
public readonly byte microseconds;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum TagIdentifier : ushort
|
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
|
PrimaryVolumeDescriptor = 1, AnchorVolumeDescriptorPointer = 2, VolumeDescriptorPointer = 3,
|
|
|
|
|
|
ImplementationUseVolumeDescriptor = 4, PartitionDescriptor = 5, LogicalVolumeDescriptor = 6,
|
|
|
|
|
|
UnallocatedSpaceDescriptor = 7, TerminatingDescriptor = 8, LogicalVolumeIntegrityDescriptor = 9
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct DescriptorTag
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly TagIdentifier tagIdentifier;
|
|
|
|
|
|
public readonly ushort descriptorVersion;
|
|
|
|
|
|
public readonly byte tagChecksum;
|
|
|
|
|
|
public readonly byte reserved;
|
|
|
|
|
|
public readonly ushort tagSerialNumber;
|
|
|
|
|
|
public readonly ushort descriptorCrc;
|
|
|
|
|
|
public readonly ushort descriptorCrcLength;
|
|
|
|
|
|
public readonly uint tagLocation;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct ExtentDescriptor
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint length;
|
|
|
|
|
|
public readonly uint location;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct CharacterSpecification
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte type;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 63)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] information;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct AnchorVolumeDescriptorPointer
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly DescriptorTag tag;
|
|
|
|
|
|
public readonly ExtentDescriptor mainVolumeDescriptorSequenceExtent;
|
|
|
|
|
|
public readonly ExtentDescriptor reserveVolumeDescriptorSequenceExtent;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 480)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] reserved;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct PrimaryVolumeDescriptor
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly DescriptorTag tag;
|
|
|
|
|
|
public readonly uint volumeDescriptorSequenceNumber;
|
|
|
|
|
|
public readonly uint primaryVolumeDescriptorNumber;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] volumeIdentifier;
|
|
|
|
|
|
public readonly ushort volumeSequenceNumber;
|
|
|
|
|
|
public readonly ushort maximumVolumeSequenceNumber;
|
|
|
|
|
|
public readonly ushort interchangeLevel;
|
|
|
|
|
|
public readonly ushort maximumInterchangeLevel;
|
|
|
|
|
|
public readonly uint characterSetList;
|
|
|
|
|
|
public readonly uint maximumCharacterSetList;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] volumeSetIdentifier;
|
|
|
|
|
|
public readonly CharacterSpecification descriptorCharacterSet;
|
|
|
|
|
|
public readonly CharacterSpecification explanatoryCharacterSet;
|
|
|
|
|
|
public readonly ExtentDescriptor volumeAbstract;
|
|
|
|
|
|
public readonly ExtentDescriptor volumeCopyright;
|
|
|
|
|
|
public readonly EntityIdentifier applicationIdentifier;
|
|
|
|
|
|
public readonly Timestamp recordingDateTime;
|
|
|
|
|
|
public readonly EntityIdentifier implementationIdentifier;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] implementationUse;
|
|
|
|
|
|
public readonly uint predecessorVolumeDescriptorSequenceLocation;
|
|
|
|
|
|
public readonly ushort flags;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 22)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] reserved;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct LogicalVolumeDescriptor
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly DescriptorTag tag;
|
|
|
|
|
|
public readonly uint volumeDescriptorSequenceNumber;
|
|
|
|
|
|
public readonly CharacterSpecification descriptorCharacterSet;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] logicalVolumeIdentifier;
|
|
|
|
|
|
public readonly uint logicalBlockSize;
|
|
|
|
|
|
public readonly EntityIdentifier domainIdentifier;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] logicalVolumeContentsUse;
|
|
|
|
|
|
public readonly uint mapTableLength;
|
|
|
|
|
|
public readonly uint numberOfPartitionMaps;
|
|
|
|
|
|
public readonly EntityIdentifier implementationIdentifier;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] implementationUse;
|
|
|
|
|
|
public readonly ExtentDescriptor integritySequenceExtent;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct LogicalVolumeIntegrityDescriptor
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly DescriptorTag tag;
|
|
|
|
|
|
public readonly Timestamp recordingDateTime;
|
|
|
|
|
|
public readonly uint integrityType;
|
|
|
|
|
|
public readonly ExtentDescriptor nextIntegrityExtent;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] logicalVolumeContentsUse;
|
|
|
|
|
|
public readonly uint numberOfPartitions;
|
|
|
|
|
|
public readonly uint lengthOfImplementationUse;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
// Follows uint[numberOfPartitions] freeSpaceTable;
|
|
|
|
|
|
// Follows uint[numberOfPartitions] sizeTable;
|
|
|
|
|
|
// Follows byte[lengthOfImplementationUse] implementationUse;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct LogicalVolumeIntegrityDescriptorImplementationUse
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly EntityIdentifier implementationId;
|
|
|
|
|
|
public readonly uint files;
|
|
|
|
|
|
public readonly uint directories;
|
|
|
|
|
|
public readonly ushort minimumReadUDF;
|
|
|
|
|
|
public readonly ushort minimumWriteUDF;
|
|
|
|
|
|
public readonly ushort maximumWriteUDF;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-15 01:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|