2017-07-26 03:08:29 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-07-26 03:08:29 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2017-07-26 03:08:29 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Atheos filesystem plugin.
|
2017-07-26 03:08:29 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-07-26 03:08:29 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-07-20 07:47:12 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-07-26 03:08:29 +01:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
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;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2017-07-26 03:08:29 +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 AtheOS filesystem</summary>
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class AtheOS
|
2017-07-26 03:08:29 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong sector = AFS_BOOTBLOCK_SIZE / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
uint offset = AFS_BOOTBLOCK_SIZE % imagePlugin.Info.SectorSize;
|
|
|
|
|
|
uint run = 1;
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < AFS_SUPERBLOCK_SIZE)
|
|
|
|
|
|
run = AFS_SUPERBLOCK_SIZE / imagePlugin.Info.SectorSize;
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sector + 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(sector + partition.Start, run, out byte[] tmp);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2019-05-06 20:09:25 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
byte[] sbSector = new byte[AFS_SUPERBLOCK_SIZE];
|
2019-05-06 20:09:25 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(offset + AFS_SUPERBLOCK_SIZE > tmp.Length)
|
|
|
|
|
|
return false;
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Array.Copy(tmp, offset, sbSector, 0, AFS_SUPERBLOCK_SIZE);
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint magic = BitConverter.ToUInt32(sbSector, 0x20);
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return magic == AFS_MAGIC1;
|
|
|
|
|
|
}
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
information = "";
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ulong sector = AFS_BOOTBLOCK_SIZE / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
uint offset = AFS_BOOTBLOCK_SIZE % imagePlugin.Info.SectorSize;
|
|
|
|
|
|
uint run = 1;
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < AFS_SUPERBLOCK_SIZE)
|
|
|
|
|
|
run = AFS_SUPERBLOCK_SIZE / imagePlugin.Info.SectorSize;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(sector + partition.Start, run, out byte[] tmp);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
byte[] sbSector = new byte[AFS_SUPERBLOCK_SIZE];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Array.Copy(tmp, offset, sbSector, 0, AFS_SUPERBLOCK_SIZE);
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
SuperBlock afsSb = Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sbSector);
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.Atheos_filesystem);
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(afsSb.flags == 1)
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.Filesystem_is_read_only);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(afsSb.name, Encoding)).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_block, afsSb.block_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_blocks_in_volume_1_bytes, afsSb.num_blocks,
|
|
|
|
|
|
afsSb.num_blocks * afsSb.block_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_used_blocks_1_bytes, afsSb.used_blocks, afsSb.used_blocks * afsSb.block_size).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_i_node, afsSb.inode_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_blocks_per_allocation_group_1_bytes, afsSb.blocks_per_ag,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
afsSb.blocks_per_ag * afsSb.block_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_allocation_groups_in_volume, afsSb.num_ags).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Journal_resides_in_block_0_of_allocation_group_1_and_runs_for_2_blocks_3_bytes,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
afsSb.log_blocks_start, afsSb.log_blocks_ag, afsSb.log_blocks_len,
|
|
|
|
|
|
afsSb.log_blocks_len * afsSb.block_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Journal_starts_in_byte_0_and_has_1_bytes_in_2_blocks, afsSb.log_start,
|
|
|
|
|
|
afsSb.log_size, afsSb.log_valid_blocks).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
sb.
|
2022-11-28 02:59:53 +00:00
|
|
|
|
AppendFormat(Localization.Root_folder_s_i_node_resides_in_block_0_of_allocation_group_1_and_runs_for_2_blocks_3_bytes,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
afsSb.root_dir_start, afsSb.root_dir_ag, afsSb.root_dir_len,
|
|
|
|
|
|
afsSb.root_dir_len * afsSb.block_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
sb.
|
2022-11-28 02:59:53 +00:00
|
|
|
|
AppendFormat(Localization.Directory_containing_files_scheduled_for_deletion_i_node_resides_in_block_0_of_allocation_group_1_and_runs_for_2_blocks_3_bytes,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
afsSb.deleted_start, afsSb.deleted_ag, afsSb.deleted_len,
|
|
|
|
|
|
afsSb.deleted_len * afsSb.block_size).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
sb.
|
2022-11-28 02:59:53 +00:00
|
|
|
|
AppendFormat(Localization.Indices_i_node_resides_in_block_0_of_allocation_group_1_and_runs_for_2_blocks_3_bytes,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
afsSb.indices_start, afsSb.indices_ag, afsSb.indices_len,
|
|
|
|
|
|
afsSb.indices_len * afsSb.block_size).AppendLine();
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_blocks_for_bootloader_1_bytes, afsSb.boot_size,
|
|
|
|
|
|
afsSb.boot_size * afsSb.block_size).AppendLine();
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2017-07-26 03:08:29 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-07-26 03:08:29 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Clusters = (ulong)afsSb.num_blocks,
|
|
|
|
|
|
ClusterSize = afsSb.block_size,
|
|
|
|
|
|
Dirty = false,
|
|
|
|
|
|
FreeClusters = (ulong)(afsSb.num_blocks - afsSb.used_blocks),
|
|
|
|
|
|
FreeClustersSpecified = true,
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
VolumeName = StringHandlers.CToString(afsSb.name, Encoding)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2017-07-26 03:08:29 +01:00
|
|
|
|
}
|