2017-12-05 00:07:36 +00:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : DiscFerret.cs
|
|
|
|
|
|
// 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 ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-12-05 00:07:36 +00:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
using DiscImageChef.Filters;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class DiscFerret : IMediaImage
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2017-12-24 00:12:31 +00:00
|
|
|
|
/// "DFER"
|
2017-12-05 00:07:36 +00:00
|
|
|
|
/// </summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
|
const uint DFI_MAGIC = 0x52454644;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
/// <summary>
|
2017-12-24 00:12:31 +00:00
|
|
|
|
/// "DFE2"
|
2017-12-05 00:07:36 +00:00
|
|
|
|
/// </summary>
|
2017-12-20 17:15:26 +00:00
|
|
|
|
const uint DFI_MAGIC2 = 0x32454644;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ImageInfo imageInfo;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
// TODO: These variables have been made public so create-sidecar can access to this information until I define an API >4.0
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public SortedDictionary<int, long> TrackLengths;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
public SortedDictionary<int, long> TrackOffsets;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
|
|
|
|
|
public DiscFerret()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo = new ImageInfo
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
ReadableSectorTags = new List<SectorTagType>(),
|
|
|
|
|
|
ReadableMediaTags = new List<MediaTagType>(),
|
2017-12-26 02:51:10 +00:00
|
|
|
|
HasPartitions = false,
|
|
|
|
|
|
HasSessions = false,
|
|
|
|
|
|
Version = null,
|
|
|
|
|
|
Application = null,
|
|
|
|
|
|
ApplicationVersion = null,
|
|
|
|
|
|
Creator = null,
|
|
|
|
|
|
Comments = null,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
MediaManufacturer = null,
|
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
|
MediaSerialNumber = null,
|
|
|
|
|
|
MediaBarcode = null,
|
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
|
DriveSerialNumber = null,
|
|
|
|
|
|
DriveFirmwareRevision = null
|
2017-12-05 00:07:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string Name => "DiscFerret";
|
|
|
|
|
|
public Guid Id => new Guid("70EA7B9B-5323-42EB-9B40-8DDA37C5EB4D");
|
|
|
|
|
|
public ImageInfo Info => imageInfo;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public string Format => "DiscFerret";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Partition> Partitions =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> Tracks =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Session> Sessions =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Identify(IFilter imageFilter)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] magicB = new byte[4];
|
2017-12-05 00:07:36 +00:00
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2017-12-20 17:15:26 +00:00
|
|
|
|
stream.Read(magicB, 0, 4);
|
|
|
|
|
|
uint magic = BitConverter.ToUInt32(magicB, 0);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
return magic == DFI_MAGIC || magic == DFI_MAGIC2;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] magicB = new byte[4];
|
2017-12-05 00:07:36 +00:00
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
2017-12-20 17:15:26 +00:00
|
|
|
|
stream.Read(magicB, 0, 4);
|
|
|
|
|
|
uint magic = BitConverter.ToUInt32(magicB, 0);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(magic != DFI_MAGIC && magic != DFI_MAGIC2) return false;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
TrackOffsets = new SortedDictionary<int, long>();
|
|
|
|
|
|
TrackLengths = new SortedDictionary<int, long>();
|
2017-12-05 00:07:36 +00:00
|
|
|
|
int t = -1;
|
|
|
|
|
|
ushort lastCylinder = 0, lastHead = 0;
|
|
|
|
|
|
long offset = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-05 00:07:36 +00:00
|
|
|
|
while(stream.Position < stream.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
long thisOffset = stream.Position;
|
|
|
|
|
|
|
|
|
|
|
|
DfiBlockHeader blockHeader = new DfiBlockHeader();
|
|
|
|
|
|
byte[] blk = new byte[Marshal.SizeOf(blockHeader)];
|
|
|
|
|
|
stream.Read(blk, 0, Marshal.SizeOf(blockHeader));
|
|
|
|
|
|
blockHeader = BigEndianMarshal.ByteArrayToStructureBigEndian<DfiBlockHeader>(blk);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.cylinder = {1}", thisOffset,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
blockHeader.cylinder);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
DicConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.head = {1}", thisOffset, blockHeader.head);
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.sector = {1}", thisOffset,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
blockHeader.sector);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
DicConsole.DebugWriteLine("DiscFerret plugin", "block@{0}.length = {1}", thisOffset,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
blockHeader.length);
|
|
|
|
|
|
|
2017-12-05 00:07:36 +00:00
|
|
|
|
if(stream.Position + blockHeader.length > stream.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("DiscFerret plugin", "Invalid track block found at {0}", thisOffset);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stream.Position += blockHeader.length;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-05 00:07:36 +00:00
|
|
|
|
if(blockHeader.cylinder > 0 && blockHeader.cylinder > lastCylinder)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastCylinder = blockHeader.cylinder;
|
|
|
|
|
|
lastHead = 0;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
TrackOffsets.Add(t, offset);
|
|
|
|
|
|
TrackLengths.Add(t, thisOffset - offset + 1);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
offset = thisOffset;
|
|
|
|
|
|
t++;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(blockHeader.head > 0 && blockHeader.head > lastHead)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastHead = blockHeader.head;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
TrackOffsets.Add(t, offset);
|
|
|
|
|
|
TrackLengths.Add(t, thisOffset - offset + 1);
|
2017-12-05 00:07:36 +00:00
|
|
|
|
offset = thisOffset;
|
|
|
|
|
|
t++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(blockHeader.cylinder > imageInfo.Cylinders) imageInfo.Cylinders = blockHeader.cylinder;
|
|
|
|
|
|
if(blockHeader.head > imageInfo.Heads) imageInfo.Heads = blockHeader.head;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Heads++;
|
|
|
|
|
|
imageInfo.Cylinders++;
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Application = "DiscFerret";
|
|
|
|
|
|
imageInfo.ApplicationVersion = magic == DFI_MAGIC2 ? "2.0" : "1.0";
|
2017-12-05 00:07:36 +00:00
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifyMediaImage()
|
2017-12-05 00:07:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct DfiBlockHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
public ushort cylinder;
|
|
|
|
|
|
public ushort head;
|
|
|
|
|
|
public ushort sector;
|
|
|
|
|
|
public uint length;
|
|
|
|
|
|
}
|
2017-12-05 00:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|