/// <summary> /// Initializes a new instance of the BiosPartitionedDiskBuilder class. /// </summary> /// <param name="capacity">The capacity of the disk (in bytes)</param> /// <param name="biosGeometry">The BIOS geometry of the disk</param> public BiosPartitionedDiskBuilder(long capacity, Geometry biosGeometry) { _capacity = capacity; _biosGeometry = biosGeometry; _bootSectors = new SparseMemoryStream(); _bootSectors.SetLength(capacity); _partitionTable = BiosPartitionTable.Initialize(_bootSectors, _biosGeometry); _partitionContents = new Dictionary<int, BuilderExtent>(); }
public BiosPartitionedDiskBuilder(long capacity, byte[] bootSectors, Geometry biosGeometry) { _capacity = capacity; _biosGeometry = biosGeometry; _bootSectors = new SparseMemoryStream(); _bootSectors.SetLength(capacity); _bootSectors.Write(bootSectors, 0, bootSectors.Length); _partitionTable = new BiosPartitionTable(_bootSectors, biosGeometry); _partitionContents = new Dictionary<int, BuilderExtent>(); }
public override PartitionTable DetectPartitionTable(VirtualDisk disk) { if (BiosPartitionTable.IsValid(disk.Content)) { BiosPartitionTable table = new BiosPartitionTable(disk); if (table.Count == 1 && table[0].BiosType == BiosPartitionTypes.GptProtective) { return new GuidPartitionTable(disk); } else { return table; } } else { return null; } }
public void Basic() { long capacity = 10 * 1024 * 1024; Geometry geometry = Geometry.FromCapacity(capacity); BiosPartitionedDiskBuilder builder = new BiosPartitionedDiskBuilder(capacity, geometry); builder.PartitionTable.Create(WellKnownPartitionType.WindowsNtfs, true); SparseStream partitionContent = SparseStream.FromStream(new MemoryStream((int)(builder.PartitionTable[0].SectorCount * 512)), Ownership.Dispose); partitionContent.Position = 4053; partitionContent.WriteByte(0xAf); builder.SetPartitionContent(0, partitionContent); SparseStream constructedStream = builder.Build(); BiosPartitionTable bpt = new BiosPartitionTable(constructedStream, geometry); Assert.AreEqual(1, bpt.Count); using(Stream builtPartitionStream = bpt.Partitions[0].Open()) { builtPartitionStream.Position = 4053; Assert.AreEqual(0xAf, builtPartitionStream.ReadByte()); } }
internal BiosPartitionInfo(BiosPartitionTable table, BiosPartitionRecord record) { _table = table; _record = record; }
/// <summary> /// Initializes a new instance of the BiosPartitionedDiskBuilder class by /// cloning the partition structure of a source disk. /// </summary> /// <param name="sourceDisk">The disk to clone</param> public BiosPartitionedDiskBuilder(VirtualDisk sourceDisk) { _capacity = sourceDisk.Capacity; _biosGeometry = sourceDisk.BiosGeometry; _bootSectors = new SparseMemoryStream(); _bootSectors.SetLength(_capacity); foreach (var extent in new BiosPartitionTable(sourceDisk).GetMetadataDiskExtents()) { sourceDisk.Content.Position = extent.Start; byte[] buffer = Utilities.ReadFully(sourceDisk.Content, (int)extent.Length); _bootSectors.Position = extent.Start; _bootSectors.Write(buffer, 0, buffer.Length); } _partitionTable = new BiosPartitionTable(_bootSectors, _biosGeometry); _partitionContents = new Dictionary<int, BuilderExtent>(); }
private static void UpdateBiosGeometry(SparseStream contentStream, Geometry oldGeometry, Geometry newGeometry) { BiosPartitionTable partTable = new BiosPartitionTable(contentStream, oldGeometry); partTable.UpdateBiosGeometry(newGeometry); VolumeManager volMgr = new VolumeManager(contentStream); foreach (var volume in volMgr.GetLogicalVolumes()) { foreach (var fsInfo in FileSystemManager.DetectDefaultFileSystems(volume.Open())) { if (fsInfo.Name == "NTFS") { using (NtfsFileSystem fs = new NtfsFileSystem(volume.Open())) { fs.UpdateBiosGeometry(newGeometry); } } } } }