Files
Aaru/Aaru.Filesystems/AppleDOS/Info.cs

114 lines
4.4 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Info.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Apple DOS filesystem plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the Apple DOS filesystem 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
// ****************************************************************************/
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;
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-07-20 15:43:52 +01:00
namespace Aaru.Filesystems
{
2020-07-22 13:20:25 +01:00
public sealed partial class AppleDOS
{
2021-08-17 13:56:05 +01:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
2020-02-29 18:03:35 +00:00
if(imagePlugin.Info.Sectors != 455 &&
imagePlugin.Info.Sectors != 560)
return false;
2020-02-29 18:03:35 +00:00
if(partition.Start > 0 ||
imagePlugin.Info.SectorSize != 256)
return false;
2018-06-20 22:22:21 +01:00
int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;
var errno = imagePlugin.ReadSector((ulong)(17 * spt), out byte[] vtocB);
if(errno != ErrorNumber.NoError)
return false;
2020-07-20 21:11:32 +01:00
_vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocB);
2020-07-20 21:11:32 +01:00
return _vtoc.catalogSector < spt && _vtoc.maxTrackSectorPairsPerSector <= 122 &&
_vtoc.sectorsPerTrack == spt && _vtoc.bytesPerSector == 256;
}
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)
{
2018-06-22 08:08:38 +01:00
Encoding = encoding ?? new Apple2();
information = "";
2020-02-29 18:03:35 +00:00
var sb = new StringBuilder();
2020-07-22 13:20:25 +01:00
int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;
var errno = imagePlugin.ReadSector((ulong)(17 * spt), out byte[] vtocB);
if(errno != ErrorNumber.NoError)
return;
2020-07-20 21:11:32 +01:00
_vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocB);
sb.AppendLine("Apple DOS File System");
sb.AppendLine();
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
sb.AppendFormat("Catalog starts at sector {0} of track {1}", _vtoc.catalogSector, _vtoc.catalogTrack).
2020-02-29 18:03:35 +00:00
AppendLine();
2020-07-20 21:11:32 +01:00
sb.AppendFormat("File system initialized by DOS release {0}", _vtoc.dosRelease).AppendLine();
sb.AppendFormat("Disk volume number {0}", _vtoc.volumeNumber).AppendLine();
sb.AppendFormat("Sectors allocated at most in track {0}", _vtoc.lastAllocatedSector).AppendLine();
sb.AppendFormat("{0} tracks in volume", _vtoc.tracks).AppendLine();
sb.AppendFormat("{0} sectors per track", _vtoc.sectorsPerTrack).AppendLine();
sb.AppendFormat("{0} bytes per sector", _vtoc.bytesPerSector).AppendLine();
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
sb.AppendFormat("Track allocation is {0}", _vtoc.allocationDirection > 0 ? "forward" : "reverse").
2020-02-29 18:03:35 +00:00
AppendLine();
information = sb.ToString();
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
{
2020-07-20 04:34:16 +01:00
Bootable = true,
Clusters = imagePlugin.Info.Sectors,
ClusterSize = imagePlugin.Info.SectorSize,
Type = "Apple DOS"
};
}
}
2017-12-19 20:33:03 +00:00
}