mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: Final cleanup of DiscImageChef.Filesystems.
This commit is contained in:
@@ -45,6 +45,12 @@ namespace DiscImageChef.Filesystems
|
||||
// TODO: Detect bootable
|
||||
public class UDF : Filesystem
|
||||
{
|
||||
readonly byte[] UDF_Magic =
|
||||
{
|
||||
0x2A, 0x4F, 0x53, 0x54, 0x41, 0x20, 0x55, 0x44, 0x46, 0x20, 0x43, 0x6F, 0x6D, 0x70, 0x6C, 0x69, 0x61, 0x6E,
|
||||
0x74, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
public UDF()
|
||||
{
|
||||
Name = "Universal Disk Format";
|
||||
@@ -68,11 +74,304 @@ namespace DiscImageChef.Filesystems
|
||||
CurrentEncoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
readonly byte[] UDF_Magic =
|
||||
public override bool Identify(ImagePlugin imagePlugin, Partition partition)
|
||||
{
|
||||
0x2A, 0x4F, 0x53, 0x54, 0x41, 0x20, 0x55, 0x44, 0x46, 0x20, 0x43, 0x6F, 0x6D, 0x70, 0x6C, 0x69, 0x61, 0x6E,
|
||||
0x74, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
// UDF needs at least that
|
||||
if(partition.End - partition.Start < 256) return false;
|
||||
|
||||
// UDF needs at least that
|
||||
if(imagePlugin.ImageInfo.SectorSize < 512) return false;
|
||||
|
||||
byte[] sector;
|
||||
AnchorVolumeDescriptorPointer anchor = new AnchorVolumeDescriptorPointer();
|
||||
// All positions where anchor may reside
|
||||
ulong[] positions = {256, 512, partition.End - 256, partition.End};
|
||||
bool anchorFound = false;
|
||||
|
||||
foreach(ulong position in positions.Where(position => position + partition.Start < partition.End))
|
||||
{
|
||||
sector = imagePlugin.ReadSector(position);
|
||||
anchor = new AnchorVolumeDescriptorPointer();
|
||||
IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor));
|
||||
Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor));
|
||||
anchor =
|
||||
(AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr,
|
||||
typeof(AnchorVolumeDescriptorPointer));
|
||||
Marshal.FreeHGlobal(anchorPtr);
|
||||
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagIdentifier = {0}", anchor.tag.tagIdentifier);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorVersion = {0}",
|
||||
anchor.tag.descriptorVersion);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagChecksum = 0x{0:X2}", anchor.tag.tagChecksum);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.reserved = {0}", anchor.tag.reserved);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagSerialNumber = {0}", anchor.tag.tagSerialNumber);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrc = 0x{0:X4}",
|
||||
anchor.tag.descriptorCrc);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrcLength = {0}",
|
||||
anchor.tag.descriptorCrcLength);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagLocation = {0}", anchor.tag.tagLocation);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.length = {0}",
|
||||
anchor.mainVolumeDescriptorSequenceExtent.length);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.location = {0}",
|
||||
anchor.mainVolumeDescriptorSequenceExtent.location);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.length = {0}",
|
||||
anchor.reserveVolumeDescriptorSequenceExtent.length);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.location = {0}",
|
||||
anchor.reserveVolumeDescriptorSequenceExtent.location);
|
||||
|
||||
if(anchor.tag.tagIdentifier != TagIdentifier.AnchorVolumeDescriptorPointer ||
|
||||
anchor.tag.tagLocation != position ||
|
||||
anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start >= partition.End) continue;
|
||||
|
||||
anchorFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!anchorFound) return false;
|
||||
|
||||
ulong count = 0;
|
||||
|
||||
while(count < 256)
|
||||
{
|
||||
sector = imagePlugin.ReadSector(partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location +
|
||||
count);
|
||||
TagIdentifier tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0);
|
||||
uint location = BitConverter.ToUInt32(sector, 0x0C);
|
||||
|
||||
if(location == partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count)
|
||||
{
|
||||
if(tagId == TagIdentifier.TerminatingDescriptor) break;
|
||||
|
||||
if(tagId == TagIdentifier.LogicalVolumeDescriptor)
|
||||
{
|
||||
LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor();
|
||||
IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd));
|
||||
Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd));
|
||||
lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor));
|
||||
Marshal.FreeHGlobal(lvdPtr);
|
||||
|
||||
return UDF_Magic.SequenceEqual(lvd.domainIdentifier.identifier);
|
||||
}
|
||||
}
|
||||
else break;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void GetInformation(ImagePlugin imagePlugin, Partition partition, out string information)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
StringBuilder sbInformation = new StringBuilder();
|
||||
|
||||
sbInformation.AppendLine("Universal Disk Format");
|
||||
|
||||
AnchorVolumeDescriptorPointer anchor = new AnchorVolumeDescriptorPointer();
|
||||
// All positions where anchor may reside
|
||||
ulong[] positions = {256, 512, partition.End - 256, partition.End};
|
||||
|
||||
foreach(ulong position in positions)
|
||||
{
|
||||
sector = imagePlugin.ReadSector(position);
|
||||
anchor = new AnchorVolumeDescriptorPointer();
|
||||
IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor));
|
||||
Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor));
|
||||
anchor =
|
||||
(AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr,
|
||||
typeof(AnchorVolumeDescriptorPointer));
|
||||
Marshal.FreeHGlobal(anchorPtr);
|
||||
|
||||
if(anchor.tag.tagIdentifier == TagIdentifier.AnchorVolumeDescriptorPointer &&
|
||||
anchor.tag.tagLocation == position &&
|
||||
anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start < partition.End) break;
|
||||
}
|
||||
|
||||
ulong count = 0;
|
||||
|
||||
PrimaryVolumeDescriptor pvd = new PrimaryVolumeDescriptor();
|
||||
LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor();
|
||||
LogicalVolumeIntegrityDescriptor lvid = new LogicalVolumeIntegrityDescriptor();
|
||||
LogicalVolumeIntegrityDescriptorImplementationUse lvidiu =
|
||||
new LogicalVolumeIntegrityDescriptorImplementationUse();
|
||||
|
||||
while(count < 256)
|
||||
{
|
||||
sector = imagePlugin.ReadSector(partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location +
|
||||
count);
|
||||
TagIdentifier tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0);
|
||||
uint location = BitConverter.ToUInt32(sector, 0x0C);
|
||||
|
||||
if(location == partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count)
|
||||
{
|
||||
if(tagId == TagIdentifier.TerminatingDescriptor) break;
|
||||
|
||||
switch(tagId)
|
||||
{
|
||||
case TagIdentifier.LogicalVolumeDescriptor:
|
||||
IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd));
|
||||
Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd));
|
||||
lvd = (LogicalVolumeDescriptor)
|
||||
Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor));
|
||||
Marshal.FreeHGlobal(lvdPtr);
|
||||
break;
|
||||
case TagIdentifier.PrimaryVolumeDescriptor:
|
||||
IntPtr pvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pvd));
|
||||
Marshal.Copy(sector, 0, pvdPtr, Marshal.SizeOf(pvd));
|
||||
pvd = (PrimaryVolumeDescriptor)
|
||||
Marshal.PtrToStructure(pvdPtr, typeof(PrimaryVolumeDescriptor));
|
||||
Marshal.FreeHGlobal(pvdPtr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else break;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
sector = imagePlugin.ReadSector(lvd.integritySequenceExtent.location);
|
||||
IntPtr lvidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvid));
|
||||
Marshal.Copy(sector, 0, lvidPtr, Marshal.SizeOf(lvid));
|
||||
lvid =
|
||||
(LogicalVolumeIntegrityDescriptor)
|
||||
Marshal.PtrToStructure(lvidPtr, typeof(LogicalVolumeIntegrityDescriptor));
|
||||
Marshal.FreeHGlobal(lvidPtr);
|
||||
|
||||
if(lvid.tag.tagIdentifier == TagIdentifier.LogicalVolumeIntegrityDescriptor &&
|
||||
lvid.tag.tagLocation == lvd.integritySequenceExtent.location)
|
||||
{
|
||||
IntPtr lvidiuPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvidiu));
|
||||
Marshal.Copy(sector, (int)(lvid.numberOfPartitions * 8 + 80), lvidiuPtr, Marshal.SizeOf(lvidiu));
|
||||
lvidiu =
|
||||
(LogicalVolumeIntegrityDescriptorImplementationUse)Marshal.PtrToStructure(lvidiuPtr,
|
||||
typeof(
|
||||
LogicalVolumeIntegrityDescriptorImplementationUse
|
||||
));
|
||||
Marshal.FreeHGlobal(lvidiuPtr);
|
||||
}
|
||||
else lvid = new LogicalVolumeIntegrityDescriptor();
|
||||
|
||||
sbInformation.AppendFormat("Volume is number {0} of {1}", pvd.volumeSequenceNumber,
|
||||
pvd.maximumVolumeSequenceNumber).AppendLine();
|
||||
sbInformation.AppendFormat("Volume set identifier: {0}",
|
||||
StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier)).AppendLine();
|
||||
sbInformation
|
||||
.AppendFormat("Volume name: {0}", StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume uses {0} bytes per block", lvd.logicalBlockSize).AppendLine();
|
||||
sbInformation.AppendFormat("Volume was las written in {0}", EcmaToDateTime(lvid.recordingDateTime))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume contains {0} partitions", lvid.numberOfPartitions).AppendLine();
|
||||
sbInformation
|
||||
.AppendFormat("Volume contains {0} files and {1} directories", lvidiu.files, lvidiu.directories)
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume conforms to {0}",
|
||||
CurrentEncoding.GetString(lvd.domainIdentifier.identifier).TrimEnd('\u0000'))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume was last written by: {0}",
|
||||
CurrentEncoding
|
||||
.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000'))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be read",
|
||||
Convert.ToInt32($"{(lvidiu.minimumReadUDF & 0xFF00) >> 8}", 10),
|
||||
Convert.ToInt32($"{lvidiu.minimumReadUDF & 0xFF}", 10)).AppendLine();
|
||||
sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be written to",
|
||||
Convert.ToInt32($"{(lvidiu.minimumWriteUDF & 0xFF00) >> 8}", 10),
|
||||
Convert.ToInt32($"{lvidiu.minimumWriteUDF & 0xFF}", 10)).AppendLine();
|
||||
sbInformation.AppendFormat("Volume cannot be written by any UDF version higher than {0}.{1:X2}",
|
||||
Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10),
|
||||
Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10)).AppendLine();
|
||||
|
||||
XmlFsType = new FileSystemType
|
||||
{
|
||||
Type =
|
||||
$"UDF v{Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10)}.{Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10):X2}",
|
||||
ApplicationIdentifier =
|
||||
CurrentEncoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000'),
|
||||
ClusterSize = (int)lvd.logicalBlockSize,
|
||||
ModificationDate = EcmaToDateTime(lvid.recordingDateTime),
|
||||
ModificationDateSpecified = true,
|
||||
Files = lvidiu.files,
|
||||
FilesSpecified = true,
|
||||
VolumeName = StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier),
|
||||
VolumeSetIdentifier = StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier),
|
||||
SystemIdentifier = CurrentEncoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000')
|
||||
};
|
||||
XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.ImageInfo.SectorSize /
|
||||
(ulong)XmlFsType.ClusterSize);
|
||||
|
||||
information = sbInformation.ToString();
|
||||
}
|
||||
|
||||
static DateTime EcmaToDateTime(Timestamp timestamp)
|
||||
{
|
||||
return DateHandlers.EcmaToDateTime(timestamp.typeAndZone, timestamp.year, timestamp.month, timestamp.day,
|
||||
timestamp.hour, timestamp.minute, timestamp.second,
|
||||
timestamp.centiseconds, timestamp.hundredsMicroseconds,
|
||||
timestamp.microseconds);
|
||||
}
|
||||
|
||||
public override Errno Mount()
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Mount(bool debug)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Unmount()
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno ReadDir(string path, ref List<string> contents)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno StatFs(ref FileSystemInfo stat)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Stat(string path, ref FileEntryInfo stat)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno ReadLink(string path, ref string dest)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
enum EntityFlags : byte
|
||||
@@ -85,15 +384,15 @@ namespace DiscImageChef.Filesystems
|
||||
struct EntityIdentifier
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity flags
|
||||
/// Entity flags
|
||||
/// </summary>
|
||||
public EntityFlags flags;
|
||||
/// <summary>
|
||||
/// Structure identifier
|
||||
/// Structure identifier
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 23)] public byte[] identifier;
|
||||
/// <summary>
|
||||
/// Structure data
|
||||
/// Structure data
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] identifierSuffix;
|
||||
}
|
||||
@@ -231,307 +530,5 @@ namespace DiscImageChef.Filesystems
|
||||
public ushort minimumWriteUDF;
|
||||
public ushort maximumWriteUDF;
|
||||
}
|
||||
|
||||
public override bool Identify(ImagePlugin imagePlugin, Partition partition)
|
||||
{
|
||||
// UDF needs at least that
|
||||
if(partition.End - partition.Start < 256) return false;
|
||||
|
||||
// UDF needs at least that
|
||||
if(imagePlugin.ImageInfo.SectorSize < 512) return false;
|
||||
|
||||
byte[] sector;
|
||||
AnchorVolumeDescriptorPointer anchor = new AnchorVolumeDescriptorPointer();
|
||||
// All positions where anchor may reside
|
||||
ulong[] positions = {256, 512, partition.End - 256, partition.End};
|
||||
bool anchorFound = false;
|
||||
|
||||
foreach(ulong position in positions.Where(position => position + partition.Start < partition.End)) {
|
||||
sector = imagePlugin.ReadSector(position);
|
||||
anchor = new AnchorVolumeDescriptorPointer();
|
||||
IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor));
|
||||
Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor));
|
||||
anchor =
|
||||
(AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr,
|
||||
typeof(AnchorVolumeDescriptorPointer));
|
||||
Marshal.FreeHGlobal(anchorPtr);
|
||||
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagIdentifier = {0}", anchor.tag.tagIdentifier);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorVersion = {0}",
|
||||
anchor.tag.descriptorVersion);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagChecksum = 0x{0:X2}", anchor.tag.tagChecksum);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.reserved = {0}", anchor.tag.reserved);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagSerialNumber = {0}", anchor.tag.tagSerialNumber);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrc = 0x{0:X4}",
|
||||
anchor.tag.descriptorCrc);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorCrcLength = {0}",
|
||||
anchor.tag.descriptorCrcLength);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagLocation = {0}", anchor.tag.tagLocation);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.length = {0}",
|
||||
anchor.mainVolumeDescriptorSequenceExtent.length);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.mainVolumeDescriptorSequenceExtent.location = {0}",
|
||||
anchor.mainVolumeDescriptorSequenceExtent.location);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.length = {0}",
|
||||
anchor.reserveVolumeDescriptorSequenceExtent.length);
|
||||
DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.location = {0}",
|
||||
anchor.reserveVolumeDescriptorSequenceExtent.location);
|
||||
|
||||
if(anchor.tag.tagIdentifier != TagIdentifier.AnchorVolumeDescriptorPointer ||
|
||||
anchor.tag.tagLocation != position ||
|
||||
anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start >= partition.End) continue;
|
||||
|
||||
anchorFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!anchorFound) return false;
|
||||
|
||||
ulong count = 0;
|
||||
|
||||
while(count < 256)
|
||||
{
|
||||
sector = imagePlugin.ReadSector(partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location +
|
||||
count);
|
||||
TagIdentifier tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0);
|
||||
uint location = BitConverter.ToUInt32(sector, 0x0C);
|
||||
|
||||
if(location == partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count)
|
||||
{
|
||||
if(tagId == TagIdentifier.TerminatingDescriptor) break;
|
||||
|
||||
if(tagId == TagIdentifier.LogicalVolumeDescriptor)
|
||||
{
|
||||
LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor();
|
||||
IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd));
|
||||
Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd));
|
||||
lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor));
|
||||
Marshal.FreeHGlobal(lvdPtr);
|
||||
|
||||
return UDF_Magic.SequenceEqual(lvd.domainIdentifier.identifier);
|
||||
}
|
||||
}
|
||||
else break;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void GetInformation(ImagePlugin imagePlugin, Partition partition,
|
||||
out string information)
|
||||
{
|
||||
byte[] sector;
|
||||
|
||||
StringBuilder sbInformation = new StringBuilder();
|
||||
|
||||
sbInformation.AppendLine("Universal Disk Format");
|
||||
|
||||
AnchorVolumeDescriptorPointer anchor = new AnchorVolumeDescriptorPointer();
|
||||
// All positions where anchor may reside
|
||||
ulong[] positions = {256, 512, partition.End - 256, partition.End};
|
||||
|
||||
foreach(ulong position in positions)
|
||||
{
|
||||
sector = imagePlugin.ReadSector(position);
|
||||
anchor = new AnchorVolumeDescriptorPointer();
|
||||
IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor));
|
||||
Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor));
|
||||
anchor =
|
||||
(AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr,
|
||||
typeof(AnchorVolumeDescriptorPointer));
|
||||
Marshal.FreeHGlobal(anchorPtr);
|
||||
|
||||
if(anchor.tag.tagIdentifier == TagIdentifier.AnchorVolumeDescriptorPointer &&
|
||||
anchor.tag.tagLocation == position &&
|
||||
anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start < partition.End) break;
|
||||
}
|
||||
|
||||
ulong count = 0;
|
||||
|
||||
PrimaryVolumeDescriptor pvd = new PrimaryVolumeDescriptor();
|
||||
LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor();
|
||||
LogicalVolumeIntegrityDescriptor lvid = new LogicalVolumeIntegrityDescriptor();
|
||||
LogicalVolumeIntegrityDescriptorImplementationUse lvidiu =
|
||||
new LogicalVolumeIntegrityDescriptorImplementationUse();
|
||||
|
||||
while(count < 256)
|
||||
{
|
||||
sector = imagePlugin.ReadSector(partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location +
|
||||
count);
|
||||
TagIdentifier tagId = (TagIdentifier)BitConverter.ToUInt16(sector, 0);
|
||||
uint location = BitConverter.ToUInt32(sector, 0x0C);
|
||||
|
||||
if(location == partition.Start + anchor.mainVolumeDescriptorSequenceExtent.location + count)
|
||||
{
|
||||
if(tagId == TagIdentifier.TerminatingDescriptor) break;
|
||||
|
||||
switch(tagId) {
|
||||
case TagIdentifier.LogicalVolumeDescriptor:
|
||||
IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd));
|
||||
Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd));
|
||||
lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor));
|
||||
Marshal.FreeHGlobal(lvdPtr);
|
||||
break;
|
||||
case TagIdentifier.PrimaryVolumeDescriptor:
|
||||
IntPtr pvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pvd));
|
||||
Marshal.Copy(sector, 0, pvdPtr, Marshal.SizeOf(pvd));
|
||||
pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(pvdPtr, typeof(PrimaryVolumeDescriptor));
|
||||
Marshal.FreeHGlobal(pvdPtr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else break;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
sector = imagePlugin.ReadSector(lvd.integritySequenceExtent.location);
|
||||
IntPtr lvidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvid));
|
||||
Marshal.Copy(sector, 0, lvidPtr, Marshal.SizeOf(lvid));
|
||||
lvid =
|
||||
(LogicalVolumeIntegrityDescriptor)
|
||||
Marshal.PtrToStructure(lvidPtr, typeof(LogicalVolumeIntegrityDescriptor));
|
||||
Marshal.FreeHGlobal(lvidPtr);
|
||||
|
||||
if(lvid.tag.tagIdentifier == TagIdentifier.LogicalVolumeIntegrityDescriptor &&
|
||||
lvid.tag.tagLocation == lvd.integritySequenceExtent.location)
|
||||
{
|
||||
IntPtr lvidiuPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvidiu));
|
||||
Marshal.Copy(sector, (int)(lvid.numberOfPartitions * 8 + 80), lvidiuPtr, Marshal.SizeOf(lvidiu));
|
||||
lvidiu =
|
||||
(LogicalVolumeIntegrityDescriptorImplementationUse)Marshal.PtrToStructure(lvidiuPtr,
|
||||
typeof(
|
||||
LogicalVolumeIntegrityDescriptorImplementationUse
|
||||
));
|
||||
Marshal.FreeHGlobal(lvidiuPtr);
|
||||
}
|
||||
else lvid = new LogicalVolumeIntegrityDescriptor();
|
||||
|
||||
sbInformation.AppendFormat("Volume is number {0} of {1}", pvd.volumeSequenceNumber,
|
||||
pvd.maximumVolumeSequenceNumber).AppendLine();
|
||||
sbInformation.AppendFormat("Volume set identifier: {0}",
|
||||
StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier)).AppendLine();
|
||||
sbInformation
|
||||
.AppendFormat("Volume name: {0}", StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume uses {0} bytes per block", lvd.logicalBlockSize).AppendLine();
|
||||
sbInformation.AppendFormat("Volume was las written in {0}", EcmaToDateTime(lvid.recordingDateTime))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume contains {0} partitions", lvid.numberOfPartitions).AppendLine();
|
||||
sbInformation
|
||||
.AppendFormat("Volume contains {0} files and {1} directories", lvidiu.files, lvidiu.directories)
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume conforms to {0}",
|
||||
CurrentEncoding
|
||||
.GetString(lvd.domainIdentifier.identifier).TrimEnd('\u0000'))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume was last written by: {0}",
|
||||
CurrentEncoding
|
||||
.GetString(pvd.implementationIdentifier.identifier)
|
||||
.TrimEnd('\u0000')).AppendLine();
|
||||
sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be read",
|
||||
Convert.ToInt32($"{(lvidiu.minimumReadUDF & 0xFF00) >> 8}", 10),
|
||||
Convert.ToInt32($"{lvidiu.minimumReadUDF & 0xFF}", 10))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume requires UDF version {0}.{1:X2} to be written to",
|
||||
Convert.ToInt32($"{(lvidiu.minimumWriteUDF & 0xFF00) >> 8}",
|
||||
10),
|
||||
Convert.ToInt32($"{lvidiu.minimumWriteUDF & 0xFF}", 10))
|
||||
.AppendLine();
|
||||
sbInformation.AppendFormat("Volume cannot be written by any UDF version higher than {0}.{1:X2}",
|
||||
Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}",
|
||||
10),
|
||||
Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10))
|
||||
.AppendLine();
|
||||
|
||||
XmlFsType = new FileSystemType
|
||||
{
|
||||
Type =
|
||||
$"UDF v{Convert.ToInt32($"{(lvidiu.maximumWriteUDF & 0xFF00) >> 8}", 10)}.{Convert.ToInt32($"{lvidiu.maximumWriteUDF & 0xFF}", 10):X2}",
|
||||
ApplicationIdentifier =
|
||||
CurrentEncoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000'),
|
||||
ClusterSize = (int)lvd.logicalBlockSize,
|
||||
ModificationDate = EcmaToDateTime(lvid.recordingDateTime),
|
||||
ModificationDateSpecified = true,
|
||||
Files = lvidiu.files,
|
||||
FilesSpecified = true,
|
||||
VolumeName = StringHandlers.DecompressUnicode(lvd.logicalVolumeIdentifier),
|
||||
VolumeSetIdentifier = StringHandlers.DecompressUnicode(pvd.volumeSetIdentifier),
|
||||
SystemIdentifier = CurrentEncoding.GetString(pvd.implementationIdentifier.identifier).TrimEnd('\u0000')
|
||||
};
|
||||
XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.ImageInfo.SectorSize /
|
||||
(ulong)XmlFsType.ClusterSize);
|
||||
|
||||
information = sbInformation.ToString();
|
||||
}
|
||||
|
||||
static DateTime EcmaToDateTime(Timestamp timestamp)
|
||||
{
|
||||
return DateHandlers.EcmaToDateTime(timestamp.typeAndZone, timestamp.year, timestamp.month, timestamp.day,
|
||||
timestamp.hour, timestamp.minute, timestamp.second,
|
||||
timestamp.centiseconds, timestamp.hundredsMicroseconds,
|
||||
timestamp.microseconds);
|
||||
}
|
||||
|
||||
public override Errno Mount()
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Mount(bool debug)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Unmount()
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno ReadDir(string path, ref List<string> contents)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno StatFs(ref FileSystemInfo stat)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno Stat(string path, ref FileEntryInfo stat)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
public override Errno ReadLink(string path, ref string dest)
|
||||
{
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user