Unit VirtualDisk

From Ultibo.org
Jump to: navigation, search

Return to Unit Reference


Description


Ultibo Virtual Disk interface unit

To be documented

Constants



Virtual disk specific constants VIRTUAL_*
VIRTUAL_DEVICE_DESCRIPTION = 'Virtual Disk Device';  
VIRTUAL_CONTROLLER_DESCRIPTION = 'Virtual Disk Controller';  


Virtual flag virtualFlag*
virtualFlagNone = $00000000;  
virtualFlagFixed = $00000001;  
virtualFlagDynamic = $00000002;  
virtualFlagBase = $00000004;  
virtualFlagDelta = $00000008;  
virtualFlagDevice = $00000010;  
virtualFlagSplit = $00000020;  


VMware constants vmware*
vmwareFileExtension = '.vmdk';  
 
vmwareFileMask = '*.vmdk';  
 
vmwareNoParentCID = $FFFFFFFF; not($00000000)
 
vmwareSparseMagicNumber = $564d444b; 'VMDK'
 
vmwareEsxSparseMagicNumber = $44574f43; 'COWD'
vmwareEsxSparseMaxParentLength = 1024; COWDISK_MAX_PARENT_FILELEN
vmwareEsxSparseMaxNameLength = 60; COWDISK_MAX_NAME_LEN
vmwareEsxSparseMaxDescriptionLength = 512; COWDISK_MAX_DESC_LEN
 
vmwareSectorSize = 512;  


VMware disk type vmware*DiskType
vmwareMaxDiskType = 0;  
vmwareDiskTypeNone = 0;  


VMware descriptor tag vmwareTag*
vmwareTagDisk = 'Disk DescriptorFile';  
vmwareTagVersion = 'version';  
vmwareTagCID = 'CID';  
vmwareTagParentCID = 'parentCID';  
vmwareTagCreateType = 'createType';  
vmwareTagExtent = 'Extent Description';  
vmwareTagDatabase = 'The Disk Data Base';  
vmwareTagDDB = 'DDB';  
vmwareTagAdapter = 'ddb.adapterType';  
vmwareTagSectors = 'ddb.geometry.sectors';  
vmwareTagHeads = 'ddb.geometry.heads';  
vmwareTagCylinders = 'ddb.geometry.cylinders';  
vmwareTagParentHint = 'parentFileNameHint';  


VMware create type vmwareCreateType_*
vmwareMaxCreateType = 11;  
vmwareCreateType_monolithicSparse = 0;  
vmwareCreateType_vmfsSparse = 1;  
vmwareCreateType_monolithicFlat = 2;  
vmwareCreateType_vmfs = 3;  
vmwareCreateType_twoGbMaxExtentSparse = 4;  
vmwareCreateType_twoGbMaxExtentFlat = 5;  
vmwareCreateType_fullDevice = 6;  
vmwareCreateType_vmfsRaw = 7;  
vmwareCreateType_partitionedDevice = 8;  
vmwareCreateType_vmfsRawDeviceMap = 9;  
vmwareCreateType_vmfsPassthroughRawDeviceMap = 10;  
vmwareCreateType_streamOptimized = 11;  


VMware access type vmwareAccessType_*
vmwareMaxAccessType = 2;  
vmwareAccessType_RW = 0;  
vmwareAccessType_RDONLY = 1;  
vmwareAccessType_NOACCESS = 2;  


VMware extent type vmwareExtentType_*
vmwareMaxExtentType = 6;  
vmwareExtentType_FLAT = 0;  
vmwareExtentType_SPARSE = 1;  
vmwareExtentType_ZERO = 2;  
vmwareExtentType_VMFS = 3;  
vmwareExtentType_VMFSSPARSE = 4;  
vmwareExtentType_VMFSRDM = 5;  
vmwareExtentType_VMFSRAW = 6;  


VMware disk flag vmwareFlag*
vmwareFlagValidTest = $00000001; bit 0: valid new line detection test
vmwareFlagRedundantGrain = $00000002; bit 1: redundant grain table will be used
vmwareFlagGrainCompressed = $00010000; bit 16: the grains are compressed. The type of compression is described by compressAlgorithm
vmwareFlagLBAMarkers = $00020000; bit 17: there are markers in the virtual disk to identify every block of metadata or data and the markers for the virtual machine data contain a LBA


