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

154 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/>.
//
// ----------------------------------------------------------------------------
2022-12-03 16:07:10 +00:00
// Copyright © 2011-2023 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>
2022-12-07 13:07:31 +00:00
public sealed partial class Reiser : IFilesystem
{
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
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;
2022-03-06 13:29:38 +00:00
if(sbAddr == 0)
sbAddr = 1;
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
sbSize++;
2017-07-23 19:58:11 +01:00
2022-03-06 13:29:38 +00:00
if(partition.Start + sbAddr + sbSize >= partition.End)
return false;
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize, out byte[] sector);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return false;
2022-03-06 13:29:38 +00:00
if(sector.Length < Marshal.SizeOf<Superblock>())
return false;
2022-03-06 13:29:38 +00:00
Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
2022-03-06 13:29:38 +00:00
return _magic35.SequenceEqual(reiserSb.magic) || _magic36.SequenceEqual(reiserSb.magic) ||
_magicJr.SequenceEqual(reiserSb.magic);
}
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 = "";
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00: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;
2022-03-06 13:29:38 +00:00
if(sbAddr == 0)
sbAddr = 1;
2020-02-29 18:03:35 +00:00
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
2022-03-06 13:29:38 +00:00
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
sbSize++;
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize, out byte[] sector);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return;
2022-03-06 13:29:38 +00: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);
2022-03-06 13:29:38 +00:00
else if(_magicJr.SequenceEqual(reiserSb.magic))
sb.AppendLine(Localization.Reiser_Jr_filesystem);
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
2022-03-06 13:29:38 +00:00
if(reiserSb.umount_state == 2)
sb.AppendLine(Localization.Volume_has_not_been_cleanly_umounted);
2020-02-29 18:03:35 +00: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
};
2022-03-06 13:29:38 +00: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
}
}