Files
Aaru/Aaru.Images/WCDiskImage/Identify.cs

84 lines
2.9 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Identify.cs
// Author(s) : Michael Drüing <michael@drueing.de>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies d2f/WC DISK IMAGE 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2018-2025 Michael Drüing
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
2023-10-05 01:05:23 +01:00
using System.Diagnostics.CodeAnalysis;
using System.IO;
2018-12-31 13:17:27 +00:00
using System.Text;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Images;
2023-10-05 01:05:23 +01:00
[SuppressMessage("ReSharper", "UnusedType.Global")]
2022-03-06 13:29:38 +00:00
public sealed partial class WCDiskImage
{
2023-10-03 23:34:59 +01:00
#region IMediaImage Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IFilter imageFilter)
{
2022-03-06 13:29:38 +00:00
Stream stream = imageFilter.GetDataForkStream();
stream.Seek(0, SeekOrigin.Begin);
2024-05-01 04:05:22 +01:00
if(stream.Length < 32) return false;
2023-10-03 23:34:59 +01:00
var header = new byte[32];
stream.EnsureRead(header, 0, 32);
2022-03-06 13:29:38 +00:00
FileHeader fheader = Marshal.ByteArrayToStructureLittleEndian<FileHeader>(header);
2022-03-06 13:29:38 +00:00
/* check the signature */
2024-05-01 04:05:22 +01:00
if(Encoding.ASCII.GetString(fheader.signature).TrimEnd('\x00') != FILE_SIGNATURE) return false;
2022-03-06 13:29:38 +00:00
/* Some sanity checks on the values we just read. */
2024-05-01 04:05:22 +01:00
if(fheader.version > 1) return false;
2024-05-01 04:05:22 +01:00
if(fheader.heads is < 1 or > 2) return false;
2024-05-01 04:05:22 +01:00
if(fheader.sectorsPerTrack is < 8 or > 18) return false;
2024-05-01 04:05:22 +01:00
if(fheader.cylinders is < 1 or > 80) return false;
2022-03-06 13:29:38 +00:00
if(fheader.extraTracks[0] > 1 ||
fheader.extraTracks[1] > 1 ||
fheader.extraTracks[2] > 1 ||
fheader.extraTracks[3] > 1)
return false;
2022-03-06 13:29:38 +00:00
// TODO: validate all sectors
// For now, having a valid header will suffice.
return ((byte)fheader.extraFlags & ~0x03) == 0;
}
2023-10-03 23:34:59 +01:00
#endregion
}