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

185 lines
6.9 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/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
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;
2017-12-21 14:30:38 +00:00
using Encoding = System.Text.Encoding;
using Partition = Aaru.CommonTypes.Partition;
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
{
2024-05-01 04:05:22 +01:00
#region IReadOnlyFilesystem 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(partition.Start > 0) return false;
2024-05-01 04:05:22 +01: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);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2022-03-06 13:29:38 +00:00
Header cbmHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(sector);
2024-05-01 04:05:22 +01:00
if(cbmHdr.diskDosVersion == 0x44 && cbmHdr is { dosVersion: 0x33, diskVersion: 0x44 }) return true;
2022-03-06 13:29:38 +00:00
}
else
{
ErrorNumber errno = imagePlugin.ReadSector(357, out sector);
2024-05-01 04:05:22 +01: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 />
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 PETSCII();
2022-03-06 13:29:38 +00:00
information = "";
byte[] sector;
2022-03-06 13:29:38 +00:00
var sbInformation = new StringBuilder();
sbInformation.AppendLine(Localization.Commodore_file_system);
metadata = new FileSystem
2022-03-06 13:29:38 +00:00
{
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);
2024-05-01 04:05:22 +01: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
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.Directory_starts_at_track_0_sector_1,
cbmHdr.directoryTrack,
cbmHdr.directorySector)
.AppendLine();
sbInformation.AppendFormat(Localization.Disk_DOS_Version_0,
Encoding.ASCII.GetString(new[]
{
cbmHdr.diskDosVersion
}))
.AppendLine();
sbInformation.AppendFormat(Localization.DOS_Version_0,
Encoding.ASCII.GetString(new[]
{
cbmHdr.dosVersion
}))
.AppendLine();
sbInformation.AppendFormat(Localization.Disk_Version_0,
Encoding.ASCII.GetString(new[]
{
cbmHdr.diskVersion
}))
.AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_ID_0, cbmHdr.diskId).AppendLine();
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.Disk_name_0, StringHandlers.CToString(cbmHdr.name, encoding))
.AppendLine();
metadata.VolumeName = StringHandlers.CToString(cbmHdr.name, encoding);
metadata.VolumeSerial = $"{cbmHdr.diskId}";
2022-03-06 13:29:38 +00:00
}
else
{
ErrorNumber errno = imagePlugin.ReadSector(357, out sector);
2024-05-01 04:05:22 +01: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
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.Directory_starts_at_track_0_sector_1,
cbmBam.directoryTrack,
cbmBam.directorySector)
.AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_DOS_type_0,
2024-05-01 04:05:22 +01:00
Encoding.ASCII.GetString(BitConverter.GetBytes(cbmBam.dosType)))
.AppendLine();
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.DOS_Version_0,
Encoding.ASCII.GetString(new[]
{
cbmBam.dosVersion
}))
.AppendLine();
2020-02-29 18:03:35 +00:00
sbInformation.AppendFormat(Localization.Disk_ID_0, cbmBam.diskId).AppendLine();
2024-05-01 04:05:22 +01:00
sbInformation.AppendFormat(Localization.Disk_name_0, StringHandlers.CToString(cbmBam.name, encoding))
.AppendLine();
metadata.VolumeName = StringHandlers.CToString(cbmBam.name, encoding);
metadata.VolumeSerial = $"{cbmBam.diskId}";
}
2022-03-06 13:29:38 +00:00
information = sbInformation.ToString();
}
#endregion
}