Refactor, pass whole partition structure to filesystems.

This commit is contained in:
2017-07-19 16:31:08 +01:00
parent 68537136d8
commit 711d19fd04
154 changed files with 980 additions and 760 deletions

View File

@@ -1,4 +1,4 @@
// /***************************************************************************
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
@@ -31,10 +31,11 @@
// ****************************************************************************/
using System;
using System.Text;
using System.Collections.Generic;
using DiscImageChef.Console;
using System.Runtime.InteropServices;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.Console;
namespace DiscImageChef.Filesystems
{
@@ -47,7 +48,7 @@ namespace DiscImageChef.Filesystems
CurrentEncoding = Encoding.GetEncoding("iso-8859-1");
}
public AmigaDOSPlugin(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, Encoding encoding)
public AmigaDOSPlugin(ImagePlugins.ImagePlugin imagePlugin, Partition partition, Encoding encoding)
{
Name = "Amiga DOS filesystem";
PluginUUID = new Guid("3c882400-208c-427d-a086-9119852a1bc7");
@@ -203,9 +204,9 @@ namespace DiscImageChef.Filesystems
public const uint TypeHeader = 2;
public const uint SubTypeRoot = 1;
public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, Partition partition)
{
if(partitionStart >= partitionEnd)
if(partition.PartitionStartSector >= partition.PartitionEndSector)
return false;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
@@ -216,14 +217,14 @@ namespace DiscImageChef.Filesystems
// However while you can set a block size different from the sector size on formatting, the bootblock block
// size for floppies is the sector size, and for RDB is usually is the hard disk sector size,
// so this is not entirely wrong...
byte[] sector = imagePlugin.ReadSectors(0 + partitionStart, 2);
byte[] sector = imagePlugin.ReadSectors(0 + partition.PartitionStartSector, 2);
BootBlock bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
// AROS boot floppies...
if(sector.Length >= 512 && sector[510] == 0x55 && sector[511] == 0xAA &&
(bblk.diskType & FFS_Mask) != FFS_Mask && (bblk.diskType & MuFS_Mask) != MuFS_Mask)
{
sector = imagePlugin.ReadSectors(1 + partitionStart, 2);
sector = imagePlugin.ReadSectors(1 + partition.PartitionStartSector, 2);
bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
}
@@ -244,19 +245,19 @@ namespace DiscImageChef.Filesystems
// If bootblock is correct, let's take its rootblock pointer
if(bsum == bblk.checksum)
{
b_root_ptr = bblk.root_ptr + partitionStart;
b_root_ptr = bblk.root_ptr + partition.PartitionStartSector;
DicConsole.DebugWriteLine("AmigaDOS plugin", "Bootblock points to {0} as Rootblock", b_root_ptr);
}
ulong[] root_ptrs = { b_root_ptr + partitionStart, ((partitionEnd - partitionStart) + 1) / 2 + partitionStart - 2,
((partitionEnd - partitionStart) + 1) / 2 + partitionStart - 1, ((partitionEnd - partitionStart) + 1) / 2 + partitionStart};
ulong[] root_ptrs = { b_root_ptr + partition.PartitionStartSector, ((partition.PartitionEndSector - partition.PartitionStartSector) + 1) / 2 + partition.PartitionStartSector - 2,
((partition.PartitionEndSector - partition.PartitionStartSector) + 1) / 2 + partition.PartitionStartSector - 1, ((partition.PartitionEndSector - partition.PartitionStartSector) + 1) / 2 + partition.PartitionStartSector};
RootBlock rblk = new RootBlock();
// So to handle even number of sectors
foreach(ulong root_ptr in root_ptrs)
{
if(root_ptr >= partitionEnd || root_ptr < partitionStart)
if(root_ptr >= partition.PartitionEndSector || root_ptr < partition.PartitionStartSector)
continue;
DicConsole.DebugWriteLine("AmigaDOS plugin", "Searching for Rootblock in sector {0}", root_ptr);
@@ -281,7 +282,7 @@ namespace DiscImageChef.Filesystems
if(blockSize % sector.Length > 0)
sectorsPerBlock++;
if(root_ptr + sectorsPerBlock >= partitionEnd)
if(root_ptr + sectorsPerBlock >= partition.PartitionEndSector)
continue;
sector = imagePlugin.ReadSectors(root_ptr, sectorsPerBlock);
@@ -304,14 +305,14 @@ namespace DiscImageChef.Filesystems
return false;
}
public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, out string information)
public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, Partition partition, out string information)
{
StringBuilder sbInformation = new StringBuilder();
xmlFSType = new Schemas.FileSystemType();
information = null;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] BootBlockSectors = imagePlugin.ReadSectors(0 + partitionStart, 2);
byte[] BootBlockSectors = imagePlugin.ReadSectors(0 + partition.PartitionStartSector, 2);
BootBlock bootBlk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(BootBlockSectors);
bootBlk.bootCode = new byte[BootBlockSectors.Length - 12];
@@ -324,12 +325,12 @@ namespace DiscImageChef.Filesystems
// If bootblock is correct, let's take its rootblock pointer
if(bsum == bootBlk.checksum)
{
b_root_ptr = bootBlk.root_ptr + partitionStart;
b_root_ptr = bootBlk.root_ptr + partition.PartitionStartSector;
DicConsole.DebugWriteLine("AmigaDOS plugin", "Bootblock points to {0} as Rootblock", b_root_ptr);
}
ulong[] root_ptrs = { b_root_ptr + partitionStart, ((partitionEnd - partitionStart) + 1) / 2 + partitionStart - 2,
((partitionEnd - partitionStart) + 1) / 2 + partitionStart - 1, ((partitionEnd - partitionStart) + 1) / 2 + partitionStart};
ulong[] root_ptrs = { b_root_ptr + partition.PartitionStartSector, ((partition.PartitionEndSector - partition.PartitionStartSector) + 1) / 2 + partition.PartitionStartSector - 2,
((partition.PartitionEndSector - partition.PartitionStartSector) + 1) / 2 + partition.PartitionStartSector - 1, ((partition.PartitionEndSector - partition.PartitionStartSector) + 1) / 2 + partition.PartitionStartSector};
RootBlock rootBlk = new RootBlock();
byte[] RootBlockSector = null;
@@ -340,7 +341,7 @@ namespace DiscImageChef.Filesystems
// So to handle even number of sectors
foreach(ulong root_ptr in root_ptrs)
{
if(root_ptr >= partitionEnd || root_ptr < partitionStart)
if(root_ptr >= partition.PartitionEndSector || root_ptr < partition.PartitionStartSector)
continue;
DicConsole.DebugWriteLine("AmigaDOS plugin", "Searching for Rootblock in sector {0}", root_ptr);
@@ -365,7 +366,7 @@ namespace DiscImageChef.Filesystems
if(blockSize % RootBlockSector.Length > 0)
sectorsPerBlock++;
if(root_ptr + sectorsPerBlock >= partitionEnd)
if(root_ptr + sectorsPerBlock >= partition.PartitionEndSector)
continue;
RootBlockSector = imagePlugin.ReadSectors(root_ptr, sectorsPerBlock);
@@ -457,7 +458,7 @@ namespace DiscImageChef.Filesystems
if((bootBlk.diskType & 0xFF) == 4 || (bootBlk.diskType & 0xFF) == 5)
sbInformation.AppendFormat("Directory cache starts at block {0}", rootBlk.extension).AppendLine();
long blocks = (long)((((partitionEnd - partitionStart) + 1) * imagePlugin.ImageInfo.sectorSize) / blockSize);
long blocks = (long)((((partition.PartitionEndSector - partition.PartitionStartSector) + 1) * imagePlugin.ImageInfo.sectorSize) / blockSize);
sbInformation.AppendFormat("Volume block size is {0} bytes", blockSize).AppendLine();
sbInformation.AppendFormat("Volume has {0} blocks", blocks).AppendLine();