2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-07-31 20:55:58 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Info.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Component : U.C.S.D. Pascal filesystem plugin.
|
2016-07-31 20:55:58 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Identifies the U.C.S.D. Pascal filesystem and shows information.
|
2016-07-31 20:55:58 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2016-07-31 20:55:58 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2016-07-31 20:55:58 +01:00
|
|
|
|
using System;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.Console;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
using Claunia.Encoding;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2017-12-26 18:52:21 +00:00
|
|
|
|
using Encoding = System.Text.Encoding;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems.UCSDPascal
|
2016-07-31 20:55:58 +01:00
|
|
|
|
{
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Information from Call-A.P.P.L.E. Pascal Disk Directory Structure
|
2017-12-21 16:27:09 +00:00
|
|
|
|
public partial class PascalPlugin
|
2016-07-31 20:55:58 +01:00
|
|
|
|
{
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-07-31 20:56:53 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.Length < 3)
|
|
|
|
|
|
return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
|
multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
|
|
|
|
|
|
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Blocks 0 and 1 are boot code
|
2020-02-29 18:03:35 +00:00
|
|
|
|
byte[] volBlock = imagePlugin.ReadSectors((multiplier * 2) + partition.Start, multiplier);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
|
// On Apple II, it's little endian
|
2019-05-11 20:49:32 +01:00
|
|
|
|
// TODO: Fix
|
|
|
|
|
|
/*BigEndianBitConverter.IsLittleEndian =
|
|
|
|
|
|
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;*/
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var volEntry = new PascalVolumeEntry
|
2019-05-11 20:49:32 +01:00
|
|
|
|
{
|
|
|
|
|
|
FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00),
|
|
|
|
|
|
LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02),
|
2020-07-20 04:34:16 +01:00
|
|
|
|
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04),
|
|
|
|
|
|
VolumeName = new byte[8],
|
2019-05-11 20:49:32 +01:00
|
|
|
|
Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E),
|
|
|
|
|
|
Files = BigEndianBitConverter.ToInt16(volBlock, 0x10),
|
|
|
|
|
|
Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12),
|
|
|
|
|
|
LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14),
|
|
|
|
|
|
Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16)
|
|
|
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
|
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
|
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.firstBlock = {0}", volEntry.FirstBlock);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.lastBlock = {0}", volEntry.LastBlock);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.entryType = {0}", volEntry.EntryType);
|
2020-02-27 23:48:41 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.volumeName = {0}", volEntry.VolumeName);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.blocks = {0}", volEntry.Blocks);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.files = {0}", volEntry.Files);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.dummy = {0}", volEntry.Dummy);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.lastBoot = {0}", volEntry.LastBoot);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.tail = {0}", volEntry.Tail);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// First block is always 0 (even is it's sector 2)
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.FirstBlock != 0)
|
|
|
|
|
|
return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Last volume record block must be after first block, and before end of device
|
2018-01-06 00:41:14 +00:00
|
|
|
|
if(volEntry.LastBlock <= volEntry.FirstBlock ||
|
2020-02-29 18:03:35 +00:00
|
|
|
|
(ulong)volEntry.LastBlock > (imagePlugin.Info.Sectors / multiplier) - 2)
|
|
|
|
|
|
return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume record entry type must be volume or secure
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.EntryType != PascalFileKind.Volume &&
|
|
|
|
|
|
volEntry.EntryType != PascalFileKind.Secure)
|
|
|
|
|
|
return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume name is max 7 characters
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.VolumeName[0] > 7)
|
|
|
|
|
|
return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume blocks is equal to volume sectors
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.Blocks < 0 ||
|
|
|
|
|
|
(ulong)volEntry.Blocks != imagePlugin.Info.Sectors / multiplier)
|
|
|
|
|
|
return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// There can be not less than zero files
|
2018-01-06 00:41:14 +00:00
|
|
|
|
return volEntry.Files >= 0;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding encoding)
|
2016-07-31 20:55:58 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = encoding ?? new Apple2();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2018-06-22 08:08:38 +01:00
|
|
|
|
information = "";
|
|
|
|
|
|
multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors < 3)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Blocks 0 and 1 are boot code
|
2020-02-29 18:03:35 +00:00
|
|
|
|
byte[] volBlock = imagePlugin.ReadSectors((multiplier * 2) + partition.Start, multiplier);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
|
// On Apple //, it's little endian
|
2019-05-11 20:49:32 +01:00
|
|
|
|
// TODO: Fix
|
|
|
|
|
|
//BigEndianBitConverter.IsLittleEndian =
|
|
|
|
|
|
// multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var volEntry = new PascalVolumeEntry
|
2019-05-11 20:49:32 +01:00
|
|
|
|
{
|
|
|
|
|
|
FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00),
|
|
|
|
|
|
LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02),
|
2020-07-20 04:34:16 +01:00
|
|
|
|
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04),
|
|
|
|
|
|
VolumeName = new byte[8],
|
2019-05-11 20:49:32 +01:00
|
|
|
|
Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E),
|
|
|
|
|
|
Files = BigEndianBitConverter.ToInt16(volBlock, 0x10),
|
|
|
|
|
|
Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12),
|
|
|
|
|
|
LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14),
|
|
|
|
|
|
Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16)
|
|
|
|
|
|
};
|
2018-01-06 00:41:14 +00:00
|
|
|
|
|
|
|
|
|
|
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// First block is always 0 (even is it's sector 2)
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.FirstBlock != 0)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Last volume record block must be after first block, and before end of device
|
2018-01-06 00:41:14 +00:00
|
|
|
|
if(volEntry.LastBlock <= volEntry.FirstBlock ||
|
2020-02-29 18:03:35 +00:00
|
|
|
|
(ulong)volEntry.LastBlock > (imagePlugin.Info.Sectors / multiplier) - 2)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume record entry type must be volume or secure
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.EntryType != PascalFileKind.Volume &&
|
|
|
|
|
|
volEntry.EntryType != PascalFileKind.Secure)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume name is max 7 characters
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.VolumeName[0] > 7)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume blocks is equal to volume sectors
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.Blocks < 0 ||
|
|
|
|
|
|
(ulong)volEntry.Blocks != imagePlugin.Info.Sectors / multiplier)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// There can be not less than zero files
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(volEntry.Files < 0)
|
|
|
|
|
|
return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume record spans from block {0} to block {1}", volEntry.FirstBlock,
|
|
|
|
|
|
volEntry.LastBlock).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Volume name: {0}", StringHandlers.PascalToString(volEntry.VolumeName, Encoding)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume has {0} blocks", volEntry.Blocks).AppendLine();
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume has {0} files", volEntry.Files).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Volume last booted at {0}", DateHandlers.UcsdPascalToDateTime(volEntry.LastBoot)).
|
|
|
|
|
|
AppendLine();
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(imagePlugin.ReadSectors(partition.Start, multiplier * 2)),
|
|
|
|
|
|
Clusters = (ulong)volEntry.Blocks,
|
|
|
|
|
|
ClusterSize = imagePlugin.Info.SectorSize,
|
|
|
|
|
|
Files = (ulong)volEntry.Files,
|
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
|
Type = "UCSD Pascal",
|
2020-02-29 18:03:35 +00:00
|
|
|
|
VolumeName = StringHandlers.PascalToString(volEntry.VolumeName, Encoding)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
};
|
2016-07-31 20:55:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|