/*************************************************************************** The Disc Image Chef ---------------------------------------------------------------------------- Filename : ImagePlugin.cs Version : 1.0 Author(s) : Natalia Portillo Component : Disc image plugins Revision : $Revision$ Last change by : $Author$ Date : $Date$ --[ Description ] ---------------------------------------------------------- Defines functions to be used by disc image plugins and several constants. --[ License ] -------------------------------------------------------------- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ---------------------------------------------------------------------------- Copyright (C) 2011-2014 Claunia.com ****************************************************************************/ //$Id$ using System; using System.Collections.Generic; using DiscImageChef.CommonTypes; namespace DiscImageChef.ImagePlugins { /// /// Abstract class to implement disk image reading plugins. /// public abstract class ImagePlugin { /// Plugin name. public string Name; /// Plugin UUID. public Guid PluginUUID; /// Image information public ImageInfo ImageInfo; protected ImagePlugin() { } // Basic image handling functions /// /// Identifies the image. /// /// true, if image was identified, false otherwise. /// Image path. public abstract bool IdentifyImage(string imagePath); /// /// Opens the image. /// /// true, if image was opened, false otherwise. /// Image path. public abstract bool OpenImage(string imagePath); /// /// Asks the disk image plugin if the image contains partitions /// /// true, if the image contains partitions, false otherwise. public abstract bool ImageHasPartitions(); // Image size functions /// /// Gets the size of the image, without headers. /// /// The image size. public abstract UInt64 GetImageSize(); /// /// Gets the number of sectors in the image. /// /// Sectors in image. public abstract UInt64 GetSectors(); /// /// Returns the size of the biggest sector, counting user data only. /// /// Biggest sector size (user data only). public abstract UInt32 GetSectorSize(); // Image reading functions /// /// Reads a disk tag. /// /// Disk tag /// Tag type to read. public abstract byte[] ReadDiskTag(DiskTagType tag); /// /// Reads a sector's user data. /// /// The sector's user data. /// Sector address (LBA). public abstract byte[] ReadSector(UInt64 sectorAddress); /// /// Reads a sector's tag. /// /// The sector's tag. /// Sector address (LBA). /// Tag type. public abstract byte[] ReadSectorTag(UInt64 sectorAddress, SectorTagType tag); /// /// Reads a sector's user data, relative to track. /// /// The sector's user data. /// Sector address (relative LBA). /// Track. public abstract byte[] ReadSector(UInt64 sectorAddress, UInt32 track); /// /// Reads a sector's tag, relative to track. /// /// The sector's tag. /// Sector address (relative LBA). /// Track. /// Tag type. public abstract byte[] ReadSectorTag(UInt64 sectorAddress, UInt32 track, SectorTagType tag); /// /// Reads user data from several sectors. /// /// The sectors user data. /// Starting sector address (LBA). /// How many sectors to read. public abstract byte[] ReadSectors(UInt64 sectorAddress, UInt32 length); /// /// Reads tag from several sectors. /// /// The sectors tag. /// Starting sector address (LBA). /// How many sectors to read. /// Tag type. public abstract byte[] ReadSectorsTag(UInt64 sectorAddress, UInt32 length, SectorTagType tag); /// /// Reads user data from several sectors, relative to track. /// /// The sectors user data. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. public abstract byte[] ReadSectors(UInt64 sectorAddress, UInt32 length, UInt32 track); /// /// Reads tag from several sectors, relative to track. /// /// The sectors tag. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. /// Tag type. public abstract byte[] ReadSectorsTag(UInt64 sectorAddress, UInt32 length, UInt32 track, SectorTagType tag); /// /// Reads a complete sector (user data + all tags). /// /// The complete sector. Format depends on disk type. /// Sector address (LBA). public abstract byte[] ReadSectorLong(UInt64 sectorAddress); /// /// Reads a complete sector (user data + all tags), relative to track. /// /// The complete sector. Format depends on disk type. /// Sector address (relative LBA). /// Track. public abstract byte[] ReadSectorLong(UInt64 sectorAddress, UInt32 track); /// /// Reads several complete sector (user data + all tags). /// /// The complete sectors. Format depends on disk type. /// Starting sector address (LBA). /// How many sectors to read. public abstract byte[] ReadSectorsLong(UInt64 sectorAddress, UInt32 length); /// /// Reads several complete sector (user data + all tags), relative to track. /// /// The complete sectors. Format depends on disk type. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. public abstract byte[] ReadSectorsLong(UInt64 sectorAddress, UInt32 length, UInt32 track); // Image information functions /// /// Gets the image format. /// /// The image format. public abstract string GetImageFormat(); /// /// Gets the image version. /// /// The image version. public abstract string GetImageVersion(); /// /// Gets the application that created the image. /// /// The application that created the image. public abstract string GetImageApplication(); /// /// Gets the version of the application that created the image. /// /// The version of the application that created the image. public abstract string GetImageApplicationVersion(); /// /// Gets the image creator. /// /// Who created the image. public abstract string GetImageCreator(); /// /// Gets the image creation time. /// /// The image creation time. public abstract DateTime GetImageCreationTime(); /// /// Gets the image last modification time. /// /// The image last modification time. public abstract DateTime GetImageLastModificationTime(); /// /// Gets the name of the image. /// /// The image name. public abstract string GetImageName(); /// /// Gets the image comments. /// /// The image comments. public abstract string GetImageComments(); // Functions to get information from disk represented by image /// /// Gets the disk manufacturer. /// /// The disk manufacturer. public abstract string GetDiskManufacturer(); /// /// Gets the disk model. /// /// The disk model. public abstract string GetDiskModel(); /// /// Gets the disk serial number. /// /// The disk serial number. public abstract string GetDiskSerialNumber(); /// /// Gets the disk (or product) barcode. /// /// The disk barcode. public abstract string GetDiskBarcode(); /// /// Gets the disk part number. /// /// The disk part number. public abstract string GetDiskPartNumber(); /// /// Gets the type of the disk. /// /// The disk type. public abstract DiskType GetDiskType(); /// /// Gets the disk sequence. /// /// The disk sequence, starting at 1. public abstract int GetDiskSequence(); /// /// Gets the last disk in the sequence. /// /// The last disk in the sequence. public abstract int GetLastDiskSequence(); // Functions to get information from drive used to create image /// /// Gets the manufacturer of the drive used to create the image. /// /// The drive manufacturer. public abstract string GetDriveManufacturer(); /// /// Gets the model of the drive used to create the image. /// /// The drive model. public abstract string GetDriveModel(); /// /// Gets the serial number of the drive used to create the image. /// /// The drive serial number. public abstract string GetDriveSerialNumber(); // Partitioning functions /// /// Gets an array partitions. Typically only useful for optical disc /// images where each track and index means a different partition, as /// reads can be relative to them. /// /// The partitions. public abstract List GetPartitions(); /// /// Gets the disc track extents (start, length). /// /// The track extents. public abstract List GetTracks(); /// /// Gets the disc track extents for a specified session. /// /// The track exents for that session. /// Session. public abstract List GetSessionTracks(Session session); /// /// Gets the disc track extents for a specified session. /// /// The track exents for that session. /// Session. public abstract List GetSessionTracks(UInt16 session); /// /// Gets the sessions (optical discs only). /// /// The sessions. public abstract List GetSessions(); /// /// Verifies a sector. /// /// True if correct, false if incorrect, null if uncheckable. /// Sector address (LBA). public abstract bool? VerifySector(UInt64 sectorAddress); /// /// Verifies a sector, relative to track. /// /// True if correct, false if incorrect, null if uncheckable. /// Sector address (relative LBA). /// Track. public abstract bool? VerifySector(UInt64 sectorAddress, UInt32 track); /// /// Verifies several sectors. /// /// True if all are correct, false if any is incorrect, null if any is uncheckable. /// Starting sector address (LBA). /// How many sectors to read. /// List of incorrect sectors /// List of uncheckable sectors public abstract bool? VerifySectors(UInt64 sectorAddress, UInt32 length, out List FailingLBAs, out List UnknownLBAs); /// /// Verifies several sectors, relative to track. /// /// True if all are correct, false if any is incorrect, null if any is uncheckable. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. /// List of incorrect sectors /// List of uncheckable sectors public abstract bool? VerifySectors(UInt64 sectorAddress, UInt32 length, UInt32 track, out List FailingLBAs, out List UnknownLBAs); /// /// Verifies disk image internal checksum. /// /// True if correct, false if incorrect, null if there is no internal checksum available public abstract bool? VerifyDiskImage(); // CD flags bitmask /// Track is quadraphonic. public const byte CDFlagsFourChannel = 0x20; /// Track is non-audio (data). public const byte CDFlagsDataTrack = 0x10; /// Track is copy protected. public const byte CDFlagsCopyPrevent = 0x08; /// Track has pre-emphasis. public const byte CDFlagsPreEmphasis = 0x04; } /// /// Track (as partitioning element) types. /// public enum TrackType { /// Audio track Audio, /// Data track (not any of the below defined ones) Data, /// Data track, compact disc mode 1 CDMode1, /// Data track, compact disc mode 2, formless CDMode2Formless, /// Data track, compact disc mode 2, form 1 CDMode2Form1, /// Data track, compact disc mode 2, form 2 CDMode2Form2 }; /// /// Track defining structure. /// public struct Track { /// Track number, 1-started public UInt32 TrackSequence; /// Partition type public TrackType TrackType; /// Track starting sector public UInt64 TrackStartSector; /// Track ending sector public UInt64 TrackEndSector; /// Track pre-gap public UInt64 TrackPregap; /// Session this track belongs to public UInt16 TrackSession; /// Information that does not find space in this struct public string TrackDescription; /// Indexes, 00 to 99 and sector offset public Dictionary Indexes; } /// /// Session defining structure. /// public struct Session { /// Session number, 1-started public UInt16 SessionSequence; /// First track present on this session public UInt32 StartTrack; /// Last track present on this session public UInt32 EndTrack; /// First sector present on this session public UInt64 StartSector; /// Last sector present on this session public UInt64 EndSector; } /// /// Metadata present for each sector (aka, "tag"). /// public enum SectorTagType { /// Apple's GCR sector tags, 12 bytes AppleSectorTag, /// Sync frame from CD sector, 12 bytes CDSectorSync, /// CD sector header, 4 bytes CDSectorHeader, /// CD mode 2 sector subheader CDSectorSubHeader, /// CD sector EDC, 4 bytes CDSectorEDC, /// CD sector ECC P, 172 bytes CDSectorECC_P, /// CD sector ECC Q, 104 bytes CDSectorECC_Q, /// CD sector ECC (P and Q), 276 bytes CDSectorECC, /// CD sector subchannel, 96 bytes CDSectorSubchannel, /// CD track ISRC, string, 12 bytes CDTrackISRC, /// CD track text, string, 13 bytes CDTrackText, /// CD track flags, 1 byte CDTrackFlags, /// DVD sector copyright information DVD_CMI }; /// /// Metadata present for each disk. /// public enum DiskTagType { /// CD table of contents CD_TOC, /// CD session information CD_SessionInfo, /// CD full table of contents CD_FullTOC, /// CD PMA CD_PMA, /// CD Adress-Time-In-Pregroove CD_ATIP, /// CD-Text CD_TEXT, /// CD Media Catalogue Number CD_MCN, /// DVD/HD DVD Physical Format Information DVD_PFI, /// DVD Lead-in Copyright Management Information DVD_CMI, /// DVD disc key DVD_DiscKey, /// DVD/HD DVD Burst Cutting Area DVD_BCA, /// DVD/HD DVD Lead-in Disc Manufacturer Information DVD_DMI, /// Media identifier DVD_MediaIdentifier, /// Media key block DVD_MKB, /// DVD-RAM/HD DVD-RAM DDS information DVDRAM_DDS, /// DVD-RAM/HD DVD-RAM Medium status DVDRAM_MediumStatus, /// DVD-RAM/HD DVD-RAM Spare area information DVDRAM_SpareArea, /// DVD-R/-RW/HD DVD-R RMD in last border-out DVDR_RMD, /// Pre-recorded information from DVD-R/-RW lead-in DVDR_PreRecordedInfo, /// DVD-R/-RW/HD DVD-R media identifier DVDR_MediaIdentifier, /// DVD-R/-RW/HD DVD-R physical format information DVDR_PFI, /// ADIP information DVD_ADIP, /// HD DVD Lead-in copyright protection information HDDVD_CPI, /// HD DVD-R Medium Status HDDVD_MediumStatus, /// DVD+/-R DL Layer capacity DVDDL_LayerCapacity, /// DVD-R DL Middle Zone start address DVDDL_MiddleZoneAddress, /// DVD-R DL Jump Interval Size DVDDL_JumpIntervalSize, /// DVD-R DL Start LBA of the manual layer jump DVDDL_ManualLayerJumpLBA, /// Blu-ray Disc Information BD_DI, /// Blu-ray Burst Cutting Area BD_BCA, /// Blu-ray Disc Definition Structure BD_DDS, /// Blu-ray Cartridge Status BD_CartridgeStatus, /// Blu-ray Status of Spare Area BD_SpareArea, /// AACS volume identifier AACS_VolumeIdentifier, /// AACS pre-recorded media serial number AACS_SerialNumber, /// AACS media identifier AACS_MediaIdentifier, /// Lead-in AACS media key block AACS_MKB, /// AACS data keys AACS_DataKeys, /// LBA extents flagged for bus encryption by AACS AACS_LBAExtents, /// CPRM media key block in Lead-in AACS_CPRM_MKB, /// Recognized layer formats in hybrid discs Hybrid_RecognizedLayers, /// Disc write protection status MMC_WriteProtection, /// Disc standard information MMC_DiscInformation, /// Disc track resources information MMC_TrackResourcesInformation, /// BD-R Pseudo-overwrite information MMC_POWResourcesInformation, /// SCSI INQUIRY response SCSI_INQUIRY, /// ATA IDENTIFY DEVICE response ATA_IDENTIFY, /// ATA IDENTIFY PACKET DEVICE response ATAPI_IDENTIFY }; public enum XmlMediaType { OpticalDisc, BlockMedia, LinearMedia } /// /// Feature is supported by image but not implemented yet. /// [Serializable] public class FeatureSupportedButNotImplementedImageException : Exception { public FeatureSupportedButNotImplementedImageException(string message, Exception inner) : base(message, inner) { } public FeatureSupportedButNotImplementedImageException(string message) : base(message) { } protected FeatureSupportedButNotImplementedImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); } } /// /// Feature is not supported by image. /// [Serializable] public class FeatureUnsupportedImageException : Exception { public FeatureUnsupportedImageException(string message, Exception inner) : base(message, inner) { } public FeatureUnsupportedImageException(string message) : base(message) { } protected FeatureUnsupportedImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); } } /// /// Feature is supported by image but not present on it. /// [Serializable] public class FeatureNotPresentImageException : Exception { public FeatureNotPresentImageException(string message, Exception inner) : base(message, inner) { } public FeatureNotPresentImageException(string message) : base(message) { } protected FeatureNotPresentImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); } } /// /// Feature is supported by image but not by the disc it represents. /// [Serializable] public class FeaturedNotSupportedByDiscImageException : Exception { public FeaturedNotSupportedByDiscImageException(string message, Exception inner) : base(message, inner) { } public FeaturedNotSupportedByDiscImageException(string message) : base(message) { } protected FeaturedNotSupportedByDiscImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); } } /// /// Corrupt, incorrect or unhandled feature found on image /// [Serializable] public class ImageNotSupportedException : Exception { public ImageNotSupportedException(string message, Exception inner) : base(message, inner) { } public ImageNotSupportedException(string message) : base(message) { } protected ImageNotSupportedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); } } }