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);
        }
Example #2
0
        /// <summary>
        /// Will lock physical basic disk and all volumes on it.
        /// If the operation is not completed successfully, all locks will be releases.
        /// </summary>
        public static LockStatus LockBasicDiskAndVolumesOrNone(PhysicalDisk disk)
        {
            bool success = disk.ExclusiveLock();

            if (!success)
            {
                return(LockStatus.CannotLockDisk);
            }
            List <Partition> partitions  = BasicDiskHelper.GetPartitions(disk);
            List <Guid>      volumeGuids = new List <Guid>();

            foreach (Partition partition in partitions)
            {
                Guid?windowsVolumeGuid = WindowsVolumeHelper.GetWindowsVolumeGuid(partition);
                if (windowsVolumeGuid.HasValue)
                {
                    volumeGuids.Add(windowsVolumeGuid.Value);
                }
                else
                {
                    return(LockStatus.CannotLockVolume);
                }
            }

            success = LockAllVolumesOrNone(volumeGuids);
            if (!success)
            {
                disk.ReleaseLock();
                return(LockStatus.CannotLockVolume);
            }
            return(LockStatus.Success);
        }
        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);
        }
Example #4
0
        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);
        }
        public static Partition GetPartitionByStartOffset(Disk disk, long firstSector)
        {
            List <Partition> partitions = BasicDiskHelper.GetPartitions(disk);

            foreach (Partition partition in partitions)
            {
                if (partition.FirstSector == firstSector)
                {
                    return(partition);
                }
            }
            return(null);
        }
Example #6
0
        public static void UnlockBasicDiskAndVolumes(PhysicalDisk disk)
        {
            List <Partition> partitions = BasicDiskHelper.GetPartitions(disk);

            foreach (Partition partition in partitions)
            {
                Guid?windowsVolumeGuid = WindowsVolumeHelper.GetWindowsVolumeGuid(partition);
                if (windowsVolumeGuid.HasValue)
                {
                    WindowsVolumeManager.ReleaseLock(windowsVolumeGuid.Value);
                }
            }

            disk.ReleaseLock();
        }