windows 如何确定存储类型(SSD 驱动器或 HHD .mechanical 驱动器),使用 C 语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1712642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine storage type (SSD drive or HHD .mechanical drive), using C language
提问by Shaobo Wang
How can I, from a C program, read the hardware information of a drive? (I.e. to determine if the drive is an SSD or a mechanical disk.)
如何从 C 程序中读取驱动器的硬件信息?(即判断驱动器是SSD还是机械盘。)
回答by pan1nx
SSD are supposed to identify themselves as non-rotative. For linux, as example, you can get the info via sysfs:
SSD 应该将自己标识为非旋转的。例如,对于 linux,您可以通过 sysfs 获取信息:
cat /sys/block/sda/queue/rotational
If it returns 0, you have SSD...
如果它返回 0,你有 SSD...
回答by Simon_Weaver
Have you considered doing a read/write test to try to determine capabilities ?
您是否考虑过进行读/写测试来尝试确定功能?
回答by Jeremy Morgan
You can use the GetDriveTypeMethod from the win32 library, and you might be able to differentiate that way, or you use GetVolumeInformation to try and determine it from the label.
您可以使用win32 库中的GetDriveType方法,您也许可以通过这种方式进行区分,或者您可以使用 GetVolumeInformation 尝试从标签中确定它。
回答by Windows programmer
This guess is a long shot but I can't find anything better. In the device's identification structure, see if it supports acoustic management. Old disk drives didn't, but maybe most modern disk drives do. Obviously SSDs don't need acoustic management but let's hope they'll say they don't, instead of pretending to be disk drives.
这个猜测很长,但我找不到更好的。在设备的标识结构中,查看是否支持声音管理。旧磁盘驱动器没有,但也许大多数现代磁盘驱动器都有。显然 SSD 不需要声学管理,但我们希望他们会说不需要,而不是假装是磁盘驱动器。