Files
Aaru/Aaru.Filesystems/dump/Info.cs

250 lines
9.5 KiB
C#
Raw Normal View History

2017-09-16 00:57:26 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2017-09-16 00:57:26 +01:00
// ----------------------------------------------------------------------------
//
2022-12-07 13:07:31 +00:00
// Filename : Info.cs
2017-09-16 00:57:26 +01:00
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : dump(8) file system plugin
2017-09-16 00:57:26 +01:00
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies backups created with dump(8) shows information.
2017-09-16 00:57:26 +01:00
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
2017-09-16 00:57:26 +01:00
// ****************************************************************************/
using System.Diagnostics.CodeAnalysis;
2017-09-16 00:57:26 +01:00
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 Aaru.Logging;
using Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
/// <summary>Implements identification of a dump(8) image (virtual filesystem on a file)</summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "UnusedMember.Local")]
2023-10-05 02:31:59 +01:00
public sealed partial class Dump
2017-09-16 00:57:26 +01:00
{
#region IFilesystem Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
2017-09-16 00:57:26 +01:00
{
2024-05-01 04:05:22 +01:00
if(imagePlugin.Info.SectorSize < 512) return false;
2017-09-16 00:57:26 +01:00
2022-03-06 13:29:38 +00:00
// It should be start of a tape or floppy or file
2024-05-01 04:05:22 +01:00
if(partition.Start != 0) return false;
2017-09-16 00:57:26 +01:00
var sbSize = (uint)(Marshal.SizeOf<s_spcl>() / imagePlugin.Info.SectorSize);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(Marshal.SizeOf<s_spcl>() % imagePlugin.Info.SectorSize != 0) sbSize++;
2017-09-16 00:57:26 +01:00
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, false, sbSize, out byte[] sector, out _);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(sector.Length < Marshal.SizeOf<s_spcl>()) return false;
2017-09-16 00:57:26 +01:00
2022-03-06 13:29:38 +00:00
spcl16 oldHdr = Marshal.ByteArrayToStructureLittleEndian<spcl16>(sector);
spcl_aix aixHdr = Marshal.ByteArrayToStructureLittleEndian<spcl_aix>(sector);
s_spcl newHdr = Marshal.ByteArrayToStructureLittleEndian<s_spcl>(sector);
2017-09-16 00:57:26 +01:00
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(MODULE_NAME, "old magic = 0x{0:X8}", oldHdr.c_magic);
AaruLogging.Debug(MODULE_NAME, "aix magic = 0x{0:X8}", aixHdr.c_magic);
AaruLogging.Debug(MODULE_NAME, "new magic = 0x{0:X8}", newHdr.c_magic);
2017-09-16 00:57:26 +01:00
return oldHdr.c_magic == OFS_MAGIC ||
aixHdr.c_magic is XIX_MAGIC or XIX_CIGAM ||
newHdr.c_magic == OFS_MAGIC ||
newHdr.c_magic == NFS_MAGIC ||
newHdr.c_magic == OFS_CIGAM ||
newHdr.c_magic == NFS_CIGAM ||
newHdr.c_magic == UFS2_MAGIC ||
newHdr.c_magic == UFS2_CIGAM;
2022-03-06 13:29:38 +00:00
}
2017-09-16 00:57:26 +01: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
{
information = "";
metadata = new FileSystem();
2017-09-16 00:57:26 +01:00
2024-05-01 04:05:22 +01:00
if(imagePlugin.Info.SectorSize < 512) return;
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(partition.Start != 0) return;
2017-09-16 00:57:26 +01:00
var sbSize = (uint)(Marshal.SizeOf<s_spcl>() / imagePlugin.Info.SectorSize);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(Marshal.SizeOf<s_spcl>() % imagePlugin.Info.SectorSize != 0) sbSize++;
2017-09-16 00:57:26 +01:00
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, false, sbSize, out byte[] sector, out _);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return;
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(sector.Length < Marshal.SizeOf<s_spcl>()) return;
2017-09-16 00:57:26 +01:00
2022-03-06 13:29:38 +00:00
spcl16 oldHdr = Marshal.ByteArrayToStructureLittleEndian<spcl16>(sector);
spcl_aix aixHdr = Marshal.ByteArrayToStructureLittleEndian<spcl_aix>(sector);
s_spcl newHdr = Marshal.ByteArrayToStructureLittleEndian<s_spcl>(sector);
2017-09-16 00:57:26 +01:00
var useOld = false;
var useAix = false;
2017-09-16 00:57:26 +01:00
2022-03-06 13:29:38 +00:00
if(newHdr.c_magic == OFS_MAGIC ||
newHdr.c_magic == NFS_MAGIC ||
newHdr.c_magic == OFS_CIGAM ||
newHdr.c_magic == NFS_CIGAM ||
newHdr.c_magic == UFS2_MAGIC ||
newHdr.c_magic == UFS2_CIGAM)
{
if(newHdr.c_magic == OFS_CIGAM || newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_CIGAM)
newHdr = Marshal.ByteArrayToStructureBigEndian<s_spcl>(sector);
2022-03-06 13:29:38 +00:00
}
2022-03-16 11:47:00 +00:00
else if(aixHdr.c_magic is XIX_MAGIC or XIX_CIGAM)
2022-03-06 13:29:38 +00:00
{
useAix = true;
if(aixHdr.c_magic == XIX_CIGAM) aixHdr = Marshal.ByteArrayToStructureBigEndian<spcl_aix>(sector);
2022-03-06 13:29:38 +00:00
}
else if(oldHdr.c_magic == OFS_MAGIC)
{
useOld = true;
// Swap PDP-11 endian
oldHdr.c_date = (int)Swapping.PDPFromLittleEndian((uint)oldHdr.c_date);
oldHdr.c_ddate = (int)Swapping.PDPFromLittleEndian((uint)oldHdr.c_ddate);
}
else
{
information = Localization.Could_not_read_dump_8_header_block;
2022-03-06 13:29:38 +00:00
return;
}
var sb = new StringBuilder();
metadata = new FileSystem
2022-03-06 13:29:38 +00:00
{
ClusterSize = 1024,
Clusters = partition.Size / 1024
};
if(useOld)
{
metadata.Type = Localization.Old_16_bit_dump_8;
sb.AppendLine(metadata.Type);
2022-03-06 13:29:38 +00:00
if(oldHdr.c_date > 0)
2017-09-16 00:57:26 +01:00
{
metadata.CreationDate = DateHandlers.UnixToDateTime(oldHdr.c_date);
sb.AppendFormat(Localization.Dump_created_on_0, metadata.CreationDate).AppendLine();
2017-09-16 00:57:26 +01:00
}
2022-03-06 13:29:38 +00:00
if(oldHdr.c_ddate > 0)
2017-09-16 00:57:26 +01:00
{
metadata.BackupDate = DateHandlers.UnixToDateTime(oldHdr.c_ddate);
sb.AppendFormat(Localization.Previous_dump_created_on_0, metadata.BackupDate).AppendLine();
2017-09-16 00:57:26 +01:00
}
2022-03-06 13:29:38 +00:00
sb.AppendFormat(Localization.Dump_volume_number_0, oldHdr.c_volume).AppendLine();
2022-03-06 13:29:38 +00:00
}
else if(useAix)
{
metadata.Type = FS_TYPE;
sb.AppendLine(metadata.Type);
2022-03-06 13:29:38 +00:00
if(aixHdr.c_date > 0)
2017-09-16 00:57:26 +01:00
{
metadata.CreationDate = DateHandlers.UnixToDateTime(aixHdr.c_date);
sb.AppendFormat(Localization.Dump_created_on_0, metadata.CreationDate).AppendLine();
2022-03-06 13:29:38 +00:00
}
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if(aixHdr.c_ddate > 0)
{
metadata.BackupDate = DateHandlers.UnixToDateTime(aixHdr.c_ddate);
sb.AppendFormat(Localization.Previous_dump_created_on_0, metadata.BackupDate).AppendLine();
2017-09-16 00:57:26 +01:00
}
sb.AppendFormat(Localization.Dump_volume_number_0, aixHdr.c_volume).AppendLine();
2022-03-06 13:29:38 +00:00
}
else
{
metadata.Type = FS_TYPE;
sb.AppendLine(metadata.Type);
2017-09-16 00:57:26 +01:00
2022-03-06 13:29:38 +00:00
if(newHdr.c_ndate > 0)
{
metadata.CreationDate = DateHandlers.UnixToDateTime(newHdr.c_ndate);
sb.AppendFormat(Localization.Dump_created_on_0, metadata.CreationDate).AppendLine();
2022-03-06 13:29:38 +00:00
}
else if(newHdr.c_date > 0)
2020-02-29 18:03:35 +00:00
{
metadata.CreationDate = DateHandlers.UnixToDateTime(newHdr.c_date);
sb.AppendFormat(Localization.Dump_created_on_0, metadata.CreationDate).AppendLine();
2022-03-06 13:29:38 +00:00
}
2017-09-16 00:57:26 +01:00
2022-03-06 13:29:38 +00:00
if(newHdr.c_nddate > 0)
2017-09-16 00:57:26 +01:00
{
metadata.BackupDate = DateHandlers.UnixToDateTime(newHdr.c_nddate);
sb.AppendFormat(Localization.Previous_dump_created_on_0, metadata.BackupDate).AppendLine();
2017-09-16 00:57:26 +01:00
}
2022-03-06 13:29:38 +00:00
else if(newHdr.c_ddate > 0)
2017-09-16 00:57:26 +01:00
{
metadata.BackupDate = DateHandlers.UnixToDateTime(newHdr.c_ddate);
sb.AppendFormat(Localization.Previous_dump_created_on_0, metadata.BackupDate).AppendLine();
2017-09-16 00:57:26 +01:00
}
2022-03-06 13:29:38 +00:00
sb.AppendFormat(Localization.Dump_volume_number_0, newHdr.c_volume).AppendLine();
sb.AppendFormat(Localization.Dump_level_0, newHdr.c_level).AppendLine();
2022-03-06 13:29:38 +00:00
string dumpname = StringHandlers.CToString(newHdr.c_label);
if(!string.IsNullOrEmpty(dumpname))
2017-09-16 00:57:26 +01:00
{
metadata.VolumeName = dumpname;
sb.AppendFormat(Localization.Dump_label_0, dumpname).AppendLine();
2017-09-16 00:57:26 +01:00
}
2022-03-06 13:29:38 +00:00
string str = StringHandlers.CToString(newHdr.c_filesys);
2017-09-16 00:57:26 +01:00
2024-05-01 04:05:22 +01:00
if(!string.IsNullOrEmpty(str)) sb.AppendFormat(Localization.Dumped_filesystem_name_0, str).AppendLine();
2022-03-06 13:29:38 +00:00
str = StringHandlers.CToString(newHdr.c_dev);
2024-05-01 04:05:22 +01:00
if(!string.IsNullOrEmpty(str)) sb.AppendFormat(Localization.Dumped_device_0, str).AppendLine();
2022-03-06 13:29:38 +00:00
str = StringHandlers.CToString(newHdr.c_host);
2024-05-01 04:05:22 +01:00
if(!string.IsNullOrEmpty(str)) sb.AppendFormat(Localization.Dump_hostname_0, str).AppendLine();
}
2022-03-06 13:29:38 +00:00
information = sb.ToString();
}
#endregion
2017-09-16 00:57:26 +01:00
}