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>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : dump(8) file system plugin
|
2017-09-16 00:57:26 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-09-16 00:57:26 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-09-16 00:57:26 +01:00
|
|
|
|
using System.Text;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.Console;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2023-10-03 23:22:08 +01:00
|
|
|
|
using ufs_daddr_t = int;
|
2022-11-15 15:58:43 +00:00
|
|
|
|
|
|
|
|
|
|
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>
|
2023-10-03 23:22:08 +01:00
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class dump
|
2017-09-16 00:57:26 +01:00
|
|
|
|
{
|
2023-10-03 23:22:08 +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
|
|
|
|
{
|
2022-03-06 13:29:38 +00: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
|
|
|
|
|
|
if(partition.Start != 0)
|
|
|
|
|
|
return false;
|
2017-09-16 00:57:26 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var sbSize = (uint)(Marshal.SizeOf<s_spcl>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<s_spcl>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-09-16 00:57:26 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, sbSize, out byte[] sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00: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
|
|
|
|
|
2023-10-03 17:47:32 +01:00
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "old magic = 0x{0:X8}", oldHdr.c_magic);
|
|
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "aix magic = 0x{0:X8}", aixHdr.c_magic);
|
|
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, "new magic = 0x{0:X8}", newHdr.c_magic);
|
2017-09-16 00:57:26 +01:00
|
|
|
|
|
2023-10-04 17:34:40 +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 />
|
2022-12-17 22:41:56 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
|
|
|
|
|
|
out FileSystem metadata)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
information = "";
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem();
|
2017-09-16 00:57:26 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(partition.Start != 0)
|
|
|
|
|
|
return;
|
2017-09-16 00:57:26 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var sbSize = (uint)(Marshal.SizeOf<s_spcl>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<s_spcl>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-09-16 00:57:26 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, sbSize, out byte[] sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00: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
|
|
|
|
|
2023-10-03 23:22:08 +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)
|
|
|
|
|
|
{
|
2023-10-04 17:34:40 +01:00
|
|
|
|
if(newHdr.c_magic == OFS_CIGAM || newHdr.c_magic == NFS_CIGAM || newHdr.c_magic == UFS2_CIGAM)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
newHdr = Marshal.ByteArrayToStructureBigEndian<s_spcl>(sector);
|
|
|
|
|
|
}
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
information = Localization.Could_not_read_dump_8_header_block;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
ClusterSize = 1024,
|
|
|
|
|
|
Clusters = partition.Size / 1024
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(useOld)
|
|
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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
|
|
|
|
{
|
2022-12-17 22:41:56 +00: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
|
|
|
|
{
|
2022-12-17 22:41:56 +00: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
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Dump_volume_number_0, oldHdr.c_volume).AppendLine();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if(useAix)
|
|
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.CreationDate = DateHandlers.UnixToDateTime(aixHdr.c_date);
|
2022-12-15 22:21:07 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Dump_volume_number_0, aixHdr.c_volume).AppendLine();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.CreationDate = DateHandlers.UnixToDateTime(newHdr.c_ndate);
|
2022-12-15 22:21:07 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.CreationDate = DateHandlers.UnixToDateTime(newHdr.c_date);
|
2022-12-15 22:21:07 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
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
|
|
|
|
{
|
2022-12-17 22:41:56 +00: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
|
|
|
|
{
|
2022-12-17 22:41:56 +00: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
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Dump_volume_number_0, newHdr.c_volume).AppendLine();
|
2023-10-03 23:22:08 +01:00
|
|
|
|
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
|
|
|
|
{
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.VolumeName = dumpname;
|
2022-11-28 02:59:53 +00:00
|
|
|
|
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
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(str))
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Dumped_filesystem_name_0, str).AppendLine();
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
str = StringHandlers.CToString(newHdr.c_dev);
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!string.IsNullOrEmpty(str))
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Dumped_device_0, str).AppendLine();
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
str = StringHandlers.CToString(newHdr.c_host);
|
|
|
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrEmpty(str))
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Dump_hostname_0, str).AppendLine();
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-09-16 00:57:26 +01:00
|
|
|
|
}
|