2017-08-07 16:06:51 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-08-07 16:06:51 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2017-08-07 16:06:51 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Fossil filesystem plugin
|
2017-08-07 16:06:51 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2017-08-07 16:06:51 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
|
|
|
|
|
using System.Text;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
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;
|
2025-08-17 05:50:25 +01:00
|
|
|
|
using Aaru.Logging;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection for the Plan-9 Fossil on-disk filesystem</summary>
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class Fossil
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
|
#region IFilesystem Members
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2017-08-07 16:06:51 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ulong hdrSector = HEADER_POS / imagePlugin.Info.SectorSize;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(partition.Start + hdrSector > imagePlugin.Info.Sectors) return false;
|
2017-09-28 15:44:36 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(partition.Start + hdrSector, out byte[] sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2025-10-21 03:02:21 +01:00
|
|
|
|
Header hdr = Marshal.ByteArrayToStructureBigEndianGenerated<Header>(sector);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.magic_at_0_expected_1, hdr.magic, FOSSIL_HDR_MAGIC);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return hdr.magic == FOSSIL_HDR_MAGIC;
|
|
|
|
|
|
}
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-12-17 22:41:56 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
|
|
|
|
|
|
out FileSystem metadata)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
// Technically everything on Plan 9 from Bell Labs is in UTF-8
|
2022-12-17 23:17:18 +00:00
|
|
|
|
encoding = Encoding.UTF8;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = "";
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ulong hdrSector = HEADER_POS / imagePlugin.Info.SectorSize;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(partition.Start + hdrSector, out byte[] sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2025-10-21 03:02:21 +01:00
|
|
|
|
Header hdr = Marshal.ByteArrayToStructureBigEndianGenerated<Header>(sector);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.magic_at_0_expected_1, hdr.magic, FOSSIL_HDR_MAGIC);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.Fossil_filesystem);
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.Filesystem_version_0, hdr.version).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_block, hdr.blockSize).AppendLine();
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Superblock_resides_in_block_0, hdr.super).AppendLine();
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.Labels_resides_in_block_0, hdr.label).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Data_starts_at_block_0, hdr.data).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_has_0_blocks, hdr.end).AppendLine();
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
ulong sbLocation = hdr.super * (hdr.blockSize / imagePlugin.Info.SectorSize) + partition.Start;
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ClusterSize = hdr.blockSize,
|
|
|
|
|
|
Clusters = hdr.end
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(sbLocation <= partition.End)
|
|
|
|
|
|
{
|
2022-03-17 23:54:41 +00:00
|
|
|
|
imagePlugin.ReadSector(sbLocation, out sector);
|
2025-10-21 03:02:21 +01:00
|
|
|
|
SuperBlock fsb = Marshal.ByteArrayToStructureBigEndianGenerated<SuperBlock>(sector);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
|
AaruLogging.Debug(MODULE_NAME, Localization.magic_0_expected_1, fsb.magic, FOSSIL_SB_MAGIC);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
if(fsb.magic == FOSSIL_SB_MAGIC)
|
2017-08-07 16:15:57 +01:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Epoch_low_0, fsb.epochLow).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Epoch_high_0, fsb.epochHigh).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Next_QID_0, fsb.qid).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Active_root_block_0, fsb.active).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Next_root_block_0, fsb.next).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Current_root_block_0, fsb.current).AppendLine();
|
2022-12-17 23:17:18 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_label_0, StringHandlers.CToString(fsb.name, encoding)).AppendLine();
|
|
|
|
|
|
metadata.VolumeName = StringHandlers.CToString(fsb.name, encoding);
|
2017-08-07 16:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-08-07 16:15:57 +01:00
|
|
|
|
}
|