// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Michael Drüing // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // // Contains structures for d2f disk images. // // --[ 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 © 2018-2019 Michael Drüing // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System.Runtime.InteropServices; namespace Aaru.DiscImages; public sealed partial class WCDiskImage { /// The expected signature of a proper image file. const string FILE_SIGNATURE = "WC DISK IMAGE\x1a\x1a"; /// The global header of a WCDiskImage file [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct FileHeader { /// The signature should be "WC DISK IMAGE\0x1a\0x1a\0x00" [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] signature; /// Version (currently only version 0 and 1 is known) public readonly byte version; /// The number of heads. Only 1 or 2 is supported public readonly byte heads; /// Sectors per track, maximum is 18 public readonly byte sectorsPerTrack; /// The number of tracks/cylinders. 80 is the maximum public readonly byte cylinders; /// /// The "extra tracks" that are present. What this means is that the tracks 81 and 82 might contain data (on an /// 80-track disk) and that this data was dumped too. The order is head0extra1, head1extra1, head0extra2, head1extra2. /// 1 means track is present. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public readonly byte[] extraTracks; /// Additional metadata present flags. public readonly ExtraFlag extraFlags; /// Padding to make the header 32 bytes. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public readonly byte[] reserved; } enum ExtraFlag : byte { /// Set if a Comment is present after the image Comment = 0x01, /// Set if a directory listing is present after the image Directory = 0x02 } /// The Sector header that precedes each sector [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct SectorHeader { /// The sector flag (i.e. type) public readonly SectorFlag flag; /// The head this sector belongs to. public readonly byte head; /// The sector number within the track. Must be consecutive. public readonly byte sector; /// The cylinder number this sector belongs to. public readonly byte cylinder; /// A simple CRC16 over the data, to detect errors. public readonly short crc; } enum SectorFlag : byte { /// A normal sector Normal = 0x00, /// A bad sector that could not be read BadSector = 0x01, /// A sector filled with a repeating byte value. The value is encoded in the LSB of the crc field. RepeatByte = 0x02, /// /// Not a sector but a comment. Must come after all user data. The crc field is the length of the comment /// data. /// Comment = 0x03, /// Not a sector but the directory information. The crc field is the length of the data. Directory = 0x04 } }