public static string GetVolumeInformation(Volume volume) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("Volume size: {0} bytes\n", volume.Size.ToString("###,###,###,###,##0")); builder.AppendFormat("Volume type: {0}\n", VolumeHelper.GetVolumeTypeString(volume)); if (volume is GPTPartition) { builder.AppendFormat("Partition name: {0}\n", ((GPTPartition)volume).PartitionName); } else if (volume is DynamicVolume) { builder.AppendFormat("Volume name: {0}\n", ((DynamicVolume)volume).Name); builder.AppendFormat("Volume status: {0}\n", VolumeHelper.GetVolumeStatusString(volume)); } Guid?windowsVolumeGuid = WindowsVolumeHelper.GetWindowsVolumeGuid(volume); if (windowsVolumeGuid.HasValue) { List <string> mountPoints = WindowsVolumeManager.GetMountPoints(windowsVolumeGuid.Value); foreach (string volumePath in mountPoints) { builder.AppendFormat("Volume path: {0}\n", volumePath); } bool isMounted = WindowsVolumeManager.IsMounted(windowsVolumeGuid.Value); builder.AppendFormat("Mounted: {0}\n", isMounted); } builder.AppendLine(); if (volume is MirroredVolume) { builder.AppendLine("Extents:"); List <DynamicVolume> components = ((MirroredVolume)volume).Components; for (int componentIndex = 0; componentIndex < components.Count; componentIndex++) { if (componentIndex != 0) { builder.AppendLine(); } DynamicVolume component = components[componentIndex]; builder.AppendFormat("Component {0}:\n", componentIndex); builder.Append(GetExtentsInformation(component)); } } else if (volume is DynamicVolume) { builder.AppendLine("Extents:"); builder.Append(GetExtentsInformation((DynamicVolume)volume)); } else if (volume is Partition) { Partition partition = (Partition)volume; long partitionOffset = partition.FirstSector * partition.BytesPerSector; string partitionOffsetString = FormattingHelper.GetStandardSizeString(partitionOffset); builder.AppendFormat("Partiton Offset: {0}, Start Sector: {1}\n", partitionOffsetString, partition.FirstSector); } return(builder.ToString()); }
public static string GetExtentLabel(Volume volume, DiskExtent extent, int width) { StringBuilder builder = new StringBuilder(); if (volume != null) { Guid?volumeGuid = WindowsVolumeHelper.GetWindowsVolumeGuid(volume); if (volumeGuid.HasValue) { List <string> mountPoints = WindowsVolumeManager.GetMountPoints(volumeGuid.Value); if (mountPoints.Count > 0) { builder.AppendLine(mountPoints[0]); } } } long size = extent.Size; if (width <= 60) { builder.AppendLine(FormattingHelper.GetCompactSizeString(extent.Size)); } else { builder.AppendLine(FormattingHelper.GetStandardSizeString(extent.Size)); } if (volume != null) { string statusString = VolumeHelper.GetVolumeStatusString(volume); builder.AppendLine(statusString); } return(builder.ToString()); }
private void SelectPhysicalDiskForm_Load(object sender, EventArgs e) { List <Volume> volumes = WindowsVolumeHelper.GetVolumes(); for (int index = 0; index < volumes.Count; index++) { Volume volume = volumes[index]; string title = String.Format("Volume {0}", index); string type = VolumeHelper.GetVolumeTypeString(volume); string status = VolumeHelper.GetVolumeStatusString(volume); ulong volumeID = 0; string name = String.Empty; if (volume is DynamicVolume) { volumeID = ((DynamicVolume)volume).VolumeID; name = ((DynamicVolume)volume).Name; } else if (volume is GPTPartition) { name = ((GPTPartition)volume).PartitionName; } ListViewItem item = new ListViewItem(title); item.SubItems.Add(name); item.SubItems.Add(type); item.SubItems.Add(status); item.SubItems.Add(FormattingHelper.GetStandardSizeString(volume.Size)); item.Tag = volume; listVolumes.Items.Add(item); } }