public static List <DynamicVolume> GetDynamicDiskVolumes(DynamicDisk disk) { VolumeManagerDatabase database = VolumeManagerDatabase.ReadFromDisk(disk); List <DynamicDisk> disks = new List <DynamicDisk>(); disks.Add(disk); List <DynamicVolume> result = new List <DynamicVolume>(); if (database != null) { foreach (VolumeRecord volumeRecord in database.VolumeRecords) { DynamicVolume volume = GetVolume(disks, database, volumeRecord); if (volume != null) { foreach (DynamicDiskExtent extent in volume.Extents) { if (extent.DiskGuid == disk.DiskGuid) { result.Add(volume); break; } } } } } return(result); }
public static List <Volume> GetVolumes(List <Disk> disks) { List <Volume> result = new List <Volume>(); List <DynamicDisk> dynamicDisks = new List <DynamicDisk>(); // Get partitions: foreach (Disk disk in disks) { if (!DynamicDisk.IsDynamicDisk(disk)) { List <Partition> partitions = BasicDiskHelper.GetPartitions(disk); foreach (Partition partition in partitions) { result.Add(partition); } } else { dynamicDisks.Add(DynamicDisk.ReadFromDisk(disk)); } } // Get dynamic volumes List <DynamicVolume> dynamicVolumes = DynamicVolumeHelper.GetDynamicVolumes(dynamicDisks); foreach (DynamicVolume volume in dynamicVolumes) { result.Add(volume); } return(result); }
public static List <Volume> GetDiskVolumes(Disk disk) { List <Volume> result = new List <Volume>(); DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk); if (dynamicDisk == null) { // basic disk List <Partition> partitions = BasicDiskHelper.GetPartitions(disk); foreach (MBRPartition partition in partitions) { result.Add(partition); } } else { // dynamic disk List <DynamicVolume> dynamicVolumes = DynamicVolumeHelper.GetDynamicDiskVolumes(dynamicDisk); foreach (DynamicVolume volume in dynamicVolumes) { result.Add(volume); } } return(result); }
/// <returns>Number of bytes</returns> public static long GetMaximumSizeToExtendDynamicDiskExtent(DynamicDiskExtent targetExtent) { DynamicDisk disk = DynamicDisk.ReadFromDisk(targetExtent.Disk); PrivateHeader privateHeader = disk.PrivateHeader; List <DynamicDiskExtent> extents = DynamicDiskHelper.GetDiskExtents(disk); if (extents == null) { throw new InvalidDataException("Cannot read extents information from disk"); } long endOfData = (long)((privateHeader.PublicRegionStartLBA + privateHeader.PublicRegionSizeLBA) * (ulong)disk.BytesPerSector); long max = endOfData - (targetExtent.FirstSector * targetExtent.BytesPerSector + targetExtent.Size); // space from the extent end to the end of the disk foreach (DynamicDiskExtent extent in extents) { if (extent.FirstSector > targetExtent.FirstSector) { long spaceBetweenExtents = (extent.FirstSector - targetExtent.FirstSector) * disk.BytesPerSector - targetExtent.Size; max = Math.Min(max, spaceBetweenExtents); } } return(max); }
private void listDisks_SelectedIndexChanged(object sender, EventArgs e) { DynamicDisk dynamicDisk = (DynamicDisk)listDisks.SelectedValue; PrivateHeader privateHeader = dynamicDisk.PrivateHeader; long publicRegionEndLBA = (long)(privateHeader.PublicRegionStartLBA + privateHeader.PublicRegionSizeLBA); numericDiskOffset.Minimum = (long)privateHeader.PublicRegionStartLBA * dynamicDisk.BytesPerSector; numericDiskOffset.Maximum = publicRegionEndLBA * dynamicDisk.BytesPerSector - m_extent.Size; if (dynamicDisk.Disk != m_extent.Disk) { DiskExtent allocation = DynamicDiskHelper.FindExtentAllocation(dynamicDisk, m_extent.Size); numericDiskOffset.Enabled = (allocation != null); btnOK.Enabled = (allocation != null); if (allocation != null) { numericDiskOffset.Value = allocation.FirstSector * allocation.BytesPerSector; m_previousSuffixIndex = 0; listSuffixes.SelectedIndex = 0; CompactNumericOffset(); } } else { numericDiskOffset.Enabled = true; btnOK.Enabled = true; numericDiskOffset.Value = m_extent.FirstSector * m_extent.Disk.BytesPerSector; m_previousSuffixIndex = 0; listSuffixes.SelectedIndex = 0; CompactNumericOffset(); } }
public static List <Volume> GetVolumes() { List <PhysicalDisk> disks = PhysicalDiskHelper.GetPhysicalDisks(); List <Volume> result = new List <Volume>(); // Get partitions: foreach (Disk disk in disks) { if (!DynamicDisk.IsDynamicDisk(disk)) { List <Partition> partitions = BasicDiskHelper.GetPartitions(disk); foreach (Partition partition in partitions) { result.Add(partition); } } } // Get dynamic volumes List <DynamicVolume> dynamicVolumes = WindowsDynamicVolumeHelper.GetDynamicVolumes(); foreach (DynamicVolume volume in dynamicVolumes) { result.Add(volume); } return(result); }
public const int BackupBufferSizeLBA = 128; // there are about 180 contiguous free sectors in a private region /// <summary> /// Move extent to another disk /// </summary> public static void MoveExtentToAnotherDisk(DiskGroupDatabase database, DynamicVolume volume, DynamicDiskExtent sourceExtent, DiskExtent relocatedExtent, ref long bytesCopied) { // copy the data long transferSizeLBA = Settings.MaximumTransferSizeLBA; for (long sectorIndex = 0; sectorIndex < relocatedExtent.TotalSectors; sectorIndex += transferSizeLBA) { long sectorsLeft = relocatedExtent.TotalSectors - sectorIndex; int sectorsToRead = (int)Math.Min(transferSizeLBA, sectorsLeft); byte[] data = sourceExtent.ReadSectors(sectorIndex, sectorsToRead); relocatedExtent.WriteSectors(sectorIndex, data); bytesCopied += sectorsToRead * sourceExtent.BytesPerSector; } // Update the database to point to the relocated extent DynamicDisk targetDisk = DynamicDisk.ReadFromDisk(relocatedExtent.Disk); DynamicDiskExtent dynamicRelocatedExtent = new DynamicDiskExtent(relocatedExtent, sourceExtent.ExtentID); dynamicRelocatedExtent.Name = sourceExtent.Name; dynamicRelocatedExtent.DiskGuid = targetDisk.DiskGuid; VolumeManagerDatabaseHelper.UpdateExtentLocation(database, volume, dynamicRelocatedExtent); }
/// <returns>In bytes</returns> public static long GetMaxNewExtentLength(DynamicDisk disk, long alignInSectors) { List <DiskExtent> unallocatedExtents = GetUnallocatedSpace(disk); if (unallocatedExtents == null) { return(-1); } long result = 0; for (int index = 0; index < unallocatedExtents.Count; index++) { DiskExtent extent = unallocatedExtents[index]; if (alignInSectors > 1) { extent = DiskExtentHelper.GetAlignedDiskExtent(extent, alignInSectors); } if (extent.Size > result) { result = extent.Size; } } return(result); }
public static void ListPhysicalDisks() { List <PhysicalDisk> disks = PhysicalDiskHelper.GetPhysicalDisks(); Console.WriteLine("Disk ## Size GPT Dyn DiskID Disk Group Name "); Console.WriteLine("------- ------- --- --- ------ ------------------"); foreach (PhysicalDisk disk in disks) { int index = disk.PhysicalDiskIndex; string diskNumber = index.ToString().PadLeft(2); MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk); string isGPTStr = (mbr != null && mbr.IsGPTBasedDisk) ? " * " : " "; string isDynStr = DynamicDisk.IsDynamicDisk(disk) ? " * " : " "; string diskID = String.Empty; string diskGroupName = String.Empty; VolumeManagerDatabase database = VolumeManagerDatabase.ReadFromDisk(disk); if (database != null) { PrivateHeader privateHeader = PrivateHeader.ReadFromDisk(disk); DiskRecord diskRecord = database.FindDiskByDiskGuid(privateHeader.DiskGuid); diskID = diskRecord.DiskId.ToString(); diskGroupName = database.DiskGroupName; } diskID = diskID.PadLeft(6); Console.WriteLine("Disk {0} {1} {2} {3} {4} {5}", diskNumber, GetStandardSizeString(disk.Size), isGPTStr, isDynStr, diskID, diskGroupName); } }
/// <param name="targetOffset">in bytes</param> public static bool IsMoveLocationValid(DynamicDisk disk, DynamicDiskExtent sourceExtent, long targetOffset) { List <DynamicDiskExtent> extents = GetDiskExtents(disk); // extents are sorted by first sector if (extents == null) { return(false); } PrivateHeader privateHeader = disk.PrivateHeader; if (targetOffset % privateHeader.BytesPerSector > 0) { return(false); } int index = GetIndexOfExtentID(extents, sourceExtent.ExtentID); extents.RemoveAt(index); long targetStartSector = targetOffset / disk.BytesPerSector; long publicRegionStartSector = (long)privateHeader.PublicRegionStartLBA; long startSector = publicRegionStartSector; long publicRegionSizeLBA = (long)privateHeader.PublicRegionSizeLBA; if (targetStartSector < publicRegionStartSector) { return(false); } if (targetStartSector + sourceExtent.TotalSectors > publicRegionStartSector + publicRegionSizeLBA) { return(false); } foreach (DynamicDiskExtent extent in extents) { long extentStartSector = extent.FirstSector; long extentEndSector = extent.FirstSector + extent.Size / disk.BytesPerSector - 1; if (extentStartSector >= targetStartSector && extentStartSector <= targetStartSector + sourceExtent.TotalSectors) { // extent start within the requested region return(false); } if (extentEndSector >= targetStartSector && extentEndSector <= targetStartSector + sourceExtent.TotalSectors) { // extent end within the requested region return(false); } } return(true); }
internal DynamicDiskGroup(VirtualDisk disk) { _disks = new Dictionary<Guid, DynamicDisk>(); DynamicDisk dynDisk = new DynamicDisk(disk); _database = dynDisk.Database; _disks.Add(dynDisk.Id, dynDisk); _record = dynDisk.Database.GetDiskGroup(dynDisk.GroupId); }
public static string GetDiskInformation(Disk disk) { StringBuilder builder = new StringBuilder(); if (disk is PhysicalDisk) { PhysicalDisk physicalDisk = (PhysicalDisk)disk; builder.AppendLine(physicalDisk.Description); builder.AppendLine("S/N: " + physicalDisk.SerialNumber); builder.AppendLine(); } builder.AppendFormat("Size: {0} bytes\n", disk.Size.ToString("###,###,###,###,##0")); builder.AppendFormat("Bytes per sector (logical): {0}\n", disk.BytesPerSector); if (disk is PhysicalDisk) { PhysicalDisk physicalDisk = (PhysicalDisk)disk; builder.AppendFormat("Geometry: Cylinders: {0}, Heads: {1}, Sectors Per Track: {2}\n", physicalDisk.Cylinders, physicalDisk.TracksPerCylinder, physicalDisk.SectorsPerTrack); } else if (disk is DiskImage) { DiskImage diskImage = (DiskImage)disk; builder.AppendFormat("Disk image path: {0}\n", diskImage.Path); } builder.AppendLine(); MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk); if (mbr != null) { builder.AppendFormat("Partitioning scheme: {0}\n", (mbr.IsGPTBasedDisk ? "GPT" : "MBR")); } DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk); builder.AppendFormat("Disk type: {0}\n", ((dynamicDisk != null) ? "Dynamic Disk" : "Basic Disk")); if (dynamicDisk != null) { VolumeManagerDatabase database = VolumeManagerDatabase.ReadFromDisk(dynamicDisk); if (database != null) { DiskRecord diskRecord = database.FindDiskByDiskGuid(dynamicDisk.PrivateHeader.DiskGuid); if (diskRecord != null) { builder.AppendLine("Disk ID: " + diskRecord.DiskId); } } builder.AppendLine("Disk GUID: " + dynamicDisk.PrivateHeader.DiskGuid); builder.AppendLine("Disk Group GUID: " + dynamicDisk.PrivateHeader.DiskGroupGuidString); builder.AppendLine(); builder.AppendLine("Public region start sector: " + dynamicDisk.PrivateHeader.PublicRegionStartLBA); builder.AppendLine("Public region size (sectors): " + dynamicDisk.PrivateHeader.PublicRegionSizeLBA); builder.AppendLine(); builder.AppendLine("Private region start sector: " + dynamicDisk.PrivateHeader.PrivateRegionStartLBA); builder.AppendLine("Private region size (sectors): " + dynamicDisk.PrivateHeader.PrivateRegionSizeLBA); } return(builder.ToString()); }
public static PrivateHeader FindDiskPrivateHeader(Guid diskGuid) { DynamicDisk disk = FindDisk(diskGuid); if (disk != null) { return(disk.PrivateHeader); } return(null); }
/// <summary> /// Support null disks /// </summary> public static ulong GetExtentStartSector(DynamicDisk disk, ExtentRecord extentRecord) { ulong dataStartLBA = 0; if (disk != null) { PrivateHeader privateHeader = disk.PrivateHeader; dataStartLBA = privateHeader.PublicRegionStartLBA; } ulong extentStartSector = dataStartLBA + extentRecord.DiskOffsetLBA; return(extentStartSector); }
public static long FindUnusedSectorInPrivateRegion(DynamicDisk disk) { bool[] bitmap = GetPrivateRegionUsageBitmap(disk); for (int index = 0; index < bitmap.Length; index++) { if (bitmap[index] == false) { return((long)disk.PrivateHeader.PrivateRegionStartLBA + index); } } return(-1); }
public static List <DynamicDisk> GetPhysicalDynamicDisks() { List <PhysicalDisk> disks = PhysicalDiskHelper.GetPhysicalDisks(); List <DynamicDisk> result = new List <DynamicDisk>(); foreach (PhysicalDisk disk in disks) { DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk); if (dynamicDisk != null) { result.Add(dynamicDisk); } } return(result); }
private void createVolumeMenuItem_Click(object sender, EventArgs e) { DiskExtent extent = (DiskExtent)((KeyValuePair <Volume, DiskExtent>)extentContextMenu.Tag).Value; List <DynamicDisk> dynamicDisks = GetDynamicDisks(); DynamicDisk disk = DynamicDisk.ReadFromDisk(extent.Disk); List <DynamicDisk> diskGroup = DynamicDiskHelper.FindDiskGroup(dynamicDisks, disk.DiskGroupGuid); CreateVolumeForm createVolume = new CreateVolumeForm(diskGroup, extent); DialogResult result = createVolume.ShowDialog(); if (result == DialogResult.OK) { UpdateView(); } }
private List <DynamicDisk> GetDynamicDisks() { if (m_dynamicDisks == null) { m_dynamicDisks = new List <DynamicDisk>(); foreach (PhysicalDisk disk in m_disks) { DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk); if (dynamicDisk != null) { m_dynamicDisks.Add(dynamicDisk); } } } return(m_dynamicDisks); }
public static List <DiskExtent> GetUnallocatedExtents(List <Disk> disks) { List <DiskExtent> extents = new List <DiskExtent>(); foreach (Disk disk in disks) { if (DynamicDisk.IsDynamicDisk(disk)) { DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk); extents.AddRange(DynamicDiskHelper.GetUnallocatedExtents(dynamicDisk)); } else { extents.AddRange(BasicDiskHelper.GetUnallocatedExtents(disk)); } } return(extents); }
/// <summary> /// Support null disks /// </summary> public static DynamicDiskExtent GetDiskExtent(DynamicDisk dynamicDisk, ExtentRecord extentRecord) { ulong extentStartSector = GetExtentStartSector(dynamicDisk, extentRecord); int bytesPerSector = 512; // default for missing disk Disk disk = null; Guid diskGuid = Guid.Empty; if (dynamicDisk != null) { bytesPerSector = dynamicDisk.BytesPerSector; disk = dynamicDisk.Disk; diskGuid = dynamicDisk.DiskGuid; } DynamicDiskExtent extent = new DynamicDiskExtent(disk, (long)extentStartSector, (long)extentRecord.SizeLBA * bytesPerSector, extentRecord.ExtentId); extent.Name = extentRecord.Name; extent.DiskGuid = diskGuid; return(extent); }
public static bool[] GetPrivateRegionUsageBitmap(DynamicDisk disk) { // usage bitmap: bool[] bitmap = new bool[disk.PrivateHeader.PrivateRegionSizeLBA]; bitmap[disk.PrivateHeader.PrimaryPrivateHeaderLBA] = true; bitmap[disk.PrivateHeader.SecondaryPrivateHeaderLBA] = true; bitmap[disk.PrivateHeader.PrimaryTocLBA] = true; bitmap[disk.PrivateHeader.PreviousPrimaryTocLBA] = true; bitmap[disk.PrivateHeader.SecondaryTocLBA] = true; bitmap[disk.PrivateHeader.PreviousSecondaryTocLBA] = true; foreach (TOCRegion region in disk.TOCBlock.Regions) { for (int index = 0; index < (int)region.SizeLBA; index++) { bitmap[(int)region.StartLBA + index] = true; } } return(bitmap); }
private static List <DiskExtent> GetUnallocatedSpace(DynamicDisk disk) { List <DynamicDiskExtent> extents = GetDiskExtents(disk); // extents are sorted by first sector if (extents == null) { return(null); } List <DiskExtent> result = new List <DiskExtent>(); PrivateHeader privateHeader = disk.PrivateHeader; long publicRegionStartSector = (long)privateHeader.PublicRegionStartLBA; long startSector = publicRegionStartSector; long publicRegionSize = (long)privateHeader.PublicRegionSizeLBA * disk.Disk.BytesPerSector; // see if there is room before each extent foreach (DynamicDiskExtent extent in extents) { long extentStartSector = extent.FirstSector; long nextStartSector = extent.FirstSector + extent.Size / disk.BytesPerSector; long freeSpaceInBytes = (extentStartSector - startSector) * disk.BytesPerSector; if (freeSpaceInBytes > 0) { result.Add(new DiskExtent(disk.Disk, startSector, freeSpaceInBytes)); } startSector = nextStartSector; } // see if there is room after the last extent long spaceInBytes = publicRegionSize - (startSector - publicRegionStartSector) * disk.Disk.BytesPerSector; if (spaceInBytes > 0) { result.Add(new DiskExtent(disk.Disk, startSector, spaceInBytes)); } return(result); }
/// <summary> /// If a disk has more than one partition, the last one is the only one we'll be able to resize without moving partitions around /// </summary> public static Partition GetLastPartition(Disk disk) { MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk); if (mbr == null) { return(new RemovableVolume(disk)); } else { if (!DynamicDisk.IsDynamicDisk(disk)) { List <Partition> partitions = BasicDiskHelper.GetPartitions(disk); if (partitions.Count > 0) { return(partitions[partitions.Count - 1]); } } return(null); } }
private static List <DynamicColumn> GetDynamicVolumeColumns(List <DynamicDisk> disks, VolumeManagerDatabase database, ComponentRecord componentRecord, VolumeRecord volumeRecord) { // extentRecords are sorted by offset in column List <ExtentRecord> extentRecords = database.FindExtentsByComponentID(componentRecord.ComponentId); if (componentRecord.NumberOfExtents != extentRecords.Count || extentRecords.Count == 0) { // database record is invalid throw new InvalidDataException("Number of extents in component record does not match actual number of extent records"); } SortedList <uint, List <DynamicDiskExtent> > columns = new SortedList <uint, List <DynamicDiskExtent> >(); foreach (ExtentRecord extentRecord in extentRecords) { DiskRecord diskRecord = database.FindDiskByDiskID(extentRecord.DiskId); DynamicDisk disk = DynamicDiskHelper.FindDisk(disks, diskRecord.DiskGuid); // we add nulls as well DynamicDiskExtent extent = DynamicDiskExtentHelper.GetDiskExtent(disk, extentRecord); if (columns.ContainsKey(extentRecord.ColumnIndex)) { columns[extentRecord.ColumnIndex].Add(extent); } else { List <DynamicDiskExtent> list = new List <DynamicDiskExtent>(); list.Add(extent); columns.Add(extentRecord.ColumnIndex, list); } } List <DynamicColumn> result = new List <DynamicColumn>(); foreach (List <DynamicDiskExtent> extents in columns.Values) { result.Add(new DynamicColumn(extents)); } return(result); }
/// <summary> /// Sorted by first sector /// </summary> /// <returns>null if there was a problem reading extent information from disk</returns> public static List <DynamicDiskExtent> GetDiskExtents(DynamicDisk disk) { List <DynamicDiskExtent> result = new List <DynamicDiskExtent>(); PrivateHeader privateHeader = disk.PrivateHeader; if (privateHeader != null) { VolumeManagerDatabase database = VolumeManagerDatabase.ReadFromDisk(disk); if (database != null) { DiskRecord diskRecord = database.FindDiskByDiskGuid(privateHeader.DiskGuid); List <ExtentRecord> extentRecords = database.FindExtentsByDiskID(diskRecord.DiskId); foreach (ExtentRecord extentRecord in extentRecords) { DynamicDiskExtent extent = GetDiskExtent(disk, extentRecord); result.Add(extent); } SortExtentsByFirstSector(result); return(result); } } return(null); }
/// <param name="allocationLength">In bytes</param> /// <param name="alignInSectors">0 or 1 for no alignment</param> /// <returns>Allocated DiskExtent or null if there is not enough free disk space</returns> public static DiskExtent AllocateNewExtent(DynamicDisk disk, long allocationLength, long alignInSectors) { List <DiskExtent> unallocatedExtents = GetUnallocatedSpace(disk); if (unallocatedExtents == null) { return(null); } for (int index = 0; index < unallocatedExtents.Count; index++) { DiskExtent extent = unallocatedExtents[index]; if (alignInSectors > 1) { extent = DiskExtentHelper.GetAlignedDiskExtent(extent, alignInSectors); } if (extent.Size >= allocationLength) { return(new DiskExtent(extent.Disk, extent.FirstSector, allocationLength)); } } return(null); }
private static string GetDiskType(Disk disk) { MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk); if (DynamicDisk.IsDynamicDisk(disk)) { return("Dynamic"); } else { if (mbr == null) { return("Uninitialized"); } else if (!mbr.IsGPTBasedDisk) { return("MBR"); } else { return("GPT"); } } }
private void DiskCollectionView_ExtentRightClick(object sender, ExtentRightClickEventArgs e) { bool isDynamicDisk = false; bool hasResumeRecord = false; try { isDynamicDisk = DynamicDisk.IsDynamicDisk(e.Extent.Disk); if (e.Volume != null && (!(e.Volume is DynamicVolume) || ((DynamicVolume)e.Volume).IsOperational)) { hasResumeRecord = DynamicDiskPartitionerResumeRecord.HasValidSignature(e.Volume.ReadSector(0)); } } catch (IOException) { } createVolumeMenuItem.Visible = (e.Volume == null && isDynamicDisk); moveExtentMenuItem.Visible = (e.Volume != null && e.Volume is DynamicVolume); resumeOperationMenuItem.Visible = hasResumeRecord; extendVolumeMenuItem.Visible = (e.Volume != null); volumePropertiesMenuItem.Visible = (e.Volume != null); fileSystemMenuItem.Visible = (e.Volume != null); addDiskToVolumeMenuItem.Visible = (e.Volume != null && e.Volume is Raid5Volume); bool isHealthy = (e.Volume != null && (!(e.Volume is DynamicVolume) || ((DynamicVolume)e.Volume).IsHealthy)); bool isOperational = (e.Volume != null && (!(e.Volume is DynamicVolume) || ((DynamicVolume)e.Volume).IsOperational)); bool isMirroredVolume = (e.Volume != null && e.Volume is MirroredVolume); extendVolumeMenuItem.Enabled = isHealthy && !isMirroredVolume; moveExtentMenuItem.Enabled = isOperational; fileSystemMenuItem.Enabled = isOperational; addDiskToVolumeMenuItem.Enabled = isHealthy; extentContextMenu.Tag = new KeyValuePair <Volume, DiskExtent>(e.Volume, e.Extent); extentContextMenu.Show((Control)sender, e.Location); }
public static DynamicDisk FindDisk(Guid diskGuid) { List <int> diskIndexList = PhysicalDiskUtils.GetPhysicalDiskIndexList(); foreach (int diskIndex in diskIndexList) { PhysicalDisk disk; try { disk = new PhysicalDisk(diskIndex); // will throw an exception if disk is not valid } catch (DriveNotFoundException) { // The disk must have been removed from the system continue; } catch (DeviceNotReadyException) { continue; } catch (SharingViolationException) // skip this disk, it's probably being used { continue; } DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk); if (dynamicDisk != null) { if (dynamicDisk.DiskGuid == diskGuid) { return(dynamicDisk); } } } return(null); }
private static SimpleVolume GetSimpleVolume(List <DynamicDisk> disks, VolumeManagerDatabase database, ComponentRecord componentRecord, VolumeRecord volumeRecord) { List <ExtentRecord> extentRecords = database.FindExtentsByComponentID(componentRecord.ComponentId); if (extentRecords.Count == 1) { ExtentRecord extentRecord = extentRecords[0]; DiskRecord diskRecord = database.FindDiskByDiskID(extentRecord.DiskId); DynamicDisk disk = DynamicDiskHelper.FindDisk(disks, diskRecord.DiskGuid); // we add nulls as well DynamicDiskExtent extent = DynamicDiskExtentHelper.GetDiskExtent(disk, extentRecord); SimpleVolume volume = new SimpleVolume(extent, volumeRecord.VolumeGuid, database.DiskGroupGuid); volume.VolumeID = volumeRecord.VolumeId; volume.Name = volumeRecord.Name; volume.DiskGroupName = database.DiskGroupName; return(volume); } else { // component / extent records are invalid throw new InvalidDataException("Number of extents in component record does not match actual number of extent records"); } }
public static long FindUnusedRegionInPrivateRegion(DynamicDisk disk, int sectorCount) { bool[] bitmap = GetPrivateRegionUsageBitmap(disk); int startIndex = 0; int freeCount = 0; for (int index = 0; index < bitmap.Length; index++) { if (freeCount == 0) { if (bitmap[index] == false) // free { startIndex = index; freeCount++; } } else { if (bitmap[index] == false) // free { freeCount++; if (freeCount == sectorCount) { return((long)disk.PrivateHeader.PrivateRegionStartLBA + startIndex); } } else { freeCount = 0; } } } return(-1); }
public void Add(VirtualDisk disk) { DynamicDisk dynDisk = new DynamicDisk(disk); _disks.Add(dynDisk.Id, dynDisk); }