Files
Aaru/Aaru.Filesystems/CBM/Info.cs

175 lines
6.2 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
2022-12-07 13:07:31 +00:00
// Filename : Info.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Commodore file system plugin.
//
// --[ 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
// ****************************************************************************/
using System;
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;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
/// <summary>Implements detection of the filesystem used in 8-bit Commodore microcomputers</summary>
2022-12-07 13:07:31 +00:00
public sealed partial class CBM
{
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
if(partition.Start > 0)
return false;
2022-03-06 13:29:38 +00:00
if(imagePlugin.Info.SectorSize != 256)
return false;
2022-03-06 13:29:38 +00:00
if(imagePlugin.Info.Sectors != 683 &&
imagePlugin.Info.Sectors != 768 &&
imagePlugin.Info.Sectors != 1366 &&
imagePlugin.Info.Sectors != 3200)
return false;
2022-03-06 13:29:38 +00:00
byte[] sector;
2022-03-06 13:29:38 +00:00
if(imagePlugin.Info.Sectors == 3200)
{
ErrorNumber errno = imagePlugin.ReadSector(1560, out sector);
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return false;
2022-03-06 13:29:38 +00:00
Header cbmHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(sector);
2022-03-06 13:29:38 +00:00
if(cbmHdr.diskDosVersion == 0x44 &&
cbmHdr is { dosVersion: 0x33, diskVersion: 0x44 })
2022-03-06 13:29:38 +00:00
return true;
}
else
{
ErrorNumber errno = imagePlugin.ReadSector(357, out sector);
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return false;
2022-03-06 13:29:38 +00:00
BAM cbmBam = Marshal.ByteArrayToStructureLittleEndian<BAM>(sector);
if(cbmBam is { dosVersion: 0x41, doubleSided: 0x00 or 0x80 } and { unused1: 0x00, directoryTrack: 0x12 })
2022-03-06 13:29:38 +00:00
return true;
}
2022-03-06 13:29:38 +00:00
return false;
}
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 PETSCII();
information = "";
byte[] sector;
2022-03-06 13:29:38 +00:00
var sbInformation = new StringBuilder();
sbInformation.AppendLine(Localization.Commodore_file_system);
2022-03-06 13:29:38 +00:00
XmlFsType = new FileSystemType
{
Type = FS_TYPE,
2022-03-06 13:29:38 +00:00
Clusters = imagePlugin.Info.Sectors,
ClusterSize = 256
};
2022-03-06 13:29:38 +00:00
if(imagePlugin.Info.Sectors == 3200)
{
ErrorNumber errno = imagePlugin.ReadSector(1560, out sector);
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return;
2022-03-06 13:29:38 +00:00
Header cbmHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(sector);
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Directory_starts_at_track_0_sector_1, cbmHdr.directoryTrack,
2022-03-06 13:29:38 +00:00
cbmHdr.directorySector).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_DOS_Version_0, Encoding.ASCII.GetString(new[]
2022-03-06 13:29:38 +00:00
{
cbmHdr.diskDosVersion
})).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.DOS_Version_0, Encoding.ASCII.GetString(new[]
2022-03-06 13:29:38 +00:00
{
cbmHdr.dosVersion
})).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_Version_0, Encoding.ASCII.GetString(new[]
2022-03-06 13:29:38 +00:00
{
cbmHdr.diskVersion
})).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_ID_0, cbmHdr.diskId).AppendLine();
sbInformation.AppendFormat(Localization.Disk_name_0, StringHandlers.CToString(cbmHdr.name, Encoding)).
AppendLine();
2022-03-06 13:29:38 +00:00
XmlFsType.VolumeName = StringHandlers.CToString(cbmHdr.name, Encoding);
XmlFsType.VolumeSerial = $"{cbmHdr.diskId}";
}
else
{
ErrorNumber errno = imagePlugin.ReadSector(357, out sector);
2022-03-06 13:29:38 +00:00
if(errno != ErrorNumber.NoError)
return;
2022-03-06 13:29:38 +00:00
BAM cbmBam = Marshal.ByteArrayToStructureLittleEndian<BAM>(sector);
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Directory_starts_at_track_0_sector_1, cbmBam.directoryTrack,
2022-03-06 13:29:38 +00:00
cbmBam.directorySector).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_DOS_type_0,
2022-03-07 07:36:44 +00:00
Encoding.ASCII.GetString(BitConverter.GetBytes(cbmBam.dosType))).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.DOS_Version_0, Encoding.ASCII.GetString(new[]
2022-03-06 13:29:38 +00:00
{
cbmBam.dosVersion
})).AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_ID_0, cbmBam.diskId).AppendLine();
sbInformation.AppendFormat(Localization.Disk_name_0, StringHandlers.CToString(cbmBam.name, Encoding)).
AppendLine();
2022-03-06 13:29:38 +00:00
XmlFsType.VolumeName = StringHandlers.CToString(cbmBam.name, Encoding);
XmlFsType.VolumeSerial = $"{cbmBam.diskId}";
}
2022-03-06 13:29:38 +00:00
information = sbInformation.ToString();
}
}