/// <summary>Gets the device number for a specified handle</summary> /// <param name="deviceHandle">Device handle</param> /// <returns>Device number</returns> static uint GetDeviceNumber(SafeFileHandle deviceHandle) { var sdn = new StorageDeviceNumber { deviceNumber = -1 }; uint k = 0; if (!Extern.DeviceIoControlGetDeviceNumber(deviceHandle, WindowsIoctl.IoctlStorageGetDeviceNumber, IntPtr.Zero, 0, ref sdn, (uint)Marshal.SizeOf(sdn), ref k, IntPtr.Zero)) { return(uint.MaxValue); } return((uint)sdn.deviceNumber); }
internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, WindowsIoctl ioControlCode, IntPtr inBuffer, uint nInBufferSize, ref StorageDeviceNumber outBuffer, uint nOutBufferSize, ref uint pBytesReturned, IntPtr overlapped);