internal static PrivateHeader GetPrivateHeader(VirtualDisk disk) { if (disk.IsPartitioned) { long headerPos = 0; PartitionTable pt = disk.Partitions; if (pt is BiosPartitionTable) { headerPos = 0xc00; } else { foreach (var part in pt.Partitions) { if (part.GuidType == GuidPartitionTypes.WindowsLdmMetadata) { headerPos = part.LastSector * Sizes.Sector; } } } if (headerPos != 0) { disk.Content.Position = headerPos; byte[] buffer = new byte[Sizes.Sector]; disk.Content.Read(buffer, 0, buffer.Length); PrivateHeader hdr = new PrivateHeader(); hdr.ReadFrom(buffer, 0); return(hdr); } } return(null); }
internal DynamicDisk(VirtualDisk disk) { _disk = disk; _header = GetPrivateHeader(_disk); TocBlock toc = GetTableOfContents(); long dbStart = (_header.ConfigurationStartLba * 512) + (toc.Item1Start * 512); _disk.Content.Position = dbStart; _database = new Database(_disk.Content); }
/// <summary> /// Adds a new disk to be managed. /// </summary> /// <param name="disk">The disk to manage</param> public void Add(VirtualDisk disk) { PrivateHeader header = DynamicDisk.GetPrivateHeader(disk); DynamicDiskGroup group; if (_groups.TryGetValue(header.DiskGroupId, out group)) { group.Add(disk); } else { group = new DynamicDiskGroup(disk); _groups.Add(header.DiskGroupId, group); } }