mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Code restyling.
This commit is contained in:
@@ -45,7 +45,8 @@ namespace Aaru.DiscImages
|
||||
Stream stream = imageFilter.GetDataForkStream();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
if(stream.Length < 32) return false;
|
||||
if(stream.Length < 32)
|
||||
return false;
|
||||
|
||||
byte[] header = new byte[32];
|
||||
stream.Read(header, 0, 32);
|
||||
@@ -53,21 +54,33 @@ namespace Aaru.DiscImages
|
||||
WCDiskImageFileHeader fheader = Marshal.ByteArrayToStructureLittleEndian<WCDiskImageFileHeader>(header);
|
||||
|
||||
/* check the signature */
|
||||
if(Encoding.ASCII.GetString(fheader.signature).TrimEnd('\x00') != fileSignature) return false;
|
||||
if(Encoding.ASCII.GetString(fheader.signature).TrimEnd('\x00') != fileSignature)
|
||||
return false;
|
||||
|
||||
/* Some sanity checks on the values we just read. */
|
||||
if(fheader.version > 1) return false;
|
||||
if(fheader.version > 1)
|
||||
return false;
|
||||
|
||||
if(fheader.heads < 1 || fheader.heads > 2) return false;
|
||||
if(fheader.heads < 1 ||
|
||||
fheader.heads > 2)
|
||||
return false;
|
||||
|
||||
if(fheader.sectorsPerTrack < 8 || fheader.sectorsPerTrack > 18) return false;
|
||||
if(fheader.sectorsPerTrack < 8 ||
|
||||
fheader.sectorsPerTrack > 18)
|
||||
return false;
|
||||
|
||||
if(fheader.cylinders < 1 || fheader.cylinders > 80) return false;
|
||||
if(fheader.cylinders < 1 ||
|
||||
fheader.cylinders > 80)
|
||||
return false;
|
||||
|
||||
if(fheader.extraTracks[0] > 1 || fheader.extraTracks[1] > 1 || fheader.extraTracks[2] > 1 ||
|
||||
fheader.extraTracks[3] > 1) return false;
|
||||
if(fheader.extraTracks[0] > 1 ||
|
||||
fheader.extraTracks[1] > 1 ||
|
||||
fheader.extraTracks[2] > 1 ||
|
||||
fheader.extraTracks[3] > 1)
|
||||
return false;
|
||||
|
||||
if(((byte)fheader.extraFlags & ~0x03) != 0) return false;
|
||||
if(((byte)fheader.extraFlags & ~0x03) != 0)
|
||||
return false;
|
||||
|
||||
// TODO: validate all sectors
|
||||
// For now, having a valid header will suffice.
|
||||
|
||||
@@ -57,8 +57,8 @@ namespace Aaru.DiscImages
|
||||
WCDiskImageFileHeader fheader = Marshal.ByteArrayToStructureLittleEndian<WCDiskImageFileHeader>(header);
|
||||
|
||||
AaruConsole.DebugWriteLine("d2f plugin",
|
||||
"Detected WC DISK IMAGE with {0} heads, {1} tracks and {2} sectors per track.",
|
||||
fheader.heads, fheader.cylinders, fheader.sectorsPerTrack);
|
||||
"Detected WC DISK IMAGE with {0} heads, {1} tracks and {2} sectors per track.",
|
||||
fheader.heads, fheader.cylinders, fheader.sectorsPerTrack);
|
||||
|
||||
imageInfo.Cylinders = fheader.cylinders;
|
||||
imageInfo.SectorsPerTrack = fheader.sectorsPerTrack;
|
||||
@@ -175,7 +175,7 @@ namespace Aaru.DiscImages
|
||||
if(badSectors[(cylinderNumber, headNumber, sectorNumber)])
|
||||
{
|
||||
AaruConsole.DebugWriteLine("d2f plugin", "reading bad sector {0} ({1},{2},{3})", sectorAddress,
|
||||
cylinderNumber, headNumber, sectorNumber);
|
||||
cylinderNumber, headNumber, sectorNumber);
|
||||
|
||||
/* if we have sector data, return that */
|
||||
if(sectorCache.ContainsKey((cylinderNumber, headNumber, sectorNumber)))
|
||||
@@ -248,8 +248,8 @@ namespace Aaru.DiscImages
|
||||
|
||||
if(calculatedCRC != sheader.crc)
|
||||
AaruConsole.DebugWriteLine("d2f plugin",
|
||||
"CHS {0},{1},{2}: CRC mismatch: stored CRC=0x{3:x4}, calculated CRC=0x{4:x4}",
|
||||
cyl, head, sect, sheader.crc, calculatedCRC);
|
||||
"CHS {0},{1},{2}: CRC mismatch: stored CRC=0x{3:x4}, calculated CRC=0x{4:x4}",
|
||||
cyl, head, sect, sheader.crc, calculatedCRC);
|
||||
|
||||
break;
|
||||
case SectorFlag.BadSector:
|
||||
|
||||
@@ -37,137 +37,92 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
public partial class WCDiskImage
|
||||
{
|
||||
/// <summary>
|
||||
/// The expected signature of a proper image file.
|
||||
/// </summary>
|
||||
/// <summary>The expected signature of a proper image file.</summary>
|
||||
const string fileSignature = "WC DISK IMAGE\x1a\x1a";
|
||||
|
||||
/// <summary>
|
||||
/// The global header of a WCDiskImage file
|
||||
/// </summary>
|
||||
/// <summary>The global header of a WCDiskImage file</summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct WCDiskImageFileHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// The signature should be "WC DISK IMAGE\0x1a\0x1a\0x00"
|
||||
/// </summary>
|
||||
/// <summary>The signature should be "WC DISK IMAGE\0x1a\0x1a\0x00"</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||
public byte[] signature;
|
||||
public readonly byte[] signature;
|
||||
|
||||
/// <summary>Version (currently only version 0 and 1 is known)</summary>
|
||||
public readonly byte version;
|
||||
|
||||
/// <summary>The number of heads. Only 1 or 2 is supported</summary>
|
||||
public readonly byte heads;
|
||||
|
||||
/// <summary>Sectors per track, maximum is 18</summary>
|
||||
public readonly byte sectorsPerTrack;
|
||||
|
||||
/// <summary>The number of tracks/cylinders. 80 is the maximum</summary>
|
||||
public readonly byte cylinders;
|
||||
|
||||
/// <summary>
|
||||
/// Version (currently only version 0 and 1 is known)
|
||||
/// </summary>
|
||||
public byte version;
|
||||
|
||||
/// <summary>
|
||||
/// The number of heads. Only 1 or 2 is supported
|
||||
/// </summary>
|
||||
public byte heads;
|
||||
|
||||
/// <summary>
|
||||
/// Sectors per track, maximum is 18
|
||||
/// </summary>
|
||||
public byte sectorsPerTrack;
|
||||
|
||||
/// <summary>
|
||||
/// The number of tracks/cylinders. 80 is the maximum
|
||||
/// </summary>
|
||||
public byte cylinders;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
||||
public byte[] extraTracks;
|
||||
public readonly byte[] extraTracks;
|
||||
|
||||
/// <summary>
|
||||
/// Additional metadata present flags.
|
||||
/// </summary>
|
||||
public ExtraFlag extraFlags;
|
||||
/// <summary>Additional metadata present flags.</summary>
|
||||
public readonly ExtraFlag extraFlags;
|
||||
|
||||
/// <summary>
|
||||
/// Padding to make the header 32 bytes.
|
||||
/// </summary>
|
||||
/// <summary>Padding to make the header 32 bytes.</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
|
||||
public byte[] reserved;
|
||||
public readonly byte[] reserved;
|
||||
}
|
||||
|
||||
enum ExtraFlag : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Set if a Comment is present after the image
|
||||
/// </summary>
|
||||
/// <summary>Set if a Comment is present after the image</summary>
|
||||
Comment = 0x01,
|
||||
|
||||
/// <summary>
|
||||
/// Set if a directory listing is present after the image
|
||||
/// </summary>
|
||||
/// <summary>Set if a directory listing is present after the image</summary>
|
||||
Directory = 0x02
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Sector header that precedes each sector
|
||||
/// </summary>
|
||||
/// <summary>The Sector header that precedes each sector</summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct WCDiskImageSectorHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// The sector flag (i.e. type)
|
||||
/// </summary>
|
||||
public SectorFlag flag;
|
||||
/// <summary>The sector flag (i.e. type)</summary>
|
||||
public readonly SectorFlag flag;
|
||||
|
||||
/// <summary>
|
||||
/// The head this sector belongs to.
|
||||
/// </summary>
|
||||
public byte head;
|
||||
/// <summary>The head this sector belongs to.</summary>
|
||||
public readonly byte head;
|
||||
|
||||
/// <summary>
|
||||
/// The sector number within the track. Must be consecutive.
|
||||
/// </summary>
|
||||
public byte sector;
|
||||
/// <summary>The sector number within the track. Must be consecutive.</summary>
|
||||
public readonly byte sector;
|
||||
|
||||
/// <summary>
|
||||
/// The cylinder number this sector belongs to.
|
||||
/// </summary>
|
||||
public byte cylinder;
|
||||
/// <summary>The cylinder number this sector belongs to.</summary>
|
||||
public readonly byte cylinder;
|
||||
|
||||
/// <summary>
|
||||
/// A simple CRC16 over the data, to detect errors.
|
||||
/// </summary>
|
||||
public short crc;
|
||||
/// <summary>A simple CRC16 over the data, to detect errors.</summary>
|
||||
public readonly short crc;
|
||||
}
|
||||
|
||||
enum SectorFlag : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// A normal sector
|
||||
/// </summary>
|
||||
/// <summary>A normal sector</summary>
|
||||
Normal = 0x00,
|
||||
|
||||
/// <summary>
|
||||
/// A bad sector that could not be read
|
||||
/// </summary>
|
||||
/// <summary>A bad sector that could not be read</summary>
|
||||
BadSector = 0x01,
|
||||
|
||||
/// <summary>
|
||||
/// A sector filled with a repeating byte value. The value
|
||||
/// is encoded in the LSB of the <c>crc</c> field.
|
||||
/// </summary>
|
||||
/// <summary>A sector filled with a repeating byte value. The value is encoded in the LSB of the <c>crc</c> field.</summary>
|
||||
RepeatByte = 0x02,
|
||||
|
||||
/// <summary>
|
||||
/// Not a sector but a comment. Must come after all user data.
|
||||
/// The <c>crc</c> field is the length of the comment data.
|
||||
/// Not a sector but a comment. Must come after all user data. The <c>crc</c> field is the length of the comment
|
||||
/// data.
|
||||
/// </summary>
|
||||
Comment = 0x03,
|
||||
|
||||
/// <summary>
|
||||
/// Not a sector but the directory information.
|
||||
/// The <c>crc</c> field is the length of the data.
|
||||
/// </summary>
|
||||
/// <summary>Not a sector but the directory information. The <c>crc</c> field is the length of the data.</summary>
|
||||
Directory = 0x04
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@ namespace Aaru.DiscImages
|
||||
{
|
||||
public Dictionary<(int cylinder, int head, int sector), bool> badSectors =
|
||||
new Dictionary<(int cylinder, int head, int sector), bool>();
|
||||
/// <summary>
|
||||
/// The file header after the image has been opened
|
||||
/// </summary>
|
||||
/// <summary>The file header after the image has been opened</summary>
|
||||
WCDiskImageFileHeader fileHeader;
|
||||
ImageInfo imageInfo;
|
||||
|
||||
@@ -52,36 +50,21 @@ namespace Aaru.DiscImages
|
||||
public Dictionary<(int cylinder, int head, int sector), byte[]> sectorCache =
|
||||
new Dictionary<(int cylinder, int head, int sector), byte[]>();
|
||||
|
||||
/// <summary>
|
||||
/// The ImageFilter we're reading from, after the file has been opened
|
||||
/// </summary>
|
||||
/// <summary>The ImageFilter we're reading from, after the file has been opened</summary>
|
||||
IFilter wcImageFilter;
|
||||
|
||||
public WCDiskImage()
|
||||
public WCDiskImage() => imageInfo = new ImageInfo
|
||||
{
|
||||
imageInfo = new ImageInfo
|
||||
{
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false,
|
||||
HasSessions = false,
|
||||
Version = null,
|
||||
Application = null,
|
||||
ApplicationVersion = null,
|
||||
Creator = null,
|
||||
Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaSerialNumber = null,
|
||||
MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
ReadableSectorTags = new List<SectorTagType>(), ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false, HasSessions = false, Version = null,
|
||||
Application = null,
|
||||
ApplicationVersion = null, Creator = null, Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null, MediaSerialNumber = null, MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0, LastMediaSequence = 0, DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null, DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user