/// <summary> /// Check, if Drive has NoSeekPenalty. If it's true, then it is a SSD /// </summary> /// <param name="diskindex">The Drive-Index</param> /// <returns></returns> public static string HasNoSeekPenalty(byte diskindex) { string sDrive = @"\\.\PhysicalDrive" + diskindex.ToString(); SafeFileHandle hDrive = WinAPI.CreateFileW(sDrive, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero); // No access to drive if (hDrive == null || hDrive.IsInvalid) { string message = GetErrorMessage(Marshal.GetLastWin32Error()); return("CreateFile failed. " + message); } uint IOCTL_STORAGE_QUERY_PROPERTY = CTL_CODE(IOCTL_STORAGE_BASE, 0x500, METHOD_BUFFERED, FILE_ANY_ACCESS); // From winioctl.h WinAPI.STORAGE_PROPERTY_QUERY query_seek_penalty = new WinAPI.STORAGE_PROPERTY_QUERY(); query_seek_penalty.PropertyId = StorageDeviceSeekPenaltyProperty; query_seek_penalty.QueryType = PropertyStandardQuery; WinAPI.DEVICE_SEEK_PENALTY_DESCRIPTOR query_seek_penalty_desc = new WinAPI.DEVICE_SEEK_PENALTY_DESCRIPTOR(); uint returned_query_seek_penalty_size = 0; bool query_seek_penalty_result = WinAPI.DeviceIoControl(hDrive, IOCTL_STORAGE_QUERY_PROPERTY, ref query_seek_penalty, Convert.ToUInt32(Marshal.SizeOf(query_seek_penalty)), ref query_seek_penalty_desc, Convert.ToUInt32(Marshal.SizeOf(query_seek_penalty_desc)), ref returned_query_seek_penalty_size, IntPtr.Zero); hDrive.Close(); if (query_seek_penalty_result == false) { string message = GetErrorMessage(Marshal.GetLastWin32Error()); return("DeviceIoControl failed. " + message); } else { if (query_seek_penalty_desc.IncursSeekPenalty == false) { return("Result: This drive has NO SEEK penalty."); } else { return("Result: This drive has SEEK penalty."); } } }
/// <summary> /// Check, if Drive has NoSeekPenalty. If it's true, then it is a SSD /// </summary> /// <param name="diskindex">The Drive-Index</param> /// <returns></returns> public static string HasNoSeekPenalty(byte diskindex) { string sDrive = @"\\.\PhysicalDrive" + diskindex.ToString(); SafeFileHandle hDrive = WinAPI.CreateFileW(sDrive, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero); // No access to drive if (hDrive == null || hDrive.IsInvalid) { string message = GetErrorMessage(Marshal.GetLastWin32Error()); return "CreateFile failed. " + message; } uint IOCTL_STORAGE_QUERY_PROPERTY = CTL_CODE(IOCTL_STORAGE_BASE, 0x500, METHOD_BUFFERED, FILE_ANY_ACCESS); // From winioctl.h WinAPI.STORAGE_PROPERTY_QUERY query_seek_penalty = new WinAPI.STORAGE_PROPERTY_QUERY(); query_seek_penalty.PropertyId = StorageDeviceSeekPenaltyProperty; query_seek_penalty.QueryType = PropertyStandardQuery; WinAPI.DEVICE_SEEK_PENALTY_DESCRIPTOR query_seek_penalty_desc = new WinAPI.DEVICE_SEEK_PENALTY_DESCRIPTOR(); uint returned_query_seek_penalty_size = 0; bool query_seek_penalty_result = WinAPI.DeviceIoControl(hDrive, IOCTL_STORAGE_QUERY_PROPERTY, ref query_seek_penalty, Convert.ToUInt32(Marshal.SizeOf(query_seek_penalty)), ref query_seek_penalty_desc, Convert.ToUInt32(Marshal.SizeOf(query_seek_penalty_desc)), ref returned_query_seek_penalty_size, IntPtr.Zero); hDrive.Close(); if (query_seek_penalty_result == false) { string message = GetErrorMessage(Marshal.GetLastWin32Error()); return "DeviceIoControl failed. " + message; } else { if (query_seek_penalty_desc.IncursSeekPenalty == false) { return "Result: This drive has NO SEEK penalty."; } else { return "Result: This drive has SEEK penalty."; } } }