For Win32, there is no single API that directly tells whether a file or directory is on an HDD or SSD.
DEVICE_SEEK_PENALTY_DESCRIPTOR from IOCTL_STORAGE_QUERY_PROPERTY is one supported way to determine whether a device incurs a seek penalty:
-
IncursSeekPenalty = TRUEtypically indicates rotating media behavior. -
IncursSeekPenalty = FALSEindicates no seek penalty.
That is the API in the provided Win32 context that is relevant to distinguishing storage behavior.
For media type information, these APIs and classes are available:
-
SHGetDriveMediareturns the type of media in a given drive, asARCONTENTflags. -
DEVICE_MEDIA_INFOcontainsMediaTypefor disk and removable disk media. -
Win32_DiskDrive.MediaTypecan report values such as:-
External hard disk media -
Removable media -
Fixed hard disk -
Unknown
-
Those describe media category, but the provided context does not state that they reliably distinguish HDD versus SSD.
To determine which physical disk a drive or path belongs to, the documented Win32 method is:
- Call
GetVolumePathNamewith the file or directory path to get the mount point. - Call
GetVolumeNameForVolumeMountPointwith that mount point to get the volume name. - Remove the trailing backslash from the volume name.
- Call
CreateFileon the volume name to open the volume. - Send
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTSto get the disk numbers. - Build physical disk paths such as
\\?\PhysicalDriveX. - Call
CreateFileon each physical disk path. - Send
IOCTL_DISK_GET_DRIVE_LAYOUT_EXto get the partition list. - Inspect the returned partition entries as needed.
If only fixed versus removable is needed, WMI can also help:
- Query
Win32_LogicalDisk - Check
DriveType-
2= Removable drive -
3= Local hard disk
-