public static void AddDiskToRaid5Volume(DiskGroupDatabase database, Raid5Volume volume, DiskExtent newExtent, ref long bytesCopied) { // If there will be a power failure during the conversion, our RAID volume will resync during boot, // To prevent destruction of the data, we temporarily convert the array to striped volume VolumeManagerDatabaseHelper.ConvertRaidToStripedVolume(database, volume.VolumeGuid); ulong newExtentID = VolumeManagerDatabaseHelper.AddNewExtentToVolume(database, volume, newExtent); // Backup the first sector of the first extent to the last sector of the new extent // (We replace the filesystem boot record with our own sector for recovery purposes) byte[] filesystemBootRecord = volume.Extents[0].ReadSector(0); newExtent.WriteSectors(newExtent.TotalSectors - 1, filesystemBootRecord); AddDiskOperationResumeRecord resumeRecord = new AddDiskOperationResumeRecord(); resumeRecord.VolumeGuid = volume.VolumeGuid; PrivateHeader privateHeader = PrivateHeader.ReadFromDisk(newExtent.Disk); // privateHeader cannot be null at this point resumeRecord.NumberOfCommittedSectors = 0; // we use volume.WriteSectors so that the parity information will be update // this way, we could recover the first sector of each extent if a disk will fail volume.WriteSectors(0, resumeRecord.GetBytes(volume.BytesPerSector)); ResumeAddDiskToRaid5Volume(database, volume, new DynamicDiskExtent(newExtent, newExtentID), resumeRecord, ref bytesCopied); }
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); } }