2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public 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
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
readonly byte[] Reiser35_Magic = {0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x46, 0x73, 0x00, 0x00};
|
|
|
|
|
|
readonly byte[] Reiser36_Magic = {0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x32, 0x46, 0x73, 0x00};
|
|
|
|
|
|
readonly byte[] ReiserJr_Magic = {0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x33, 0x46, 0x73, 0x00};
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding currentEncoding;
|
|
|
|
|
|
FileSystemType xmlFsType;
|
|
|
|
|
|
public virtual FileSystemType XmlFsType => xmlFsType;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual Encoding Encoding => currentEncoding;
|
|
|
|
|
|
public virtual string Name => "Reiser Filesystem Plugin";
|
|
|
|
|
|
public virtual Guid Id => new Guid("1D8CD8B8-27E6-410F-9973-D16409225FBA");
|
2017-10-12 23:54:02 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return false;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sbAddr == 0) sbAddr = 1;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
Reiser_Superblock reiserSb = new Reiser_Superblock();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.Info.SectorSize);
|
|
|
|
|
|
if(Marshal.SizeOf(reiserSb) % imagePlugin.Info.SectorSize != 0) sbSize++;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start + sbAddr + sbSize >= partition.End) return false;
|
2017-07-23 19:58:11 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sector.Length < Marshal.SizeOf(reiserSb)) return false;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
reiserSb = (Reiser_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser_Superblock));
|
|
|
|
|
|
Marshal.FreeHGlobal(sbPtr);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
return Reiser35_Magic.SequenceEqual(reiserSb.magic) || Reiser36_Magic.SequenceEqual(reiserSb.magic) ||
|
|
|
|
|
|
ReiserJr_Magic.SequenceEqual(reiserSb.magic);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public virtual void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
currentEncoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
|
2016-09-02 19:33:30 +01:00
|
|
|
|
information = "";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
uint sbAddr = REISER_SUPER_OFFSET / imagePlugin.Info.SectorSize;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sbAddr == 0) sbAddr = 1;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
Reiser_Superblock reiserSb = new Reiser_Superblock();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.Info.SectorSize);
|
|
|
|
|
|
if(Marshal.SizeOf(reiserSb) % imagePlugin.Info.SectorSize != 0) sbSize++;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(sector.Length < Marshal.SizeOf(reiserSb)) return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
reiserSb = (Reiser_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser_Superblock));
|
|
|
|
|
|
Marshal.FreeHGlobal(sbPtr);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!Reiser35_Magic.SequenceEqual(reiserSb.magic) && !Reiser36_Magic.SequenceEqual(reiserSb.magic) &&
|
|
|
|
|
|
!ReiserJr_Magic.SequenceEqual(reiserSb.magic)) return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(Reiser35_Magic.SequenceEqual(reiserSb.magic)) sb.AppendLine("Reiser 3.5 filesystem");
|
|
|
|
|
|
else if(Reiser36_Magic.SequenceEqual(reiserSb.magic)) sb.AppendLine("Reiser 3.6 filesystem");
|
|
|
|
|
|
else if(ReiserJr_Magic.SequenceEqual(reiserSb.magic)) sb.AppendLine("Reiser Jr. filesystem");
|
|
|
|
|
|
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();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(reiserSb.umount_state == 2) sb.AppendLine("Volume has not been cleanly umounted");
|
2017-12-23 03:59:48 +00:00
|
|
|
|
sb.AppendFormat("Volume last checked on {0}", DateHandlers.UnixUnsignedToDateTime(reiserSb.last_check))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
if(reiserSb.version >= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sb.AppendFormat("Volume name: {0}", currentEncoding.GetString(reiserSb.label)).AppendLine();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType = new FileSystemType();
|
|
|
|
|
|
if(Reiser35_Magic.SequenceEqual(reiserSb.magic)) xmlFsType.Type = "Reiser 3.5 filesystem";
|
|
|
|
|
|
else if(Reiser36_Magic.SequenceEqual(reiserSb.magic)) xmlFsType.Type = "Reiser 3.6 filesystem";
|
|
|
|
|
|
else if(ReiserJr_Magic.SequenceEqual(reiserSb.magic)) xmlFsType.Type = "Reiser Jr. filesystem";
|
|
|
|
|
|
xmlFsType.ClusterSize = reiserSb.blocksize;
|
|
|
|
|
|
xmlFsType.Clusters = reiserSb.block_count;
|
|
|
|
|
|
xmlFsType.FreeClusters = reiserSb.free_blocks;
|
|
|
|
|
|
xmlFsType.FreeClustersSpecified = true;
|
|
|
|
|
|
xmlFsType.Dirty = reiserSb.umount_state == 2;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(reiserSb.version < 2) return;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType.VolumeName = currentEncoding.GetString(reiserSb.label);
|
|
|
|
|
|
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)]
|
|
|
|
|
|
struct ReiserJournalParams
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint journal_1stblock;
|
|
|
|
|
|
public uint journal_dev;
|
|
|
|
|
|
public uint journal_size;
|
|
|
|
|
|
public uint journal_trans_max;
|
|
|
|
|
|
public uint journal_magic;
|
|
|
|
|
|
public uint journal_max_batch;
|
|
|
|
|
|
public uint journal_max_commit_age;
|
|
|
|
|
|
public uint journal_max_trans_age;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct Reiser_Superblock
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint block_count;
|
|
|
|
|
|
public uint free_blocks;
|
|
|
|
|
|
public uint root_block;
|
|
|
|
|
|
public ReiserJournalParams journal;
|
|
|
|
|
|
public ushort blocksize;
|
|
|
|
|
|
public ushort oid_maxsize;
|
|
|
|
|
|
public ushort oid_cursize;
|
|
|
|
|
|
public ushort umount_state;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] public byte[] magic;
|
|
|
|
|
|
public ushort fs_state;
|
|
|
|
|
|
public uint hash_function_code;
|
|
|
|
|
|
public ushort tree_height;
|
|
|
|
|
|
public ushort bmap_nr;
|
|
|
|
|
|
public ushort version;
|
|
|
|
|
|
public ushort reserved_for_journal;
|
|
|
|
|
|
public uint inode_generation;
|
|
|
|
|
|
public uint flags;
|
|
|
|
|
|
public Guid uuid;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] label;
|
|
|
|
|
|
public ushort mnt_count;
|
|
|
|
|
|
public ushort max_mnt_count;
|
|
|
|
|
|
public uint last_check;
|
|
|
|
|
|
public uint check_interval;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 76)] public byte[] unused;
|
|
|
|
|
|
}
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|