2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Reiser4.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Component
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Reiser4 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-05-19 20:28:49 +01:00
|
|
|
|
// Copyright © 2011-2017 Natalia Portillo
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Linq;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-07-01 03:26:08 +01:00
|
|
|
|
public class Reiser4 : Filesystem
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct Reiser4_Superblock
|
|
|
|
|
|
{
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] magic;
|
|
|
|
|
|
public ushort diskformat;
|
|
|
|
|
|
public ushort blocksize;
|
|
|
|
|
|
public Guid uuid;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] label;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
readonly byte[] Reiser4_Magic = { 0x52, 0x65, 0x49, 0x73, 0x45, 0x72, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
const uint Reiser4_SuperOffset = 0x10000;
|
|
|
|
|
|
|
|
|
|
|
|
public Reiser4()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Reiser4 Filesystem Plugin";
|
|
|
|
|
|
PluginUUID = new Guid("301F2D00-E8D5-4F04-934E-81DFB21D15BA");
|
2017-06-06 21:23:20 +01:00
|
|
|
|
CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:54:02 +01:00
|
|
|
|
public Reiser4(Encoding encoding)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Reiser4 Filesystem Plugin";
|
|
|
|
|
|
PluginUUID = new Guid("301F2D00-E8D5-4F04-934E-81DFB21D15BA");
|
|
|
|
|
|
if(encoding == null)
|
|
|
|
|
|
CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
else
|
|
|
|
|
|
CurrentEncoding = encoding;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-19 16:31:08 +01:00
|
|
|
|
public Reiser4(ImagePlugins.ImagePlugin imagePlugin, Partition partition, Encoding encoding)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Reiser4 Filesystem Plugin";
|
|
|
|
|
|
PluginUUID = new Guid("301F2D00-E8D5-4F04-934E-81DFB21D15BA");
|
2017-06-06 21:23:20 +01:00
|
|
|
|
if(encoding == null)
|
|
|
|
|
|
CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
|
2017-07-26 12:25:18 +01:00
|
|
|
|
else
|
|
|
|
|
|
CurrentEncoding = encoding;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-19 16:31:08 +01:00
|
|
|
|
public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, Partition partition)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
if(imagePlugin.GetSectorSize() < 512)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
uint sbAddr = Reiser4_SuperOffset / imagePlugin.GetSectorSize();
|
|
|
|
|
|
if(sbAddr == 0)
|
|
|
|
|
|
sbAddr = 1;
|
|
|
|
|
|
|
|
|
|
|
|
Reiser4_Superblock reiserSb = new Reiser4_Superblock();
|
|
|
|
|
|
|
|
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.GetSectorSize());
|
|
|
|
|
|
if(Marshal.SizeOf(reiserSb) % imagePlugin.GetSectorSize() != 0)
|
|
|
|
|
|
sbSize++;
|
|
|
|
|
|
|
2017-07-23 19:58:11 +01:00
|
|
|
|
if(partition.Start + sbAddr + sbSize >= partition.End)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
if(sector.Length < Marshal.SizeOf(reiserSb))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
reiserSb = (Reiser4_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser4_Superblock));
|
|
|
|
|
|
Marshal.FreeHGlobal(sbPtr);
|
|
|
|
|
|
|
|
|
|
|
|
return Reiser4_Magic.SequenceEqual(reiserSb.magic);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-19 16:31:08 +01:00
|
|
|
|
public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, Partition partition, out string information)
|
2016-09-02 19:33:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
information = "";
|
|
|
|
|
|
if(imagePlugin.GetSectorSize() < 512)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
uint sbAddr = Reiser4_SuperOffset / imagePlugin.GetSectorSize();
|
|
|
|
|
|
if(sbAddr == 0)
|
|
|
|
|
|
sbAddr = 1;
|
|
|
|
|
|
|
|
|
|
|
|
Reiser4_Superblock reiserSb = new Reiser4_Superblock();
|
|
|
|
|
|
|
|
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf(reiserSb) / imagePlugin.GetSectorSize());
|
|
|
|
|
|
if(Marshal.SizeOf(reiserSb) % imagePlugin.GetSectorSize() != 0)
|
|
|
|
|
|
sbSize++;
|
|
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
if(sector.Length < Marshal.SizeOf(reiserSb))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
|
|
|
|
|
|
reiserSb = (Reiser4_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser4_Superblock));
|
|
|
|
|
|
Marshal.FreeHGlobal(sbPtr);
|
|
|
|
|
|
|
|
|
|
|
|
if(!Reiser4_Magic.SequenceEqual(reiserSb.magic))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("Reiser 4 filesystem");
|
|
|
|
|
|
sb.AppendFormat("{0} bytes per block", reiserSb.blocksize).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Volume disk format: {0}", reiserSb.diskformat).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("Volume UUID: {0}", reiserSb.uuid).AppendLine();
|
2017-07-11 02:32:51 +01:00
|
|
|
|
sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(reiserSb.label, CurrentEncoding)).AppendLine();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
xmlFSType = new Schemas.FileSystemType();
|
|
|
|
|
|
xmlFSType.Type = "Reiser 4 filesystem";
|
|
|
|
|
|
xmlFSType.ClusterSize = reiserSb.blocksize;
|
2017-07-19 16:37:11 +01:00
|
|
|
|
xmlFSType.Clusters = (long)(((partition.End - partition.Start) * imagePlugin.GetSectorSize()) / reiserSb.blocksize);
|
2017-07-11 02:32:51 +01:00
|
|
|
|
xmlFSType.VolumeName = StringHandlers.CToString(reiserSb.label, CurrentEncoding);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
xmlFSType.VolumeSerial = reiserSb.uuid.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Mount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Mount(bool debug)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Unmount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ReadDir(string path, ref List<string> contents)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno StatFs(ref FileSystemInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ReadLink(string path, ref string dest)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|