public static extern bool DeviceIoControl( SafeFileHandle hDevice, EIOControlCode IoControlCode, IntPtr InBuffer, uint nInBufferSize, ref DISK_GEOMETRY OutBuffer, uint nOutBufferSize, out uint pBytesReturned, IntPtr Overlapped );
public static ulong GetDiskSize(SafeFileHandle handle) { uint dummy; DISK_GEOMETRY diskGeo = new DISK_GEOMETRY(); Win32.DeviceIoControl(handle, EIOControlCode.DiskGetDriveGeometry, IntPtr.Zero, 0, ref diskGeo, (uint)Marshal.SizeOf(typeof(DISK_GEOMETRY)), out dummy, IntPtr.Zero); return (ulong)((DISK_GEOMETRY)diskGeo).DiskSize; }