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

158 lines
7.3 KiB
C#
Raw Normal View History

// /***************************************************************************
2016-07-31 20:55:58 +01:00
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
2016-07-31 20:55:58 +01:00
// ****************************************************************************/
2016-07-31 20:55:58 +01:00
using System;
using System.Text;
using Claunia.Encoding;
using DiscImageChef.CommonTypes;
2017-12-21 14:30:38 +00:00
using DiscImageChef.DiscImages;
using Schemas;
using Encoding = System.Text.Encoding;
2016-07-31 20:55:58 +01:00
namespace DiscImageChef.Filesystems.UCSDPascal
{
// Information from Call-A.P.P.L.E. Pascal Disk Directory Structure
public partial class PascalPlugin
2016-07-31 20:55:58 +01:00
{
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
2017-12-19 20:33:03 +00:00
if(partition.Length < 3) return false;
// Blocks 0 and 1 are boot code
2017-07-19 16:37:11 +01:00
byte[] volBlock = imagePlugin.ReadSector(2 + partition.Start);
PascalVolumeEntry volEntry = new PascalVolumeEntry();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
volEntry.firstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
volEntry.lastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
volEntry.entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
volEntry.volumeName = new byte[8];
Array.Copy(volBlock, 0x06, volEntry.volumeName, 0, 8);
volEntry.blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
volEntry.files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
volEntry.dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
volEntry.lastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
volEntry.tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
// First block is always 0 (even is it's sector 2)
2017-12-19 20:33:03 +00:00
if(volEntry.firstBlock != 0) return false;
// Last volume record block must be after first block, and before end of device
2017-12-19 20:33:03 +00:00
if(volEntry.lastBlock <= volEntry.firstBlock ||
(ulong)volEntry.lastBlock > imagePlugin.Info.Sectors - 2) return false;
// Volume record entry type must be volume or secure
2017-12-19 20:33:03 +00:00
if(volEntry.entryType != PascalFileKind.Volume && volEntry.entryType != PascalFileKind.Secure) return false;
// Volume name is max 7 characters
2017-12-19 20:33:03 +00:00
if(volEntry.volumeName[0] > 7) return false;
// Volume blocks is equal to volume sectors
if(volEntry.blocks < 0 || (ulong)volEntry.blocks != imagePlugin.Info.Sectors) return false;
// There can be not less than zero files
return volEntry.files >= 0;
}
2017-12-26 08:01:40 +00:00
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding)
2016-07-31 20:55:58 +01:00
{
Encoding = encoding ?? new Apple2();
StringBuilder sbInformation = new StringBuilder();
information = "";
if(imagePlugin.Info.Sectors < 3) return;
// Blocks 0 and 1 are boot code
2017-07-19 16:37:11 +01:00
byte[] volBlock = imagePlugin.ReadSector(2 + partition.Start);
PascalVolumeEntry volEntry = new PascalVolumeEntry();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
volEntry.firstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
volEntry.lastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
volEntry.entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
volEntry.volumeName = new byte[8];
Array.Copy(volBlock, 0x06, volEntry.volumeName, 0, 8);
volEntry.blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
volEntry.files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
volEntry.dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
volEntry.lastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
volEntry.tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
// First block is always 0 (even is it's sector 2)
2017-12-19 20:33:03 +00:00
if(volEntry.firstBlock != 0) return;
// Last volume record block must be after first block, and before end of device
2017-12-19 20:33:03 +00:00
if(volEntry.lastBlock <= volEntry.firstBlock ||
(ulong)volEntry.lastBlock > imagePlugin.Info.Sectors - 2) return;
// Volume record entry type must be volume or secure
2017-12-19 20:33:03 +00:00
if(volEntry.entryType != PascalFileKind.Volume && volEntry.entryType != PascalFileKind.Secure) return;
// Volume name is max 7 characters
2017-12-19 20:33:03 +00:00
if(volEntry.volumeName[0] > 7) return;
// Volume blocks is equal to volume sectors
if(volEntry.blocks < 0 || (ulong)volEntry.blocks != imagePlugin.Info.Sectors) return;
// There can be not less than zero files
2017-12-19 20:33:03 +00:00
if(volEntry.files < 0) return;
2017-12-19 20:33:03 +00:00
sbInformation.AppendFormat("Volume record spans from block {0} to block {1}", volEntry.firstBlock,
volEntry.lastBlock).AppendLine();
2017-12-26 08:01:40 +00:00
sbInformation.AppendFormat("Volume name: {0}", StringHandlers.PascalToString(volEntry.volumeName, Encoding))
2017-12-19 20:33:03 +00:00
.AppendLine();
sbInformation.AppendFormat("Volume has {0} blocks", volEntry.blocks).AppendLine();
sbInformation.AppendFormat("Volume has {0} files", volEntry.files).AppendLine();
2017-12-19 20:33:03 +00:00
sbInformation
2017-12-23 03:59:48 +00:00
.AppendFormat("Volume last booted at {0}", DateHandlers.UcsdPascalToDateTime(volEntry.lastBoot))
2017-12-19 20:33:03 +00:00
.AppendLine();
information = sbInformation.ToString();
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
{
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(imagePlugin.ReadSectors(partition.Start, 2)),
Clusters = volEntry.blocks,
ClusterSize = (int)imagePlugin.Info.SectorSize,
Files = volEntry.files,
FilesSpecified = true,
Type = "UCSD Pascal",
2017-12-26 08:01:40 +00:00
VolumeName = StringHandlers.PascalToString(volEntry.volumeName, Encoding)
};
2016-07-31 20:55:58 +01:00
}
}
2017-12-19 20:33:03 +00:00
}