2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : BeOS filesystem 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
|
2011-03-28 13:46:30 +00:00
|
|
|
|
using System;
|
2020-07-20 07:47:12 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-07-19 16:31:08 +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;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2011-03-28 13:46:30 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// Information from Practical Filesystem Design, ISBN 1-55860-497-9
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection of the Be (new) filesystem</summary>
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class BeFS
|
2011-03-28 13:46:30 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(2 + partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(0 + partition.Start, out byte[] sbSector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint magic = BitConverter.ToUInt32(sbSector, 0x20);
|
|
|
|
|
|
uint magicBe = BigEndianBitConverter.ToUInt32(sbSector, 0x20);
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(magic == BEFS_MAGIC1 ||
|
|
|
|
|
|
magicBe == BEFS_MAGIC1)
|
|
|
|
|
|
return true;
|
2015-11-09 19:42:00 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sbSector.Length >= 0x400)
|
|
|
|
|
|
{
|
|
|
|
|
|
magic = BitConverter.ToUInt32(sbSector, 0x220);
|
|
|
|
|
|
magicBe = BigEndianBitConverter.ToUInt32(sbSector, 0x220);
|
|
|
|
|
|
}
|
2015-11-09 19:42:00 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(magic == BEFS_MAGIC1 ||
|
|
|
|
|
|
magicBe == BEFS_MAGIC1)
|
|
|
|
|
|
return true;
|
2015-11-09 19:42:00 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
errno = imagePlugin.ReadSector(1 + partition.Start, out sbSector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
magic = BitConverter.ToUInt32(sbSector, 0x20);
|
|
|
|
|
|
magicBe = BigEndianBitConverter.ToUInt32(sbSector, 0x20);
|
2011-03-28 22:56:20 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return magic == BEFS_MAGIC1 || magicBe == BEFS_MAGIC1;
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00: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();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
var besb = new SuperBlock();
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(0 + partition.Start, out byte[] sbSector);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
bool littleEndian;
|
|
|
|
|
|
|
|
|
|
|
|
besb.magic1 = BigEndianBitConverter.ToUInt32(sbSector, 0x20);
|
|
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
|
if(besb.magic1 is BEFS_MAGIC1 or BEFS_CIGAM1) // Magic is at offset
|
2022-03-06 13:29:38 +00:00
|
|
|
|
littleEndian = besb.magic1 == BEFS_CIGAM1;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
errno = imagePlugin.ReadSector(1 + partition.Start, out sbSector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2014-04-14 01:14:20 +00:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
besb.magic1 = BigEndianBitConverter.ToUInt32(sbSector, 0x20);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
|
if(besb.magic1 is BEFS_MAGIC1 or BEFS_CIGAM1) // There is a boot sector
|
2017-07-23 21:01:26 +01:00
|
|
|
|
littleEndian = besb.magic1 == BEFS_CIGAM1;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else if(sbSector.Length >= 0x400)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
errno = imagePlugin.ReadSector(0 + partition.Start, out byte[] temp);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
besb.magic1 = BigEndianBitConverter.ToUInt32(temp, 0x220);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
|
if(besb.magic1 is BEFS_MAGIC1 or BEFS_CIGAM1) // There is a boot sector
|
2015-11-09 19:42:00 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
littleEndian = besb.magic1 == BEFS_CIGAM1;
|
|
|
|
|
|
sbSector = new byte[0x200];
|
|
|
|
|
|
Array.Copy(temp, 0x200, sbSector, 0, 0x200);
|
2015-11-09 19:42:00 +00:00
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
else
|
|
|
|
|
|
return;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2012-08-05 00:43:49 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
besb = littleEndian ? Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sbSector)
|
|
|
|
|
|
: Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(littleEndian ? Localization.Little_endian_BeFS : Localization.Big_endian_BeFS);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(besb.magic1 != BEFS_MAGIC1 ||
|
|
|
|
|
|
besb.fs_byte_order != BEFS_ENDIAN ||
|
|
|
|
|
|
besb.magic2 != BEFS_MAGIC2 ||
|
|
|
|
|
|
besb.magic3 != BEFS_MAGIC3 ||
|
|
|
|
|
|
besb.root_dir_len != 1 ||
|
|
|
|
|
|
besb.indices_len != 1 ||
|
|
|
|
|
|
1 << (int)besb.block_shift != besb.block_size)
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.Superblock_seems_corrupt_following_information_may_be_incorrect);
|
|
|
|
|
|
sb.AppendFormat(Localization.Magic_one_0_Should_be_0x42465331, besb.magic1).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Magic_two_0_Should_be_0xDD121031, besb.magic2).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Magic_three_0_Should_be_0x15B6830E, besb.magic3).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Filesystem_endianness_0_Should_be_0x42494745, besb.fs_byte_order).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Root_folder_i_node_size_0_blocks_Should_be_one, besb.root_dir_len).
|
|
|
|
|
|
AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Indices_i_node_size_0_blocks_Should_be_one, besb.indices_len).AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(Localization.blockshift_0_1_should_be_2, besb.block_shift, 1 << (int)besb.block_shift,
|
|
|
|
|
|
besb.block_size).AppendLine();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
switch(besb.flags)
|
|
|
|
|
|
{
|
|
|
|
|
|
case BEFS_CLEAN:
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(besb.log_start == besb.log_end ? Localization.Filesystem_is_clean
|
|
|
|
|
|
: Localization.Filesystem_is_dirty);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case BEFS_DIRTY:
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.Filesystem_is_dirty);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Unknown_flags_0_X8, besb.flags).AppendLine();
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-12-17 23:17:18 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(besb.name, encoding)).AppendLine();
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_block, besb.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, besb.num_blocks, besb.num_blocks * besb.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_used_blocks_1_bytes, besb.used_blocks, besb.used_blocks * besb.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, besb.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, besb.blocks_per_ag,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
besb.blocks_per_ag * besb.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, besb.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
|
|
|
|
besb.log_blocks_start, besb.log_blocks_ag, besb.log_blocks_len,
|
|
|
|
|
|
besb.log_blocks_len * besb.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_ends_in_byte_1, besb.log_start, besb.log_end).
|
|
|
|
|
|
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-07 07:36:44 +00:00
|
|
|
|
besb.root_dir_start, besb.root_dir_ag, besb.root_dir_len, besb.root_dir_len * besb.block_size).
|
|
|
|
|
|
AppendLine();
|
2016-04-19 02:11:47 +01: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
|
|
|
|
besb.indices_start, besb.indices_ag, besb.indices_len, besb.indices_len * besb.block_size).
|
|
|
|
|
|
AppendLine();
|
2015-12-05 17:10:27 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
|
Clusters = (ulong)besb.num_blocks,
|
|
|
|
|
|
ClusterSize = besb.block_size,
|
|
|
|
|
|
Dirty = besb.flags == BEFS_DIRTY,
|
|
|
|
|
|
FreeClusters = (ulong)(besb.num_blocks - besb.used_blocks),
|
|
|
|
|
|
Type = FS_TYPE,
|
2022-12-17 23:17:18 +00:00
|
|
|
|
VolumeName = StringHandlers.CToString(besb.name, encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|