Example #1
0
        public static bool LockAllVolumesOrNone(List <Guid> volumeGuids)
        {
            bool success = true;
            int  lockIndex;

            for (lockIndex = 0; lockIndex < volumeGuids.Count; lockIndex++)
            {
                Guid volumeGuid = volumeGuids[lockIndex];
                if (WindowsVolumeManager.IsMounted(volumeGuid))
                {
                    success = WindowsVolumeManager.ExclusiveLock(volumeGuid);
                    if (!success)
                    {
                        break;
                    }
                }
            }

            if (!success)
            {
                // release the volumes that were locked
                for (int index = 0; index < lockIndex; index++)
                {
                    WindowsVolumeManager.ReleaseLock(volumeGuids[lockIndex]);
                }
            }

            return(success);
        }
Example #2
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();
        }