Files
Aaru/Aaru.Images/DiscFerret/Read.cs

164 lines
6.2 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Read.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Reads DiscFerret flux images.
//
// --[ 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
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Console;
using Aaru.Helpers;
2020-02-27 00:33:26 +00:00
namespace Aaru.DiscImages
{
2020-07-22 13:20:25 +01:00
public sealed partial class DiscFerret
{
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
public ErrorNumber Open(IFilter imageFilter)
{
byte[] magicB = new byte[4];
Stream stream = imageFilter.GetDataForkStream();
stream.Read(magicB, 0, 4);
uint magic = BitConverter.ToUInt32(magicB, 0);
2020-02-29 18:03:35 +00:00
if(magic != DFI_MAGIC &&
magic != DFI_MAGIC2)
return ErrorNumber.InvalidArgument;
2018-06-22 08:08:38 +01:00
TrackOffsets = new SortedDictionary<int, long>();
TrackLengths = new SortedDictionary<int, long>();
int t = -1;
ushort lastCylinder = 0, lastHead = 0;
long offset = 0;
2017-12-19 20:33:03 +00:00
while(stream.Position < stream.Length)
{
long thisOffset = stream.Position;
byte[] blk = new byte[Marshal.SizeOf<BlockHeader>()];
stream.Read(blk, 0, Marshal.SizeOf<BlockHeader>());
BlockHeader blockHeader = Marshal.ByteArrayToStructureBigEndian<BlockHeader>(blk);
2020-02-27 23:48:41 +00:00
AaruConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.cylinder = {1}", thisOffset,
2020-02-29 18:03:35 +00:00
blockHeader.cylinder);
2020-02-27 23:48:41 +00:00
AaruConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.head = {1}", thisOffset, blockHeader.head);
2020-02-29 18:03:35 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.sector = {1}", thisOffset,
2020-02-29 18:03:35 +00:00
blockHeader.sector);
2020-02-27 23:48:41 +00:00
AaruConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.length = {1}", thisOffset,
2020-02-29 18:03:35 +00:00
blockHeader.length);
2017-12-19 20:33:03 +00:00
if(stream.Position + blockHeader.length > stream.Length)
{
2020-02-27 23:48:41 +00:00
AaruConsole.DebugWriteLine("DiscFerret plugin", "Invalid track block found at {0}", thisOffset);
2020-02-29 18:03:35 +00:00
break;
}
stream.Position += blockHeader.length;
2017-12-19 20:33:03 +00:00
2020-02-29 18:03:35 +00:00
if(blockHeader.cylinder > 0 &&
blockHeader.cylinder > lastCylinder)
{
lastCylinder = blockHeader.cylinder;
lastHead = 0;
TrackOffsets.Add(t, offset);
2021-08-17 14:27:19 +01:00
TrackLengths.Add(t, thisOffset - offset + 1);
offset = thisOffset;
t++;
}
2020-02-29 18:03:35 +00:00
else if(blockHeader.head > 0 &&
blockHeader.head > lastHead)
{
lastHead = blockHeader.head;
TrackOffsets.Add(t, offset);
2021-08-17 14:27:19 +01:00
TrackLengths.Add(t, thisOffset - offset + 1);
offset = thisOffset;
t++;
}
2020-07-20 21:11:32 +01:00
if(blockHeader.cylinder > _imageInfo.Cylinders)
_imageInfo.Cylinders = blockHeader.cylinder;
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
if(blockHeader.head > _imageInfo.Heads)
_imageInfo.Heads = blockHeader.head;
}
2020-07-20 21:11:32 +01:00
_imageInfo.Heads++;
_imageInfo.Cylinders++;
2020-07-20 21:11:32 +01:00
_imageInfo.Application = "DiscFerret";
_imageInfo.ApplicationVersion = magic == DFI_MAGIC2 ? "2.0" : "1.0";
AaruConsole.ErrorWriteLine("Flux decoding is not yet implemented.");
return ErrorNumber.NotImplemented;
}
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
{
buffer = null;
return ErrorNumber.NotImplemented;
}
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) => ReadSectors(sectorAddress, 1, out buffer);
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2018-12-31 13:17:27 +00:00
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) =>
throw new NotImplementedException("Flux decoding is not yet implemented.");
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
{
buffer = null;
return ErrorNumber.NotImplemented;
}
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2018-12-31 13:17:27 +00:00
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag) =>
throw new NotImplementedException("Flux decoding is not yet implemented.");
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2018-12-31 13:17:27 +00:00
public byte[] ReadSectorLong(ulong sectorAddress) =>
throw new NotImplementedException("Flux decoding is not yet implemented.");
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2018-12-31 13:17:27 +00:00
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
throw new NotImplementedException("Flux decoding is not yet implemented.");
}
}