VMware compression type vmwareCompression*
vmwareCompressionNone = 0;  
vmwareCompressionDeflate = 1; The deflate algorithm is described in RFC 1951


VPC constants vpc*
vpcFileExtension = '.vhd';  
vpcUndoExtension = '.vud';  
 
vpcFileMask = '*.vhd';  
vpcUndoMask = '*.vud';  
vpcSplitMask = '*.v??'; .v01, v02 etc up to 64
 
vpcFooterCookie = 'conectix';  
vpcDynamicCookie = 'cxsparse';  
 
vpcMaxDiskExtents = 64; Maximum number of 4GB split files in a disk image
vpcExtentMaxSize = 4294967296; Maximum size of s split file (4GB)
 
vpcUnixTimeOffset = 946684800; Offset from 1/1/1970 to 1/1/2000
 
vpcFooterVersion = $00010000;  
vpcDynamicVersion = $00010000;  
 
vpcSectorSize = 512;  
 
vpcUnallocatedBlock = $FFFFFFFF;  
vpcFixedDiskTableOffset = $FFFFFFFFFFFFFFFF;  
vpcDynamicDiskDataOffset = $FFFFFFFFFFFFFFFF;  
 
vpcMaxBlockGroup = $FF;  
vpcBlockGroupMask = $FF;  
vpcBlockGroupOffset = $100;  


VPC disk type vpcDiskType*
vpcMaxDiskType = 6;  
vpcDiskTypeNone = 0;  
vpcDiskTypeReserved1 = 1;  
vpcDiskTypeFixed = 2;  
vpcDiskTypeDynamic = 3;  
vpcDiskTypeDifferencing = 4;  
vpcDiskTypeReserved2 = 5;  
vpcDiskTypeReserved3 = 6;  


VPC feature vpcFeature*
vpcFeatureNone = $00000000;  
vpcFeatureTemporary = $00000001;  
vpcFeatureReserved = $00000002; This bit must always be set to 1


VPC creator host OS vpcCreator*
vpcCreatorWindows = $5769326B; Wi2k
vpcCreatorMacintosh = $4D616320; Mac


VPC platform code vpcPlatform*
vpcPlatformNone = $00000000;  
vpcPlatformWi2r = $57693272; Wi2r deprecated
vpcPlatformWi2k = $5769326B; Wi2k deprecated
vpcPlatformW2ru = $57327275; W2ru Unicode pathname (UTF-16) on Windows relative to the differencing disk pathname
vpcPlatformW2ku = $57326B75; W2ku Absolute Unicode (UTF-16) pathname on Windows
vpcPlatformMac = $4D616320; Mac OS alias stored as a blob
vpcPlatformMacX = $4D616358; MacX A file URL with UTF-8 encoding conforming to RFC 2396


VPC bitmap mask vpcBitmapMask*
vpcBitmapMaskBits = 32; LongWord Bitmap Masks
vpcBitmapMaskNone = $00000000; LongWord (Used for fast counting of free blocks)
vpcBitmapMaskAll = $FFFFFFFF; LongWord (Used for fast counting of used blocks)
 
vpcBitmapMasks:array[0..31] of LongWord = (
$00000001,$00000002,$00000004,$00000008,$00000010,$00000020,$00000040,$00000080,
$00000100,$00000200,$00000400,$00000800,$00001000,$00002000,$00004000,$00008000,
$00010000,$00020000,$00040000,$00080000,$00100000,$00200000,$00400000,$00800000,
$01000000,$02000000,$04000000,$08000000,$10000000,$20000000,$40000000,$80000000);
 
vpcBitmapMasks:array[0..31] of LongWord = ( Ordered to allow for big endian bitmap
$00000080,$00000040,$00000020,$00000010,$00000008,$00000004,$00000002,$00000001,
$00008000,$00004000,$00002000,$00001000,$00000800,$00000400,$00000200,$00000100,
$00800000,$00400000,$00200000,$00100000,$00080000,$00040000,$00020000,$00010000,
$80000000,$40000000,$20000000,$10000000,$08000000,$04000000,$02000000,$01000000);


VirtualBox constants vbox*
vboxFileExtension = '.vdi';  
 
