// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // Filename : PFS.cs // Author(s) : Natalia Portillo // // Component : Professional File System plugin. // // --[ 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System; using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; using Schemas; using Marshal = DiscImageChef.Helpers.Marshal; namespace DiscImageChef.Filesystems { public class PFS : IFilesystem { /// /// Identifier for AFS (PFS v1) /// const uint AFS_DISK = 0x41465301; /// /// Identifier for PFS v2 /// const uint PFS2_DISK = 0x50465302; /// /// Identifier for PFS v3 /// const uint PFS_DISK = 0x50465301; /// /// Identifier for multi-user AFS /// const uint MUAF_DISK = 0x6D754146; /// /// Identifier for multi-user PFS /// const uint MUPFS_DISK = 0x6D755046; public FileSystemType XmlFsType { get; private set; } public Encoding Encoding { get; private set; } public string Name => "Professional File System"; public Guid Id => new Guid("68DE769E-D957-406A-8AE4-3781CA8CDA77"); public string Author => "Natalia Portillo"; public bool Identify(IMediaImage imagePlugin, Partition partition) { if(partition.Length < 3) return false; byte[] sector = imagePlugin.ReadSector(2 + partition.Start); uint magic = BigEndianBitConverter.ToUInt32(sector, 0x00); return magic == AFS_DISK || magic == PFS2_DISK || magic == PFS_DISK || magic == MUAF_DISK || magic == MUPFS_DISK; } public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1"); byte[] rootBlockSector = imagePlugin.ReadSector(2 + partition.Start); RootBlock rootBlock = Marshal.ByteArrayToStructureBigEndian(rootBlockSector); StringBuilder sbInformation = new StringBuilder(); XmlFsType = new FileSystemType(); switch(rootBlock.diskType) { case AFS_DISK: case MUAF_DISK: sbInformation.Append("Professional File System v1"); XmlFsType.Type = "PFS v1"; break; case PFS2_DISK: sbInformation.Append("Professional File System v2"); XmlFsType.Type = "PFS v2"; break; case PFS_DISK: case MUPFS_DISK: sbInformation.Append("Professional File System v3"); XmlFsType.Type = "PFS v3"; break; } if(rootBlock.diskType == MUAF_DISK || rootBlock.diskType == MUPFS_DISK) sbInformation.Append(", with multi-user support"); sbInformation.AppendLine(); 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(); sbInformation.AppendFormat("Volume created on {0}", DateHandlers.AmigaToDateTime(rootBlock.creationday, rootBlock.creationminute, rootBlock.creationtick)).AppendLine(); if(rootBlock.extension > 0) sbInformation.AppendFormat("Root block extension resides at block {0}", rootBlock.extension) .AppendLine(); information = sbInformation.ToString(); XmlFsType.CreationDate = DateHandlers.AmigaToDateTime(rootBlock.creationday, rootBlock.creationminute, rootBlock.creationtick); XmlFsType.CreationDateSpecified = true; XmlFsType.FreeClusters = rootBlock.blocksfree; XmlFsType.FreeClustersSpecified = true; XmlFsType.Clusters = rootBlock.diskSize; XmlFsType.ClusterSize = imagePlugin.Info.SectorSize; XmlFsType.VolumeName = StringHandlers.PascalToString(rootBlock.diskname, Encoding); } /// /// Boot block, first 2 sectors /// [StructLayout(LayoutKind.Sequential, Pack = 1)] struct BootBlock { /// /// "PFS\1" disk type /// public readonly uint diskType; /// /// Boot code, til completion /// public readonly byte[] bootCode; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct RootBlock { /// /// Disk type /// public readonly uint diskType; /// /// Options /// public readonly uint options; /// /// Current datestamp /// public readonly uint datestamp; /// /// Volume creation day /// public readonly ushort creationday; /// /// Volume creation minute /// public readonly ushort creationminute; /// /// Volume creation tick /// public readonly ushort creationtick; /// /// AmigaDOS protection bits /// public readonly ushort protection; /// /// Volume label (Pascal string) /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public readonly byte[] diskname; /// /// Last reserved block /// public readonly uint lastreserved; /// /// First reserved block /// public readonly uint firstreserved; /// /// Free reserved blocks /// public readonly uint reservedfree; /// /// Size of reserved blocks in bytes /// public readonly ushort reservedblocksize; /// /// Blocks in rootblock, including bitmap /// public readonly ushort rootblockclusters; /// /// Free blocks /// public readonly uint blocksfree; /// /// Blocks that must be always free /// public readonly uint alwaysfree; /// /// Current bitmapfield number for allocation /// public readonly uint rovingPointer; /// /// Pointer to deldir /// public readonly uint delDirPtr; /// /// Disk size in sectors /// public readonly uint diskSize; /// /// Rootblock extension /// public readonly uint extension; /// /// Unused /// public readonly uint unused; } } }