2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-14 14:59:17 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2016-09-14 14:59:17 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-07-20 07:47:12 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-09-14 14:59:17 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
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-14 14:59:17 +01:00
|
|
|
|
|
2020-07-20 07:47:12 +01:00
|
|
|
|
// ReSharper disable UnusedMember.Local
|
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2016-09-14 14:59:17 +01:00
|
|
|
|
{
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Implements detection of the CRAM filesystem
|
|
|
|
|
|
/// </summary>
|
2020-07-20 07:47:12 +01:00
|
|
|
|
[SuppressMessage("ReSharper", "UnusedType.Local")]
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed class Cram : IFilesystem
|
2016-09-14 14:59:17 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for Cram</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint CRAM_MAGIC = 0x28CD3D45;
|
|
|
|
|
|
const uint CRAM_CIGAM = 0x453DCD28;
|
|
|
|
|
|
|
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 />
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public string Name => "Cram filesystem";
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Guid Id => new Guid("F8F6E46F-7A2A-48E3-9C0A-46AF4DC29E09");
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-08-29 22:15:43 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2016-09-14 14:59:17 +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-14 14:59:17 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2016-09-14 14:59:17 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2016-09-14 14:59:17 +01:00
|
|
|
|
|
|
|
|
|
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return magic == CRAM_MAGIC || magic == CRAM_CIGAM;
|
2016-09-14 14:59:17 +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-14 14:59:17 +01:00
|
|
|
|
{
|
2017-12-26 08:01:40 +00:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
2016-09-14 14:59:17 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
var crSb = new SuperBlock();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
bool littleEndian = true;
|
2016-09-14 14:59:17 +01:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
switch(magic)
|
|
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
case CRAM_MAGIC:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
crSb = Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
case CRAM_CIGAM:
|
2020-07-20 21:11:32 +01:00
|
|
|
|
crSb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sector);
|
2017-12-21 04:43:29 +00:00
|
|
|
|
littleEndian = false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
break;
|
2016-09-14 14:59:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2016-09-14 14:59:17 +01:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine("Cram file system");
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sbInformation.AppendLine(littleEndian ? "Little-endian" : "Big-endian");
|
2016-09-14 14:59:17 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume edition {0}", crSb.edition).AppendLine();
|
2017-12-26 08:01:40 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume name: {0}", StringHandlers.CToString(crSb.name, Encoding)).AppendLine();
|
2016-09-14 14:59:17 +01:00
|
|
|
|
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();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
|
VolumeName = StringHandlers.CToString(crSb.name, Encoding),
|
|
|
|
|
|
Type = "Cram file system",
|
|
|
|
|
|
Clusters = crSb.blocks,
|
|
|
|
|
|
Files = crSb.files,
|
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
|
FreeClusters = 0,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
FreeClustersSpecified = true
|
|
|
|
|
|
};
|
2016-09-14 14:59:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
enum CramCompression : ushort
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Zlib = 1, Lzma = 2, Lzo = 3,
|
|
|
|
|
|
Xz = 4, Lz4 = 5
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct SuperBlock
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly uint magic;
|
|
|
|
|
|
public readonly uint size;
|
|
|
|
|
|
public readonly uint flags;
|
|
|
|
|
|
public readonly uint future;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly byte[] signature;
|
|
|
|
|
|
public readonly uint crc;
|
|
|
|
|
|
public readonly uint edition;
|
|
|
|
|
|
public readonly uint blocks;
|
|
|
|
|
|
public readonly uint files;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly byte[] name;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-14 14:59:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|