2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-14 17:59:54 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : CBM.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Commodore file system plugin.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Commodore file system 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-09-14 17:59:54 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Claunia.Encoding;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
|
|
|
|
|
using Encoding = System.Text.Encoding;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class CBM : IFilesystem
|
2016-09-14 17:59:54 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Encoding currentEncoding;
|
|
|
|
|
|
FileSystemType xmlFsType;
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public FileSystemType XmlFsType => xmlFsType;
|
2017-10-12 23:54:02 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string Name => "Commodore file system";
|
|
|
|
|
|
public Guid Id => new Guid("D104744E-A376-450C-BAC0-1347C93F983B");
|
|
|
|
|
|
public Encoding Encoding => currentEncoding;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-14 17:59:54 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start > 0) return false;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize != 256) return false;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +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
|
|
|
|
|
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 3200)
|
2016-09-14 17:59:54 +01:00
|
|
|
|
{
|
|
|
|
|
|
sector = imagePlugin.ReadSector(1560);
|
|
|
|
|
|
CommodoreHeader cbmHdr = new CommodoreHeader();
|
|
|
|
|
|
IntPtr cbmHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmHdr));
|
|
|
|
|
|
Marshal.Copy(sector, 0, cbmHdrPtr, Marshal.SizeOf(cbmHdr));
|
|
|
|
|
|
cbmHdr = (CommodoreHeader)Marshal.PtrToStructure(cbmHdrPtr, typeof(CommodoreHeader));
|
|
|
|
|
|
Marshal.FreeHGlobal(cbmHdrPtr);
|
|
|
|
|
|
|
|
|
|
|
|
if(cbmHdr.diskDosVersion == 0x44 && cbmHdr.dosVersion == 0x33 && cbmHdr.diskVersion == 0x44)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = imagePlugin.ReadSector(357);
|
|
|
|
|
|
CommodoreBAM cbmBam = new CommodoreBAM();
|
|
|
|
|
|
IntPtr cbmBamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmBam));
|
|
|
|
|
|
Marshal.Copy(sector, 0, cbmBamPtr, Marshal.SizeOf(cbmBam));
|
|
|
|
|
|
cbmBam = (CommodoreBAM)Marshal.PtrToStructure(cbmBamPtr, typeof(CommodoreBAM));
|
|
|
|
|
|
Marshal.FreeHGlobal(cbmBamPtr);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(cbmBam.dosVersion == 0x41 && (cbmBam.doubleSided == 0x00 || cbmBam.doubleSided == 0x80) &&
|
|
|
|
|
|
cbmBam.unused1 == 0x00 && cbmBam.directoryTrack == 0x12) return true;
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2016-09-14 17:59:54 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
currentEncoding = new PETSCII();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sbInformation = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine("Commodore file system");
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
Type = "Commodore file system",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
Clusters = (long)imagePlugin.Info.Sectors,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ClusterSize = 256
|
|
|
|
|
|
};
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.Sectors == 3200)
|
2016-09-14 17:59:54 +01:00
|
|
|
|
{
|
|
|
|
|
|
sector = imagePlugin.ReadSector(1560);
|
|
|
|
|
|
CommodoreHeader cbmHdr = new CommodoreHeader();
|
|
|
|
|
|
IntPtr cbmHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmHdr));
|
|
|
|
|
|
Marshal.Copy(sector, 0, cbmHdrPtr, Marshal.SizeOf(cbmHdr));
|
|
|
|
|
|
cbmHdr = (CommodoreHeader)Marshal.PtrToStructure(cbmHdrPtr, typeof(CommodoreHeader));
|
|
|
|
|
|
Marshal.FreeHGlobal(cbmHdrPtr);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Directory starts at track {0} sector {1}", cbmHdr.directoryTrack,
|
|
|
|
|
|
cbmHdr.directorySector).AppendLine();
|
|
|
|
|
|
sbInformation
|
2017-12-24 02:37:41 +00:00
|
|
|
|
.AppendFormat("Disk DOS Version: {0}", Encoding.ASCII.GetString(new[] {cbmHdr.diskDosVersion}))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2017-12-24 02:37:41 +00:00
|
|
|
|
sbInformation.AppendFormat("DOS Version: {0}", Encoding.ASCII.GetString(new[] {cbmHdr.dosVersion}))
|
|
|
|
|
|
.AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat("Disk Version: {0}", Encoding.ASCII.GetString(new[] {cbmHdr.diskVersion}))
|
|
|
|
|
|
.AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
sbInformation.AppendFormat("Disk ID: {0}", cbmHdr.diskId).AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sbInformation.AppendFormat("Disk name: {0}", StringHandlers.CToString(cbmHdr.name, currentEncoding))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType.VolumeName = StringHandlers.CToString(cbmHdr.name, currentEncoding);
|
|
|
|
|
|
xmlFsType.VolumeSerial = $"{cbmHdr.diskId}";
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = imagePlugin.ReadSector(357);
|
|
|
|
|
|
CommodoreBAM cbmBam = new CommodoreBAM();
|
|
|
|
|
|
IntPtr cbmBamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmBam));
|
|
|
|
|
|
Marshal.Copy(sector, 0, cbmBamPtr, Marshal.SizeOf(cbmBam));
|
|
|
|
|
|
cbmBam = (CommodoreBAM)Marshal.PtrToStructure(cbmBamPtr, typeof(CommodoreBAM));
|
|
|
|
|
|
Marshal.FreeHGlobal(cbmBamPtr);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Directory starts at track {0} sector {1}", cbmBam.directoryTrack,
|
|
|
|
|
|
cbmBam.directorySector).AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat("Disk DOS type: {0}",
|
|
|
|
|
|
Encoding.ASCII.GetString(BitConverter.GetBytes(cbmBam.dosType)))
|
|
|
|
|
|
.AppendLine();
|
2017-12-21 14:30:38 +00:00
|
|
|
|
sbInformation.AppendFormat("DOS Version: {0}", Encoding.ASCII.GetString(new[] {cbmBam.dosVersion}))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
sbInformation.AppendFormat("Disk ID: {0}", cbmBam.diskId).AppendLine();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sbInformation.AppendFormat("Disk name: {0}", StringHandlers.CToString(cbmBam.name, currentEncoding))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
2016-09-14 17:59:54 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
xmlFsType.VolumeName = StringHandlers.CToString(cbmBam.name, currentEncoding);
|
|
|
|
|
|
xmlFsType.VolumeSerial = $"{cbmBam.diskId}";
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
information = sbInformation.ToString();
|
|
|
|
|
|
}
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct CommodoreBAM
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Track where directory starts
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte directoryTrack;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sector where directory starts
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte directorySector;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk DOS version, 0x41
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte dosVersion;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set to 0x80 if 1571, 0x00 if not
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte doubleSided;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block allocation map
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 140)] public byte[] bam;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk name
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] name;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Filled with 0xA0
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort fill1;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk ID
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort diskId;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Filled with 0xA0
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte fill2;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// DOS type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort dosType;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Filled with 0xA0
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint fill3;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Unused
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte unused1;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block allocation map for Dolphin DOS extended tracks
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] dolphinBam;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Block allocation map for Speed DOS extended tracks
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] speedBam;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Unused
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] public byte[] unused2;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Free sector count for second side in 1571
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] public byte[] freeCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct CommodoreHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Track where directory starts
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte directoryTrack;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sector where directory starts
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte directorySector;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk DOS version, 0x44
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte diskDosVersion;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Unusued
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte unused1;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk name
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] name;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Filled with 0xA0
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort fill1;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk ID
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ushort diskId;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Filled with 0xA0
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte fill2;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// DOS version ('3')
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte dosVersion;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disk version ('D')
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public byte diskVersion;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Filled with 0xA0
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public short fill3;
|
|
|
|
|
|
}
|
2016-09-14 17:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|