public FixedDiskBlockFactory(VhdFile vhdFile, long blockSize) { this.vhdFile = vhdFile; this.blockSize = blockSize; this.BlockCount = CalculateBlockCount(); this.sectorFactory = new SectorFactory(vhdFile, this); }
public static VhdFilePath GetFilePathBy(this VhdFile vhdFile, Guid uniqueId) { VhdFilePath result = null; string baseVhdPath = String.Empty; var newBlocksOwners = new List <Guid> { Guid.Empty }; var current = vhdFile; while (current != null && current.Footer.UniqueId != uniqueId) { newBlocksOwners.Add(current.Footer.UniqueId); if (current.Parent != null) { result = new VhdFilePath(current.Header.GetAbsoluteParentPath(), current.Header.GetRelativeParentPath()); } current = current.Parent; } if (result == null) { string message = String.Format("There is no parent VHD file with with the id '{0}'", uniqueId); throw new InvalidOperationException(message); } return(result); }
private VhdFile Create(Stream stream, string vhdDirectory) { var reader = new BinaryReader(stream, Encoding.Unicode); try { 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) { var parentPath = vhdDirectory == null ? header.ParentPath : Path.Combine(vhdDirectory, header.GetRelativeParentPath()); parent = Create(parentPath); } } return(new VhdFile(footer, header, blockAllocationTable, parent, stream)); } catch (EndOfStreamException) { throw new VhdParsingException("unsupported format"); } }
public DifferencingDiskBlockFactory(VhdFile vhdFile) : base(vhdFile) { this.bitMapFactory = new BitMapFactory(vhdFile); this.sectorFactory = new SectorFactory(vhdFile, this); this.parentBlockFactory = vhdFile.Parent.DiskType != DiskType.Fixed ? vhdFile.Parent.GetBlockFactory() : new FixedDiskBlockFactory(vhdFile.Parent, this.GetBlockSize()); }
public VirtualDiskStream(string vhdPath) { this.vhdFile = new VhdFileFactory().Create(vhdPath); this.blockFactory = vhdFile.GetBlockFactory(); footerRange = this.blockFactory.GetFooterRange(); fileDataRange = IndexRange.FromLength(0, this.Length - footerRange.Length); }
public VirtualDiskStream(string vhdPath) { this.vhdFile = new VhdFileFactory().Create(vhdPath); this.blockFactory = vhdFile.GetBlockFactory(); footerRange = this.blockFactory.GetFooterRange(); fileDataRange = IndexRange.FromLength(0, this.Length - footerRange.Length); }
public FixedDiskBlockFactory(VhdFile vhdFile, long blockSize) { this.vhdFile = vhdFile; this.blockSize = blockSize; this.BlockCount = CalculateBlockCount(); this.sectorFactory = new SectorFactory(vhdFile, this); }
public static IEnumerable <Guid> GetChildrenIds(this VhdFile vhdFile, Guid uniqueId) { var identityChain = vhdFile.GetIdentityChain(); if (!identityChain.Contains(uniqueId)) { yield break; } foreach (var id in identityChain.TakeWhile(id => id != uniqueId)) { yield return(id); } }
private IEnumerable <CompletionPort> CreateAsync(AsyncMachine <VhdFile> machine, StreamSource streamSource) { var disposer = new Action(() => { if (streamSource.DisposeOnException) { streamSource.Stream.Dispose(); } }); var reader = TryCatch(() => new BinaryReader(streamSource.Stream, Encoding.Unicode), disposer); var dataReader = TryCatch(() => new VhdDataReader(reader), disposer); var footerFactory = TryCatch(() => new VhdFooterFactory(dataReader), disposer); footerFactory.BeginCreateFooter(machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); var footer = TryCatch <VhdFooter>(footerFactory.EndCreateFooter, disposer, machine.CompletionResult); VhdHeader header = null; BlockAllocationTable blockAllocationTable = null; VhdFile parent = null; if (footer.DiskType != DiskType.Fixed) { var headerFactory = new VhdHeaderFactory(dataReader, footer); headerFactory.BeginCreateHeader(machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); header = TryCatch <VhdHeader>(headerFactory.EndCreateHeader, disposer, machine.CompletionResult); var tableFactory = new BlockAllocationTableFactory(dataReader, header); tableFactory.BeginCreate(machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); blockAllocationTable = TryCatch <BlockAllocationTable>(tableFactory.EndCreate, disposer, machine.CompletionResult); if (footer.DiskType == DiskType.Differencing) { var parentPath = streamSource.VhdDirectory == null ? header.ParentPath : Path.Combine(streamSource.VhdDirectory, header.GetRelativeParentPath()); BeginCreate(parentPath, machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); parent = TryCatch <VhdFile>(EndCreate, disposer, machine.CompletionResult); } } machine.ParameterValue = new VhdFile(footer, header, blockAllocationTable, parent, streamSource.Stream); }
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(); } } }
protected AbstractDiskBlockFactory(VhdFile vhdFile) { this.vhdFile = vhdFile; }
public FixedDiskBlockFactory(VhdFile vhdFile) : this(vhdFile, VhdConstants.VHD_DEFAULT_BLOCK_SIZE) { }
public DifferencingDiskBlockFactory(VhdFile vhdFile) : base(vhdFile) { this.bitMapFactory = new BitMapFactory(vhdFile); this.sectorFactory = new SectorFactory(vhdFile, this); this.parentBlockFactory = vhdFile.Parent.DiskType != DiskType.Fixed ? vhdFile.Parent.GetBlockFactory() : new FixedDiskBlockFactory(vhdFile.Parent, this.GetBlockSize()); }
protected AbstractDiskBlockFactory(VhdFile vhdFile) { this.vhdFile = vhdFile; }
public DynamicDiskBlockFactory(VhdFile vhdFile) : base(vhdFile) { this.bitMapFactory = new BitMapFactory(vhdFile); this.sectorFactory = new SectorFactory(vhdFile, this); }
public DynamicDiskBlockFactory(VhdFile vhdFile) : base(vhdFile) { this.bitMapFactory = new BitMapFactory(vhdFile); this.sectorFactory = new SectorFactory(vhdFile, this); }
public FixedDiskBlockFactory(VhdFile vhdFile) : this(vhdFile, VhdConstants.VHD_DEFAULT_BLOCK_SIZE) { }
public SectorFactory(VhdFile vhdFile, IBlockFactory blockFactory) { this.vhdFile = vhdFile; this.blockFactory = blockFactory; }
public BitMapFactory(VhdFile vhdFile) { this.vhdFile = vhdFile; }
public SectorFactory(VhdFile vhdFile, IBlockFactory blockFactory) { this.vhdFile = vhdFile; this.blockFactory = blockFactory; }
public BitMapFactory(VhdFile vhdFile) { this.vhdFile = vhdFile; }
protected AbstractDiskBlockFactory(VhdFile vhdFile) { this.vhdFile = vhdFile; this.BlockCount = CalculateBlockCount(); }