Files
Aaru/Aaru.Filesystems/AODOS.cs

144 lines
5.8 KiB
C#
Raw Normal View History

2017-08-25 01:58:22 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2017-08-25 01:58:22 +01:00
// ----------------------------------------------------------------------------
//
// Filename : AODOS.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Commodore file system plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the AO-DOS 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/>.
//
// ----------------------------------------------------------------------------
2020-12-31 23:08:23 +00:00
// Copyright © 2011-2021 Natalia Portillo
2017-08-25 01:58:22 +01:00
// ****************************************************************************/
using System;
2017-12-19 19:33:46 +00:00
using System.Linq;
2017-08-25 01:58:22 +01:00
using System.Runtime.InteropServices;
using System.Text;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
2017-12-21 14:30:38 +00:00
using Schemas;
2020-02-27 00:33:26 +00:00
using Marshal = Aaru.Helpers.Marshal;
2017-08-25 01:58:22 +01:00
2020-02-27 00:33:26 +00:00
namespace Aaru.Filesystems
2017-08-25 01:58:22 +01:00
{
// Information has been extracted looking at available disk images
// This may be missing fields, or not, I don't know russian so any help is appreciated
2021-08-17 13:56:05 +01:00
/// <summary>
/// Implements detection of the AO-DOS filesystem
/// </summary>
2020-07-22 13:20:25 +01:00
public sealed class AODOS : IFilesystem
2017-08-25 01:58:22 +01:00
{
2020-07-20 21:11:32 +01:00
readonly byte[] _identifier =
2020-02-29 18:03:35 +00:00
{
0x20, 0x41, 0x4F, 0x2D, 0x44, 0x4F, 0x53, 0x20
};
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2020-02-29 18:03:35 +00:00
public FileSystemType XmlFsType { get; private set; }
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2020-02-29 18:03:35 +00:00
public string Name => "Alexander Osipov DOS file system";
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2020-02-29 18:03:35 +00:00
public Guid Id => new Guid("668E5039-9DDD-442A-BE1B-A315D6E38E26");
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2020-02-29 18:03:35 +00:00
public Encoding Encoding { get; private set; }
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2020-02-29 18:03:35 +00:00
public string Author => "Natalia Portillo";
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
2017-08-25 01:58:22 +01:00
{
// Does AO-DOS support hard disks?
2020-02-29 18:03:35 +00:00
if(partition.Start > 0)
return false;
2017-08-25 01:58:22 +01:00
// How is it really?
2020-02-29 18:03:35 +00:00
if(imagePlugin.Info.SectorSize != 512)
return false;
2017-08-25 01:58:22 +01:00
// Does AO-DOS support any other kind of disk?
2020-02-29 18:03:35 +00:00
if(imagePlugin.Info.Sectors != 800 &&
imagePlugin.Info.Sectors != 1600)
return false;
2017-08-25 01:58:22 +01:00
2020-07-20 21:11:32 +01:00
byte[] sector = imagePlugin.ReadSector(0);
BootBlock bb = Marshal.ByteArrayToStructureLittleEndian<BootBlock>(sector);
2017-08-25 01:58:22 +01:00
2020-07-20 21:11:32 +01:00
return bb.identifier.SequenceEqual(_identifier);
2017-08-25 01:58:22 +01:00
}
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
2017-12-26 08:01:40 +00:00
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
2020-02-29 18:03:35 +00:00
Encoding encoding)
2017-08-25 01:58:22 +01:00
{
2017-12-26 08:01:40 +00:00
Encoding = Encoding.GetEncoding("koi8-r");
2020-07-20 21:11:32 +01:00
byte[] sector = imagePlugin.ReadSector(0);
BootBlock bb = Marshal.ByteArrayToStructureLittleEndian<BootBlock>(sector);
2017-08-25 01:58:22 +01:00
2020-02-29 18:03:35 +00:00
var sbInformation = new StringBuilder();
2017-08-25 01:58:22 +01:00
sbInformation.AppendLine("Alexander Osipov DOS file system");
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
2017-08-25 01:58:22 +01:00
{
2020-07-20 04:34:16 +01:00
Type = "Alexander Osipov DOS file system",
Clusters = imagePlugin.Info.Sectors,
ClusterSize = imagePlugin.Info.SectorSize,
Files = bb.files,
FilesSpecified = true,
FreeClusters = imagePlugin.Info.Sectors - bb.usedSectors,
FreeClustersSpecified = true,
VolumeName = StringHandlers.SpacePaddedToString(bb.volumeLabel, Encoding),
Bootable = true
2017-08-25 01:58:22 +01:00
};
sbInformation.AppendFormat("{0} files on volume", bb.files).AppendLine();
sbInformation.AppendFormat("{0} used sectors on volume", bb.usedSectors).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat("Disk name: {0}", StringHandlers.CToString(bb.volumeLabel, Encoding)).
AppendLine();
2017-08-25 01:58:22 +01:00
information = sbInformation.ToString();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct BootBlock
{
2020-02-29 18:03:35 +00:00
/// <summary>A NOP opcode</summary>
2019-04-23 01:38:33 +01:00
public readonly byte nop;
2020-02-29 18:03:35 +00:00
/// <summary>A branch to real bootloader</summary>
2019-04-23 01:38:33 +01:00
public readonly ushort branch;
2020-02-29 18:03:35 +00:00
/// <summary>Unused</summary>
2019-04-23 01:38:33 +01:00
public readonly byte unused;
2020-02-29 18:03:35 +00:00
/// <summary>" AO-DOS "</summary>
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
2019-04-23 01:38:33 +01:00
public readonly byte[] identifier;
2020-02-29 18:03:35 +00:00
/// <summary>Volume label</summary>
2018-06-22 08:08:38 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
2019-04-23 01:38:33 +01:00
public readonly byte[] volumeLabel;
2020-02-29 18:03:35 +00:00
/// <summary>How many files are present in disk</summary>
2019-04-23 01:38:33 +01:00
public readonly ushort files;
2020-02-29 18:03:35 +00:00
/// <summary>How many sectors are used</summary>
2019-04-23 01:38:33 +01:00
public readonly ushort usedSectors;
}
2017-08-25 01:58:22 +01:00
}
}