public static bool IsVolumeRetained(SimpleVolume volume, out bool isBootVolume) { isBootVolume = false; DynamicDisk disk = DynamicDisk.ReadFromDisk(volume.Disk); long bootPartitionStartLBA; List <ExtentRecord> retained = GetRetainedExtentsOnDisk(disk, out bootPartitionStartLBA); foreach (ExtentRecord record in retained) { if (record.ExtentId == volume.DiskExtent.ExtentID) { if ((long)(disk.PrivateHeader.PublicRegionStartLBA + record.DiskOffsetLBA) == bootPartitionStartLBA) { isBootVolume = true; } return(true); } } return(false); }
public static void ExtendSimpleVolume(DiskGroupDatabase database, SimpleVolume volume, long numberOfAdditionalSectors) { VolumeRecord volumeRecord = database.FindVolumeByVolumeGuid(volume.VolumeGuid); volumeRecord = (VolumeRecord)volumeRecord.Clone(); volumeRecord.SizeLBA += (ulong)PublicRegionHelper.TranslateToPublicRegionSizeLBA(numberOfAdditionalSectors, volume.BytesPerSector); ExtentRecord extentRecord = database.FindExtentByExtentID(volume.DiskExtent.ExtentID); extentRecord = (ExtentRecord)extentRecord.Clone(); extentRecord.SizeLBA += (ulong)PublicRegionHelper.TranslateToPublicRegionSizeLBA(numberOfAdditionalSectors, volume.BytesPerSector); DiskRecord diskRecord = database.FindDiskByDiskID(extentRecord.DiskId); // we should update the disk, see Database.cs diskRecord = (DiskRecord)diskRecord.Clone(); List <DatabaseRecord> records = new List <DatabaseRecord>(); records.Add(volumeRecord); records.Add(extentRecord); records.Add(diskRecord); database.UpdateDatabase(records); }
public static void ExtendSimpleVolume(DiskGroupDatabase database, SimpleVolume volume, long additionalNumberOfSectors) { VolumeRecord volumeRecord = database.FindVolumeByVolumeGuid(volume.VolumeGuid); volumeRecord = (VolumeRecord)volumeRecord.Clone(); volumeRecord.SizeLBA += (ulong)additionalNumberOfSectors; ExtentRecord extentRecord = database.FindExtentByExtentID(volume.DiskExtent.ExtentID); extentRecord = (ExtentRecord)extentRecord.Clone(); extentRecord.SizeLBA += (ulong)additionalNumberOfSectors; DiskRecord diskRecord = database.FindDiskByDiskID(extentRecord.DiskId); // we should update the disk, see Database.cs diskRecord = (DiskRecord)diskRecord.Clone(); List <DatabaseRecord> records = new List <DatabaseRecord>(); records.Add(volumeRecord); records.Add(extentRecord); records.Add(diskRecord); database.UpdateDatabase(records); }
private static SimpleVolume GetSimpleVolume(DiskGroupDatabase 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(database.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"); } }