2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Reiser.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Reiser filesystem plugin
|
2016-09-02 19:33:30 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Reiser filesystem and shows information.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
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;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
2021-08-17 14:25:12 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
/// <summary>Implements detection of the Reiser v3 filesystem</summary>
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed class Reiser : IFilesystem
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint REISER_SUPER_OFFSET = 0x10000;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
readonly byte[] _magic35 =
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x46, 0x73, 0x00, 0x00
|
|
|
|
|
|
};
|
2020-07-20 21:11:32 +01:00
|
|
|
|
readonly byte[] _magic36 =
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x32, 0x46, 0x73, 0x00
|
|
|
|
|
|
};
|
2020-07-20 21:11:32 +01:00
|
|
|
|
readonly byte[] _magicJr =
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x33, 0x46, 0x73, 0x00
|
|
|
|
|
|
};
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
public string Name => "Reiser Filesystem Plugin";
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public Guid Id => new("1D8CD8B8-27E6-410F-9973-D16409225FBA");
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-08-17 21:23:10 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2017-10-12 23:54:02 +01:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return false;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
|
|
|
|
|
|
if(sbAddr == 0)
|
|
|
|
|
|
sbAddr = 1;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sbSize++;
|
|
|
|
|
|
|
|
|
|
|
|
if(partition.Start + sbAddr + sbSize >= partition.End)
|
|
|
|
|
|
return false;
|
2017-07-23 19:58:11 +01:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize, out byte[] sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<Superblock>())
|
2020-02-29 18:03:35 +00:00
|
|
|
|
return false;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
return _magic35.SequenceEqual(reiserSb.magic) || _magic36.SequenceEqual(reiserSb.magic) ||
|
|
|
|
|
|
_magicJr.SequenceEqual(reiserSb.magic);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding encoding)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
|
2016-09-02 19:33:30 +01:00
|
|
|
|
information = "";
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
|
|
|
|
|
|
if(sbAddr == 0)
|
|
|
|
|
|
sbAddr = 1;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sbSize++;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2021-09-19 21:16:47 +01:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize, out byte[] sector);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<Superblock>())
|
2020-02-29 18:03:35 +00:00
|
|
|
|
return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Superblock reiserSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(!_magic35.SequenceEqual(reiserSb.magic) &&
|
|
|
|
|
|
!_magic36.SequenceEqual(reiserSb.magic) &&
|
|
|
|
|
|
!_magicJr.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_magic35.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sb.AppendLine("Reiser 3.5 filesystem");
|
2020-07-20 21:11:32 +01:00
|
|
|
|
else if(_magic36.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sb.AppendLine("Reiser 3.6 filesystem");
|
2020-07-20 21:11:32 +01:00
|
|
|
|
else if(_magicJr.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sb.AppendLine("Reiser Jr. filesystem");
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
sb.AppendFormat("Volume has {0} blocks with {1} blocks free", reiserSb.block_count, reiserSb.free_blocks).
|
|
|
|
|
|
AppendLine();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("{0} bytes per block", reiserSb.blocksize).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Root directory resides on block {0}", reiserSb.root_block).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
if(reiserSb.umount_state == 2)
|
|
|
|
|
|
sb.AppendLine("Volume has not been cleanly umounted");
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("Volume last checked on {0}", DateHandlers.UnixUnsignedToDateTime(reiserSb.last_check)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2016-09-02 19:33:30 +01:00
|
|
|
|
if(reiserSb.version >= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine();
|
2017-12-26 08:01:40 +00:00
|
|
|
|
sb.AppendFormat("Volume name: {0}", Encoding.GetString(reiserSb.label)).AppendLine();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(_magic35.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
XmlFsType.Type = "Reiser 3.5 filesystem";
|
2020-07-20 21:11:32 +01:00
|
|
|
|
else if(_magic36.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
XmlFsType.Type = "Reiser 3.6 filesystem";
|
2020-07-20 21:11:32 +01:00
|
|
|
|
else if(_magicJr.SequenceEqual(reiserSb.magic))
|
2020-02-29 18:03:35 +00:00
|
|
|
|
XmlFsType.Type = "Reiser Jr. filesystem";
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.ClusterSize = reiserSb.blocksize;
|
|
|
|
|
|
XmlFsType.Clusters = reiserSb.block_count;
|
|
|
|
|
|
XmlFsType.FreeClusters = reiserSb.free_blocks;
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.FreeClustersSpecified = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
XmlFsType.Dirty = reiserSb.umount_state == 2;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
if(reiserSb.version < 2)
|
|
|
|
|
|
return;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2021-03-01 19:32:21 +00:00
|
|
|
|
XmlFsType.VolumeName = StringHandlers.CToString(reiserSb.label, Encoding);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.VolumeSerial = reiserSb.uuid.ToString();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct JournalParameters
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly uint journal_1stblock;
|
|
|
|
|
|
public readonly uint journal_dev;
|
|
|
|
|
|
public readonly uint journal_size;
|
|
|
|
|
|
public readonly uint journal_trans_max;
|
|
|
|
|
|
public readonly uint journal_magic;
|
|
|
|
|
|
public readonly uint journal_max_batch;
|
|
|
|
|
|
public readonly uint journal_max_commit_age;
|
|
|
|
|
|
public readonly uint journal_max_trans_age;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-07-20 21:11:32 +01:00
|
|
|
|
struct Superblock
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
public readonly uint block_count;
|
|
|
|
|
|
public readonly uint free_blocks;
|
|
|
|
|
|
public readonly uint root_block;
|
|
|
|
|
|
public readonly JournalParameters journal;
|
|
|
|
|
|
public readonly ushort blocksize;
|
|
|
|
|
|
public readonly ushort oid_maxsize;
|
|
|
|
|
|
public readonly ushort oid_cursize;
|
|
|
|
|
|
public readonly ushort umount_state;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly byte[] magic;
|
|
|
|
|
|
public readonly ushort fs_state;
|
|
|
|
|
|
public readonly uint hash_function_code;
|
|
|
|
|
|
public readonly ushort tree_height;
|
|
|
|
|
|
public readonly ushort bmap_nr;
|
|
|
|
|
|
public readonly ushort version;
|
|
|
|
|
|
public readonly ushort reserved_for_journal;
|
|
|
|
|
|
public readonly uint inode_generation;
|
|
|
|
|
|
public readonly uint flags;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
public readonly Guid uuid;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly byte[] label;
|
|
|
|
|
|
public readonly ushort mnt_count;
|
|
|
|
|
|
public readonly ushort max_mnt_count;
|
|
|
|
|
|
public readonly uint last_check;
|
|
|
|
|
|
public readonly uint check_interval;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 76)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly byte[] unused;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|