2017-08-02 20:44:50 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Anex86.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2017-08-02 20:44:50 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages Anex86 disk images.
|
2017-08-02 20:44:50 +01: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-08-02 20:44:50 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-08-02 20:44:50 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.IO;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
using System.Linq;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-08-02 20:44:50 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using DiscImageChef.Console;
|
2017-08-02 20:44:50 +01:00
|
|
|
|
using DiscImageChef.Filters;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
2017-08-02 20:44:50 +01:00
|
|
|
|
{
|
2018-01-01 14:54:03 +00:00
|
|
|
|
public class Anex86 : IWritableImage
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-28 04:57:26 +00:00
|
|
|
|
IFilter anexImageFilter;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Anex86Header fdihdr;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
ImageInfo imageInfo;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
FileStream writingStream;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
public Anex86()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo = new ImageInfo
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-28 04:57:26 +00:00
|
|
|
|
ReadableSectorTags = new List<SectorTagType>(),
|
|
|
|
|
|
ReadableMediaTags = new List<MediaTagType>(),
|
|
|
|
|
|
HasPartitions = false,
|
|
|
|
|
|
HasSessions = false,
|
|
|
|
|
|
Version = null,
|
|
|
|
|
|
Application = null,
|
|
|
|
|
|
ApplicationVersion = null,
|
|
|
|
|
|
Creator = null,
|
|
|
|
|
|
Comments = null,
|
|
|
|
|
|
MediaManufacturer = null,
|
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
|
MediaSerialNumber = null,
|
|
|
|
|
|
MediaBarcode = null,
|
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
|
DriveSerialNumber = null,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DriveFirmwareRevision = null
|
2017-12-19 20:33:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public ImageInfo Info => imageInfo;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string Name => "Anex86 Disk Image";
|
2017-12-28 04:57:26 +00:00
|
|
|
|
public Guid Id => new Guid("0410003E-6E7B-40E6-9328-BA5651ADF6B7");
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public string Format => "Anex86 disk image";
|
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-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
fdihdr = new Anex86Header();
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < Marshal.SizeOf(fdihdr)) return false;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] hdrB = new byte[Marshal.SizeOf(fdihdr)];
|
|
|
|
|
|
stream.Read(hdrB, 0, hdrB.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);
|
2017-12-28 04:57:26 +00:00
|
|
|
|
fdihdr = (Anex86Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Anex86Header));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
handle.Free();
|
|
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.unknown = {0}", fdihdr.unknown);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.hddtype = {0}", fdihdr.hddtype);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.hdrSize = {0}", fdihdr.hdrSize);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.dskSize = {0}", fdihdr.dskSize);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.bps = {0}", fdihdr.bps);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.spt = {0}", fdihdr.spt);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.heads = {0}", fdihdr.heads);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "fdihdr.cylinders = {0}", fdihdr.cylinders);
|
|
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
return stream.Length == fdihdr.hdrSize + fdihdr.dskSize &&
|
2017-12-19 20:33:03 +00:00
|
|
|
|
fdihdr.dskSize == fdihdr.bps * fdihdr.spt * fdihdr.heads * fdihdr.cylinders;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
fdihdr = new Anex86Header();
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < Marshal.SizeOf(fdihdr)) return false;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] hdrB = new byte[Marshal.SizeOf(fdihdr)];
|
|
|
|
|
|
stream.Read(hdrB, 0, hdrB.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);
|
2017-12-28 04:57:26 +00:00
|
|
|
|
fdihdr = (Anex86Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Anex86Header));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
handle.Free();
|
|
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.MediaType =
|
|
|
|
|
|
Geometry.GetMediaType(((ushort)fdihdr.cylinders, (byte)fdihdr.heads, (ushort)fdihdr.spt,
|
|
|
|
|
|
(uint)fdihdr.bps, MediaEncoding.MFM, false));
|
|
|
|
|
|
if(imageInfo.MediaType == MediaType.Unknown) imageInfo.MediaType = MediaType.GENERIC_HDD;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Anex86 plugin", "MediaType: {0}", imageInfo.MediaType);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.ImageSize = (ulong)fdihdr.dskSize;
|
|
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
|
|
|
|
|
|
imageInfo.Sectors = (ulong)(fdihdr.cylinders * fdihdr.heads * fdihdr.spt);
|
|
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
|
|
|
|
|
imageInfo.SectorSize = (uint)fdihdr.bps;
|
|
|
|
|
|
imageInfo.Cylinders = (uint)fdihdr.cylinders;
|
|
|
|
|
|
imageInfo.Heads = (uint)fdihdr.heads;
|
|
|
|
|
|
imageInfo.SectorsPerTrack = (uint)fdihdr.spt;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
anexImageFilter = imageFilter;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
byte[] buffer = new byte[length * imageInfo.SectorSize];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
Stream stream = anexImageFilter.GetDataForkStream();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
stream.Seek((long)((ulong)fdihdr.hdrSize + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
stream.Read(buffer, 0, (int)(length * imageInfo.SectorSize));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +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-19 20:33:03 +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, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +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-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +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-19 20:33:03 +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-19 20:33:03 +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-19 20:33:03 +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-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +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, out List<ulong> failingLbas,
|
2017-12-28 04:57:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
2017-12-28 04:57:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifyMediaImage()
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
2018-01-01 14:54:03 +00:00
|
|
|
|
public IEnumerable<MediaTagType> SupportedMediaTags => new MediaTagType[] { };
|
|
|
|
|
|
public IEnumerable<SectorTagType> SupportedSectorTags => new SectorTagType[] { };
|
|
|
|
|
|
// TODO: Test with real hardware to see real supported media
|
|
|
|
|
|
public IEnumerable<MediaType> SupportedMediaTypes =>
|
|
|
|
|
|
new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
MediaType.IBM23FD, MediaType.ECMA_66, MediaType.DOS_525_SS_DD_8, MediaType.DOS_525_SS_DD_9,
|
|
|
|
|
|
MediaType.ACORN_525_SS_SD_40, MediaType.ACORN_525_SS_DD_40, MediaType.ATARI_525_SD,
|
|
|
|
|
|
MediaType.ATARI_525_DD, MediaType.ATARI_525_ED, MediaType.DOS_525_DS_DD_8, MediaType.DOS_525_DS_DD_9,
|
|
|
|
|
|
MediaType.ECMA_70, MediaType.Apricot_35, MediaType.RX01, MediaType.RX02, MediaType.NEC_525_HD,
|
|
|
|
|
|
MediaType.ECMA_99_15, MediaType.NEC_8_SD, MediaType.RX03, MediaType.DOS_35_SS_DD_8,
|
|
|
|
|
|
MediaType.DOS_35_SS_DD_9, MediaType.ACORN_525_SS_SD_80, MediaType.RX50, MediaType.ATARI_35_SS_DD_11,
|
|
|
|
|
|
MediaType.ACORN_525_SS_DD_80, MediaType.ACORN_35_DS_DD, MediaType.DOS_35_DS_DD_8,
|
|
|
|
|
|
MediaType.DOS_35_DS_DD_9, MediaType.ACORN_35_DS_HD, MediaType.DOS_525_HD, MediaType.ACORN_525_DS_DD,
|
|
|
|
|
|
MediaType.DOS_35_HD, MediaType.XDF_525, MediaType.DMF, MediaType.XDF_35, MediaType.DOS_35_ED,
|
|
|
|
|
|
MediaType.FDFORMAT_35_DD, MediaType.FDFORMAT_525_HD, MediaType.FDFORMAT_35_HD, MediaType.NEC_35_TD,
|
2018-01-18 23:18:56 +00:00
|
|
|
|
MediaType.Unknown, MediaType.GENERIC_HDD, MediaType.FlashDrive, MediaType.CompactFlash,
|
|
|
|
|
|
MediaType.CompactFlashType2, MediaType.PCCardTypeI, MediaType.PCCardTypeII, MediaType.PCCardTypeIII,
|
|
|
|
|
|
MediaType.PCCardTypeIV
|
2018-01-01 14:54:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
|
|
|
|
|
new(string name, Type type, string description)[] { };
|
|
|
|
|
|
public IEnumerable<string> KnownExtensions => new[] {".fdi", ".hdi"};
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsWriting { get; private set; }
|
|
|
|
|
|
public string ErrorMessage { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
|
|
|
|
|
uint sectorSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sectorSize == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Unsupported sector size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sectors * sectorSize > int.MaxValue || sectors > (long)int.MaxValue * 8 * 33)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = $"Too many sectors";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!SupportedMediaTypes.Contains(mediaType))
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = $"Unsupport media format {mediaType}";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
imageInfo = new ImageInfo {MediaType = mediaType, SectorSize = sectorSize, Sectors = sectors};
|
|
|
|
|
|
|
2018-01-18 23:18:56 +00:00
|
|
|
|
try { writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); }
|
2018-01-01 14:54:03 +00:00
|
|
|
|
catch(IOException e)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = $"Could not create new image file, exception {e.Message}";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
fdihdr = new Anex86Header {hdrSize = 4096, dskSize = (int)(sectors * sectorSize), bps = (int)sectorSize};
|
2018-01-01 14:54:03 +00:00
|
|
|
|
|
|
|
|
|
|
IsWriting = true;
|
|
|
|
|
|
ErrorMessage = null;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteMediaTag(byte[] data, MediaTagType tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Writing media tags is not supported.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSector(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write on a non-writable image";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(data.Length != imageInfo.SectorSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Incorrect data size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress >= imageInfo.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write past image size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
writingStream.Seek((long)(4096 + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
|
|
|
|
|
writingStream.Write(data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write on a non-writable image";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(data.Length % imageInfo.SectorSize != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Incorrect data size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write past image size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
writingStream.Seek((long)(4096 + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
|
|
|
|
|
writingStream.Write(data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Writing sectors with tags is not supported.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Writing sectors with tags is not supported.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool SetTracks(List<Track> tracks)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Unsupported feature";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Close()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Image is not opened for writing";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-18 23:18:56 +00:00
|
|
|
|
if((imageInfo.MediaType == MediaType.Unknown || imageInfo.MediaType == MediaType.GENERIC_HDD ||
|
|
|
|
|
|
imageInfo.MediaType == MediaType.FlashDrive || imageInfo.MediaType == MediaType.CompactFlash ||
|
|
|
|
|
|
imageInfo.MediaType == MediaType.CompactFlashType2 || imageInfo.MediaType == MediaType.PCCardTypeI ||
|
|
|
|
|
|
imageInfo.MediaType == MediaType.PCCardTypeII || imageInfo.MediaType == MediaType.PCCardTypeIII ||
|
|
|
|
|
|
imageInfo.MediaType == MediaType.PCCardTypeIV) && fdihdr.cylinders == 0)
|
2018-01-01 14:54:03 +00:00
|
|
|
|
{
|
2018-01-01 20:56:33 +00:00
|
|
|
|
fdihdr.cylinders = (int)(imageInfo.Sectors / 8 / 33);
|
|
|
|
|
|
fdihdr.heads = 8;
|
|
|
|
|
|
fdihdr.spt = 33;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
while(fdihdr.cylinders == 0)
|
2018-01-01 14:54:03 +00:00
|
|
|
|
{
|
2018-01-01 20:56:33 +00:00
|
|
|
|
fdihdr.heads--;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
if(fdihdr.heads == 0)
|
2018-01-01 14:54:03 +00:00
|
|
|
|
{
|
2018-01-01 20:56:33 +00:00
|
|
|
|
fdihdr.spt--;
|
|
|
|
|
|
fdihdr.heads = 8;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
fdihdr.cylinders = (int)imageInfo.Sectors / fdihdr.heads / fdihdr.spt;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
if(fdihdr.cylinders == 0 && fdihdr.heads == 0 && fdihdr.spt == 0) break;
|
2018-01-01 14:54:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte[] hdr = new byte[Marshal.SizeOf(fdihdr)];
|
|
|
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fdihdr));
|
|
|
|
|
|
Marshal.StructureToPtr(fdihdr, hdrPtr, true);
|
|
|
|
|
|
Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
|
|
|
|
|
Marshal.FreeHGlobal(hdrPtr);
|
|
|
|
|
|
|
|
|
|
|
|
writingStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
writingStream.Write(hdr, 0, hdr.Length);
|
|
|
|
|
|
|
|
|
|
|
|
writingStream.Flush();
|
|
|
|
|
|
writingStream.Close();
|
|
|
|
|
|
|
2018-01-18 23:18:56 +00:00
|
|
|
|
IsWriting = false;
|
|
|
|
|
|
ErrorMessage = "";
|
2018-01-01 14:54:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool SetMetadata(ImageInfo metadata)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
public bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(cylinders > int.MaxValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Too many cylinders.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(heads > int.MaxValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Too many heads.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorsPerTrack > int.MaxValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Too many sectors per track.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fdihdr.spt = (int)sectorsPerTrack;
|
|
|
|
|
|
fdihdr.heads = (int)heads;
|
|
|
|
|
|
fdihdr.cylinders = (int)cylinders;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 22:19:31 +00:00
|
|
|
|
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Unsupported feature";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Unsupported feature";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct Anex86Header
|
|
|
|
|
|
{
|
|
|
|
|
|
public int unknown;
|
|
|
|
|
|
public int hddtype;
|
|
|
|
|
|
public int hdrSize;
|
|
|
|
|
|
public int dskSize;
|
|
|
|
|
|
public int bps;
|
|
|
|
|
|
public int spt;
|
|
|
|
|
|
public int heads;
|
|
|
|
|
|
public int cylinders;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
2017-08-02 20:44:50 +01:00
|
|
|
|
}
|