// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ using System.Runtime.InteropServices; using Aaru.CommonTypes.Attributes; using Aaru.CommonTypes.Interfaces; using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes; namespace Aaru.Filesystems; /// /// Implements detection of the filesystem used in 8-bit Commodore microcomputers public sealed partial class CBM { #region Nested type: BAM [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct BAM { /// Track where directory starts public byte directoryTrack; /// Sector where directory starts public byte directorySector; /// Disk DOS version, 0x41 public byte dosVersion; /// Set to 0x80 if 1571, 0x00 if not public byte doubleSided; /// Block allocation map [MarshalAs(UnmanagedType.ByValArray, SizeConst = 140)] public byte[] bam; /// Disk name [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] name; /// Filled with 0xA0 public ushort fill1; /// Disk ID public ushort diskId; /// Filled with 0xA0 public byte fill2; /// DOS type public ushort dosType; /// Filled with 0xA0 public uint fill3; /// Unused public byte unused1; /// Block allocation map for Dolphin DOS extended tracks [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] dolphinBam; /// Block allocation map for Speed DOS extended tracks [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] speedBam; /// Unused [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] public byte[] unused2; /// Free sector count for second side in 1571 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] public byte[] freeCount; } #endregion #region Nested type: CachedFile struct CachedFile { public byte[] data; public ulong length; public FileAttributes attributes; public int blocks; public ulong id; } #endregion #region Nested type: CbmDirNode sealed class CbmDirNode : IDirNode { internal string[] Contents; internal int Position; #region IDirNode Members /// public string Path { get; init; } #endregion } #endregion #region Nested type: CbmFileNode sealed class CbmFileNode : IFileNode { internal byte[] Cache; #region IFileNode Members /// public string Path { get; init; } /// public long Length { get; init; } /// public long Offset { get; set; } #endregion } #endregion #region Nested type: DirectoryEntry [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct DirectoryEntry { public byte nextDirBlockTrack; public byte nextDirBlockSector; public byte fileType; public byte firstFileBlockTrack; public byte firstFileBlockSector; /// Filename [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] name; public byte firstSideBlockTrack; public byte firstSideBlockSector; public uint unused; public byte replacementTrack; public byte replacementSector; public short blocks; } #endregion #region Nested type: Header [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct Header { /// Track where directory starts public byte directoryTrack; /// Sector where directory starts public byte directorySector; /// Disk DOS version, 0x44 public byte diskDosVersion; /// Unusued public byte unused1; /// Disk name [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] name; /// Filled with 0xA0 public ushort fill1; /// Disk ID public ushort diskId; /// Filled with 0xA0 public byte fill2; /// DOS version ('3') public byte dosVersion; /// Disk version ('D') public byte diskVersion; /// Filled with 0xA0 public short fill3; } #endregion }