Files
Aaru/Aaru.Filesystems/Reiser/Info.cs

147 lines
5.6 KiB
C#
Raw 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>
//
// Component : Reiser 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System.Linq;
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 Reiser v3 filesystem</summary>
public sealed partial class Reiser
{
#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(imagePlugin.Info.SectorSize < 512) return false;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize;
2024-05-01 04:05:22 +01:00
if(sbAddr == 0) sbAddr = 1;
var sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0) sbSize++;
2017-07-23 19:58:11 +01:00
2024-05-01 04:05:22 +01:00
if(partition.Start + sbAddr + sbSize >= partition.End) return false;
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, false, sbSize, out byte[] sector, out _);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2024-05-01 04:05:22 +01:00
if(sector.Length < Marshal.SizeOf<Superblock>()) return false;
2022-03-06 13:29:38 +00:00
Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
return _magic35.SequenceEqual(reiserSb.magic) ||
_magic36.SequenceEqual(reiserSb.magic) ||
2022-03-06 13:29:38 +00:00
_magicJr.SequenceEqual(reiserSb.magic);
}
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
{
encoding ??= Encoding.GetEncoding("iso-8859-15");
information = "";
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;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize;
2024-05-01 04:05:22 +01:00
if(sbAddr == 0) sbAddr = 1;
2020-02-29 18:03:35 +00:00
var sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
2024-05-01 04:05:22 +01:00
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0) sbSize++;
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, false, sbSize, out byte[] sector, out _);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return;
2024-05-01 04:05:22 +01:00
if(sector.Length < Marshal.SizeOf<Superblock>()) return;
2022-03-06 13:29:38 +00:00
Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(!_magic35.SequenceEqual(reiserSb.magic) &&
!_magic36.SequenceEqual(reiserSb.magic) &&
!_magicJr.SequenceEqual(reiserSb.magic))
return;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
var sb = new StringBuilder();
2022-03-06 13:29:38 +00:00
if(_magic35.SequenceEqual(reiserSb.magic))
sb.AppendLine(Localization.Reiser_3_5_filesystem);
2022-03-06 13:29:38 +00:00
else if(_magic36.SequenceEqual(reiserSb.magic))
sb.AppendLine(Localization.Reiser_3_6_filesystem);
2024-05-01 04:05:22 +01:00
else if(_magicJr.SequenceEqual(reiserSb.magic)) sb.AppendLine(Localization.Reiser_Jr_filesystem);
2024-05-01 04:05:22 +01:00
sb.AppendFormat(Localization.Volume_has_0_blocks_with_1_blocks_free, reiserSb.block_count, reiserSb.free_blocks)
.AppendLine();
2020-02-29 18:03:35 +00:00
sb.AppendFormat(Localization._0_bytes_per_block, reiserSb.blocksize).AppendLine();
sb.AppendFormat(Localization.Root_directory_resides_on_block_0, reiserSb.root_block).AppendLine();
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(reiserSb.umount_state == 2) sb.AppendLine(Localization.Volume_has_not_been_cleanly_umounted);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
sb.AppendFormat(Localization.Volume_last_checked_on_0, DateHandlers.UnixUnsignedToDateTime(reiserSb.last_check))
.AppendLine();
2022-03-06 13:29:38 +00:00
if(reiserSb.version >= 2)
{
sb.AppendFormat(Localization.Volume_UUID_0, reiserSb.uuid).AppendLine();
sb.AppendFormat(Localization.Volume_name_0, encoding.GetString(reiserSb.label)).AppendLine();
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
information = sb.ToString();
2020-02-29 18:03:35 +00:00
metadata = new FileSystem
{
Type = FS_TYPE,
ClusterSize = reiserSb.blocksize,
Clusters = reiserSb.block_count,
FreeClusters = reiserSb.free_blocks,
Dirty = reiserSb.umount_state == 2
};
2024-05-01 04:05:22 +01:00
if(reiserSb.version < 2) return;
metadata.VolumeName = StringHandlers.CToString(reiserSb.label, encoding);
metadata.VolumeSerial = reiserSb.uuid.ToString();
2022-03-06 13:29:38 +00:00
}
#endregion
}