Files
Aaru/Aaru.Filesystems/RT11/Info.cs

126 lines
4.6 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
// ----------------------------------------------------------------------------
//
2022-12-07 13:07:31 +00:00
// Filename : Info.cs
2017-08-25 03:02:55 +01:00
// 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/>.
//
// ----------------------------------------------------------------------------
2024-05-01 04:17:32 +01:00
// Copyright © 2011-2024 Natalia Portillo
2017-08-25 03:02:55 +01:00
// ****************************************************************************/
using System;
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;
2020-02-29 18:03:35 +00:00
using Claunia.Encoding;
using Encoding = System.Text.Encoding;
using Partition = Aaru.CommonTypes.Partition;
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>
2022-12-07 13:07:31 +00:00
public sealed partial class RT11
2017-08-25 03:02:55 +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(1 + partition.Start >= partition.End) return false;
2017-08-25 03:02:55 +01:00
var magicB = new byte[12];
2022-03-06 13:29:38 +00:00
ErrorNumber errno = imagePlugin.ReadSector(1 + partition.Start, out byte[] hbSector);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2017-08-25 03:02:55 +01:00
2024-05-01 04:05:22 +01: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 />
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
out FileSystem metadata)
2022-03-06 13:29:38 +00:00
{
encoding = new Radix50();
2022-03-06 13:29:38 +00:00
information = "";
metadata = new FileSystem();
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
2024-05-01 04:05:22 +01: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
2024-05-01 04:05:22 +01:00
for(var i = 0; i < 512; i += 2) check += BitConverter.ToUInt16(hbSector, i);
2020-02-29 18:03:35 +00:00
sb.AppendFormat(Localization.Volume_format_is_0,
2024-05-01 04:05:22 +01:00
StringHandlers.SpacePaddedToString(homeblock.format, Encoding.ASCII))
.AppendLine();
2017-08-25 03:02:55 +01:00
2024-05-01 04:05:22 +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
metadata = new FileSystem
{
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),
2022-03-06 13:29:38 +00:00
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlock)
};
information = sb.ToString();
}
#endregion
2017-08-25 03:02:55 +01:00
}