2017-12-05 00:07:36 +00:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-12-05 00:07:36 +00:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Filename : Read.cs
|
2017-12-05 00:07:36 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2017-12-05 00:07:36 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads DiscFerret flux images.
|
2017-12-05 00:07:36 +00: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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2017-12-05 00:07:36 +00:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
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.Helpers;
|
2025-08-17 05:50:25 +01:00
|
|
|
|
using Aaru.Logging;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2023-10-06 01:16:28 +01:00
|
|
|
|
namespace Aaru.Images;
|
2022-11-15 15:58:43 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public sealed partial class DiscFerret
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2023-10-03 23:34:59 +01:00
|
|
|
|
#region IMediaImage Members
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber Open(IFilter imageFilter)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2025-10-21 10:34:36 +01:00
|
|
|
|
var magicB = new byte[4];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2022-11-14 09:43:16 +00:00
|
|
|
|
stream.EnsureRead(magicB, 0, 4);
|
2025-10-21 10:34:36 +01:00
|
|
|
|
var magic = BitConverter.ToUInt32(magicB, 0);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(magic != DFI_MAGIC && magic != DFI_MAGIC2) return ErrorNumber.InvalidArgument;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
TrackOffsets = new SortedDictionary<int, long>();
|
|
|
|
|
|
TrackLengths = new SortedDictionary<int, long>();
|
|
|
|
|
|
int t = -1;
|
|
|
|
|
|
ushort lastCylinder = 0, lastHead = 0;
|
|
|
|
|
|
long offset = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while(stream.Position < stream.Length)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
long thisOffset = stream.Position;
|
|
|
|
|
|
|
2025-10-21 10:34:36 +01:00
|
|
|
|
var blk = new byte[Marshal.SizeOf<BlockHeader>()];
|
2022-11-14 09:43:16 +00:00
|
|
|
|
stream.EnsureRead(blk, 0, Marshal.SizeOf<BlockHeader>());
|
2025-10-21 10:34:36 +01:00
|
|
|
|
BlockHeader blockHeader = Marshal.ByteArrayToStructureBigEndianGenerated<BlockHeader>(blk);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "block@{0}.cylinder = {1}", thisOffset, blockHeader.cylinder);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "block@{0}.head = {1}", thisOffset, blockHeader.head);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "block@{0}.sector = {1}", thisOffset, blockHeader.sector);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, "block@{0}.length = {1}", thisOffset, blockHeader.length);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
if(stream.Position + blockHeader.length > stream.Length)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.Invalid_track_block_found_at_0, thisOffset);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
stream.Position += blockHeader.length;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
if(blockHeader.cylinder > 0 && blockHeader.cylinder > lastCylinder)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
lastCylinder = blockHeader.cylinder;
|
|
|
|
|
|
lastHead = 0;
|
|
|
|
|
|
TrackOffsets.Add(t, offset);
|
|
|
|
|
|
TrackLengths.Add(t, thisOffset - offset + 1);
|
|
|
|
|
|
offset = thisOffset;
|
|
|
|
|
|
t++;
|
|
|
|
|
|
}
|
2023-10-04 17:34:40 +01:00
|
|
|
|
else if(blockHeader.head > 0 && blockHeader.head > lastHead)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
lastHead = blockHeader.head;
|
|
|
|
|
|
TrackOffsets.Add(t, offset);
|
|
|
|
|
|
TrackLengths.Add(t, thisOffset - offset + 1);
|
|
|
|
|
|
offset = thisOffset;
|
|
|
|
|
|
t++;
|
|
|
|
|
|
}
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(blockHeader.cylinder > _imageInfo.Cylinders) _imageInfo.Cylinders = blockHeader.cylinder;
|
2021-09-16 19:10:39 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(blockHeader.head > _imageInfo.Heads) _imageInfo.Heads = blockHeader.head;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.Heads++;
|
|
|
|
|
|
_imageInfo.Cylinders++;
|
2021-09-18 15:01:31 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.Application = "DiscFerret";
|
|
|
|
|
|
_imageInfo.ApplicationVersion = magic == DFI_MAGIC2 ? "2.0" : "1.0";
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Error(Localization.Flux_decoding_is_not_yet_implemented);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return ErrorNumber.NotImplemented;
|
|
|
|
|
|
}
|
2021-09-20 20:52:18 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer = null;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return ErrorNumber.NotImplemented;
|
|
|
|
|
|
}
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
|
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) => ReadSectors(sectorAddress, 1, out buffer);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer = null;
|
2021-09-20 20:52:18 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return ErrorNumber.NotImplemented;
|
|
|
|
|
|
}
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer = null;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return ErrorNumber.NotImplemented;
|
|
|
|
|
|
}
|
2021-09-20 14:22:22 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag, out byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
|
|
|
|
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NotImplemented;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|
2023-10-03 23:34:59 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|