vboxDiskBanner = '<<< Sun xVM VirtualBox Disk Image >>>'; Plus a LF character in some images (#10)
vboxDiskVersion = $00010001;  
vboxDiskSignature = $BEDA107F;  
 
vboxFileMask = '*.vdi';  
vboxPathMask = '*.*';  
vboxDeltaPath = '..\Machines\';  
vboxParentPath = '..\..\..\VDI\';  
vboxNewParentPath = '..\..\..\HardDisks\';  
vboxSnapshotPath = '\Snapshots\';  
 
vboxUnallocatedBlock = $FFFFFFFF;  


VirtualBox disk type vboxDiskType*
vboxMaxDiskType = 4;  
vboxDiskTypeNone = 0;  
vboxDiskTypeDynamic = 1;  
vboxDiskTypeStatic = 2;  
vboxDiskTypeUnknown = 3;  
vboxDiskTypeDifferencing = 4;  


VirtualBox disk flag vboxDiskFlags*
vboxDiskFlagsNone = $00000000;  


Type definitions



ESX sparse extent header

PEsxSparseExtentHeader = ^TEsxSparseExtentHeader;

TEsxSparseExtentHeader = packed record

Note: Always 2048 bytes (Only used for Delta disks, not Dynamic)
magicNumber:LongWord; 0x44574f43/'COWD'
version:LongWord; The value of this entry should be 1
flags:LongWord; set to 3
numSectors:LongWord; total number of sectors on the base disk
grainSize:LongWord; one sector by default. Can vary from one sector to 1MB
gdOffset:LongWord; starts at the fourth sector, because the COWDisk_Header structure takes four sectors
numGDEntries:LongWord; is CEILING(numSectors, gtCoverage)
freeSector:LongWord; the next free data sector. This needs to be less than the length of the delta link. It is initially set to gdOffset + numGDSectors
case Integer of  
0: (cylinders:LongWord; root
heads:LongWord;  
sectors:LongWord;  
generation:LongWord; cont
name:array[0..vmwareEsxSparseMaxNameLength - 1] of Char;  
description:array[0..vmwareEsxSparseMaxDescriptionLength - 1] of Char;  
savedGeneration:LongWord; used to detect the unclean shutdown of the delta link. It is initially set to 0
reserved:array[0..7] of Char;  
uncleanShutdown:LongWord; used to trigger the metadata consistency check in case there is an abnormal termination of the program
padding:array[0..395] of Char);  
1: (parentFileName:array[0..vmwareEsxSparseMaxParentLength - 1] of Char; child
parentGeneration:LongWord;  
generationx:LongWord; cont
namex:array[0..vmwareEsxSparseMaxNameLength - 1] of Char;  
descriptionx:array[0..vmwareEsxSparseMaxDescriptionLength - 1] of Char;  
savedGenerationx:LongWord; used to detect the unclean shutdown of the delta link. It is initially set to 0
reservedx:array[0..7] of Char;  
uncleanShutdownx:LongWord; used to trigger the metadata consistency check in case there is an abnormal termination of the program
paddingx:array[0..395] of Char); remaining fields are not used. They are present to maintain compatibility with legacy virtual disk formats

VMware sparse extent header

PVmwareSparseExtentHeader = ^TVmwareSparseExtentHeader;

TVmwareSparseExtentHeader = packed record

Note: Always 512 bytes (Used for both Dynamic and Delta disks)
magicNumber:LongWord; 0x564d444b/'VMDK'
version:LongWord; The value of this entry should be 1
flags:LongWord; See above
capacity:Int64; the capacity of this extent in sectors (should be a multiple of the grain size)
grainSize:Int64; size of a grain in sectors (must be a power of 2 and must be greater than 8 (4KB))
descriptorOffset:Int64; offset of the embedded descriptor in the extent (expressed in sectors)
descriptorSize:Int64; valid only if descriptorOffset is non-zero (expressed in sectors)
numGTEsPerGT:LongWord; the number of entries in a grain table (for VMware virtual disks is 512)
rgdOffset:Int64; redundant level 0 of metadata (expressed in sectors)
gdOffset:Int64; level 0 of metadata (expressed in sectors)
overHead:Int64; number of sectors occupied by the metadata
uncleanShutdown:ByteBool; set to FALSE when VMware software closes an extent. Four entries are used to detect when an extent file has been corrupted by transferring it using FTP in text mode. The entries should be initialized with the following values
singleEndLineChar:Char; '\n'
nonEndLineChar:Char; ' '
doubleEndLineChar1:Char; '\r'
doubleEndLineChar2:Char; '\n'
compressAlgorithm:Word; See above
pad:array[0..432] of Byte;  

VPC dish geometry

PVpcDiskGeometry = ^TVpcDiskGeometry;

TVpcDiskGeometry = packed record

Note: Always 4 bytes
Cylinders:Word; Cylinders
Heads:Byte; Heads
Sectors:Byte; Sectors per track

VPC parent locator

PVpcParentLocator = ^TVpcParentLocator;

TVpcParentLocator = packed record

Note: Always 24 bytes
PlatformCode:LongWord; describes which platform-specific format is used for the file locator (see above)
PlatformDataSpace:LongWord; the number of 512-byte sectors needed to store the parent hard disk locator
PlatformDataLength:LongWord; length of the parent hard disk locator in bytes
Reserved:LongWord; Reserved, must be zero
PlatformDataOffset:Int64; offset in bytes where the platform specific file locator data is stored

VPC hard disk footer

PVpcHardDiskFooter = ^TVpcHardDiskFooter;

TVpcHardDiskFooter = packed record

Note: Always 512 bytes (At end of file on Fixed disks, at start and end on Dynamic and Differencing disks)
Cookie:array[0..7] of Char; conectix
Features:LongWord;  
Version:LongWord; 0x00010000
DataOffset:Int64; Offset to Dynamic Disk Header, Must be 0xFFFFFFFF for Fixed Disks
TimeStamp:LongWord; seconds since January 1, 2000 12:00:00 AM in UTC/GMT (Unix Time minus 30 years)
CreatorApplication:array[0..3] of Char; Microsoft Virtual PC = "vpc "/Microsoft Virtual Server = "vs "
CreatorVersion:LongWord; Virtual Server 2004 = 0x00010000/Virtual PC 2004 = 0x00050000
CreatorHostOS:LongWord; Windows 0x5769326B (Wi2k)/Macintosh 0x4D616320 (Mac )
OriginalSize:Int64; Size in Bytes of the VHD at Creation
CurrentSize:Int64; Current Size in Bytes of the VHD
DiskGeometry:TVpcDiskGeometry; See above
DiskType:LongWord; See above
Checksum:LongWord; 1s compliment checksum of the footer
UniqueId:TGUID;  
SavedState:ByteBool; Set to 1 if disk is in a saved state
Reserved:array[0..426] of Byte; Reserved, must be zero

VPC dynamic disk header

PVpcDynamicDiskHeader = ^TVpcDynamicDiskHeader;

TVpcDynamicDiskHeader = packed record

Note: Always 1024 bytes (Used for both Dynamic and Differencing disks)
Cookie:array[0..7] of Char; cxsparse
DataOffset:Int64; currently unused by existing formats and should be set to 0xFFFFFFFF
TableOffset:Int64; absolute byte offset of the Block Allocation Table (BAT)
HeaderVersion:LongWord; must be initialized to 0x00010000
MaxTableEntries:LongWord; maximum entries present in the BAT. equal to the number of blocks in the disk (disk size divided by the blocksize)
BlockSize:LongWord; The default value is 0x00200000 (indicating a block size of 2 MB)
Checksum:LongWord; 1s compliment checksum of the header
ParentUniqueId:TGUID; only used for differencing hard disks
ParentTimeStamp:LongWord; number of seconds since January 1, 2000 12:00:00 AM in UTC/GMT
Reserved1:LongWord; Must be zero
ParentUnicodeName:array[0..255] of WideChar; parent hard disk filename (Unicode/UTF16 string)
ParentLocator1:TVpcParentLocator; These entries store an absolute byte offset in the file where the parent locator for a differencing hard disk is stored
ParentLocator2:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
ParentLocator3:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
ParentLocator4:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
ParentLocator5:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
ParentLocator6:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
ParentLocator7:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
ParentLocator8:TVpcParentLocator; These fields are used only for differencing disks and should be set to zero for dynamic disks
Reserved2:array[0..255] of Byte; Reserved, must be zero

VirtualBox disk header

PVboxDiskHeader = ^TVboxDiskHeader;

TVboxDiskHeader = packed record

Note: Always 512 bytes (At start of file for both Fixed and Dynamic disks)
Banner:array[0..63] of Char; <<< Sun xVM VirtualBox Disk Image >>>
Signature:LongWord; 7F 10 DA BE
Version:LongWord; 1.1
HeaderSize:LongWord; 0x190
DiskType:LongWord; see above
DiskFlags:LongWord; see above
Description:array[0..255] of Char; Unused
BlocksOffset:LongWord;  
DataOffset:LongWord;  
Cylinders:LongWord;  
Heads:LongWord;  
Sectors:LongWord;  
SectorSize:LongWord;  
Reserved1:LongWord; Must be zero
DiskSize:Int64; Bytes
BlockSize:LongWord;  
BlockExtra:LongWord;  
TotalBlocks:LongWord;  
AllocatedBlocks:LongWord;  
UUID:TGUID;  
SnapshotUUID:TGUID;  
LinkUUID:TGUID;  
ParentUUID:TGUID;  
Unknown1:LongWord;  
Unknown2:LongWord;  
Reserved2:LongWord; Must be 0x3F
Reserved3:LongWord; Must be 0x200
Unused:array[0..9] of LongWord;  


Class definitions



Virtual disk specific classes

TVirtualDiskController = class(TDiskController)
TVirtualDiskDevice = class(TDiskDevice)
TVirtualDiskPartition = class(TDiskPartition)
TVirtualDiskImage = class(TDiskImage)
TVirtualDiskMemoryImage = class(TVirtualDiskImage)
TVirtualDiskFileImage = class(TVirtualDiskImage)
TVirtualDiskDeviceImage = class(TVirtualDiskImage)
TVirtualDiskIsoImage = class(TVirtualDiskImage)
TVirtualDiskBochsImage = class(TVirtualDiskImage)
TVirtualDiskVmwareImage = class(TVirtualDiskImage)
TVirtualDiskVpcImage = class(TVirtualDiskImage)
TVirtualDiskVboxImage = class(TVirtualDiskImage)
TVirtualRecognizer = class(TRecognizer)
TVirtualDiskResizer = class(TDiskResizer)
TVirtualDiskCopier = class(TDiskCopier)
TVirtualDiskImager = class(TDiskImager)
TVirtualDiskExtent = class(TListObject)
TVirtualDiskVmwareExtent = class(TVirtualDiskExtent)
TVirtualDiskVpcExtent = class(TVirtualDiskExtent)
TVirtualDiskVboxExtent = class(TVirtualDiskExtent)
TVirtualDiskTable = class(TListObject)
TVirtualDiskVmwareTable = class(TVirtualDiskTable)
TVirtualDiskVpcTable = class(TVirtualDiskTable)
TVirtualDiskVboxTable = class(TVirtualDiskTable)
TVirtualDiskBlock = class(TListObject)
TVirtualDiskVmwareBlock = class(TVirtualDiskBlock)
TVirtualDiskVpcGroup = class(TListObject)
TVirtualDiskVpcBlock = class(TVirtualDiskBlock)


Public variables


None defined

Function declarations



Initialization functions

procedure VirtualInit;
Description: To be documented
Note None documented


procedure VirtualQuit;
Description: To be documented
Note None documented


Virtual disk helper functions

function VirtualDataToPointer(const AData; ASize:Integer; ASwap:Boolean):Pointer;
Description: Creates a pointer and copies data from a buffer
Note Allows byte order swapping on copy


function VirtualPointerToData(APointer:Pointer; var AData; ASize:Integer; ASwap:Boolean):Boolean;
Description: Copies data to a buffer from supplied pointer
Note Allows byte order swapping on copy


function VirtualDataToString(const AData; ASize:Integer; AUnicode:Boolean):String;
Description: Converts the supplied data to a string
Note Accounts for unicode and byte ordering


function VirtualStringToData(const AString:String; var AData; ASize:Integer ;AUnicode:Boolean):Boolean;
Description: Converts the supplied string to data
Note Accounts for unicode and byte ordering


Return to Unit Reference