mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Adds support for cram filesystem, closes #24
This commit is contained in:
205
DiscImageChef.Filesystems/Cram.cs
Normal file
205
DiscImageChef.Filesystems/Cram.cs
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : Cram.cs
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Component : Cram file system plugin.
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Identifies the Cram file system 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/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2011-2016 Natalia Portillo
|
||||||
|
// ****************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Security.Policy;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Filesystems
|
||||||
|
{
|
||||||
|
class Cram : Filesystem
|
||||||
|
{
|
||||||
|
public Cram()
|
||||||
|
{
|
||||||
|
Name = "Cram filesystem";
|
||||||
|
PluginUUID = new Guid("F8F6E46F-7A2A-48E3-9C0A-46AF4DC29E09");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cram(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
|
||||||
|
{
|
||||||
|
Name = "Cram filesystem";
|
||||||
|
PluginUUID = new Guid("F8F6E46F-7A2A-48E3-9C0A-46AF4DC29E09");
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CramCompression : ushort
|
||||||
|
{
|
||||||
|
Zlib = 1,
|
||||||
|
Lzma = 2,
|
||||||
|
Lzo = 3,
|
||||||
|
Xz = 4,
|
||||||
|
Lz4 = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
|
struct CramSuperBlock
|
||||||
|
{
|
||||||
|
public uint magic;
|
||||||
|
public uint size;
|
||||||
|
public uint flags;
|
||||||
|
public uint future;
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||||
|
public byte[] signature;
|
||||||
|
public uint crc;
|
||||||
|
public uint edition;
|
||||||
|
public uint blocks;
|
||||||
|
public uint files;
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||||
|
public byte[] name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Identifier for Cram
|
||||||
|
/// </summary>
|
||||||
|
const uint Cram_MAGIC = 0x28CD3D45;
|
||||||
|
const uint Cram_CIGAM = 0x453DCD28;
|
||||||
|
|
||||||
|
public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
|
||||||
|
{
|
||||||
|
if(partitionStart >= partitionEnd)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
byte[] sector = imagePlugin.ReadSector(partitionStart);
|
||||||
|
|
||||||
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
||||||
|
|
||||||
|
return magic == Cram_MAGIC || magic == Cram_CIGAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, out string information)
|
||||||
|
{
|
||||||
|
byte[] sector = imagePlugin.ReadSector(partitionStart);
|
||||||
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
||||||
|
|
||||||
|
CramSuperBlock crSb = new CramSuperBlock();
|
||||||
|
bool littleEndian = true;
|
||||||
|
|
||||||
|
if(magic == Cram_MAGIC)
|
||||||
|
{
|
||||||
|
IntPtr crSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(crSb));
|
||||||
|
Marshal.Copy(sector, 0, crSbPtr, Marshal.SizeOf(crSb));
|
||||||
|
crSb = (CramSuperBlock)Marshal.PtrToStructure(crSbPtr, typeof(CramSuperBlock));
|
||||||
|
Marshal.FreeHGlobal(crSbPtr);
|
||||||
|
}
|
||||||
|
else if(magic == Cram_CIGAM)
|
||||||
|
{
|
||||||
|
crSb = BigEndianMarshal.ByteArrayToStructureBigEndian<CramSuperBlock>(sector);
|
||||||
|
littleEndian = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sbInformation = new StringBuilder();
|
||||||
|
|
||||||
|
sbInformation.AppendLine("Cram file system");
|
||||||
|
if(littleEndian)
|
||||||
|
sbInformation.AppendLine("Little-endian");
|
||||||
|
else
|
||||||
|
sbInformation.AppendLine("Big-endian");
|
||||||
|
sbInformation.AppendFormat("Volume edition {0}", crSb.edition).AppendLine();
|
||||||
|
sbInformation.AppendFormat("Volume name: {0}", StringHandlers.CToString(crSb.name)).AppendLine();
|
||||||
|
sbInformation.AppendFormat("Volume has {0} bytes", crSb.size).AppendLine();
|
||||||
|
sbInformation.AppendFormat("Volume has {0} blocks", crSb.blocks).AppendLine();
|
||||||
|
sbInformation.AppendFormat("Volume has {0} files", crSb.files).AppendLine();
|
||||||
|
|
||||||
|
information = sbInformation.ToString();
|
||||||
|
|
||||||
|
xmlFSType = new Schemas.FileSystemType();
|
||||||
|
xmlFSType.VolumeName = StringHandlers.CToString(crSb.name);
|
||||||
|
xmlFSType.Type = "Cram file system";
|
||||||
|
xmlFSType.Clusters = crSb.blocks;
|
||||||
|
xmlFSType.Files = crSb.files;
|
||||||
|
xmlFSType.FilesSpecified = true;
|
||||||
|
xmlFSType.FreeClusters = 0;
|
||||||
|
xmlFSType.FreeClustersSpecified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -110,6 +110,7 @@
|
|||||||
<Compile Include="VMfs.cs" />
|
<Compile Include="VMfs.cs" />
|
||||||
<Compile Include="VxFS.cs" />
|
<Compile Include="VxFS.cs" />
|
||||||
<Compile Include="Squash.cs" />
|
<Compile Include="Squash.cs" />
|
||||||
|
<Compile Include="Cram.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ Supported file systems for identification and information only
|
|||||||
* VMware file system (VMFS)
|
* VMware file system (VMFS)
|
||||||
* Veritas file system
|
* Veritas file system
|
||||||
* Squash file system
|
* Squash file system
|
||||||
|
* Cram file system
|
||||||
|
|
||||||
Supported checksums
|
Supported checksums
|
||||||
===================
|
===================
|
||||||
|
|||||||
1
TODO
1
TODO
@@ -13,7 +13,6 @@ Filesystem plugins:
|
|||||||
--- Add support for CBM filesystem
|
--- Add support for CBM filesystem
|
||||||
--- Add support for ZFS
|
--- Add support for ZFS
|
||||||
--- Add support for UDF
|
--- Add support for UDF
|
||||||
--- Add support for CramFS
|
|
||||||
--- Add support for NwFS
|
--- Add support for NwFS
|
||||||
--- Add support for X-Box filesystems
|
--- Add support for X-Box filesystems
|
||||||
--- Add support for ReFS
|
--- Add support for ReFS
|
||||||
|
|||||||
Reference in New Issue
Block a user