Files
Aaru/Aaru.Images/HDCopy/Identify.cs

82 lines
3.0 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Identify.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies HD-Copy 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2017 Michael Drüing
2020-01-03 17:51:30 +00:00
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
using System.IO;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
2020-02-27 00:33:26 +00:00
namespace Aaru.DiscImages
{
2020-07-22 13:20:25 +01:00
public sealed partial class HdCopy
{
public bool Identify(IFilter imageFilter)
{
Stream stream = imageFilter.GetDataForkStream();
stream.Seek(0, SeekOrigin.Begin);
2020-02-29 18:03:35 +00:00
if(stream.Length < 2 + (2 * 82))
return false;
2020-02-29 18:03:35 +00:00
byte[] header = new byte[2 + (2 * 82)];
stream.Read(header, 0, 2 + (2 * 82));
FileHeader fheader = Marshal.ByteArrayToStructureLittleEndian<FileHeader>(header);
/* Some sanity checks on the values we just read.
* We know the image is from a DOS floppy disk, so assume
* some sane cylinder and sectors-per-track count.
*/
2020-02-29 18:03:35 +00:00
if(fheader.sectorsPerTrack < 8 ||
fheader.sectorsPerTrack > 40)
return false;
2020-02-29 18:03:35 +00:00
if(fheader.lastCylinder < 37 ||
fheader.lastCylinder >= 82)
return false;
// Validate the trackmap. First two tracks need to be present
2020-02-29 18:03:35 +00:00
if(fheader.trackMap[0] != 1 ||
fheader.trackMap[1] != 1)
return false;
// all other tracks must be either present (=1) or absent (=0)
for(int i = 0; i < 2 * 82; i++)
if(fheader.trackMap[i] > 1)
return false;
// TODO: validate the tracks
// For now, having a valid header should be sufficient.
return true;
}
}
}