REFACTOR: Fixed MOST name inconsistencies.

This commit is contained in:
2017-12-20 17:15:26 +00:00
parent 542520f5cd
commit a4650c61aa
428 changed files with 16205 additions and 16320 deletions

View File

@@ -40,36 +40,36 @@ using DiscImageChef.Filters;
using SharpCompress.Compressors;
using SharpCompress.Compressors.Deflate;
namespace DiscImageChef.ImagePlugins
namespace DiscImageChef.DiscImages
{
public class QCOW2 : ImagePlugin
public class Qcow2 : ImagePlugin
{
#region Internal constants
/// <summary>
/// Magic number: 'Q', 'F', 'I', 0xFB
/// </summary>
const uint QCowMagic = 0x514649FB;
const uint QCowVersion2 = 2;
const uint QCowVersion3 = 3;
const uint QCowEncryptionNone = 0;
const uint QCowEncryptionAES = 1;
const uint QCOW_MAGIC = 0x514649FB;
const uint QCOW_VERSION2 = 2;
const uint QCOW_VERSION3 = 3;
const uint QCOW_ENCRYPTION_NONE = 0;
const uint QCOW_ENCRYPTION_AES = 1;
const ulong QcowFeatureDirty = 0x01;
const ulong QcowFeatureCorrupt = 0x02;
const ulong QcowFeatureMask = 0xFFFFFFFFFFFFFFFC;
const ulong QCOW_FEATURE_DIRTY = 0x01;
const ulong QCOW_FEATURE_CORRUPT = 0x02;
const ulong QCOW_FEATURE_MASK = 0xFFFFFFFFFFFFFFFC;
const ulong QcowCompatFeatureLazyRefcounts = 0x01;
const ulong QcowAutoClearFeatureBitmap = 0x01;
const ulong QCOW_COMPAT_FEATURE_LAZY_REFCOUNTS = 0x01;
const ulong QCOW_AUTO_CLEAR_FEATURE_BITMAP = 0x01;
const ulong QCowFlagsMask = 0x3FFFFFFFFFFFFFFF;
const ulong QCowCopied = 0x8000000000000000;
const ulong QCowCompressed = 0x4000000000000000;
const ulong QCOW_FLAGS_MASK = 0x3FFFFFFFFFFFFFFF;
const ulong QCOW_COPIED = 0x8000000000000000;
const ulong QCOW_COMPRESSED = 0x4000000000000000;
const ulong QCowHeaderExtensionBackingFile = 0xE2792ACA;
const ulong QCowHeaderExtensionFeatureTable = 0x6803F857;
const ulong QCowHeaderExtensionBitmaps = 0x23852875;
const ulong QCOW_HEADER_EXTENSION_BACKING_FILE = 0xE2792ACA;
const ulong QCOW_HEADER_EXTENSION_FEATURE_TABLE = 0x6803F857;
const ulong QCOW_HEADER_EXTENSION_BITMAPS = 0x23852875;
const int MaxCacheSize = 16777216;
const int MAX_CACHE_SIZE = 16777216;
#endregion
#region Internal Structures
@@ -80,7 +80,7 @@ namespace DiscImageChef.ImagePlugins
struct QCow2Header
{
/// <summary>
/// <see cref="QCowMagic"/>
/// <see cref="Qcow2.QCOW_MAGIC"/>
/// </summary>
public uint magic;
/// <summary>
@@ -157,37 +157,37 @@ namespace DiscImageChef.ImagePlugins
Dictionary<ulong, byte[]> clusterCache;
Dictionary<ulong, ulong[]> l2TableCache;
int maxCachedSectors = MaxCacheSize / 512;
int maxCachedSectors = MAX_CACHE_SIZE / 512;
int maxL2TableCache;
int maxClusterCache;
Stream imageStream;
public QCOW2()
public Qcow2()
{
Name = "QEMU Copy-On-Write disk image v2";
PluginUUID = new Guid("F20107CB-95B3-4398-894B-975261F1E8C5");
PluginUuid = new Guid("F20107CB-95B3-4398-894B-975261F1E8C5");
ImageInfo = new ImageInfo();
ImageInfo.readableSectorTags = new List<SectorTagType>();
ImageInfo.readableMediaTags = new List<MediaTagType>();
ImageInfo.imageHasPartitions = false;
ImageInfo.imageHasSessions = false;
ImageInfo.imageVersion = null;
ImageInfo.imageApplication = "QEMU";
ImageInfo.imageApplicationVersion = null;
ImageInfo.imageCreator = null;
ImageInfo.imageComments = null;
ImageInfo.mediaManufacturer = null;
ImageInfo.mediaModel = null;
ImageInfo.mediaSerialNumber = null;
ImageInfo.mediaBarcode = null;
ImageInfo.mediaPartNumber = null;
ImageInfo.mediaSequence = 0;
ImageInfo.lastMediaSequence = 0;
ImageInfo.driveManufacturer = null;
ImageInfo.driveModel = null;
ImageInfo.driveSerialNumber = null;
ImageInfo.driveFirmwareRevision = null;
ImageInfo.ReadableSectorTags = new List<SectorTagType>();
ImageInfo.ReadableMediaTags = new List<MediaTagType>();
ImageInfo.ImageHasPartitions = false;
ImageInfo.ImageHasSessions = false;
ImageInfo.ImageVersion = null;
ImageInfo.ImageApplication = "QEMU";
ImageInfo.ImageApplicationVersion = null;
ImageInfo.ImageCreator = null;
ImageInfo.ImageComments = null;
ImageInfo.MediaManufacturer = null;
ImageInfo.MediaModel = null;
ImageInfo.MediaSerialNumber = null;
ImageInfo.MediaBarcode = null;
ImageInfo.MediaPartNumber = null;
ImageInfo.MediaSequence = 0;
ImageInfo.LastMediaSequence = 0;
ImageInfo.DriveManufacturer = null;
ImageInfo.DriveModel = null;
ImageInfo.DriveSerialNumber = null;
ImageInfo.DriveFirmwareRevision = null;
}
public override bool IdentifyImage(Filter imageFilter)
@@ -197,14 +197,14 @@ namespace DiscImageChef.ImagePlugins
if(stream.Length < 512) return false;
byte[] qHdr_b = new byte[Marshal.SizeOf(qHdr)];
stream.Read(qHdr_b, 0, Marshal.SizeOf(qHdr));
qHdr = BigEndianMarshal.ByteArrayToStructureBigEndian<QCow2Header>(qHdr_b);
byte[] qHdrB = new byte[Marshal.SizeOf(qHdr)];
stream.Read(qHdrB, 0, Marshal.SizeOf(qHdr));
qHdr = BigEndianMarshal.ByteArrayToStructureBigEndian<QCow2Header>(qHdrB);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.magic = 0x{0:X8}", qHdr.magic);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.version = {0}", qHdr.version);
return qHdr.magic == QCowMagic && (qHdr.version == QCowVersion2 || qHdr.version == QCowVersion3);
return qHdr.magic == QCOW_MAGIC && (qHdr.version == QCOW_VERSION2 || qHdr.version == QCOW_VERSION3);
}
public override bool OpenImage(Filter imageFilter)
@@ -214,9 +214,9 @@ namespace DiscImageChef.ImagePlugins
if(stream.Length < 512) return false;
byte[] qHdr_b = new byte[Marshal.SizeOf(qHdr)];
stream.Read(qHdr_b, 0, Marshal.SizeOf(qHdr));
qHdr = BigEndianMarshal.ByteArrayToStructureBigEndian<QCow2Header>(qHdr_b);
byte[] qHdrB = new byte[Marshal.SizeOf(qHdr)];
stream.Read(qHdrB, 0, Marshal.SizeOf(qHdr));
qHdr = BigEndianMarshal.ByteArrayToStructureBigEndian<QCow2Header>(qHdrB);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.magic = 0x{0:X8}", qHdr.magic);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.version = {0}", qHdr.version);
@@ -233,7 +233,7 @@ namespace DiscImageChef.ImagePlugins
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.nb_snapshots = {0}", qHdr.nb_snapshots);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.snapshots_offset = {0}", qHdr.snapshots_offset);
if(qHdr.version >= QCowVersion3)
if(qHdr.version >= QCOW_VERSION3)
{
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.features = {0:X}", qHdr.features);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.compat_features = {0:X}", qHdr.compat_features);
@@ -241,10 +241,10 @@ namespace DiscImageChef.ImagePlugins
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.refcount_order = {0}", qHdr.refcount_order);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.header_length = {0}", qHdr.header_length);
if((qHdr.features & QcowFeatureMask) != 0)
if((qHdr.features & QCOW_FEATURE_MASK) != 0)
throw new
ImageNotSupportedException(string.Format("Unknown incompatible features {0:X} enabled, not proceeding.",
qHdr.features & QcowFeatureMask));
qHdr.features & QCOW_FEATURE_MASK));
}
if(qHdr.size <= 1) throw new ArgumentOutOfRangeException(nameof(qHdr.size), "Image size is too small");
@@ -253,10 +253,10 @@ namespace DiscImageChef.ImagePlugins
throw new ArgumentOutOfRangeException(nameof(qHdr.cluster_bits),
"Cluster size must be between 512 bytes and 64 Kbytes");
if(qHdr.crypt_method > QCowEncryptionAES)
if(qHdr.crypt_method > QCOW_ENCRYPTION_AES)
throw new ArgumentOutOfRangeException(nameof(qHdr.crypt_method), "Invalid encryption method");
if(qHdr.crypt_method > QCowEncryptionNone)
if(qHdr.crypt_method > QCOW_ENCRYPTION_NONE)
throw new NotImplementedException("AES encrypted images not yet supported");
if(qHdr.backing_file_offset != 0)
@@ -276,18 +276,18 @@ namespace DiscImageChef.ImagePlugins
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.clusterSectors = {0}", clusterSectors);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.qHdr.l1_size = {0}", qHdr.l1_size);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.l2Size = {0}", l2Size);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.sectors = {0}", ImageInfo.sectors);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.sectors = {0}", ImageInfo.Sectors);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] l1Table_b = new byte[qHdr.l1_size * 8];
byte[] l1TableB = new byte[qHdr.l1_size * 8];
stream.Seek((long)qHdr.l1_table_offset, SeekOrigin.Begin);
stream.Read(l1Table_b, 0, (int)qHdr.l1_size * 8);
stream.Read(l1TableB, 0, (int)qHdr.l1_size * 8);
l1Table = new ulong[qHdr.l1_size];
// TODO: Optimize this
DicConsole.DebugWriteLine("QCOW plugin", "Reading L1 table");
for(long i = 0; i < l1Table.LongLength; i++)
l1Table[i] = BigEndianBitConverter.ToUInt64(l1Table_b, (int)(i * 8));
l1Table[i] = BigEndianBitConverter.ToUInt64(l1TableB, (int)(i * 8));
l1Mask = 0;
int c = 0;
@@ -317,8 +317,8 @@ namespace DiscImageChef.ImagePlugins
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.l2Mask = {0:X}", l2Mask);
DicConsole.DebugWriteLine("QCOW plugin", "qHdr.sectorMask = {0:X}", sectorMask);
maxL2TableCache = MaxCacheSize / (l2Size * 8);
maxClusterCache = MaxCacheSize / clusterSize;
maxL2TableCache = MAX_CACHE_SIZE / (l2Size * 8);
maxClusterCache = MAX_CACHE_SIZE / clusterSize;
imageStream = stream;
@@ -326,26 +326,26 @@ namespace DiscImageChef.ImagePlugins
l2TableCache = new Dictionary<ulong, ulong[]>();
clusterCache = new Dictionary<ulong, byte[]>();
ImageInfo.imageCreationTime = imageFilter.GetCreationTime();
ImageInfo.imageLastModificationTime = imageFilter.GetLastWriteTime();
ImageInfo.imageName = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
ImageInfo.sectors = qHdr.size / 512;
ImageInfo.sectorSize = 512;
ImageInfo.xmlMediaType = XmlMediaType.BlockMedia;
ImageInfo.mediaType = MediaType.GENERIC_HDD;
ImageInfo.imageSize = qHdr.size;
ImageInfo.imageVersion = string.Format("{0}", qHdr.version);
ImageInfo.ImageCreationTime = imageFilter.GetCreationTime();
ImageInfo.ImageLastModificationTime = imageFilter.GetLastWriteTime();
ImageInfo.ImageName = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
ImageInfo.Sectors = qHdr.size / 512;
ImageInfo.SectorSize = 512;
ImageInfo.XmlMediaType = XmlMediaType.BlockMedia;
ImageInfo.MediaType = MediaType.GENERIC_HDD;
ImageInfo.ImageSize = qHdr.size;
ImageInfo.ImageVersion = string.Format("{0}", qHdr.version);
ImageInfo.cylinders = (uint)((ImageInfo.sectors / 16) / 63);
ImageInfo.heads = 16;
ImageInfo.sectorsPerTrack = 63;
ImageInfo.Cylinders = (uint)((ImageInfo.Sectors / 16) / 63);
ImageInfo.Heads = 16;
ImageInfo.SectorsPerTrack = 63;
return true;
}
public override byte[] ReadSector(ulong sectorAddress)
{
if(sectorAddress > ImageInfo.sectors - 1)
if(sectorAddress > ImageInfo.Sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
string.Format("Sector address {0} not found", sectorAddress));
@@ -372,12 +372,12 @@ namespace DiscImageChef.ImagePlugins
if(!l2TableCache.TryGetValue(l1Off, out l2Table))
{
l2Table = new ulong[l2Size];
imageStream.Seek((long)(l1Table[l1Off] & QCowFlagsMask), SeekOrigin.Begin);
byte[] l2Table_b = new byte[l2Size * 8];
imageStream.Read(l2Table_b, 0, l2Size * 8);
imageStream.Seek((long)(l1Table[l1Off] & QCOW_FLAGS_MASK), SeekOrigin.Begin);
byte[] l2TableB = new byte[l2Size * 8];
imageStream.Read(l2TableB, 0, l2Size * 8);
DicConsole.DebugWriteLine("QCOW plugin", "Reading L2 table #{0}", l1Off);
for(long i = 0; i < l2Table.LongLength; i++)
l2Table[i] = BigEndianBitConverter.ToUInt64(l2Table_b, (int)(i * 8));
l2Table[i] = BigEndianBitConverter.ToUInt64(l2TableB, (int)(i * 8));
if(l2TableCache.Count >= maxL2TableCache) l2TableCache.Clear();
@@ -390,12 +390,12 @@ namespace DiscImageChef.ImagePlugins
sector = new byte[512];
if((offset & QCowFlagsMask) != 0)
if((offset & QCOW_FLAGS_MASK) != 0)
{
byte[] cluster;
if(!clusterCache.TryGetValue(offset, out cluster))
{
if((offset & QCowCompressed) == QCowCompressed)
if((offset & QCOW_COMPRESSED) == QCOW_COMPRESSED)
{
ulong compSizeMask = 0;
ulong offMask = 0;
@@ -403,7 +403,7 @@ namespace DiscImageChef.ImagePlugins
compSizeMask = (ulong)(1 << (int)(qHdr.cluster_bits - 8)) - 1;
byte countbits = (byte)(qHdr.cluster_bits - 8);
compSizeMask <<= (62 - countbits);
offMask = (~compSizeMask) & QCowFlagsMask;
offMask = (~compSizeMask) & QCOW_FLAGS_MASK;
ulong realOff = offset & offMask;
ulong compSize = (((offset & compSizeMask) >> (62 - countbits)) + 1) * 512;
@@ -425,7 +425,7 @@ namespace DiscImageChef.ImagePlugins
else
{
cluster = new byte[clusterSize];
imageStream.Seek((long)(offset & QCowFlagsMask), SeekOrigin.Begin);
imageStream.Seek((long)(offset & QCOW_FLAGS_MASK), SeekOrigin.Begin);
imageStream.Read(cluster, 0, clusterSize);
}
@@ -446,11 +446,11 @@ namespace DiscImageChef.ImagePlugins
public override byte[] ReadSectors(ulong sectorAddress, uint length)
{
if(sectorAddress > ImageInfo.sectors - 1)
if(sectorAddress > ImageInfo.Sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
string.Format("Sector address {0} not found", sectorAddress));
if(sectorAddress + length > ImageInfo.sectors)
if(sectorAddress + length > ImageInfo.Sectors)
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
MemoryStream ms = new MemoryStream();
@@ -471,17 +471,17 @@ namespace DiscImageChef.ImagePlugins
public override ulong GetImageSize()
{
return ImageInfo.imageSize;
return ImageInfo.ImageSize;
}
public override ulong GetSectors()
{
return ImageInfo.sectors;
return ImageInfo.Sectors;
}
public override uint GetSectorSize()
{
return ImageInfo.sectorSize;
return ImageInfo.SectorSize;
}
public override string GetImageFormat()
@@ -491,47 +491,47 @@ namespace DiscImageChef.ImagePlugins
public override string GetImageVersion()
{
return ImageInfo.imageVersion;
return ImageInfo.ImageVersion;
}
public override string GetImageApplication()
{
return ImageInfo.imageApplication;
return ImageInfo.ImageApplication;
}
public override string GetImageApplicationVersion()
{
return ImageInfo.imageApplicationVersion;
return ImageInfo.ImageApplicationVersion;
}
public override string GetImageCreator()
{
return ImageInfo.imageCreator;
return ImageInfo.ImageCreator;
}
public override DateTime GetImageCreationTime()
{
return ImageInfo.imageCreationTime;
return ImageInfo.ImageCreationTime;
}
public override DateTime GetImageLastModificationTime()
{
return ImageInfo.imageLastModificationTime;
return ImageInfo.ImageLastModificationTime;
}
public override string GetImageName()
{
return ImageInfo.imageName;
return ImageInfo.ImageName;
}
public override string GetImageComments()
{
return ImageInfo.imageComments;
return ImageInfo.ImageComments;
}
public override MediaType GetMediaType()
{
return ImageInfo.mediaType;
return ImageInfo.MediaType;
}
#region Unsupported features
@@ -675,18 +675,18 @@ namespace DiscImageChef.ImagePlugins
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> FailingLBAs,
out List<ulong> UnknownLBAs)
public override bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
{
FailingLBAs = new List<ulong>();
UnknownLBAs = new List<ulong>();
for(ulong i = 0; i < ImageInfo.sectors; i++) UnknownLBAs.Add(i);
failingLbas = new List<ulong>();
unknownLbas = new List<ulong>();
for(ulong i = 0; i < ImageInfo.Sectors; i++) unknownLbas.Add(i);
return null;
}
public override bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> FailingLBAs,
out List<ulong> UnknownLBAs)
public override bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}