예제 #1
0
파일: Volume.cs 프로젝트: radtek/VhdAttach
        private static bool GetExtentInfo(string volumeNameWithoutSlash, out int diskNumber, out long startingOffset, out long extentLength)
        {
            var volumeHandle = NativeMethods.CreateFile(volumeNameWithoutSlash, 0, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero);

            if (volumeHandle.IsInvalid == false)
            {
                var de = new NativeMethods.VOLUME_DISK_EXTENTS();
                de.NumberOfDiskExtents = 1;
                int bytesReturned = 0;
                if (NativeMethods.DeviceIoControl(volumeHandle, NativeMethods.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, IntPtr.Zero, 0, ref de, Marshal.SizeOf(de), ref bytesReturned, IntPtr.Zero))
                {
                    if (bytesReturned > 0)
                    {
                        diskNumber     = de.Extents.DiskNumber;
                        startingOffset = de.Extents.StartingOffset;
                        extentLength   = de.Extents.ExtentLength;
                        return(true);
                    }
                }
            }

            diskNumber     = 0;
            startingOffset = 0;
            extentLength   = 0;
            return(false);
        }
예제 #2
0
        private static bool GetExtentInfo(string volumeNameWithoutSlash, out int diskNumber, out long startingOffset, out long extentLength)
        {
            var volumeHandle = NativeMethods.CreateFile(volumeNameWithoutSlash, 0, NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero);
            if (volumeHandle.IsInvalid == false) {
                var de = new NativeMethods.VOLUME_DISK_EXTENTS();
                de.NumberOfDiskExtents = 1;
                int bytesReturned = 0;
                if (NativeMethods.DeviceIoControl(volumeHandle, NativeMethods.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, IntPtr.Zero, 0, ref de, Marshal.SizeOf(de), ref bytesReturned, IntPtr.Zero)) {
                    if (bytesReturned > 0) {
                        diskNumber = de.Extents.DiskNumber;
                        startingOffset = de.Extents.StartingOffset;
                        extentLength = de.Extents.ExtentLength;
                        return true;
                    }
                }
            }

            diskNumber = 0;
            startingOffset = 0;
            extentLength = 0;
            return false;
        }