diff --git a/DiscImageChef.Filesystems/Cram.cs b/DiscImageChef.Filesystems/Cram.cs new file mode 100644 index 00000000..a7f936de --- /dev/null +++ b/DiscImageChef.Filesystems/Cram.cs @@ -0,0 +1,205 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Cram.cs +// Author(s) : Natalia Portillo +// +// 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 . +// +// ---------------------------------------------------------------------------- +// 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; + } + + /// + /// Identifier for Cram + /// + 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(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 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 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; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj index a3f7e27d..54952f47 100644 --- a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj +++ b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj @@ -110,6 +110,7 @@ + diff --git a/README.md b/README.md index 26f591c2..59decc81 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ Supported file systems for identification and information only * VMware file system (VMFS) * Veritas file system * Squash file system +* Cram file system Supported checksums =================== diff --git a/TODO b/TODO index cae6924d..b44960ab 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,6 @@ Filesystem plugins: --- Add support for CBM filesystem --- Add support for ZFS --- Add support for UDF ---- Add support for CramFS --- Add support for NwFS --- Add support for X-Box filesystems --- Add support for ReFS