public int ReadFrom(byte[] buffer, int offset) { _data = new byte[FixedSize]; Array.Copy(buffer, offset, _data, 0, FixedSize); Signature = Utilities.ToUInt32LittleEndian(_data, 0); Checksum = Utilities.ToUInt32LittleEndian(_data, 4); EntryCount = Utilities.ToUInt32LittleEndian(_data, 8); Reserved = Utilities.ToUInt32LittleEndian(_data, 12); Regions = new Dictionary <Guid, RegionEntry>(); if (IsValid) { for (int i = 0; i < EntryCount; ++i) { RegionEntry entry = Utilities.ToStruct <RegionEntry>(_data, 16 + (32 * i)); Regions.Add(entry.Guid, entry); } } return(Size); }
/// <summary> /// Opens an existing region within the VHDX file. /// </summary> /// <param name="region">Identifier for the region to open.</param> /// <returns>A stream containing the region data.</returns> /// <remarks>Regions are an extension mechanism in VHDX - with some regions defined by /// the VHDX specification to hold metadata and the block allocation data.</remarks> public Stream OpenRegion(Guid region) { RegionEntry metadataRegion = _regionTable.Regions[region]; return(new SubStream(_fileStream, metadataRegion.FileOffset, metadataRegion.Length)); }