2017-09-22 23:02:30 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Apridisk.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2017-09-22 23:02:30 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages Apridisk images.
|
2017-09-22 23:02:30 +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-09-22 23:02:30 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-09-22 23:02:30 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
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-09-22 23:02:30 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class Apridisk : IMediaImage
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
readonly byte[] signature =
|
|
|
|
|
|
{
|
|
|
|
|
|
0x41, 0x43, 0x54, 0x20, 0x41, 0x70, 0x72, 0x69, 0x63, 0x6F, 0x74, 0x20, 0x64, 0x69, 0x73, 0x6B, 0x20, 0x69,
|
|
|
|
|
|
0x6D, 0x61, 0x67, 0x65, 0x1A, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00
|
|
|
|
|
|
};
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ImageInfo imageInfo;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
// Cylinder by head, sector data matrix
|
|
|
|
|
|
byte[][][][] sectorsData;
|
|
|
|
|
|
|
|
|
|
|
|
public Apridisk()
|
|
|
|
|
|
{
|
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 => "ACT Apricot Disk Image";
|
2017-12-28 04:57:26 +00:00
|
|
|
|
public Guid Id => new Guid("43408CF3-6DB3-449F-A779-2B0E497C5B14");
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public string Format => "ACT Apricot 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);
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < signature.Length) return false;
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] sigB = new byte[signature.Length];
|
|
|
|
|
|
stream.Read(sigB, 0, signature.Length);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
return sigB.SequenceEqual(signature);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip signature
|
|
|
|
|
|
stream.Seek(signature.Length, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
int totalCylinders = -1;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
int totalHeads = -1;
|
|
|
|
|
|
int maxSector = -1;
|
|
|
|
|
|
int recordSize = Marshal.SizeOf(typeof(ApridiskRecord));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
// Count cylinders
|
|
|
|
|
|
while(stream.Position < stream.Length)
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] recB = new byte[recordSize];
|
|
|
|
|
|
stream.Read(recB, 0, recordSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
GCHandle handle = GCHandle.Alloc(recB, GCHandleType.Pinned);
|
2017-12-24 00:12:31 +00:00
|
|
|
|
ApridiskRecord record =
|
|
|
|
|
|
(ApridiskRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ApridiskRecord));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
handle.Free();
|
|
|
|
|
|
|
|
|
|
|
|
switch(record.type)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Deleted record, just skip it
|
|
|
|
|
|
case RecordType.Deleted:
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Found deleted record at {0}", stream.Position);
|
2017-12-20 17:26:28 +00:00
|
|
|
|
stream.Seek(record.headerSize - recordSize + record.dataSize, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case RecordType.Comment:
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Found comment record at {0}", stream.Position);
|
|
|
|
|
|
stream.Seek(record.headerSize - recordSize, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] commentB = new byte[record.dataSize];
|
|
|
|
|
|
stream.Read(commentB, 0, commentB.Length);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Comments = StringHandlers.CToString(commentB);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Comment: \"{0}\"", imageInfo.Comments);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case RecordType.Creator:
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Found creator record at {0}", stream.Position);
|
|
|
|
|
|
stream.Seek(record.headerSize - recordSize, SeekOrigin.Current);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] creatorB = new byte[record.dataSize];
|
|
|
|
|
|
stream.Read(creatorB, 0, creatorB.Length);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Creator = StringHandlers.CToString(creatorB);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Creator: \"{0}\"", imageInfo.Creator);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case RecordType.Sector:
|
|
|
|
|
|
if(record.compression != CompressType.Compressed &&
|
|
|
|
|
|
record.compression != CompressType.Uncompresed)
|
|
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
ImageNotSupportedException($"Found record with unknown compression type 0x{(ushort)record.compression:X4} at {stream.Position}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin",
|
|
|
|
|
|
"Found {4} sector record at {0} for cylinder {1} head {2} sector {3}",
|
|
|
|
|
|
stream.Position, record.cylinder, record.head, record.sector,
|
|
|
|
|
|
record.compression == CompressType.Compressed
|
|
|
|
|
|
? "compressed"
|
|
|
|
|
|
: "uncompressed");
|
|
|
|
|
|
|
|
|
|
|
|
if(record.cylinder > totalCylinders) totalCylinders = record.cylinder;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
if(record.head > totalHeads) totalHeads = record.head;
|
|
|
|
|
|
if(record.sector > maxSector) maxSector = record.sector;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
stream.Seek(record.headerSize - recordSize + record.dataSize, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new
|
2017-12-21 17:58:51 +00:00
|
|
|
|
ImageNotSupportedException($"Found record with unknown type 0x{(uint)record.type:X8} at {stream.Position}");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
totalCylinders++;
|
|
|
|
|
|
totalHeads++;
|
|
|
|
|
|
|
|
|
|
|
|
if(totalCylinders <= 0 || totalHeads <= 0)
|
|
|
|
|
|
throw new ImageNotSupportedException("No cylinders or heads found");
|
|
|
|
|
|
|
|
|
|
|
|
sectorsData = new byte[totalCylinders][][][];
|
|
|
|
|
|
// Total sectors per track
|
|
|
|
|
|
uint[][] spts = new uint[totalCylinders][];
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Cylinders = (ushort)totalCylinders;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.Heads = (byte)totalHeads;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin",
|
|
|
|
|
|
"Found {0} cylinders and {1} heads with a maximum sector number of {2}",
|
|
|
|
|
|
totalCylinders, totalHeads, maxSector);
|
|
|
|
|
|
|
|
|
|
|
|
// Create heads
|
|
|
|
|
|
for(int i = 0; i < totalCylinders; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sectorsData[i] = new byte[totalHeads][][];
|
2017-12-28 04:57:26 +00:00
|
|
|
|
spts[i] = new uint[totalHeads];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
for(int j = 0; j < totalHeads; j++) sectorsData[i][j] = new byte[maxSector + 1][];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.SectorSize = uint.MaxValue;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
ulong headersizes = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Read sectors
|
|
|
|
|
|
stream.Seek(signature.Length, SeekOrigin.Begin);
|
|
|
|
|
|
while(stream.Position < stream.Length)
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] recB = new byte[recordSize];
|
|
|
|
|
|
stream.Read(recB, 0, recordSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
GCHandle handle = GCHandle.Alloc(recB, GCHandleType.Pinned);
|
2017-12-24 00:12:31 +00:00
|
|
|
|
ApridiskRecord record =
|
|
|
|
|
|
(ApridiskRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ApridiskRecord));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
handle.Free();
|
|
|
|
|
|
|
|
|
|
|
|
switch(record.type)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Not sector record, just skip it
|
|
|
|
|
|
case RecordType.Deleted:
|
|
|
|
|
|
case RecordType.Comment:
|
|
|
|
|
|
case RecordType.Creator:
|
2017-12-28 04:57:26 +00:00
|
|
|
|
stream.Seek(record.headerSize - recordSize + record.dataSize, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
headersizes += record.headerSize + record.dataSize;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case RecordType.Sector:
|
|
|
|
|
|
stream.Seek(record.headerSize - recordSize, SeekOrigin.Current);
|
|
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[record.dataSize];
|
|
|
|
|
|
stream.Read(data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
|
|
spts[record.cylinder][record.head]++;
|
|
|
|
|
|
uint realLength = record.dataSize;
|
|
|
|
|
|
|
|
|
|
|
|
if(record.compression == CompressType.Compressed)
|
2017-12-28 04:57:26 +00:00
|
|
|
|
realLength =
|
|
|
|
|
|
Decompress(data, out sectorsData[record.cylinder][record.head][record.sector]);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else sectorsData[record.cylinder][record.head][record.sector] = data;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(realLength < imageInfo.SectorSize) imageInfo.SectorSize = realLength;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
headersizes += record.headerSize + record.dataSize;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Found a minimum of {0} bytes per sector",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.SectorSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
// Count sectors per track
|
|
|
|
|
|
uint spt = uint.MaxValue;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
for(ushort cyl = 0; cyl < imageInfo.Cylinders; cyl++)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-28 04:57:26 +00:00
|
|
|
|
for(ushort head = 0; head < imageInfo.Heads; head++)
|
|
|
|
|
|
if(spts[cyl][head] < spt)
|
|
|
|
|
|
spt = spts[cyl][head];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.SectorsPerTrack = spt;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Apridisk plugin", "Found a minimum of {0} sectors per track",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.SectorsPerTrack);
|
|
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.MediaType =
|
|
|
|
|
|
Geometry.GetMediaType(((ushort)imageInfo.Cylinders, (byte)imageInfo.Heads,
|
|
|
|
|
|
(ushort)imageInfo.SectorsPerTrack, 512, MediaEncoding.MFM, false));
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.ImageSize = (ulong)stream.Length - headersizes;
|
|
|
|
|
|
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 = imageInfo.Cylinders * imageInfo.Heads * imageInfo.SectorsPerTrack;
|
|
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
(ushort cylinder, byte head, byte sector) = LbaToChs(sectorAddress);
|
|
|
|
|
|
|
|
|
|
|
|
if(cylinder >= sectorsData.Length)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
|
|
|
|
|
if(head >= sectorsData[cylinder].Length)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
|
|
|
|
|
if(sector > sectorsData[cylinder][head].Length)
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
|
|
|
|
|
return sectorsData[cylinder][head][sector];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
|
|
MemoryStream buffer = new MemoryStream();
|
|
|
|
|
|
for(uint i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] sector = ReadSector(sectorAddress + i);
|
|
|
|
|
|
buffer.Write(sector, 0, sector.Length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buffer.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
static uint Decompress(byte[] compressed, out byte[] decompressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
int readp = 0;
|
|
|
|
|
|
int cLen = compressed.Length;
|
|
|
|
|
|
MemoryStream buffer = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
|
|
uint uLen = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while(cLen >= 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
ushort blklen = BitConverter.ToUInt16(compressed, readp);
|
|
|
|
|
|
readp += 2;
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < blklen; i++) buffer.WriteByte(compressed[readp]);
|
|
|
|
|
|
|
|
|
|
|
|
uLen += blklen;
|
|
|
|
|
|
readp++;
|
|
|
|
|
|
cLen -= 3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decompressed = buffer.ToArray();
|
|
|
|
|
|
return uLen;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(ushort cylinder, byte head, byte sector) LbaToChs(ulong lba)
|
|
|
|
|
|
{
|
|
|
|
|
|
ushort cylinder = (ushort)(lba / (imageInfo.Heads * imageInfo.SectorsPerTrack));
|
|
|
|
|
|
byte head = (byte)(lba / imageInfo.SectorsPerTrack % imageInfo.Heads);
|
|
|
|
|
|
byte sector = (byte)(lba % imageInfo.SectorsPerTrack + 1);
|
|
|
|
|
|
|
|
|
|
|
|
return (cylinder, head, sector);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
enum RecordType : uint
|
|
|
|
|
|
{
|
|
|
|
|
|
Deleted = 0xE31D0000,
|
2017-12-28 04:57:26 +00:00
|
|
|
|
Sector = 0xE31D0001,
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Comment = 0xE31D0002,
|
|
|
|
|
|
Creator = 0xE31D0003
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum CompressType : ushort
|
|
|
|
|
|
{
|
|
|
|
|
|
Uncompresed = 0x9E90,
|
2017-12-28 04:57:26 +00:00
|
|
|
|
Compressed = 0x3E5A
|
2017-12-24 00:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct ApridiskRecord
|
|
|
|
|
|
{
|
2017-12-28 04:57:26 +00:00
|
|
|
|
public RecordType type;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
public CompressType compression;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
public ushort headerSize;
|
|
|
|
|
|
public uint dataSize;
|
|
|
|
|
|
public byte head;
|
|
|
|
|
|
public byte sector;
|
|
|
|
|
|
public ushort cylinder;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
2017-09-22 23:02:30 +01:00
|
|
|
|
}
|