Files
Aaru/Aaru.Filesystems/UCSDPascal/Info.cs

206 lines
8.7 KiB
C#
Raw Normal View History

// /***************************************************************************
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>
//
// Component : U.C.S.D. Pascal filesystem plugin.
2016-07-31 20:55:58 +01:00
//
// --[ Description ] ----------------------------------------------------------
//
// 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
2016-07-31 20:55:58 +01:00
// ****************************************************************************/
2016-07-31 20:55:58 +01:00
using System;
using System.Text;
using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Enums;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
using Aaru.Logging;
2020-02-29 18:03:35 +00:00
using Claunia.Encoding;
using Encoding = System.Text.Encoding;
using Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
// Information from Call-A.P.P.L.E. Pascal Disk Directory Structure
public sealed partial class PascalPlugin
2016-07-31 20:55:58 +01:00
{
#region IReadOnlyFilesystem Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
2016-07-31 20:55:58 +01:00
{
2024-05-01 04:05:22 +01:00
if(partition.Length < 3) return false;
2022-03-06 13:29:38 +00:00
_multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
// Blocks 0 and 1 are boot code
ErrorNumber errno =
imagePlugin.ReadSectors(_multiplier * 2 + partition.Start, _multiplier, out byte[] volBlock);
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2022-03-06 13:29:38 +00:00
// On Apple II, it's little endian
// TODO: Fix
/*BigEndianBitConverter.IsLittleEndian =
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;*/
var volEntry = new PascalVolumeEntry
{
FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00),
LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02),
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04),
VolumeName = new byte[8],
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)
};
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(MODULE_NAME, "volEntry.firstBlock = {0}", volEntry.FirstBlock);
AaruLogging.Debug(MODULE_NAME, "volEntry.lastBlock = {0}", volEntry.LastBlock);
AaruLogging.Debug(MODULE_NAME, "volEntry.entryType = {0}", volEntry.EntryType);
// AaruLogging.DebugWriteLine(MODULE_NAME, "volEntry.volumeName = {0}", volEntry.VolumeName);
AaruLogging.Debug(MODULE_NAME, "volEntry.blocks = {0}", volEntry.Blocks);
AaruLogging.Debug(MODULE_NAME, "volEntry.files = {0}", volEntry.Files);
AaruLogging.Debug(MODULE_NAME, "volEntry.dummy = {0}", volEntry.Dummy);
AaruLogging.Debug(MODULE_NAME, "volEntry.lastBoot = {0}", volEntry.LastBoot);
AaruLogging.Debug(MODULE_NAME, "volEntry.tail = {0}", volEntry.Tail);
2022-03-06 13:29:38 +00:00
// First block is always 0 (even is it's sector 2)
2024-05-01 04:05:22 +01:00
if(volEntry.FirstBlock != 0) return false;
2022-03-06 13:29:38 +00:00
// Last volume record block must be after first block, and before end of device
if(volEntry.LastBlock <= volEntry.FirstBlock ||
(ulong)volEntry.LastBlock > imagePlugin.Info.Sectors / _multiplier - 2)
2022-03-06 13:29:38 +00:00
return false;
// Volume record entry type must be volume or secure
2024-05-01 04:05:22 +01:00
if(volEntry.EntryType != PascalFileKind.Volume && volEntry.EntryType != PascalFileKind.Secure) return false;
2022-03-06 13:29:38 +00:00
// Volume name is max 7 characters
2024-05-01 04:05:22 +01:00
if(volEntry.VolumeName[0] > 7) return false;
2022-03-06 13:29:38 +00:00
// Volume blocks is equal to volume sectors
2024-05-01 04:05:22 +01:00
if(volEntry.Blocks < 0 || (ulong)volEntry.Blocks != imagePlugin.Info.Sectors / _multiplier) return false;
2022-03-06 13:29:38 +00:00
// There can be not less than zero files
return volEntry.Files >= 0;
}
/// <inheritdoc />
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
out FileSystem metadata)
2022-03-06 13:29:38 +00:00
{
encoding ??= new Apple2();
2022-03-06 13:29:38 +00:00
var sbInformation = new StringBuilder();
metadata = new FileSystem();
2022-03-06 13:29:38 +00:00
information = "";
_multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
2024-05-01 04:05:22 +01:00
if(imagePlugin.Info.Sectors < 3) return;
2022-03-06 13:29:38 +00:00
// Blocks 0 and 1 are boot code
ErrorNumber errno =
imagePlugin.ReadSectors(_multiplier * 2 + partition.Start, _multiplier, out byte[] volBlock);
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return;
2022-03-06 13:29:38 +00:00
// On Apple //, it's little endian
// TODO: Fix
//BigEndianBitConverter.IsLittleEndian =
// multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
var volEntry = new PascalVolumeEntry
{
2022-03-06 13:29:38 +00:00
FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00),
LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02),
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04),
VolumeName = new byte[8],
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)
};
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
// First block is always 0 (even is it's sector 2)
2024-05-01 04:05:22 +01:00
if(volEntry.FirstBlock != 0) return;
2022-03-06 13:29:38 +00:00
// Last volume record block must be after first block, and before end of device
if(volEntry.LastBlock <= volEntry.FirstBlock ||
(ulong)volEntry.LastBlock > imagePlugin.Info.Sectors / _multiplier - 2)
2022-03-06 13:29:38 +00:00
return;
// Volume record entry type must be volume or secure
2024-05-01 04:05:22 +01:00
if(volEntry.EntryType != PascalFileKind.Volume && volEntry.EntryType != PascalFileKind.Secure) return;
2022-03-06 13:29:38 +00:00
// Volume name is max 7 characters
2024-05-01 04:05:22 +01:00
if(volEntry.VolumeName[0] > 7) return;
2022-03-06 13:29:38 +00:00
// Volume blocks is equal to volume sectors
2024-05-01 04:05:22 +01:00
if(volEntry.Blocks < 0 || (ulong)volEntry.Blocks != imagePlugin.Info.Sectors / _multiplier) return;
2022-03-06 13:29:38 +00:00
// There can be not less than zero files
2024-05-01 04:05:22 +01:00
if(volEntry.Files < 0) return;
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.Volume_record_spans_from_block_0_to_block_1,
volEntry.FirstBlock,
volEntry.LastBlock)
.AppendLine();
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
sbInformation
.AppendFormat(Localization.Volume_name_0, StringHandlers.PascalToString(volEntry.VolumeName, encoding))
.AppendLine();
2022-03-06 13:29:38 +00:00
sbInformation.AppendFormat(Localization.Volume_has_0_blocks, volEntry.Blocks).AppendLine();
sbInformation.AppendFormat(Localization.Volume_has_0_files, volEntry.Files).AppendLine();
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
sbInformation
.AppendFormat(Localization.Volume_last_booted_on_0, DateHandlers.UcsdPascalToDateTime(volEntry.LastBoot))
.AppendLine();
2022-03-06 13:29:38 +00:00
information = sbInformation.ToString();
imagePlugin.ReadSectors(partition.Start, _multiplier * 2, out byte[] boot);
metadata = new FileSystem
2016-07-31 20:55:58 +01:00
{
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(boot),
Clusters = (ulong)volEntry.Blocks,
ClusterSize = imagePlugin.Info.SectorSize,
Files = (ulong)volEntry.Files,
Type = FS_TYPE,
VolumeName = StringHandlers.PascalToString(volEntry.VolumeName, encoding)
2022-03-06 13:29:38 +00:00
};
2016-07-31 20:55:58 +01:00
}
#endregion
2017-12-19 20:33:03 +00:00
}