Files
Aaru/Aaru.Filesystems/Cram/Info.cs

121 lines
4.3 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
2022-12-07 13:07:31 +00:00
// Filename : Info.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Cram file system plugin.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2022-12-03 16:07:10 +00:00
// Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/
2022-03-07 07:36:44 +00:00
// ReSharper disable UnusedMember.Local
using System;
2020-07-20 07:47:12 +01:00
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Enums;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
using Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
/// <summary>Implements detection of the CRAM filesystem</summary>
[SuppressMessage("ReSharper", "UnusedType.Local")]
2022-12-07 13:07:31 +00:00
public sealed partial class Cram
{
#region IFilesystem Members
/// <inheritdoc />
2022-03-06 13:29:38 +00:00
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
2022-03-06 13:29:38 +00:00
if(partition.Start >= partition.End)
return false;
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSector(partition.Start, out byte[] sector);
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return false;
var magic = BitConverter.ToUInt32(sector, 0x00);
2022-03-16 11:47:00 +00:00
return magic is CRAM_MAGIC or CRAM_CIGAM;
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
out FileSystem metadata)
2022-03-06 13:29:38 +00:00
{
encoding ??= Encoding.GetEncoding("iso-8859-15");
information = "";
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSector(partition.Start, out byte[] sector);
metadata = new FileSystem();
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return;
var magic = BitConverter.ToUInt32(sector, 0x00);
2022-03-06 13:29:38 +00:00
var crSb = new SuperBlock();
var littleEndian = true;
2022-03-06 13:29:38 +00:00
switch(magic)
{
2022-03-06 13:29:38 +00:00
case CRAM_MAGIC:
crSb = Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sector);
break;
case CRAM_CIGAM:
crSb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sector);
littleEndian = false;
break;
}
2022-03-06 13:29:38 +00:00
var sbInformation = new StringBuilder();
sbInformation.AppendLine(Localization.Cram_file_system);
sbInformation.AppendLine(littleEndian ? Localization.Little_endian : Localization.Big_endian);
sbInformation.AppendFormat(Localization.Volume_edition_0, crSb.edition).AppendLine();
sbInformation.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(crSb.name, encoding)).
AppendLine();
sbInformation.AppendFormat(Localization.Volume_has_0_bytes, crSb.size).AppendLine();
sbInformation.AppendFormat(Localization.Volume_has_0_blocks, crSb.blocks).AppendLine();
sbInformation.AppendFormat(Localization.Volume_has_0_files, crSb.files).AppendLine();
2022-03-06 13:29:38 +00:00
information = sbInformation.ToString();
metadata = new FileSystem
{
VolumeName = StringHandlers.CToString(crSb.name, encoding),
Type = FS_TYPE,
Clusters = crSb.blocks,
Files = crSb.files,
FreeClusters = 0
2022-03-06 13:29:38 +00:00
};
}
#endregion
}