2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-13 17:53:24 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-09-14 00:13:29 +01:00
|
|
|
|
// Filename : PFS.cs
|
2016-09-13 17:53:24 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-09-14 02:31:32 +01:00
|
|
|
|
// Component : Professional File System plugin.
|
2016-09-13 17:53:24 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Professional File System and shows information.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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-09-13 17:53:24 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2016-09-13 17:53:24 +01:00
|
|
|
|
|
2020-07-20 07:47:12 +01:00
|
|
|
|
// ReSharper disable UnusedType.Local
|
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2016-09-13 17:53:24 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class PFS : IFilesystem
|
2016-09-13 17:53:24 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for AFS (PFS v1)</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint AFS_DISK = 0x41465301;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for PFS v2</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint PFS2_DISK = 0x50465302;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for PFS v3</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint PFS_DISK = 0x50465301;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for multi-user AFS</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint MUAF_DISK = 0x6D754146;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for multi-user PFS</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint MUPFS_DISK = 0x6D755046;
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
public string Name => "Professional File System";
|
|
|
|
|
|
public Guid Id => new Guid("68DE769E-D957-406A-8AE4-3781CA8CDA77");
|
2018-08-29 22:15:43 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2017-10-12 23:54:02 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-13 17:53:24 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.Length < 3)
|
|
|
|
|
|
return false;
|
2016-09-13 17:53:24 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(2 + partition.Start);
|
2016-09-13 17:53:24 +01:00
|
|
|
|
|
|
|
|
|
|
uint magic = BigEndianBitConverter.ToUInt32(sector, 0x00);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
return magic == AFS_DISK || magic == PFS2_DISK || magic == PFS_DISK || magic == MUAF_DISK ||
|
|
|
|
|
|
magic == MUPFS_DISK;
|
2016-09-13 17:53:24 +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-09-13 17:53:24 +01:00
|
|
|
|
{
|
2017-12-26 08:01:40 +00:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] rootBlockSector = imagePlugin.ReadSector(2 + partition.Start);
|
2019-02-27 08:49:42 +00:00
|
|
|
|
RootBlock rootBlock = Marshal.ByteArrayToStructureBigEndian<RootBlock>(rootBlockSector);
|
2016-09-13 17:53:24 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType();
|
2016-09-13 17:53:24 +01:00
|
|
|
|
|
|
|
|
|
|
switch(rootBlock.diskType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case AFS_DISK:
|
|
|
|
|
|
case MUAF_DISK:
|
|
|
|
|
|
sbInformation.Append("Professional File System v1");
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Type = "PFS v1";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2016-09-13 17:53:24 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case PFS2_DISK:
|
|
|
|
|
|
sbInformation.Append("Professional File System v2");
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Type = "PFS v2";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2016-09-13 17:53:24 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case PFS_DISK:
|
|
|
|
|
|
case MUPFS_DISK:
|
|
|
|
|
|
sbInformation.Append("Professional File System v3");
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Type = "PFS v3";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2016-09-13 17:53:24 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(rootBlock.diskType == MUAF_DISK ||
|
|
|
|
|
|
rootBlock.diskType == MUPFS_DISK)
|
2016-09-13 17:53:24 +01:00
|
|
|
|
sbInformation.Append(", with multi-user support");
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine();
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume name: {0}", StringHandlers.PascalToString(rootBlock.diskname, Encoding)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Volume has {0} free sectors of {1}", rootBlock.blocksfree, rootBlock.diskSize).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume created on {0}",
|
|
|
|
|
|
DateHandlers.AmigaToDateTime(rootBlock.creationday, rootBlock.creationminute,
|
|
|
|
|
|
rootBlock.creationtick)).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2016-09-13 17:53:24 +01:00
|
|
|
|
if(rootBlock.extension > 0)
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sbInformation.AppendFormat("Root block extension resides at block {0}", rootBlock.extension).
|
|
|
|
|
|
AppendLine();
|
2016-09-13 17:53:24 +01:00
|
|
|
|
|
|
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.CreationDate =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DateHandlers.AmigaToDateTime(rootBlock.creationday, rootBlock.creationminute, rootBlock.creationtick);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.CreationDateSpecified = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.FreeClusters = rootBlock.blocksfree;
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.FreeClustersSpecified = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.Clusters = rootBlock.diskSize;
|
2019-04-23 01:38:33 +01:00
|
|
|
|
XmlFsType.ClusterSize = imagePlugin.Info.SectorSize;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.VolumeName = StringHandlers.PascalToString(rootBlock.diskname, Encoding);
|
2016-09-13 17:53:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Boot block, first 2 sectors</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct BootBlock
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>"PFS\1" disk type</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint diskType;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Boot code, til completion</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] bootCode;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct RootBlock
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Disk type</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint diskType;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Options</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint options;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Current datestamp</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint datestamp;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Volume creation day</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort creationday;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Volume creation minute</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort creationminute;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Volume creation tick</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort creationtick;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>AmigaDOS protection bits</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort protection;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Volume label (Pascal string)</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] diskname;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Last reserved block</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint lastreserved;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>First reserved block</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint firstreserved;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Free reserved blocks</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint reservedfree;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Size of reserved blocks in bytes</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort reservedblocksize;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Blocks in rootblock, including bitmap</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort rootblockclusters;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Free blocks</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint blocksfree;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Blocks that must be always free</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint alwaysfree;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Current bitmapfield number for allocation</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint rovingPointer;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Pointer to deldir</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint delDirPtr;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Disk size in sectors</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint diskSize;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Rootblock extension</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint extension;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Unused</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint unused;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-13 17:53:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|