2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-09 22:58:39 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Filename : Read.cs
|
2016-09-09 22:58:39 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2016-09-09 22:58:39 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads Apple Disk Archival/Retrieval Tool format.
|
2016-09-09 22:58:39 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2016-09-09 22:58:39 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2016-09-09 23:03:59 +01:00
|
|
|
|
using System.Text.RegularExpressions;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.Compression;
|
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
|
using Aaru.Helpers;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
using Claunia.Encoding;
|
|
|
|
|
|
using Claunia.RsrcFork;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Version = Resources.Version;
|
2016-09-09 22:58:39 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.DiscImages
|
2016-09-09 22:58:39 +01:00
|
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed partial class Dart
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-16 19:10:39 +01:00
|
|
|
|
public ErrorNumber Open(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(stream.Length < 84)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
2020-11-11 04:19:18 +00:00
|
|
|
|
byte[] headerB = new byte[Marshal.SizeOf<Header>()];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-11-11 04:19:18 +00:00
|
|
|
|
stream.Read(headerB, 0, Marshal.SizeOf<Header>());
|
|
|
|
|
|
Header header = Marshal.ByteArrayToStructureBigEndian<Header>(headerB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcCmp > COMPRESS_NONE)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.NotSupported;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
int expectedMaxSize = 84 + (header.srcSize * 2 * 524);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
switch(header.srcType)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case DISK_MAC:
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcSize != SIZE_MAC_SS &&
|
|
|
|
|
|
header.srcSize != SIZE_MAC)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case DISK_LISA:
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcSize != SIZE_LISA)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case DISK_APPLE2:
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcSize != DISK_APPLE2)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case DISK_MAC_HD:
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcSize != SIZE_MAC_HD)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
expectedMaxSize += 64;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case DISK_DOS:
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcSize != SIZE_DOS)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case DISK_DOS_HD:
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcSize != SIZE_DOS_HD)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
expectedMaxSize += 64;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2021-09-16 19:10:39 +01:00
|
|
|
|
default: return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(stream.Length > expectedMaxSize)
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.InvalidArgument;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
short[] bLength;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(header.srcType == DISK_MAC_HD ||
|
|
|
|
|
|
header.srcType == DISK_DOS_HD)
|
|
|
|
|
|
bLength = new short[BLOCK_ARRAY_LEN_HIGH];
|
|
|
|
|
|
else
|
|
|
|
|
|
bLength = new short[BLOCK_ARRAY_LEN_LOW];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < bLength.Length; i++)
|
|
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
byte[] tmpShort = new byte[2];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
stream.Read(tmpShort, 0, 2);
|
|
|
|
|
|
bLength[i] = BigEndianBitConverter.ToInt16(tmpShort, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var dataMs = new MemoryStream();
|
|
|
|
|
|
var tagMs = new MemoryStream();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
foreach(short l in bLength)
|
|
|
|
|
|
if(l != 0)
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
byte[] buffer = new byte[BUFFER_SIZE];
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
if(l == -1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
stream.Read(buffer, 0, BUFFER_SIZE);
|
|
|
|
|
|
dataMs.Write(buffer, 0, DATA_SIZE);
|
|
|
|
|
|
tagMs.Write(buffer, DATA_SIZE, TAG_SIZE);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
byte[] temp;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
if(header.srcCmp == COMPRESS_RLE)
|
|
|
|
|
|
{
|
|
|
|
|
|
temp = new byte[l * 2];
|
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
buffer = new byte[BUFFER_SIZE];
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-10-17 01:10:23 +01:00
|
|
|
|
AppleRle.DecodeBuffer(temp, buffer);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-01-21 15:58:12 +00:00
|
|
|
|
dataMs.Write(buffer, 0, DATA_SIZE);
|
|
|
|
|
|
tagMs.Write(buffer, DATA_SIZE, TAG_SIZE);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
temp = new byte[l];
|
|
|
|
|
|
stream.Read(temp, 0, temp.Length);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2021-09-21 04:55:28 +01:00
|
|
|
|
AaruConsole.ErrorWriteLine("LZH Compressed images not yet supported");
|
|
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NotImplemented;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dataCache = dataMs.ToArray();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
if(header.srcType == DISK_LISA ||
|
|
|
|
|
|
header.srcType == DISK_MAC ||
|
|
|
|
|
|
header.srcType == DISK_APPLE2)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ReadableSectorTags.Add(SectorTagType.AppleSectorTag);
|
|
|
|
|
|
_tagCache = tagMs.ToArray();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-09-15 11:25:26 +01:00
|
|
|
|
if(imageFilter.HasResourceFork)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var rsrcFork = new ResourceFork(imageFilter.GetResourceForkStream());
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
// "vers"
|
|
|
|
|
|
if(rsrcFork.ContainsKey(0x76657273))
|
|
|
|
|
|
{
|
|
|
|
|
|
Resource versRsrc = rsrcFork.GetResource(0x76657273);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
|
|
|
|
|
byte[] vers = versRsrc?.GetResource(versRsrc.GetIds()[0]);
|
|
|
|
|
|
|
|
|
|
|
|
if(vers != null)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var version = new Version(vers);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
|
|
|
|
|
string release = null;
|
2018-01-21 15:58:12 +00:00
|
|
|
|
string dev = null;
|
|
|
|
|
|
string pre = null;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
string major = $"{version.MajorVersion}";
|
|
|
|
|
|
string minor = $".{version.MinorVersion / 10}";
|
|
|
|
|
|
|
|
|
|
|
|
if(version.MinorVersion % 10 > 0)
|
|
|
|
|
|
release = $".{version.MinorVersion % 10}";
|
|
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
switch(version.DevStage)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-22 06:55:04 +00:00
|
|
|
|
case Version.DevelopmentStage.Alpha:
|
|
|
|
|
|
dev = "a";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case Version.DevelopmentStage.Beta:
|
|
|
|
|
|
dev = "b";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case Version.DevelopmentStage.PreAlpha:
|
|
|
|
|
|
dev = "d";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(dev == null &&
|
|
|
|
|
|
version.PreReleaseVersion > 0)
|
|
|
|
|
|
dev = "f";
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(dev != null)
|
|
|
|
|
|
pre = $"{version.PreReleaseVersion}";
|
2017-12-22 06:55:04 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
|
|
|
|
|
|
_imageInfo.Application = version.VersionString;
|
|
|
|
|
|
_imageInfo.Comments = version.VersionMessage;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// "dart"
|
|
|
|
|
|
if(rsrcFork.ContainsKey(0x44415254))
|
|
|
|
|
|
{
|
|
|
|
|
|
Resource dartRsrc = rsrcFork.GetResource(0x44415254);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(dartRsrc != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dArt = StringHandlers.PascalToString(dartRsrc.GetResource(dartRsrc.GetIds()[0]),
|
|
|
|
|
|
Encoding.GetEncoding("macintosh"));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
var dArtEx = new Regex(DART_REGEX);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Match dArtMatch = dArtEx.Match(dArt);
|
|
|
|
|
|
|
|
|
|
|
|
if(dArtMatch.Success)
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Application = "DART";
|
|
|
|
|
|
_imageInfo.ApplicationVersion = dArtMatch.Groups["version"].Value;
|
|
|
|
|
|
_dataChecksum = Convert.ToUInt32(dArtMatch.Groups["datachk"].Value, 16);
|
|
|
|
|
|
_tagChecksum = Convert.ToUInt32(dArtMatch.Groups["tagchk"].Value, 16);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// "cksm"
|
|
|
|
|
|
if(rsrcFork.ContainsKey(0x434B534D))
|
|
|
|
|
|
{
|
|
|
|
|
|
Resource cksmRsrc = rsrcFork.GetResource(0x434B534D);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 17:45:39 +00:00
|
|
|
|
if(cksmRsrc?.ContainsId(1) == true)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-21 17:45:39 +00:00
|
|
|
|
byte[] tagChk = cksmRsrc.GetResource(1);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_tagChecksum = BigEndianBitConverter.ToUInt32(tagChk, 0);
|
2017-12-21 17:45:39 +00:00
|
|
|
|
}
|
2018-01-21 15:58:12 +00:00
|
|
|
|
|
2017-12-21 17:45:39 +00:00
|
|
|
|
if(cksmRsrc?.ContainsId(2) == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] dataChk = cksmRsrc.GetResource(1);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_dataChecksum = BigEndianBitConverter.ToUInt32(dataChk, 0);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
catch(InvalidCastException) {}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine("DART plugin", "Image application = {0} version {1}", _imageInfo.Application,
|
|
|
|
|
|
_imageInfo.ApplicationVersion);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Sectors = (ulong)(header.srcSize * 2);
|
2021-09-15 11:25:26 +01:00
|
|
|
|
_imageInfo.CreationTime = imageFilter.CreationTime;
|
|
|
|
|
|
_imageInfo.LastModificationTime = imageFilter.LastWriteTime;
|
|
|
|
|
|
_imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.Filename);
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.SectorSize = SECTOR_SIZE;
|
|
|
|
|
|
_imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
|
|
|
|
|
_imageInfo.ImageSize = _imageInfo.Sectors * SECTOR_SIZE;
|
|
|
|
|
|
_imageInfo.Version = header.srcCmp == COMPRESS_NONE ? "1.4" : "1.5";
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
switch(header.srcSize)
|
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SIZE_MAC_SS:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Cylinders = 80;
|
|
|
|
|
|
_imageInfo.Heads = 1;
|
|
|
|
|
|
_imageInfo.SectorsPerTrack = 10;
|
|
|
|
|
|
_imageInfo.MediaType = MediaType.AppleSonySS;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SIZE_MAC:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Cylinders = 80;
|
|
|
|
|
|
_imageInfo.Heads = 2;
|
|
|
|
|
|
_imageInfo.SectorsPerTrack = 10;
|
|
|
|
|
|
_imageInfo.MediaType = MediaType.AppleSonyDS;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SIZE_DOS:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Cylinders = 80;
|
|
|
|
|
|
_imageInfo.Heads = 2;
|
|
|
|
|
|
_imageInfo.SectorsPerTrack = 9;
|
|
|
|
|
|
_imageInfo.MediaType = MediaType.DOS_35_DS_DD_9;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
case SIZE_MAC_HD:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.Cylinders = 80;
|
|
|
|
|
|
_imageInfo.Heads = 2;
|
|
|
|
|
|
_imageInfo.SectorsPerTrack = 18;
|
|
|
|
|
|
_imageInfo.MediaType = MediaType.DOS_35_HD;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.NoError;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
|
|
|
|
|
|
ReadSectors(sectorAddress, 1, out buffer);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-21 04:55:28 +01:00
|
|
|
|
public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer) =>
|
|
|
|
|
|
ReadSectorsTag(sectorAddress, 1, tag, out buffer);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2021-09-19 21:16:47 +01:00
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress > _imageInfo.Sectors - 1)
|
2021-09-19 21:16:47 +01:00
|
|
|
|
return ErrorNumber.OutOfRange;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _imageInfo.Sectors)
|
2021-09-19 21:16:47 +01:00
|
|
|
|
return ErrorNumber.OutOfRange;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
buffer = new byte[length * _imageInfo.SectorSize];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(_dataCache, (int)sectorAddress * _imageInfo.SectorSize, buffer, 0,
|
|
|
|
|
|
length * _imageInfo.SectorSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
return ErrorNumber.NoError;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-20 20:52:18 +01:00
|
|
|
|
public ErrorNumber ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag, out byte[] buffer)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2021-09-20 20:52:18 +01:00
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(tag != SectorTagType.AppleSectorTag)
|
2021-09-20 20:52:18 +01:00
|
|
|
|
return ErrorNumber.NotSupported;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_tagCache == null ||
|
|
|
|
|
|
_tagCache.Length == 0)
|
2021-09-20 20:52:18 +01:00
|
|
|
|
return ErrorNumber.NoData;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress > _imageInfo.Sectors - 1)
|
2021-09-20 20:52:18 +01:00
|
|
|
|
return ErrorNumber.OutOfRange;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _imageInfo.Sectors)
|
2021-09-20 20:52:18 +01:00
|
|
|
|
return ErrorNumber.OutOfRange;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-09-20 20:52:18 +01:00
|
|
|
|
buffer = new byte[length * TAG_SECTOR_SIZE];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(_tagCache, (int)sectorAddress * TAG_SECTOR_SIZE, buffer, 0, length * TAG_SECTOR_SIZE);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-09-20 20:52:18 +01:00
|
|
|
|
return ErrorNumber.NoError;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-20 14:22:22 +01:00
|
|
|
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
|
|
|
|
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-20 14:22:22 +01:00
|
|
|
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2021-09-20 14:22:22 +01:00
|
|
|
|
buffer = null;
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress > _imageInfo.Sectors - 1)
|
2021-09-20 14:22:22 +01:00
|
|
|
|
return ErrorNumber.OutOfRange;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _imageInfo.Sectors)
|
2021-09-20 14:22:22 +01:00
|
|
|
|
return ErrorNumber.OutOfRange;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ErrorNumber errno = ReadSectors(sectorAddress, length, out byte[] data);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
2021-09-20 14:22:22 +01:00
|
|
|
|
return errno;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2021-09-21 04:55:28 +01:00
|
|
|
|
errno = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag, out byte[] tags);
|
2021-09-20 20:52:18 +01:00
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return errno;
|
|
|
|
|
|
|
2021-09-20 14:22:22 +01:00
|
|
|
|
buffer = new byte[data.Length + tags.Length];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
for(uint i = 0; i < length; i++)
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(data, i * _imageInfo.SectorSize, buffer, i * (_imageInfo.SectorSize + TAG_SECTOR_SIZE),
|
|
|
|
|
|
_imageInfo.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
Array.Copy(tags, i * TAG_SECTOR_SIZE, buffer,
|
2020-07-20 21:11:32 +01:00
|
|
|
|
(i * (_imageInfo.SectorSize + TAG_SECTOR_SIZE)) + _imageInfo.SectorSize, TAG_SECTOR_SIZE);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-20 14:22:22 +01:00
|
|
|
|
return ErrorNumber.NoError;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-09-09 22:58:39 +01:00
|
|
|
|
}
|