public static void CreateFixedVhdFile(Stream destination, long virtualSize) { var footer = VhdFooterFactory.CreateFixedDiskFooter(virtualSize); var serializer = new VhdFooterSerializer(footer); var buffer = serializer.ToByteArray(); destination.SetLength(virtualSize + VhdConstants.VHD_FOOTER_SIZE); destination.Seek(-VhdConstants.VHD_FOOTER_SIZE, SeekOrigin.End); destination.Write(buffer, 0, buffer.Length); destination.Flush(); }
private static IEnumerable<CompletionPort> CreateFixedVhdFileAtAsync(AsyncMachine machine, Stream destination, long virtualSize) { var footer = VhdFooterFactory.CreateFixedDiskFooter(virtualSize); var serializer = new VhdFooterSerializer(footer); var buffer = serializer.ToByteArray(); destination.SetLength(virtualSize + VhdConstants.VHD_FOOTER_SIZE); destination.Seek(-VhdConstants.VHD_FOOTER_SIZE, SeekOrigin.End); destination.BeginWrite(buffer, 0, buffer.Length, machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; destination.EndWrite(machine.CompletionResult); destination.Flush(); }
private byte[] GenerateFooter() { var footer = vhdFile.Footer.CreateCopy(); if(vhdFile.Footer.DiskType != DiskType.Fixed) { footer.HeaderOffset = VhdConstants.VHD_NO_DATA_LONG; footer.DiskType = DiskType.Fixed; footer.CreatorApplication = VhdFooterFactory.WindowsAzureCreatorApplicationName; } var serializer = new VhdFooterSerializer(footer); return serializer.ToByteArray(); }