2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-07-31 20:55:58 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 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;
|
2017-12-26 18:52:21 +00:00
|
|
|
|
using Claunia.Encoding;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2017-12-26 18:52:21 +00:00
|
|
|
|
using Encoding = System.Text.Encoding;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2016-07-31 20:55:58 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems.UCSDPascal
|
|
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Length < 3) return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Blocks 0 and 1 are boot code
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] volBlock = imagePlugin.ReadSector(2 + partition.Start);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
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;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// 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 ||
|
2017-12-26 06:05:12 +00:00
|
|
|
|
(ulong)volEntry.lastBlock > imagePlugin.Info.Sectors - 2) return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// 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;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume name is max 7 characters
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(volEntry.volumeName[0] > 7) return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume blocks is equal to volume sectors
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(volEntry.blocks < 0 || (ulong)volEntry.blocks != imagePlugin.Info.Sectors) return false;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// There can be not less than zero files
|
2017-12-24 02:37:41 +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,
|
|
|
|
|
|
Encoding encoding)
|
2016-07-31 20:55:58 +01:00
|
|
|
|
{
|
2017-12-26 18:52:21 +00:00
|
|
|
|
Encoding = encoding ?? new Apple2();
|
2016-07-31 20:56:53 +01:00
|
|
|
|
StringBuilder sbInformation = new StringBuilder();
|
|
|
|
|
|
information = "";
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors < 3) return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Blocks 0 and 1 are boot code
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] volBlock = imagePlugin.ReadSector(2 + partition.Start);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
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;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// 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 ||
|
2017-12-26 06:05:12 +00:00
|
|
|
|
(ulong)volEntry.lastBlock > imagePlugin.Info.Sectors - 2) return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// 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;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume name is max 7 characters
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(volEntry.volumeName[0] > 7) return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// Volume blocks is equal to volume sectors
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(volEntry.blocks < 0 || (ulong)volEntry.blocks != imagePlugin.Info.Sectors) return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
// There can be not less than zero files
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(volEntry.files < 0) return;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
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();
|
2016-07-31 20:56:53 +01:00
|
|
|
|
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();
|
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
|
|
|
|
{
|
|
|
|
|
|
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(imagePlugin.ReadSectors(partition.Start, 2)),
|
|
|
|
|
|
Clusters = volEntry.blocks,
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ClusterSize = (int)imagePlugin.Info.SectorSize,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
Files = volEntry.files,
|
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
|
Type = "UCSD Pascal",
|
2017-12-26 08:01:40 +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
|
|
|
|
}
|