REFACTOR: Reformat code.

This commit is contained in:
2017-12-19 20:33:03 +00:00
parent 77edc7c91c
commit e6f6ace80b
704 changed files with 82627 additions and 83641 deletions

View File

@@ -43,7 +43,7 @@ using DiscImageChef.ImagePlugins;
namespace DiscImageChef.DiscImages
{
public class VMware : ImagePlugin
public class VMware : ImagePlugin
{
#region Internal constants
const uint VMwareExtentMagic = 0x564D444B;
@@ -69,13 +69,21 @@ namespace DiscImageChef.DiscImages
const string VMTypeStream = "streamOptimized";
const string DDFMagic = "# Disk DescriptorFile";
readonly byte[] DDFMagicBytes = { 0x23, 0x20, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6F, 0x72, 0x46, 0x69, 0x6C, 0x65 };
readonly byte[] DDFMagicBytes =
{
0x23, 0x20, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6F, 0x72, 0x46,
0x69, 0x6C, 0x65
};
const string VersionRegEx = "^\\s*version\\s*=\\s*(?<version>\\d+)$";
const string CidRegEx = "^\\s*CID\\s*=\\s*(?<cid>[0123456789abcdef]{8})$";
const string ParenCidRegEx = "^\\s*parentCID\\s*=\\s*(?<cid>[0123456789abcdef]{8})$";
const string TypeRegEx = "^\\s*createType\\s*=\\s*\\\"(?<type>custom|monolithicSparse|monolithicFlat|twoGbMaxExtentSparse|twoGbMaxExtentFlat|fullDevice|partitionedDevice|vmfs|vmfsPreallocated|vmfsEagerZeroedThick|vmfsThin|vmfsSparse|vmfsRDM|vmfsRawDeviceMap|vmfsRDMP|vmfsPassthroughRawDeviceMap|vmfsRaw|streamOptimized)\\\"$";
const string ExtentRegEx = "^\\s*(?<access>(RW|RDONLY|NOACCESS))\\s+(?<sectors>\\d+)\\s+(?<type>(FLAT|SPARSE|ZERO|VMFS|VMFSSPARSE|VMFSRDM|VMFSRAW))\\s+\\\"(?<filename>.+)\\\"(\\s*(?<offset>\\d+))?$";
const string TypeRegEx =
"^\\s*createType\\s*=\\s*\\\"(?<type>custom|monolithicSparse|monolithicFlat|twoGbMaxExtentSparse|twoGbMaxExtentFlat|fullDevice|partitionedDevice|vmfs|vmfsPreallocated|vmfsEagerZeroedThick|vmfsThin|vmfsSparse|vmfsRDM|vmfsRawDeviceMap|vmfsRDMP|vmfsPassthroughRawDeviceMap|vmfsRaw|streamOptimized)\\\"$"
;
const string ExtentRegEx =
"^\\s*(?<access>(RW|RDONLY|NOACCESS))\\s+(?<sectors>\\d+)\\s+(?<type>(FLAT|SPARSE|ZERO|VMFS|VMFSSPARSE|VMFSRDM|VMFSRAW))\\s+\\\"(?<filename>.+)\\\"(\\s*(?<offset>\\d+))?$"
;
const string DDBTypeRegEx = "^\\s*ddb\\.adapterType\\s*=\\s*\\\"(?<type>ide|buslogic|lsilogic|legacyESX)\\\"$";
const string DDBSectorsRegEx = "^\\s*ddb\\.geometry\\.sectors\\s*=\\s*\\\"(?<sectors>\\d+)\\\"$";
const string DDBHeadsRegex = "^\\s*ddb\\.geometry\\.heads\\s*=\\s*\\\"(?<heads>\\d+)\\\"$";
@@ -107,15 +115,13 @@ namespace DiscImageChef.DiscImages
public ulong rgdOffset;
public ulong gdOffset;
public ulong overhead;
[MarshalAs(UnmanagedType.U1)]
public bool uncleanShutdown;
[MarshalAs(UnmanagedType.U1)] public bool uncleanShutdown;
public byte singleEndLineChar;
public byte nonEndLineChar;
public byte doubleEndLineChar1;
public byte doubleEndLineChar2;
public ushort compression;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 433)]
public byte[] padding;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 433)] public byte[] padding;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -133,21 +139,15 @@ namespace DiscImageChef.DiscImages
public uint heads;
public uint spt;
// It stats on cylinders, above, but, don't care
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024 - 12)]
public byte[] parentFileName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024 - 12)] public byte[] parentFileName;
public uint parentGeneration;
public uint generation;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
public byte[] name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] description;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)] public byte[] name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] public byte[] description;
public uint savedGeneration;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] reserved;
[MarshalAs(UnmanagedType.U1)]
public bool uncleanShutdown;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 396)]
public byte[] padding;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] reserved;
[MarshalAs(UnmanagedType.U1)] public bool uncleanShutdown;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 396)] public byte[] padding;
}
#endregion
@@ -245,7 +245,8 @@ namespace DiscImageChef.DiscImages
Marshal.FreeHGlobal(headerPtr);
}
return DDFMagicBytes.SequenceEqual(ddfMagic) || vmEHdr.magic == VMwareExtentMagic || vmCHdr.magic == VMwareCowMagic;
return DDFMagicBytes.SequenceEqual(ddfMagic) || vmEHdr.magic == VMwareExtentMagic ||
vmCHdr.magic == VMwareCowMagic;
}
stream.Seek(0, SeekOrigin.Begin);
@@ -315,8 +316,7 @@ namespace DiscImageChef.DiscImages
stream.Seek(0, SeekOrigin.Begin);
stream.Read(ddfMagic, 0, 0x15);
if(!DDFMagicBytes.SequenceEqual(ddfMagic))
throw new Exception("Not a descriptor.");
if(!DDFMagicBytes.SequenceEqual(ddfMagic)) throw new Exception("Not a descriptor.");
stream.Seek(0, SeekOrigin.Begin);
byte[] ddfExternal = new byte[imageFilter.GetDataForkLength()];
@@ -327,9 +327,9 @@ namespace DiscImageChef.DiscImages
extents = new Dictionary<ulong, VMwareExtent>();
ulong currentSector = 0;
bool matchedCyls = false, matchedHds = false, matchedSpt = false;
bool matchedCyls = false, matchedHds = false, matchedSpt = false;
if(cowD)
if(cowD)
{
int cowCount = 1;
string basePath = Path.GetFileNameWithoutExtension(imageFilter.GetBasePath());
@@ -337,15 +337,12 @@ namespace DiscImageChef.DiscImages
while(true)
{
string curPath;
if(cowCount == 1)
curPath = basePath + ".vmdk";
else
curPath = string.Format("{0}-{1:D2}.vmdk", basePath, cowCount);
if(cowCount == 1) curPath = basePath + ".vmdk";
else curPath = string.Format("{0}-{1:D2}.vmdk", basePath, cowCount);
if(!File.Exists(curPath))
break;
if(!File.Exists(curPath)) break;
Filter extentFilter = new FiltersList().GetFilter(curPath);
Filter extentFilter = new FiltersList().GetFilter(curPath);
Stream extentStream = extentFilter.GetDataForkStream();
if(stream.Length > Marshal.SizeOf(vmCHdr))
@@ -359,8 +356,7 @@ namespace DiscImageChef.DiscImages
extHdrCow = (VMwareCowHeader)Marshal.PtrToStructure(cowPtr, typeof(VMwareCowHeader));
Marshal.FreeHGlobal(cowPtr);
if(extHdrCow.magic != VMwareCowMagic)
break;
if(extHdrCow.magic != VMwareCowMagic) break;
VMwareExtent newExtent = new VMwareExtent();
newExtent.access = "RW";
@@ -370,13 +366,14 @@ namespace DiscImageChef.DiscImages
newExtent.sectors = extHdrCow.sectors;
newExtent.type = "SPARSE";
DicConsole.DebugWriteLine("VMware plugin", "{0} {1} {2} \"{3}\" {4}", newExtent.access, newExtent.sectors, newExtent.type, newExtent.filename, newExtent.offset);
DicConsole.DebugWriteLine("VMware plugin", "{0} {1} {2} \"{3}\" {4}", newExtent.access,
newExtent.sectors, newExtent.type, newExtent.filename,
newExtent.offset);
extents.Add(currentSector, newExtent);
currentSector += newExtent.sectors;
}
else
break;
}
else break;
cowCount++;
}
@@ -393,21 +390,21 @@ namespace DiscImageChef.DiscImages
Regex RegexType = new Regex(TypeRegEx);
Regex RegexExtent = new Regex(ExtentRegEx);
Regex RegexParent = new Regex(ParentRegEx);
Regex RegexCylinders = new Regex(DDBCylindersRegEx);
Regex RegexHeads = new Regex(DDBHeadsRegex);
Regex RegexSectors = new Regex(DDBSectorsRegEx);
Regex RegexCylinders = new Regex(DDBCylindersRegEx);
Regex RegexHeads = new Regex(DDBHeadsRegex);
Regex RegexSectors = new Regex(DDBSectorsRegEx);
Match MatchVersion;
Match MatchVersion;
Match MatchCid;
Match MatchParentCid;
Match MatchType;
Match MatchExtent;
Match MatchParent;
Match MatchCylinders;
Match MatchHeads;
Match MatchSectors;
Match MatchCylinders;
Match MatchHeads;
Match MatchSectors;
StreamReader ddfStreamRdr = new StreamReader(ddfStream);
StreamReader ddfStreamRdr = new StreamReader(ddfStream);
while(ddfStreamRdr.Peek() >= 0)
{
@@ -419,96 +416,101 @@ namespace DiscImageChef.DiscImages
MatchType = RegexType.Match(_line);
MatchExtent = RegexExtent.Match(_line);
MatchParent = RegexParent.Match(_line);
MatchCylinders = RegexCylinders.Match(_line);
MatchHeads = RegexHeads.Match(_line);
MatchSectors = RegexSectors.Match(_line);
MatchCylinders = RegexCylinders.Match(_line);
MatchHeads = RegexHeads.Match(_line);
MatchSectors = RegexSectors.Match(_line);
if(MatchVersion.Success)
{
uint.TryParse(MatchVersion.Groups["version"].Value, out version);
DicConsole.DebugWriteLine("VMware plugin", "version = {0}", version);
}
else if(MatchCid.Success)
{
cid = Convert.ToUInt32(MatchCid.Groups["cid"].Value, 16);
DicConsole.DebugWriteLine("VMware plugin", "cid = {0:x8}", cid);
}
else if(MatchParentCid.Success)
{
parentCid = Convert.ToUInt32(MatchParentCid.Groups["cid"].Value, 16);
DicConsole.DebugWriteLine("VMware plugin", "parentCID = {0:x8}", parentCid);
}
else if(MatchType.Success)
{
imageType = MatchType.Groups["type"].Value;
DicConsole.DebugWriteLine("VMware plugin", "createType = \"{0}\"", imageType);
}
else if(MatchExtent.Success)
{
VMwareExtent newExtent = new VMwareExtent();
newExtent.access = MatchExtent.Groups["access"].Value;
if(!embedded)
newExtent.filter = new FiltersList().GetFilter(Path.Combine(Path.GetDirectoryName(imageFilter.GetBasePath()), MatchExtent.Groups["filename"].Value));
else
newExtent.filter = imageFilter;
uint.TryParse(MatchExtent.Groups["offset"].Value, out newExtent.offset);
uint.TryParse(MatchExtent.Groups["sectors"].Value, out newExtent.sectors);
newExtent.type = MatchExtent.Groups["type"].Value;
DicConsole.DebugWriteLine("VMware plugin", "{0} {1} {2} \"{3}\" {4}", newExtent.access, newExtent.sectors, newExtent.type, newExtent.filename, newExtent.offset);
if(MatchVersion.Success)
{
uint.TryParse(MatchVersion.Groups["version"].Value, out version);
DicConsole.DebugWriteLine("VMware plugin", "version = {0}", version);
}
else if(MatchCid.Success)
{
cid = Convert.ToUInt32(MatchCid.Groups["cid"].Value, 16);
DicConsole.DebugWriteLine("VMware plugin", "cid = {0:x8}", cid);
}
else if(MatchParentCid.Success)
{
parentCid = Convert.ToUInt32(MatchParentCid.Groups["cid"].Value, 16);
DicConsole.DebugWriteLine("VMware plugin", "parentCID = {0:x8}", parentCid);
}
else if(MatchType.Success)
{
imageType = MatchType.Groups["type"].Value;
DicConsole.DebugWriteLine("VMware plugin", "createType = \"{0}\"", imageType);
}
else if(MatchExtent.Success)
{
VMwareExtent newExtent = new VMwareExtent();
newExtent.access = MatchExtent.Groups["access"].Value;
if(!embedded)
newExtent.filter =
new FiltersList()
.GetFilter(Path.Combine(Path.GetDirectoryName(imageFilter.GetBasePath()),
MatchExtent.Groups["filename"].Value));
else newExtent.filter = imageFilter;
uint.TryParse(MatchExtent.Groups["offset"].Value, out newExtent.offset);
uint.TryParse(MatchExtent.Groups["sectors"].Value, out newExtent.sectors);
newExtent.type = MatchExtent.Groups["type"].Value;
DicConsole.DebugWriteLine("VMware plugin", "{0} {1} {2} \"{3}\" {4}", newExtent.access,
newExtent.sectors, newExtent.type, newExtent.filename,
newExtent.offset);
extents.Add(currentSector, newExtent);
currentSector += newExtent.sectors;
}
else if(MatchParent.Success)
{
parentName = MatchParent.Groups["filename"].Value;
DicConsole.DebugWriteLine("VMware plugin", "parentFileNameHint = \"{0}\"", parentName);
hasParent = true;
}
else if(MatchCylinders.Success)
{
uint.TryParse(MatchCylinders.Groups["cylinders"].Value, out ImageInfo.cylinders);
matchedCyls = true;
}
else if(MatchHeads.Success)
{
uint.TryParse(MatchHeads.Groups["heads"].Value, out ImageInfo.heads);
matchedHds = true;
}
else if(MatchSectors.Success)
{
uint.TryParse(MatchSectors.Groups["sectors"].Value, out ImageInfo.sectorsPerTrack);
matchedSpt = true;
}
}
extents.Add(currentSector, newExtent);
currentSector += newExtent.sectors;
}
else if(MatchParent.Success)
{
parentName = MatchParent.Groups["filename"].Value;
DicConsole.DebugWriteLine("VMware plugin", "parentFileNameHint = \"{0}\"", parentName);
hasParent = true;
}
else if(MatchCylinders.Success)
{
uint.TryParse(MatchCylinders.Groups["cylinders"].Value, out ImageInfo.cylinders);
matchedCyls = true;
}
else if(MatchHeads.Success)
{
uint.TryParse(MatchHeads.Groups["heads"].Value, out ImageInfo.heads);
matchedHds = true;
}
else if(MatchSectors.Success)
{
uint.TryParse(MatchSectors.Groups["sectors"].Value, out ImageInfo.sectorsPerTrack);
matchedSpt = true;
}
}
}
if(extents.Count == 0)
throw new Exception("Did not find any extent");
if(extents.Count == 0) throw new Exception("Did not find any extent");
switch(imageType)
{
case VMTypeMonoSparse://"monolithicSparse";
case VMTypeMonoFlat://"monolithicFlat";
case VMTypeSplitSparse://"twoGbMaxExtentSparse";
case VMTypeSplitFlat://"twoGbMaxExtentFlat";
case VMFSTypeFlat://"vmfsPreallocated";
case VMFSTypeZero://"vmfsEagerZeroedThick";
case VMFSTypeThin://"vmfsThin";
case VMFSTypeSparse://"vmfsSparse";
case VMFSType://"vmfs";
case VMTypeStream://"streamOptimized";
case VMTypeMonoSparse: //"monolithicSparse";
case VMTypeMonoFlat: //"monolithicFlat";
case VMTypeSplitSparse: //"twoGbMaxExtentSparse";
case VMTypeSplitFlat: //"twoGbMaxExtentFlat";
case VMFSTypeFlat: //"vmfsPreallocated";
case VMFSTypeZero: //"vmfsEagerZeroedThick";
case VMFSTypeThin: //"vmfsThin";
case VMFSTypeSparse: //"vmfsSparse";
case VMFSType: //"vmfs";
case VMTypeStream: //"streamOptimized";
break;
case VMTypeFullDevice://"fullDevice";
case VMTypePartDevice://"partitionedDevice";
case VMFSTypeRDM://"vmfsRDM";
case VMFSTypeRDMOld://"vmfsRawDeviceMap";
case VMFSTypeRDMP://"vmfsRDMP";
case VMFSTypeRDMPOld://"vmfsPassthroughRawDeviceMap";
case VMFSTypeRaw://"vmfsRaw";
throw new ImageNotSupportedException("Raw device image files are not supported, try accessing the device directly.");
case VMTypeFullDevice: //"fullDevice";
case VMTypePartDevice: //"partitionedDevice";
case VMFSTypeRDM: //"vmfsRDM";
case VMFSTypeRDMOld: //"vmfsRawDeviceMap";
case VMFSTypeRDMP: //"vmfsRDMP";
case VMFSTypeRDMPOld: //"vmfsPassthroughRawDeviceMap";
case VMFSTypeRaw: //"vmfsRaw";
throw new
ImageNotSupportedException("Raw device image files are not supported, try accessing the device directly.");
default:
throw new ImageNotSupportedException(string.Format("Dunno how to handle \"{0}\" extents.", imageType));
throw new ImageNotSupportedException(string.Format("Dunno how to handle \"{0}\" extents.",
imageType));
}
bool oneNoFlat = false || cowD;
@@ -516,21 +518,17 @@ namespace DiscImageChef.DiscImages
foreach(VMwareExtent extent in extents.Values)
{
if(extent.filter == null)
throw new Exception(string.Format("Extent file {0} not found.", extent.filename));
throw new Exception(string.Format("Extent file {0} not found.", extent.filename));
if(extent.access == "NOACCESS")
throw new Exception("Cannot access NOACCESS extents ;).");
if(extent.access == "NOACCESS") throw new Exception("Cannot access NOACCESS extents ;).");
if(extent.type != "FLAT" &&
extent.type != "ZERO" &&
extent.type != "VMFS" &&
!cowD)
if(extent.type != "FLAT" && extent.type != "ZERO" && extent.type != "VMFS" && !cowD)
{
Stream extentStream = extent.filter.GetDataForkStream();
extentStream.Seek(0, SeekOrigin.Begin);
if(extentStream.Length < sectorSize)
throw new Exception(string.Format("Extent {0} is too small.", extent.filename));
throw new Exception(string.Format("Extent {0} is too small.", extent.filename));
VMwareExtentHeader extentHdr = new VMwareExtentHeader();
byte[] extentHdr_b = new byte[Marshal.SizeOf(extentHdr)];
@@ -544,10 +542,12 @@ namespace DiscImageChef.DiscImages
throw new Exception(string.Format("{0} is not an VMware extent.", extent.filter));
if(extentHdr.capacity < extent.sectors)
throw new Exception(string.Format("Extent contains incorrect number of sectors, {0}. {1} were expected", extentHdr.capacity, extent.sectors));
throw new
Exception(string.Format("Extent contains incorrect number of sectors, {0}. {1} were expected",
extentHdr.capacity, extent.sectors));
// TODO: Support compressed extents
if(extentHdr.compression != CompressionNone)
// TODO: Support compressed extents
if(extentHdr.compression != CompressionNone)
throw new ImageNotSupportedException("Compressed extents are not yet supported.");
if(!vmEHdrSet)
@@ -562,7 +562,8 @@ namespace DiscImageChef.DiscImages
}
if(oneNoFlat && !vmEHdrSet && !cowD)
throw new Exception("There are sparse extents but there is no header to find the grain tables, cannot proceed.");
throw new
Exception("There are sparse extents but there is no header to find the grain tables, cannot proceed.");
ImageInfo.sectors = currentSector;
@@ -585,10 +586,13 @@ namespace DiscImageChef.DiscImages
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.gdOffset = {0}", vmEHdr.gdOffset);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.overhead = {0}", vmEHdr.overhead);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.uncleanShutdown = {0}", vmEHdr.uncleanShutdown);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.singleEndLineChar = 0x{0:X2}", vmEHdr.singleEndLineChar);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.singleEndLineChar = 0x{0:X2}",
vmEHdr.singleEndLineChar);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.nonEndLineChar = 0x{0:X2}", vmEHdr.nonEndLineChar);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.doubleEndLineChar1 = 0x{0:X2}", vmEHdr.doubleEndLineChar1);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.doubleEndLineChar2 = 0x{0:X2}", vmEHdr.doubleEndLineChar2);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.doubleEndLineChar1 = 0x{0:X2}",
vmEHdr.doubleEndLineChar1);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.doubleEndLineChar2 = 0x{0:X2}",
vmEHdr.doubleEndLineChar2);
DicConsole.DebugWriteLine("VMware plugin", "vmEHdr.compression = 0x{0:X4}", vmEHdr.compression);
grainSize = vmEHdr.grainSize;
@@ -596,10 +600,8 @@ namespace DiscImageChef.DiscImages
gdEntries = grains / vmEHdr.GTEsPerGT;
GTEsPerGT = vmEHdr.GTEsPerGT;
if((vmEHdr.flags & FlagsUseRedundantTable) == FlagsUseRedundantTable)
gdOffset = (long)vmEHdr.rgdOffset;
else
gdOffset = (long)vmEHdr.gdOffset;
if((vmEHdr.flags & FlagsUseRedundantTable) == FlagsUseRedundantTable) gdOffset = (long)vmEHdr.rgdOffset;
else gdOffset = (long)vmEHdr.gdOffset;
}
else if(oneNoFlat && cowD)
{
@@ -616,7 +618,8 @@ namespace DiscImageChef.DiscImages
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.spt = {0}", vmCHdr.spt);
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.generation = {0}", vmCHdr.generation);
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.name = {0}", StringHandlers.CToString(vmCHdr.name));
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.description = {0}", StringHandlers.CToString(vmCHdr.description));
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.description = {0}",
StringHandlers.CToString(vmCHdr.description));
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.savedGeneration = {0}", vmCHdr.savedGeneration);
DicConsole.DebugWriteLine("VMware plugin", "vmCHdr.uncleanShutdown = {0}", vmCHdr.uncleanShutdown);
@@ -632,10 +635,10 @@ namespace DiscImageChef.DiscImages
if(oneNoFlat)
{
if(grains == 0 || gdEntries == 0)
throw new Exception("Some error ocurred setting GD sizes");
if(grains == 0 || gdEntries == 0) throw new Exception("Some error ocurred setting GD sizes");
DicConsole.DebugWriteLine("VMware plugin", "{0} sectors in {1} grains in {2} tables", ImageInfo.sectors, grains, gdEntries);
DicConsole.DebugWriteLine("VMware plugin", "{0} sectors in {1} grains in {2} tables", ImageInfo.sectors,
grains, gdEntries);
Stream gdStream = gdFilter.GetDataForkStream();
@@ -645,8 +648,7 @@ namespace DiscImageChef.DiscImages
uint[] gd = new uint[gdEntries];
byte[] gdBytes = new byte[gdEntries * 4];
gdStream.Read(gdBytes, 0, gdBytes.Length);
for(int i = 0; i < gdEntries; i++)
gd[i] = BitConverter.ToUInt32(gdBytes, i * 4);
for(int i = 0; i < gdEntries; i++) gd[i] = BitConverter.ToUInt32(gdBytes, i * 4);
DicConsole.DebugWriteLine("VMware plugin", "Reading grain tables");
uint currentGrain = 0;
@@ -670,9 +672,9 @@ namespace DiscImageChef.DiscImages
if(hasParent)
{
Filter parentFilter = new FiltersList().GetFilter(Path.Combine(imageFilter.GetParentFolder(), parentName));
if(parentFilter == null)
throw new Exception(string.Format("Cannot find parent \"{0}\".", parentName));
Filter parentFilter =
new FiltersList().GetFilter(Path.Combine(imageFilter.GetParentFolder(), parentName));
if(parentFilter == null) throw new Exception(string.Format("Cannot find parent \"{0}\".", parentName));
parentImage = new VMware();
@@ -690,36 +692,34 @@ namespace DiscImageChef.DiscImages
ImageInfo.mediaType = MediaType.GENERIC_HDD;
ImageInfo.imageSize = ImageInfo.sectors * sectorSize;
// VMDK version 1 started on VMware 4, so there is a previous version, "COWD"
if(cowD) ImageInfo.imageVersion = string.Format("{0}", version);
else ImageInfo.imageVersion = string.Format("{0}", version + 3);
if(cowD)
ImageInfo.imageVersion = string.Format("{0}", version);
else
ImageInfo.imageVersion = string.Format("{0}", version + 3);
{
ImageInfo.cylinders = vmCHdr.cylinders;
ImageInfo.heads = vmCHdr.heads;
ImageInfo.sectorsPerTrack = vmCHdr.spt;
}
else if(!matchedCyls || !matchedHds || !matchedSpt)
{
ImageInfo.cylinders = (uint)((ImageInfo.sectors / 16) / 63);
ImageInfo.heads = 16;
ImageInfo.sectorsPerTrack = 63;
}
if(cowD)
{
ImageInfo.cylinders = vmCHdr.cylinders;
ImageInfo.heads = vmCHdr.heads;
ImageInfo.sectorsPerTrack = vmCHdr.spt;
}
else if(!matchedCyls || !matchedHds || !matchedSpt)
{
ImageInfo.cylinders = (uint)((ImageInfo.sectors / 16) / 63);
ImageInfo.heads = 16;
ImageInfo.sectorsPerTrack = 63;
}
return true;
return true;
}
public override byte[] ReadSector(ulong sectorAddress)
{
if(sectorAddress > ImageInfo.sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), string.Format("Sector address {0} not found", sectorAddress));
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
string.Format("Sector address {0} not found", sectorAddress));
byte[] sector;
if(sectorCache.TryGetValue(sectorAddress, out sector))
return sector;
if(sectorCache.TryGetValue(sectorAddress, out sector)) return sector;
VMwareExtent currentExtent = new VMwareExtent();
bool extentFound = false;
@@ -736,7 +736,8 @@ namespace DiscImageChef.DiscImages
}
if(!extentFound)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), string.Format("Sector address {0} not found", sectorAddress));
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
string.Format("Sector address {0} not found", sectorAddress));
Stream dataStream;
@@ -744,8 +745,7 @@ namespace DiscImageChef.DiscImages
{
sector = new byte[sectorSize];
if(sectorCache.Count >= maxCachedSectors)
sectorCache.Clear();
if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
return sector;
@@ -754,12 +754,12 @@ namespace DiscImageChef.DiscImages
if(currentExtent.type == "FLAT" || currentExtent.type == "VMFS")
{
dataStream = currentExtent.filter.GetDataForkStream();
dataStream.Seek((long)((currentExtent.offset + (sectorAddress - extentStartSector)) * sectorSize), SeekOrigin.Begin);
dataStream.Seek((long)((currentExtent.offset + (sectorAddress - extentStartSector)) * sectorSize),
SeekOrigin.Begin);
sector = new byte[sectorSize];
dataStream.Read(sector, 0, sector.Length);
if(sectorCache.Count >= maxCachedSectors)
sectorCache.Clear();
if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
return sector;
@@ -770,15 +770,13 @@ namespace DiscImageChef.DiscImages
uint grainOff = gTable[index];
if(grainOff == 0 && hasParent)
return parentImage.ReadSector(sectorAddress);
if(grainOff == 0 && hasParent) return parentImage.ReadSector(sectorAddress);
if(grainOff == 0 || grainOff == 1)
{
sector = new byte[sectorSize];
if(sectorCache.Count >= maxCachedSectors)
sectorCache.Clear();
if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
return sector;
@@ -793,8 +791,7 @@ namespace DiscImageChef.DiscImages
dataStream.Seek((long)(((grainOff - extentStartSector) * sectorSize)), SeekOrigin.Begin);
dataStream.Read(grain, 0, grain.Length);
if(grainCache.Count >= maxCachedGrains)
grainCache.Clear();
if(grainCache.Count >= maxCachedGrains) grainCache.Clear();
grainCache.Add(grainOff, grain);
}
@@ -802,8 +799,7 @@ namespace DiscImageChef.DiscImages
sector = new byte[sectorSize];
Array.Copy(grain, (int)secOff, sector, 0, sectorSize);
if(sectorCache.Count > maxCachedSectors)
sectorCache.Clear();
if(sectorCache.Count > maxCachedSectors) sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
@@ -813,7 +809,8 @@ namespace DiscImageChef.DiscImages
public override byte[] ReadSectors(ulong sectorAddress, uint length)
{
if(sectorAddress > ImageInfo.sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), string.Format("Sector address {0} not found", sectorAddress));
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
string.Format("Sector address {0} not found", sectorAddress));
if(sectorAddress + length > ImageInfo.sectors)
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
@@ -900,7 +897,6 @@ namespace DiscImageChef.DiscImages
}
#region Unsupported features
public override byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
@@ -1041,16 +1037,18 @@ namespace DiscImageChef.DiscImages
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);
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");
}
@@ -1059,8 +1057,6 @@ namespace DiscImageChef.DiscImages
{
return null;
}
#endregion
}
}
}