123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using Microsoft.Win32.SafeHandles;
- using Utilities;
- using DiskAccessLibrary.LogicalDiskManager;
- namespace DiskAccessLibrary
- {
- public class WindowsVolumeManager
- {
- public static bool ExclusiveLock(Guid windowsVolumeGuid)
- {
- return ExclusiveLock(windowsVolumeGuid, FileAccess.ReadWrite);
- }
-
-
-
-
-
- public static bool ExclusiveLock(Guid windowsVolumeGuid, FileAccess fileAccess)
- {
- bool newAllocation;
-
-
- SafeFileHandle handle = VolumeHandlePool.ObtainHandle(windowsVolumeGuid, fileAccess, ShareMode.None, out newAllocation);
- if (newAllocation)
- {
- if (!handle.IsInvalid)
- {
- bool success = VolumeControl.LockVolume(handle);
- if (!success)
- {
- VolumeHandlePool.ReleaseHandle(windowsVolumeGuid);
- }
- return success;
- }
- else
- {
- VolumeHandlePool.ReleaseHandle(windowsVolumeGuid);
- return false;
- }
- }
- else
- {
- return false;
- }
- }
-
-
-
- public static bool DismountVolume(Guid windowsVolumeGuid)
- {
- bool releaseHandle;
- SafeFileHandle handle = VolumeHandlePool.ObtainHandle(windowsVolumeGuid, FileAccess.ReadWrite, ShareMode.ReadWrite, out releaseHandle);
- bool success = false;
- if (!handle.IsInvalid)
- {
- success = VolumeControl.DismountVolume(handle);
- }
- if (releaseHandle)
- {
- VolumeHandlePool.ReleaseHandle(windowsVolumeGuid);
- }
- return success;
- }
- public static bool ReleaseLock(Guid windowsVolumeGuid)
- {
- return VolumeHandlePool.ReleaseHandle(windowsVolumeGuid);
- }
-
-
-
-
-
- public static bool IsMounted(Guid windowsVolumeGuid)
- {
- return VolumeControl.IsVolumeMounted(windowsVolumeGuid);
- }
- public static List<string> GetMountPoints(Guid windowsVolumeGuid)
- {
- return VolumeControl.GetVolumeMountPoints(windowsVolumeGuid);
- }
-
-
-
- public static bool HasMountPoints(Guid windowsVolumeGuid)
- {
- return (GetMountPoints(windowsVolumeGuid).Count > 0);
- }
- }
- }
|