2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-07-28 18:13:49 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Atari.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Partitioning scheme plugins.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Manages Atari ST GEMDOS partitions.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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-12-03 16:07:10 +00:00
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
2015-04-20 16:38:13 +01:00
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.Checksums;
|
|
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.Console;
|
2020-07-20 15:43:52 +01:00
|
|
|
using Aaru.Helpers;
|
2022-02-06 23:44:33 +00:00
|
|
|
using Spectre.Console;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Partitions;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>Implements decoding of Atari GEMDOS partitions</summary>
|
|
|
|
|
public sealed class AtariPartitions : IPartition
|
2015-04-20 16:38:13 +01:00
|
|
|
{
|
2023-10-03 18:46:31 +01:00
|
|
|
const uint TYPE_GEMDOS = 0x0047454D;
|
|
|
|
|
const uint TYPE_BIG_GEMDOS = 0x0042474D;
|
|
|
|
|
const uint TYPE_EXTENDED = 0x0058474D;
|
|
|
|
|
const uint TYPE_LINUX = 0x004C4E58;
|
|
|
|
|
const uint TYPE_SWAP = 0x00535750;
|
|
|
|
|
const uint TYPE_RAW = 0x00524157;
|
|
|
|
|
const uint TYPE_NETBSD = 0x004E4244;
|
|
|
|
|
const uint TYPE_NETBSD_SWAP = 0x004E4253;
|
|
|
|
|
const uint TYPE_SYSTEM_V = 0x00554E58;
|
|
|
|
|
const uint TYPE_MAC = 0x004D4143;
|
|
|
|
|
const uint TYPE_MINIX = 0x004D4958;
|
|
|
|
|
const uint TYPE_MINIX2 = 0x004D4E58;
|
|
|
|
|
const string MODULE_NAME = "Atari partitions plugin";
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
#region IPartition Members
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-29 03:13:21 +00:00
|
|
|
public string Name => Localization.AtariPartitions_Name;
|
2023-10-03 23:36:49 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Guid Id => new("d1dd0f24-ec39-4c4d-9072-be31919a3b5e");
|
2023-10-03 23:36:49 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-29 03:13:21 +00:00
|
|
|
public string Author => Authors.NataliaPortillo;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2021-08-17 14:25:12 +01:00
|
|
|
/// <inheritdoc />
|
2022-03-06 13:29:38 +00:00
|
|
|
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2015-04-20 16:38:13 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
|
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(sectorOffset, out byte[] sector);
|
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
if(errno != ErrorNumber.NoError || sector.Length < 512)
|
2022-03-06 13:29:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var table = new AtariTable
|
2015-04-20 16:38:13 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Boot = new byte[342],
|
|
|
|
|
IcdEntries = new AtariEntry[8],
|
|
|
|
|
Unused = new byte[12],
|
|
|
|
|
Entries = new AtariEntry[4]
|
|
|
|
|
};
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Array.Copy(sector, 0, table.Boot, 0, 342);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var i = 0; i < 8; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2023-10-03 23:36:49 +01:00
|
|
|
table.IcdEntries[i].Type = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 0);
|
|
|
|
|
table.IcdEntries[i].Start = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 4);
|
|
|
|
|
table.IcdEntries[i].Length = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 8);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2019-05-06 20:09:25 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Array.Copy(sector, 438, table.Unused, 0, 12);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
table.Size = BigEndianBitConverter.ToUInt32(sector, 450);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var i = 0; i < 4; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2023-10-03 23:36:49 +01:00
|
|
|
table.Entries[i].Type = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 0);
|
|
|
|
|
table.Entries[i].Start = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 4);
|
|
|
|
|
table.Entries[i].Length = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 8);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
table.BadStart = BigEndianBitConverter.ToUInt32(sector, 502);
|
|
|
|
|
table.BadLength = BigEndianBitConverter.ToUInt32(sector, 506);
|
|
|
|
|
table.Checksum = BigEndianBitConverter.ToUInt16(sector, 510);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var sha1Ctx = new Sha1Context();
|
|
|
|
|
sha1Ctx.Update(table.Boot);
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Boot_code_SHA1_0, sha1Ctx.End());
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var i = 0; i < 8; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2023-10-04 17:34:40 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.icdEntries[{0}].flag = 0x{1:X2}"), i,
|
|
|
|
|
(table.IcdEntries[i].Type & 0xFF000000) >> 24);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.icdEntries[{0}].type = 0x{1:X6}"), i,
|
|
|
|
|
table.IcdEntries[i].Type & 0x00FFFFFF);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.icdEntries[{0}].start = {1}"), i,
|
2022-03-06 13:29:38 +00:00
|
|
|
table.IcdEntries[i].Start);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.icdEntries[{0}].length = {1}"), i,
|
2022-03-06 13:29:38 +00:00
|
|
|
table.IcdEntries[i].Length);
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.size = {0}", table.Size);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var i = 0; i < 4; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.entries[{0}].flag = 0x{1:X2}"), i,
|
2022-03-06 13:29:38 +00:00
|
|
|
(table.Entries[i].Type & 0xFF000000) >> 24);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.entries[{0}].type = 0x{1:X6}"), i,
|
2022-03-06 13:29:38 +00:00
|
|
|
table.Entries[i].Type & 0x00FFFFFF);
|
|
|
|
|
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.entries[{0}].start = {1}"), i,
|
2022-03-06 13:29:38 +00:00
|
|
|
table.Entries[i].Start);
|
|
|
|
|
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Markup.Escape("table.entries[{0}].length = {1}"), i,
|
2022-03-06 13:29:38 +00:00
|
|
|
table.Entries[i].Length);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.badStart = {0}", table.BadStart);
|
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.badLength = {0}", table.BadLength);
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "table.checksum = 0x{0:X4}", table.Checksum);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
var validTable = false;
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong partitionSequence = 0;
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var i = 0; i < 4; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
uint type = table.Entries[i].Type & 0x00FFFFFF;
|
|
|
|
|
|
|
|
|
|
switch(type)
|
2015-10-18 22:04:03 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
case TYPE_GEMDOS:
|
|
|
|
|
case TYPE_BIG_GEMDOS:
|
|
|
|
|
case TYPE_LINUX:
|
|
|
|
|
case TYPE_SWAP:
|
|
|
|
|
case TYPE_RAW:
|
|
|
|
|
case TYPE_NETBSD:
|
|
|
|
|
case TYPE_NETBSD_SWAP:
|
|
|
|
|
case TYPE_SYSTEM_V:
|
|
|
|
|
case TYPE_MAC:
|
|
|
|
|
case TYPE_MINIX:
|
|
|
|
|
case TYPE_MINIX2:
|
|
|
|
|
validTable = true;
|
|
|
|
|
|
|
|
|
|
if(table.Entries[i].Start <= imagePlugin.Info.Sectors)
|
|
|
|
|
{
|
|
|
|
|
if(table.Entries[i].Start + table.Entries[i].Length > imagePlugin.Info.Sectors)
|
2023-10-03 23:36:49 +01:00
|
|
|
{
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME,
|
2022-11-29 03:13:21 +00:00
|
|
|
Localization.WARNING_End_of_partition_goes_beyond_device_size);
|
2023-10-03 23:36:49 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
ulong sectorSize = imagePlugin.Info.SectorSize;
|
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
if(sectorSize is 2448 or 2352)
|
2022-03-06 13:29:38 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
var partType = new byte[3];
|
2022-03-06 13:29:38 +00:00
|
|
|
partType[0] = (byte)((type & 0xFF0000) >> 16);
|
|
|
|
|
partType[1] = (byte)((type & 0x00FF00) >> 8);
|
|
|
|
|
partType[2] = (byte)(type & 0x0000FF);
|
|
|
|
|
|
|
|
|
|
var part = new Partition
|
|
|
|
|
{
|
|
|
|
|
Size = table.Entries[i].Length * sectorSize,
|
|
|
|
|
Length = table.Entries[i].Length,
|
|
|
|
|
Sequence = partitionSequence,
|
|
|
|
|
Name = "",
|
|
|
|
|
Offset = table.Entries[i].Start * sectorSize,
|
|
|
|
|
Start = table.Entries[i].Start,
|
|
|
|
|
Type = Encoding.ASCII.GetString(partType),
|
|
|
|
|
Scheme = Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
|
|
|
|
case TYPE_GEMDOS:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_GEMDOS_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_BIG_GEMDOS:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_GEMDOS_partition_bigger_than_32_MiB;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_LINUX:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Linux_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_SWAP:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Swap_partition;
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_RAW:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.RAW_partition;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_NETBSD:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.NetBSD_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_NETBSD_SWAP:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.NetBSD_swap_partition;
|
2017-12-21 04:43:29 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_SYSTEM_V:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_UNIX_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_MAC:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Macintosh_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_MINIX:
|
|
|
|
|
case TYPE_MINIX2:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.MINIX_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Unknown_partition_type;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
2015-04-20 16:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
partitions.Add(part);
|
|
|
|
|
partitionSequence++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_EXTENDED:
|
|
|
|
|
errno = imagePlugin.ReadSector(table.Entries[i].Start, out byte[] extendedSector);
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
2017-12-21 04:43:29 +00:00
|
|
|
break;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-11-14 01:23:52 +00:00
|
|
|
var extendedTable = new AtariTable
|
|
|
|
|
{
|
|
|
|
|
Entries = new AtariEntry[4]
|
|
|
|
|
};
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var j = 0; j < 4; j++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
extendedTable.Entries[j].Type =
|
2023-10-03 23:36:49 +01:00
|
|
|
BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 0);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
extendedTable.Entries[j].Start =
|
2023-10-03 23:36:49 +01:00
|
|
|
BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 4);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
extendedTable.Entries[j].Length =
|
2023-10-03 23:36:49 +01:00
|
|
|
BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 8);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var j = 0; j < 4; j++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
uint extendedType = extendedTable.Entries[j].Type & 0x00FFFFFF;
|
|
|
|
|
|
|
|
|
|
if(extendedType != TYPE_GEMDOS &&
|
|
|
|
|
extendedType != TYPE_BIG_GEMDOS &&
|
|
|
|
|
extendedType != TYPE_LINUX &&
|
|
|
|
|
extendedType != TYPE_SWAP &&
|
|
|
|
|
extendedType != TYPE_RAW &&
|
|
|
|
|
extendedType != TYPE_NETBSD &&
|
|
|
|
|
extendedType != TYPE_NETBSD_SWAP &&
|
|
|
|
|
extendedType != TYPE_SYSTEM_V &&
|
|
|
|
|
extendedType != TYPE_MAC &&
|
|
|
|
|
extendedType != TYPE_MINIX &&
|
|
|
|
|
extendedType != TYPE_MINIX2)
|
|
|
|
|
continue;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
validTable = true;
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(extendedTable.Entries[j].Start > imagePlugin.Info.Sectors)
|
|
|
|
|
continue;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
if(extendedTable.Entries[j].Start + extendedTable.Entries[j].Length > imagePlugin.Info.Sectors)
|
2023-10-03 23:36:49 +01:00
|
|
|
{
|
2023-10-03 18:46:31 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME,
|
2022-11-29 03:13:21 +00:00
|
|
|
Localization.WARNING_End_of_partition_goes_beyond_device_size);
|
2023-10-03 23:36:49 +01:00
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong sectorSize = imagePlugin.Info.SectorSize;
|
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
if(sectorSize is 2448 or 2352)
|
2022-03-06 13:29:38 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
var partType = new byte[3];
|
2022-03-06 13:29:38 +00:00
|
|
|
partType[0] = (byte)((extendedType & 0xFF0000) >> 16);
|
|
|
|
|
partType[1] = (byte)((extendedType & 0x00FF00) >> 8);
|
|
|
|
|
partType[2] = (byte)(extendedType & 0x0000FF);
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
var part = new Partition
|
2017-12-21 04:43:29 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Size = extendedTable.Entries[j].Length * sectorSize,
|
|
|
|
|
Length = extendedTable.Entries[j].Length,
|
|
|
|
|
Sequence = partitionSequence,
|
|
|
|
|
Name = "",
|
|
|
|
|
Offset = extendedTable.Entries[j].Start * sectorSize,
|
|
|
|
|
Start = extendedTable.Entries[j].Start,
|
|
|
|
|
Type = Encoding.ASCII.GetString(partType),
|
|
|
|
|
Scheme = Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch(extendedType)
|
|
|
|
|
{
|
|
|
|
|
case TYPE_GEMDOS:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_GEMDOS_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_BIG_GEMDOS:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_GEMDOS_partition_bigger_than_32_MiB;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_LINUX:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Linux_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_SWAP:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Swap_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_RAW:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.RAW_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_NETBSD:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.NetBSD_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_NETBSD_SWAP:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.NetBSD_swap_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_SYSTEM_V:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_UNIX_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_MAC:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Macintosh_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_MINIX:
|
|
|
|
|
case TYPE_MINIX2:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.MINIX_partition;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Unknown_partition_type;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
break;
|
2015-04-20 16:38:13 +01:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
partitions.Add(part);
|
|
|
|
|
partitionSequence++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2017-12-21 06:06:19 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!validTable)
|
|
|
|
|
return partitions.Count > 0;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
for(var i = 0; i < 8; i++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
uint type = table.IcdEntries[i].Type & 0x00FFFFFF;
|
|
|
|
|
|
|
|
|
|
if(type != TYPE_GEMDOS &&
|
|
|
|
|
type != TYPE_BIG_GEMDOS &&
|
|
|
|
|
type != TYPE_LINUX &&
|
|
|
|
|
type != TYPE_SWAP &&
|
|
|
|
|
type != TYPE_RAW &&
|
|
|
|
|
type != TYPE_NETBSD &&
|
|
|
|
|
type != TYPE_NETBSD_SWAP &&
|
|
|
|
|
type != TYPE_SYSTEM_V &&
|
|
|
|
|
type != TYPE_MAC &&
|
|
|
|
|
type != TYPE_MINIX &&
|
|
|
|
|
type != TYPE_MINIX2)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(table.IcdEntries[i].Start > imagePlugin.Info.Sectors)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(table.IcdEntries[i].Start + table.IcdEntries[i].Length > imagePlugin.Info.Sectors)
|
2023-10-03 23:36:49 +01:00
|
|
|
{
|
2023-10-04 17:34:40 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.WARNING_End_of_partition_goes_beyond_device_size);
|
2023-10-03 23:36:49 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
ulong sectorSize = imagePlugin.Info.SectorSize;
|
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
if(sectorSize is 2448 or 2352)
|
2022-03-06 13:29:38 +00:00
|
|
|
sectorSize = 2048;
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
var partType = new byte[3];
|
2022-03-06 13:29:38 +00:00
|
|
|
partType[0] = (byte)((type & 0xFF0000) >> 16);
|
|
|
|
|
partType[1] = (byte)((type & 0x00FF00) >> 8);
|
|
|
|
|
partType[2] = (byte)(type & 0x0000FF);
|
|
|
|
|
|
|
|
|
|
var part = new Partition
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Size = table.IcdEntries[i].Length * sectorSize,
|
|
|
|
|
Length = table.IcdEntries[i].Length,
|
|
|
|
|
Sequence = partitionSequence,
|
|
|
|
|
Name = "",
|
|
|
|
|
Offset = table.IcdEntries[i].Start * sectorSize,
|
|
|
|
|
Start = table.IcdEntries[i].Start,
|
|
|
|
|
Type = Encoding.ASCII.GetString(partType),
|
|
|
|
|
Scheme = Name
|
|
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
switch(type)
|
|
|
|
|
{
|
|
|
|
|
case TYPE_GEMDOS:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_GEMDOS_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_BIG_GEMDOS:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_GEMDOS_partition_bigger_than_32_MiB;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_LINUX:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Linux_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_SWAP:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Swap_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_RAW:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.RAW_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_NETBSD:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.NetBSD_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_NETBSD_SWAP:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.NetBSD_swap_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_SYSTEM_V:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Atari_UNIX_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_MAC:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Macintosh_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case TYPE_MINIX:
|
|
|
|
|
case TYPE_MINIX2:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.MINIX_partition;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2022-11-29 03:13:21 +00:00
|
|
|
part.Description = Localization.Unknown_partition_type;
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2017-12-21 06:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
partitions.Add(part);
|
|
|
|
|
partitionSequence++;
|
2015-04-20 16:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return partitions.Count > 0;
|
|
|
|
|
}
|
2015-04-20 16:38:13 +01:00
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Nested type: AtariEntry
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Atari partition entry</summary>
|
|
|
|
|
struct AtariEntry
|
|
|
|
|
{
|
|
|
|
|
/// <summary>First byte flag, three bytes type in ASCII. Flag bit 0 = active Flag bit 7 = bootable</summary>
|
|
|
|
|
public uint Type;
|
|
|
|
|
/// <summary>Starting sector</summary>
|
|
|
|
|
public uint Start;
|
|
|
|
|
/// <summary>Length in sectors</summary>
|
|
|
|
|
public uint Length;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-03 23:36:49 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Nested type: AtariTable
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
struct AtariTable
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Boot code for 342 bytes</summary>
|
|
|
|
|
public byte[] Boot;
|
|
|
|
|
/// <summary>8 extra entries for ICDPro driver</summary>
|
|
|
|
|
public AtariEntry[] IcdEntries;
|
|
|
|
|
/// <summary>Unused, 12 bytes</summary>
|
|
|
|
|
public byte[] Unused;
|
|
|
|
|
/// <summary>Disk size in sectors</summary>
|
|
|
|
|
public uint Size;
|
|
|
|
|
/// <summary>4 partition entries</summary>
|
|
|
|
|
public AtariEntry[] Entries;
|
|
|
|
|
/// <summary>Starting sector of bad block list</summary>
|
|
|
|
|
public uint BadStart;
|
|
|
|
|
/// <summary>Length in sectors of bad block list</summary>
|
|
|
|
|
public uint BadLength;
|
|
|
|
|
/// <summary>Checksum for bootable disks</summary>
|
|
|
|
|
public ushort Checksum;
|
2015-04-20 16:38:13 +01:00
|
|
|
}
|
2023-10-03 23:36:49 +01:00
|
|
|
|
|
|
|
|
#endregion
|
2015-04-20 16:38:13 +01:00
|
|
|
}
|