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); } }
public VhdFile(VhdFooter footer, VhdHeader header, BlockAllocationTable bat, VhdFile parent, Stream stream) { this.Footer = footer; this.Header = header; this.BlockAllocationTable = bat; this.Parent = parent; this.reader = new BinaryReader(stream, Encoding.Unicode); DataReader = new VhdDataReader(this.reader); }
private VhdFile Create(StreamSource streamSource) { var disposer = new Action(() => { if (streamSource.DisposeOnException) { streamSource.Stream.Dispose(); } }); bool throwing = false; try { var reader = new BinaryReader(streamSource.Stream, Encoding.Unicode); var dataReader = new VhdDataReader(reader); var footer = new VhdFooterFactory(dataReader).CreateFooter(); VhdHeader header = null; BlockAllocationTable blockAllocationTable = null; VhdFile parent = null; if (footer.DiskType != DiskType.Fixed) { header = new VhdHeaderFactory(dataReader, footer).CreateHeader(); blockAllocationTable = new BlockAllocationTableFactory(dataReader, header).Create(); if (footer.DiskType == DiskType.Differencing) { string parentPath = GetParentPath(streamSource.VhdDirectory, header); parent = Create(parentPath); } } return(new VhdFile(footer, header, blockAllocationTable, parent, streamSource.Stream)); } catch (Exception e) { throwing = true; throw new VhdParsingException("unsupported format", e); } finally { if (throwing) { disposer(); } } }
public BlockAllocationTableFactory(VhdDataReader dataReader, VhdHeader header) { this.dataReader = dataReader; this.header = header; }
public VhdFooterFactory(VhdDataReader dataReader) { this.dataReader = dataReader; this.diskTypeFactory = new DiskTypeFactory(); }
public VhdParentLocatorFactory(VhdDataReader dataReader, long offset) { this.dataReader = dataReader; this.offset = offset; attributeHelper = new AttributeHelper<ParentLocator>(); }
public VhdHeaderFactory(VhdDataReader dataReader, VhdFooter footer) { this.dataReader = dataReader; this.footer = footer; headerOffset = this.footer.HeaderOffset; }
public VhdParentLocatorFactory(VhdDataReader dataReader, long offset) { this.dataReader = dataReader; this.offset = offset; attributeHelper = new AttributeHelper <ParentLocator>(); }