Example #1
0
        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();

            var reader        = new VhdDataReader(new BinaryReader(new MemoryStream(byteArray)));
            var footerFactory = new VhdFooterFactory(reader);
            var vhdFooter     = footerFactory.CreateFooter();

            return(vhdFooter);
        }
        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();
        }
Example #3
0
        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();
        }
Example #5
0
        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();
        }