2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-14 17:59:54 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2016-09-14 17:59:54 +01:00
|
|
|
|
// 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
|
2016-09-14 17:59:54 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
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;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
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
|
2016-09-14 17:59:54 +01:00
|
|
|
|
{
|
2024-05-01 04:05:22 +01:00
|
|
|
|
#region IReadOnlyFilesystem Members
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
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;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(imagePlugin.Info.SectorSize != 256) return false;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
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;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
byte[] sector;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 3200)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(1560, out sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Header cbmHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
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);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
BAM cbmBam = Marshal.ByteArrayToStructureLittleEndian<BAM>(sector);
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
if(cbmBam is { dosVersion: 0x41, doubleSided: 0x00 or 0x80 } and { unused1: 0x00, directoryTrack: 0x12 })
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-12-17 22:41:56 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
|
|
|
|
|
|
out FileSystem metadata)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-12-17 23:17:18 +00:00
|
|
|
|
encoding = new PETSCII();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = "";
|
|
|
|
|
|
byte[] sector;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendLine(Localization.Commodore_file_system);
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Clusters = imagePlugin.Info.Sectors,
|
|
|
|
|
|
ClusterSize = 256
|
|
|
|
|
|
};
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 3200)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(1560, out sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
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
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Disk_ID_0, cbmHdr.diskId).AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
sbInformation.AppendFormat(Localization.Disk_name_0, StringHandlers.CToString(cbmHdr.name, encoding))
|
|
|
|
|
|
.AppendLine();
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-12-17 23:17:18 +00:00
|
|
|
|
metadata.VolumeName = StringHandlers.CToString(cbmHdr.name, encoding);
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.VolumeSerial = $"{cbmHdr.diskId}";
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(357, out sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
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
|
|
|
|
|
2022-11-28 02:59:53 +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
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Disk_ID_0, cbmBam.diskId).AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
sbInformation.AppendFormat(Localization.Disk_name_0, StringHandlers.CToString(cbmBam.name, encoding))
|
|
|
|
|
|
.AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2022-12-17 23:17:18 +00:00
|
|
|
|
metadata.VolumeName = StringHandlers.CToString(cbmBam.name, encoding);
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.VolumeSerial = $"{cbmBam.diskId}";
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|