2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Component : UNICOS filesystem plugin.
|
2016-09-02 19:33:30 +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-05-01 04:17:32 +01:00
|
|
|
|
// Copyright © 2011-2024 Natalia Portillo
|
2016-09-02 19:33:30 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// UNICOS is ILP64 so let's think everything is 64-bit
|
|
|
|
|
|
|
2016-09-02 19:33:30 +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;
|
2022-12-07 13:07:31 +00:00
|
|
|
|
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;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-12-07 13:07:31 +00:00
|
|
|
|
/// <summary>Implements detection for the Cray UNICOS filesystem</summary>
|
|
|
|
|
|
public sealed partial class UNICOS
|
2016-09-02 19:33:30 +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)
|
|
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0) sbSize++;
|
2017-07-23 19:58:11 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(partition.Start + sbSize >= partition.End) return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, sbSize, out byte[] sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<Superblock>()) return false;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
|
|
|
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.magic_equals_0_expected_1, unicosSb.s_magic, UNICOS_MAGIC);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
return unicosSb.s_magic == UNICOS_MAGIC;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2016-09-02 19:33:30 +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
|
|
|
|
{
|
2022-12-17 23:17:18 +00:00
|
|
|
|
encoding ??= Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
information = "";
|
|
|
|
|
|
metadata = new FileSystem();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0) sbSize++;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, sbSize, out byte[] sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<Superblock>()) return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
Superblock unicosSb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(unicosSb.s_magic != UNICOS_MAGIC) return;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-12-07 13:07:31 +00:00
|
|
|
|
sb.AppendLine(Localization.UNICOS_filesystem);
|
|
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(unicosSb.s_secure == UNICOS_SECURE) sb.AppendLine(Localization.Volume_is_secure);
|
2022-12-07 13:07:31 +00:00
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_contains_0_partitions, unicosSb.s_npart).AppendLine();
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_sector, unicosSb.s_iounit).AppendLine();
|
2022-12-07 13:07:31 +00:00
|
|
|
|
sb.AppendLine(Localization._4096_bytes_per_block);
|
|
|
|
|
|
sb.AppendFormat(Localization._0_data_blocks_in_volume, unicosSb.s_fsize).AppendLine();
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.Root_resides_on_inode_0, unicosSb.s_root).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_inodes_in_volume, unicosSb.s_isize).AppendLine();
|
2022-12-07 13:07:31 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
sb.AppendFormat(Localization.Volume_last_updated_on_0, DateHandlers.UnixToDateTime(unicosSb.s_time))
|
|
|
|
|
|
.AppendLine();
|
2022-12-07 13:07:31 +00:00
|
|
|
|
|
|
|
|
|
|
if(unicosSb.s_error > 0)
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_is_dirty_error_code_equals_0, unicosSb.s_error).AppendLine();
|
|
|
|
|
|
|
2022-12-17 23:17:18 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(unicosSb.s_fname, encoding)).AppendLine();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2016-09-02 19:33:30 +01:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
|
Type = FS_TYPE,
|
|
|
|
|
|
ClusterSize = 4096,
|
|
|
|
|
|
Clusters = (ulong)unicosSb.s_fsize,
|
2022-12-17 23:17:18 +00:00
|
|
|
|
VolumeName = StringHandlers.CToString(unicosSb.s_fname, encoding),
|
2022-12-15 22:21:07 +00:00
|
|
|
|
ModificationDate = DateHandlers.UnixToDateTime(unicosSb.s_time)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.Dirty |= unicosSb.s_error > 0;
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-09-02 19:33:30 +01:00
|
|
|
|
}
|