2017-08-09 03:09:05 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-08-09 03:09:05 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : UNICOS.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : UNICOS filesystem plugin.
|
2017-08-09 03:09:05 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the UNICOS filesystem 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-08-09 03:09:05 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
// UNICOS is ILP64 so let's think everything is 64-bit
|
|
|
|
|
|
|
2017-08-09 03:09:05 +01:00
|
|
|
|
using System;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
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;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2022-11-15 15:58:43 +00:00
|
|
|
|
using blkno_t = System.Int64;
|
|
|
|
|
|
using daddr_t = System.Int64;
|
|
|
|
|
|
using dev_t = System.Int64;
|
|
|
|
|
|
using extent_t = System.Int64;
|
|
|
|
|
|
using ino_t = System.Int64;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2022-11-15 15:58:43 +00:00
|
|
|
|
using time_t = System.Int64;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Aaru.Filesystems;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection for the Cray UNICOS filesystem</summary>
|
|
|
|
|
|
public sealed class UNICOS : IFilesystem
|
2017-08-09 03:09:05 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
const int NC1_MAXPART = 64;
|
|
|
|
|
|
const int NC1_MAXIREG = 4;
|
|
|
|
|
|
|
|
|
|
|
|
const ulong UNICOS_MAGIC = 0x6e6331667331636e;
|
|
|
|
|
|
const ulong UNICOS_SECURE = 0xcd076d1771d670cd;
|
|
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
const string FS_TYPE = "unicos";
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-28 02:59:53 +00:00
|
|
|
|
public string Name => Localization.UNICOS_Name;
|
2021-08-17 14:25:12 +01:00
|
|
|
|
/// <inheritdoc />
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public Guid Id => new("61712F04-066C-44D5-A2A0-1E44C66B33F0");
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-28 02:59:53 +00:00
|
|
|
|
public string Author => Authors.NataliaPortillo;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2017-08-09 03:09:05 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return false;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(partition.Start + sbSize >= partition.End)
|
|
|
|
|
|
return false;
|
2021-06-03 12:52:37 +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<Superblock>())
|
|
|
|
|
|
return false;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("UNICOS plugin", Localization.magic_equals_0_expected_1, unicosSb.s_magic,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
UNICOS_MAGIC);
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return unicosSb.s_magic == UNICOS_MAGIC;
|
|
|
|
|
|
}
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
information = "";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-08-09 03:09:05 +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<Superblock>())
|
|
|
|
|
|
return;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(unicosSb.s_magic != UNICOS_MAGIC)
|
|
|
|
|
|
return;
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.UNICOS_filesystem);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(unicosSb.s_secure == UNICOS_SECURE)
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.Volume_is_secure);
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_contains_0_partitions, unicosSb.s_npart).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_sector, unicosSb.s_iounit).AppendLine();
|
|
|
|
|
|
sb.AppendLine(Localization._4096_bytes_per_block);
|
|
|
|
|
|
sb.AppendFormat(Localization._0_data_blocks_in_volume, unicosSb.s_fsize).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Root_resides_on_inode_0, unicosSb.s_root).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_inodes_in_volume, unicosSb.s_isize).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_last_updated_on_0, DateHandlers.UnixToDateTime(unicosSb.s_time)).
|
|
|
|
|
|
AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(unicosSb.s_error > 0)
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_is_dirty_error_code_equals_0, unicosSb.s_error).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(unicosSb.s_fname, Encoding)).AppendLine();
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ClusterSize = 4096,
|
|
|
|
|
|
Clusters = (ulong)unicosSb.s_fsize,
|
|
|
|
|
|
VolumeName = StringHandlers.CToString(unicosSb.s_fname, Encoding),
|
|
|
|
|
|
ModificationDate = DateHandlers.UnixToDateTime(unicosSb.s_time),
|
|
|
|
|
|
ModificationDateSpecified = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
XmlFsType.Dirty |= unicosSb.s_error > 0;
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1), SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
|
readonly struct nc1ireg_sb
|
|
|
|
|
|
{
|
|
|
|
|
|
public readonly ushort i_unused; /* reserved */
|
|
|
|
|
|
public readonly ushort i_nblk; /* number of blocks */
|
|
|
|
|
|
public readonly uint i_sblk; /* start block number */
|
|
|
|
|
|
}
|
2017-08-09 03:09:05 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1), SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
|
readonly struct nc1fdev_sb
|
|
|
|
|
|
{
|
|
|
|
|
|
public readonly long fd_name; /* Physical device name */
|
|
|
|
|
|
public readonly uint fd_sblk; /* Start block number */
|
|
|
|
|
|
public readonly uint fd_nblk; /* Number of blocks */
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = NC1_MAXIREG)]
|
|
|
|
|
|
public readonly nc1ireg_sb[] fd_ireg; /* Inode regions */
|
|
|
|
|
|
}
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1), SuppressMessage("ReSharper", "InconsistentNaming"),
|
|
|
|
|
|
SuppressMessage("ReSharper", "BuiltInTypeReferenceStyle")]
|
|
|
|
|
|
readonly struct Superblock
|
|
|
|
|
|
{
|
|
|
|
|
|
public readonly ulong s_magic; /* magic number to indicate file system type */
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
|
public readonly byte[] s_fname; /* file system name */
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
|
public readonly byte[] s_fpack; /* file system pack name */
|
|
|
|
|
|
public readonly dev_t s_dev; /* major/minor device, for verification */
|
|
|
|
|
|
|
|
|
|
|
|
public readonly daddr_t s_fsize; /* size in blocks of entire volume */
|
|
|
|
|
|
public readonly long s_isize; /* Number of total inodes */
|
|
|
|
|
|
public readonly long s_bigfile; /* number of bytes at which a file is big */
|
|
|
|
|
|
public readonly long s_bigunit; /* minimum number of blocks allocated for big files */
|
|
|
|
|
|
public readonly ulong s_secure; /* security: secure FS label */
|
|
|
|
|
|
public readonly long s_maxlvl; /* security: maximum security level */
|
|
|
|
|
|
public readonly long s_minlvl; /* security: minimum security level */
|
|
|
|
|
|
public readonly long s_valcmp; /* security: valid security compartments */
|
|
|
|
|
|
public readonly time_t s_time; /* last super block update */
|
|
|
|
|
|
public readonly blkno_t s_dboff; /* Dynamic block number */
|
|
|
|
|
|
public readonly ino_t s_root; /* root inode */
|
|
|
|
|
|
public readonly long s_error; /* Type of file system error detected */
|
|
|
|
|
|
public readonly blkno_t s_mapoff; /* Start map block number */
|
|
|
|
|
|
public readonly long s_mapblks; /* Last map block number */
|
|
|
|
|
|
public readonly long s_nscpys; /* Number of copies of s.b per partition */
|
|
|
|
|
|
public readonly long s_npart; /* Number of partitions */
|
|
|
|
|
|
public readonly long s_ifract; /* Ratio of inodes to blocks */
|
|
|
|
|
|
public readonly extent_t s_sfs; /* SFS only blocks */
|
|
|
|
|
|
public readonly long s_flag; /* Flag word */
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = NC1_MAXPART)]
|
|
|
|
|
|
public readonly nc1fdev_sb[] s_part; /* Partition descriptors */
|
|
|
|
|
|
public readonly long s_iounit; /* Physical block size */
|
|
|
|
|
|
public readonly long s_numiresblks; /* number of inode reservation blocks */
|
|
|
|
|
|
/* per region (currently 1) */
|
|
|
|
|
|
/* 0 = 1*(AU) words, n = (n+1)*(AU) words */
|
|
|
|
|
|
public readonly long s_priparts; /* bitmap of primary partitions */
|
|
|
|
|
|
public readonly long s_priblock; /* block size of primary partition(s) */
|
|
|
|
|
|
/* 0 = 1*512 words, n = (n+1)*512 words */
|
|
|
|
|
|
public readonly long s_prinblks; /* number of 512 wds blocks in primary */
|
|
|
|
|
|
public readonly long s_secparts; /* bitmap of secondary partitions */
|
|
|
|
|
|
public readonly long s_secblock; /* block size of secondary partition(s) */
|
|
|
|
|
|
/* 0 = 1*512 words, n = (n+1)*512 words */
|
|
|
|
|
|
public readonly long s_secnblks; /* number of 512 wds blocks in secondary */
|
|
|
|
|
|
public readonly long s_sbdbparts; /* bitmap of partitions with file system data */
|
|
|
|
|
|
/* including super blocks, dynamic block */
|
|
|
|
|
|
/* and free block bitmaps (only primary */
|
|
|
|
|
|
/* partitions may contain these) */
|
|
|
|
|
|
public readonly long s_rootdparts; /* bitmap of partitions with root directory */
|
|
|
|
|
|
/* (only primary partitions) */
|
|
|
|
|
|
public readonly long s_nudparts; /* bitmap of no-user-data partitions */
|
|
|
|
|
|
/* (only primary partitions) */
|
|
|
|
|
|
public readonly long s_nsema; /* SFS: # fs semaphores to allocate */
|
|
|
|
|
|
public readonly long s_priactive; /* bitmap of primary partitions which contain */
|
|
|
|
|
|
/* active (up to date) dynamic blocks and */
|
|
|
|
|
|
/* free block bitmaps. All bits set indicate */
|
|
|
|
|
|
/* that all primary partitions are active, */
|
|
|
|
|
|
/* and no kernel manipulation of active flag */
|
|
|
|
|
|
/* is allowed. */
|
|
|
|
|
|
public readonly long s_sfs_arbiterid; /* SFS Arbiter ID */
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 91)]
|
|
|
|
|
|
public readonly long[] s_fill; /* reserved */
|
2017-08-09 03:09:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|