Files
Aaru/Aaru.Filesystems/RT11.cs

186 lines
7.3 KiB
C#
Raw Normal View History

2017-08-25 03:02:55 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2017-08-25 03:02:55 +01:00
// ----------------------------------------------------------------------------
//
// Filename : RT11.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : RT-11 file system plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the RT-11 file system 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-25 03:02:55 +01:00
// ****************************************************************************/
using System;
using System.Runtime.InteropServices;
using System.Text;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes;
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;
2020-02-29 18:03:35 +00:00
using Claunia.Encoding;
2017-12-21 14:30:38 +00:00
using Schemas;
using Encoding = System.Text.Encoding;
2020-02-27 00:33:26 +00:00
using Marshal = Aaru.Helpers.Marshal;
2017-08-25 03:02:55 +01:00
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
// Information from http://www.trailing-edge.com/~shoppa/rt11fs/
/// <inheritdoc />
/// <summary>Implements detection of the DEC RT-11 filesystem</summary>
public sealed class RT11 : IFilesystem
2017-08-25 03:02:55 +01:00
{
const string FS_TYPE = "rt11";
/// <inheritdoc />
2022-03-06 13:29:38 +00:00
public FileSystemType XmlFsType { get; private set; }
/// <inheritdoc />
public Encoding Encoding { get; private set; }
/// <inheritdoc />
public string Name => Localization.RT11_Name;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public Guid Id => new("DB3E2F98-8F98-463C-8126-E937843DA024");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
if(1 + partition.Start >= partition.End)
return false;
2017-08-25 03:02:55 +01:00
byte[] magicB = new byte[12];
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSector(1 + partition.Start, out byte[] hbSector);
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return false;
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
if(hbSector.Length < 512)
return false;
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
Array.Copy(hbSector, 0x1F0, magicB, 0, 12);
string magic = Encoding.ASCII.GetString(magicB);
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
return magic == "DECRT11A ";
}
2017-08-25 03:02:55 +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 = new Radix50();
information = "";
2022-03-06 13:29:38 +00:00
var sb = new StringBuilder();
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSector(1 + partition.Start, out byte[] hbSector);
2017-08-25 03:02:55 +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
HomeBlock homeblock = Marshal.ByteArrayToStructureLittleEndian<HomeBlock>(hbSector);
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
/* TODO: Is this correct?
* Assembler:
* MOV address, R0
* CLR R1
* MOV #255., R2
* 10$: ADD (R0)+, R1
* SOB R2, 10$
* MOV 1,@R0
*/
ushort check = 0;
2020-02-29 18:03:35 +00:00
for(int i = 0; i < 512; i += 2)
2022-03-06 13:29:38 +00:00
check += BitConverter.ToUInt16(hbSector, i);
2020-02-29 18:03:35 +00:00
sb.AppendFormat(Localization.Volume_format_is_0,
StringHandlers.SpacePaddedToString(homeblock.format, Encoding.ASCII)).AppendLine();
2017-08-25 03:02:55 +01:00
sb.AppendFormat(Localization._0_sectors_per_cluster_1_bytes, homeblock.cluster, homeblock.cluster * 512).
AppendLine();
2022-03-07 07:36:44 +00:00
sb.AppendFormat(Localization.First_directory_segment_starts_at_block_0, homeblock.rootBlock).AppendLine();
sb.AppendFormat(Localization.Volume_owner_is_0, Encoding.GetString(homeblock.ownername).TrimEnd()).AppendLine();
sb.AppendFormat(Localization.Volume_label_0, Encoding.GetString(homeblock.volname).TrimEnd()).AppendLine();
sb.AppendFormat(Localization.Checksum_0_calculated_1, homeblock.checksum, check).AppendLine();
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
imagePlugin.ReadSector(0, out byte[] bootBlock);
2017-08-25 03:02:55 +01:00
2022-03-06 13:29:38 +00:00
XmlFsType = new FileSystemType
{
Type = FS_TYPE,
2022-03-06 13:29:38 +00:00
ClusterSize = (uint)(homeblock.cluster * 512),
Clusters = homeblock.cluster,
VolumeName = StringHandlers.SpacePaddedToString(homeblock.volname, Encoding),
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlock)
};
information = sb.ToString();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct HomeBlock
{
/// <summary>Bad block replacement table</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 130)]
public readonly byte[] badBlockTable;
/// <summary>Unused</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public readonly byte[] unused;
/// <summary>INITIALIZE/RESTORE data area</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 38)]
public readonly byte[] initArea;
/// <summary>BUP information area</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)]
public readonly byte[] bupInformation;
/// <summary>Empty</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
public readonly byte[] empty;
/// <summary>Reserved</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public readonly byte[] reserved1;
/// <summary>Reserved</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public readonly byte[] reserved2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
public readonly byte[] empty2;
/// <summary>Cluster size</summary>
public readonly ushort cluster;
/// <summary>Block of the first directory segment</summary>
public readonly ushort rootBlock;
/// <summary>"V3A" in Radix-50</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public readonly byte[] systemVersion;
/// <summary>Name of the volume, 12 bytes</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public readonly byte[] volname;
/// <summary>Name of the volume owner, 12 bytes</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public readonly byte[] ownername;
/// <summary>RT11 defines it as "DECRT11A ", 12 bytes</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public readonly byte[] format;
/// <summary>Unused</summary>
public readonly ushort unused2;
/// <summary>Checksum of preceding 255 words (16 bit units)</summary>
public readonly ushort checksum;
2017-08-25 03:02:55 +01:00
}
}