2017-07-26 04:16:36 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-07-26 04:16:36 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2017-07-26 04:16:36 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : HAMMER filesystem plugin.
|
2017-07-26 04:16:36 +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-07-26 04:16:36 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
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;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
#pragma warning disable 169
|
|
|
|
|
|
|
|
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection for the HAMMER filesystem</summary>
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class HAMMER
|
2017-07-26 04:16:36 +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)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint run = HAMMER_VOLHDR_SIZE / imagePlugin.Info.SectorSize;
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(HAMMER_VOLHDR_SIZE % imagePlugin.Info.SectorSize > 0) run++;
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(run + partition.Start >= partition.End) return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, run, out byte[] sbSector);
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var magic = BitConverter.ToUInt64(sbSector, 0);
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
|
return magic is HAMMER_FSBUF_VOLUME or HAMMER_FSBUF_VOLUME_REV;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2017-07-26 04:16:36 +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
|
|
|
|
{
|
2022-12-17 23:17:18 +00:00
|
|
|
|
encoding ??= Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
information = "";
|
|
|
|
|
|
metadata = new FileSystem();
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2017-07-26 04:16:36 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
uint run = HAMMER_VOLHDR_SIZE / imagePlugin.Info.SectorSize;
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(HAMMER_VOLHDR_SIZE % imagePlugin.Info.SectorSize > 0) run++;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, run, out byte[] sbSector);
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return;
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var magic = BitConverter.ToUInt64(sbSector, 0);
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2022-11-13 20:27:32 +00:00
|
|
|
|
SuperBlock superBlock = magic == HAMMER_FSBUF_VOLUME
|
|
|
|
|
|
? Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sbSector)
|
|
|
|
|
|
: Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.HAMMER_filesystem);
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_version_0, superBlock.vol_version).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
sb.AppendFormat(Localization.Volume_0_of_1_on_this_filesystem, superBlock.vol_no + 1, superBlock.vol_count)
|
|
|
|
|
|
.AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
sb.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(superBlock.vol_label, encoding))
|
|
|
|
|
|
.AppendLine();
|
2017-12-22 08:43:22 +00:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.Volume_serial_0, superBlock.vol_fsid).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Filesystem_type_0, superBlock.vol_fstype).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Boot_area_starts_at_0, superBlock.vol_bot_beg).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Memory_log_starts_at_0, superBlock.vol_mem_beg).AppendLine();
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.First_volume_buffer_starts_at_0, superBlock.vol_buf_beg).AppendLine();
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.Volume_ends_at_0, superBlock.vol_buf_end).AppendLine();
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
Clusters = partition.Size / HAMMER_BIGBLOCK_SIZE,
|
|
|
|
|
|
ClusterSize = HAMMER_BIGBLOCK_SIZE,
|
|
|
|
|
|
Dirty = false,
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-12-17 23:17:18 +00:00
|
|
|
|
VolumeName = StringHandlers.CToString(superBlock.vol_label, encoding),
|
2022-03-06 13:29:38 +00:00
|
|
|
|
VolumeSerial = superBlock.vol_fsid.ToString()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(superBlock.vol_no == superBlock.vol_rootvol)
|
|
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
|
sb.AppendFormat(Localization.Filesystem_contains_0_big_blocks_1_bytes,
|
|
|
|
|
|
superBlock.vol0_stat_bigblocks,
|
|
|
|
|
|
superBlock.vol0_stat_bigblocks * HAMMER_BIGBLOCK_SIZE)
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(Localization.Filesystem_has_0_big_blocks_free_1_bytes,
|
|
|
|
|
|
superBlock.vol0_stat_freebigblocks,
|
|
|
|
|
|
superBlock.vol0_stat_freebigblocks * HAMMER_BIGBLOCK_SIZE)
|
|
|
|
|
|
.AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Filesystem_has_0_inodes_used, superBlock.vol0_stat_inodes).AppendLine();
|
2017-12-22 08:43:22 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.Clusters = (ulong)superBlock.vol0_stat_bigblocks;
|
|
|
|
|
|
metadata.FreeClusters = (ulong)superBlock.vol0_stat_freebigblocks;
|
|
|
|
|
|
metadata.Files = (ulong)superBlock.vol0_stat_inodes;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// 0 ?
|
|
|
|
|
|
//sb.AppendFormat("Volume header CRC: 0x{0:X8}", afs_sb.vol_crc).AppendLine();
|
2017-07-26 04:21:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|