public static VhdFooter CreateFixedDiskFooter(long virtualSize) { var helper = new AttributeHelper <VhdFooter>(); var footer = new VhdFooter(); var reservedAttribute = helper.GetAttribute(() => footer.Reserved); footer.Cookie = VhdCookie.CreateFooterCookie(); footer.Features = VhdFeature.Reserved; footer.FileFormatVersion = VhdFileFormatVersion.DefaultFileFormatVersion; footer.HeaderOffset = VhdConstants.VHD_NO_DATA_LONG; footer.TimeStamp = DateTime.UtcNow; footer.CreatorApplication = WindowsAzureCreatorApplicationName; footer.CreatorVersion = VhdCreatorVersion.CSUP2011; footer.CreatorHostOsType = HostOsType.Windows; footer.PhsyicalSize = virtualSize; footer.VirtualSize = virtualSize; footer.DiskGeometry = DiskGeometry.CreateFromVirtualSize(virtualSize); footer.DiskType = DiskType.Fixed; footer.UniqueId = Guid.NewGuid(); footer.SavedState = false; footer.Reserved = new byte[reservedAttribute.Size]; var footerSerializer = new VhdFooterSerializer(footer); var byteArray = footerSerializer.ToByteArray(); using (var memoryStream = new MemoryStream(byteArray)) { var binaryReader = new BinaryReader(memoryStream); var vhdDataReader = new VhdDataReader(binaryReader); var footerFactory = new VhdFooterFactory(vhdDataReader); var vhdFooter = footerFactory.CreateFooter(); return(vhdFooter); } }
private VhdCookie CreateVhdCookie(byte[] cookie) { var vhdCookie = new VhdCookie(VhdCookieType.Footer, cookie); if (!vhdCookie.IsValid()) { throw new VhdParsingException(String.Format("Invalid Vhd footer cookie:{0}", vhdCookie.StringData)); } return(vhdCookie); }
private VhdCookie EndReadHeaderCookie(IAsyncResult result) { var value = dataReader.EndReadBytes(result); var vhdCookie = new VhdCookie(VhdCookieType.Header, value); if (!vhdCookie.IsValid()) { throw new VhdParsingException(String.Format("unsupported format, Cookie:{0}", vhdCookie)); } return(vhdCookie); }
private VhdCookie ReadHeaderCookie(VhdPropertyAttribute attribute) { var cookie = dataReader.ReadBytes(headerOffset + attribute.Offset, attribute.Size); var vhdCookie = new VhdCookie(VhdCookieType.Header, cookie); if (!vhdCookie.IsValid()) { throw new VhdParsingException(String.Format("unsupported format, Cookie:{0}", vhdCookie)); } return(vhdCookie); }