Files
Aaru/Aaru.Filesystems/PFS/Info.cs

133 lines
5.0 KiB
C#
Raw Permalink Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
2022-12-07 13:07:31 +00:00
// Filename : Info.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
2016-09-14 02:31:32 +01:00
// Component : Professional File System plugin.
//
// --[ 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
// ****************************************************************************/
2022-03-07 07:36:44 +00:00
// ReSharper disable UnusedType.Local
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 Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
/// <summary>Implements detection of the Professional File System</summary>
2022-12-07 13:07:31 +00:00
public sealed partial class PFS
{
#region IFilesystem Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
2024-05-01 04:05:22 +01:00
if(partition.Length < 3) return false;
ErrorNumber errno = imagePlugin.ReadSector(2 + partition.Start, false, out byte[] sector, out _);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
var magic = BigEndianBitConverter.ToUInt32(sector, 0x00);
2022-03-16 11:47:00 +00:00
return magic is AFS_DISK or PFS2_DISK or PFS_DISK or MUAF_DISK or MUPFS_DISK;
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
out FileSystem metadata)
2022-03-06 13:29:38 +00:00
{
information = "";
encoding ??= Encoding.GetEncoding("iso-8859-1");
metadata = new FileSystem();
ErrorNumber errno = imagePlugin.ReadSector(2 + partition.Start, false, out byte[] rootBlockSector, out _);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return;
RootBlock rootBlock = Marshal.ByteArrayToStructureBigEndian<RootBlock>(rootBlockSector);
2022-03-06 13:29:38 +00:00
var sbInformation = new StringBuilder();
metadata = new FileSystem();
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
switch(rootBlock.diskType)
{
case AFS_DISK:
case MUAF_DISK:
sbInformation.Append(Localization.Professional_File_System_v1);
metadata.Type = FS_TYPE;
2022-03-06 13:29:38 +00:00
break;
case PFS2_DISK:
sbInformation.Append(Localization.Professional_File_System_v2);
metadata.Type = FS_TYPE;
2022-03-06 13:29:38 +00:00
break;
case PFS_DISK:
case MUPFS_DISK:
sbInformation.Append(Localization.Professional_File_System_v3);
metadata.Type = FS_TYPE;
2022-03-06 13:29:38 +00:00
break;
}
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(rootBlock.diskType is MUAF_DISK or MUPFS_DISK) sbInformation.Append(Localization.with_multi_user_support);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
sbInformation.AppendLine();
2024-05-01 04:05:22 +01:00
sbInformation
.AppendFormat(Localization.Volume_name_0, StringHandlers.PascalToString(rootBlock.diskname, encoding))
.AppendLine();
2024-05-01 04:05:22 +01:00
sbInformation
.AppendFormat(Localization.Volume_has_0_free_sectors_of_1, rootBlock.blocksfree, rootBlock.diskSize)
.AppendLine();
sbInformation.AppendFormat(Localization.Volume_created_on_0,
2024-05-01 04:05:22 +01:00
DateHandlers.AmigaToDateTime(rootBlock.creationday,
rootBlock.creationminute,
rootBlock.creationtick))
.AppendLine();
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(rootBlock.extension > 0)
{
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.Root_block_extension_resides_at_block_0, rootBlock.extension)
.AppendLine();
}
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
information = sbInformation.ToString();
metadata.CreationDate =
2022-03-06 13:29:38 +00:00
DateHandlers.AmigaToDateTime(rootBlock.creationday, rootBlock.creationminute, rootBlock.creationtick);
metadata.FreeClusters = rootBlock.blocksfree;
metadata.Clusters = rootBlock.diskSize;
metadata.ClusterSize = imagePlugin.Info.SectorSize;
metadata.VolumeName = StringHandlers.PascalToString(rootBlock.diskname, encoding);
2022-03-06 13:29:38 +00:00
}
#endregion
}