2017-09-21 21:20:53 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-09-21 21:20:53 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : MicroDOS.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : MicroDOS filesystem plugin
|
2017-09-21 21:20:53 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Identifies the MicroDOS filesystem and shows information.
|
2017-09-21 21:20:53 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2017-09-21 21:20:53 +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.Interfaces;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
2020-07-20 07:47:12 +01:00
|
|
|
|
// ReSharper disable UnusedType.Local
|
|
|
|
|
|
// ReSharper disable UnusedMember.Local
|
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2017-09-21 21:20:53 +01:00
|
|
|
|
{
|
|
|
|
|
|
// Information from http://www.owg.ru/mkt/BK/MKDOS.TXT
|
|
|
|
|
|
// Thanks to tarlabnor for translating it
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class MicroDOS : IFilesystem
|
2017-09-21 21:20:53 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
const ushort MAGIC = 0xA72E;
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const ushort MAGIC2 = 0x530C;
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
public string Name => "MicroDOS file system";
|
|
|
|
|
|
public Guid Id => new Guid("9F9A364A-1A27-48A3-B730-7A7122000324");
|
2018-08-29 22:15:43 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2017-09-21 21:20:53 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(1 + partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return false;
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] bk0 = imagePlugin.ReadSector(0 + partition.Start);
|
|
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
MicroDosBlock0 block0 = Marshal.ByteArrayToStructureLittleEndian<MicroDosBlock0>(bk0);
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return block0.label == MAGIC && block0.mklabel == MAGIC2;
|
2017-09-21 21:20:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding encoding)
|
2017-09-21 21:20:53 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("koi8-r");
|
2017-09-21 21:20:53 +01:00
|
|
|
|
information = "";
|
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] bk0 = imagePlugin.ReadSector(0 + partition.Start);
|
|
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
MicroDosBlock0 block0 = Marshal.ByteArrayToStructureLittleEndian<MicroDosBlock0>(bk0);
|
2017-09-21 21:20:53 +01:00
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("MicroDOS filesystem");
|
|
|
|
|
|
sb.AppendFormat("Volume has {0} blocks ({1} bytes)", block0.blocks, block0.blocks * 512).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat("Volume has {0} blocks used ({1} bytes)", block0.usedBlocks, block0.usedBlocks * 512).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-09-21 21:20:53 +01:00
|
|
|
|
sb.AppendFormat("Volume contains {0} files", block0.files).AppendLine();
|
|
|
|
|
|
sb.AppendFormat("First used block is {0}", block0.firstUsedBlock).AppendLine();
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-09-21 21:20:53 +01:00
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
|
Type = "MicroDOS",
|
|
|
|
|
|
ClusterSize = 512,
|
|
|
|
|
|
Clusters = block0.blocks,
|
|
|
|
|
|
Files = block0.files,
|
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
|
FreeClusters = (ulong)(block0.blocks - block0.usedBlocks),
|
2017-09-21 21:20:53 +01:00
|
|
|
|
FreeClustersSpecified = true
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
// Followed by directory entries
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2018-06-20 22:22:21 +01:00
|
|
|
|
struct MicroDosBlock0
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>BK starts booting here</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] bootCode;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Number of files in directory</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort files;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Total number of blocks in files of the directory</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort usedBlocks;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Unknown</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 228)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Ownership label (label that shows it belongs to Micro DOS format)</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort label;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>MK-DOS directory format label</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort mklabel;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Unknown</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown2;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// Disk size in blocks (absolute value for the system unlike NORD, NORTON etc.) that doesn't use two fixed values
|
|
|
|
|
|
/// 40 or 80 tracks, but i.e. if you drive works with 76 tracks this field will contain an appropriate number of blocks
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// </summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort blocks;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary> Number of the first file's block. Value is changable</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort firstUsedBlock;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Unknown</summary>
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown3;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct DirectoryEntry
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>File status</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte status;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Directory number (0 - root)</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte directory;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>File name 14. symbols in ASCII KOI8</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[] filename;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Block number</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort blockNo;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Length in blocks</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort blocks;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Address</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort address;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>Length</summary>
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly ushort length;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum FileStatus : byte
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
CommonFile = 0, Protected = 1, LogicalDisk = 2,
|
|
|
|
|
|
BadFile = 0x80, Deleted = 0xFF
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2017-09-21 21:20:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|