Last active
December 2, 2021 14:23
-
-
Save jgottula/fea6bb27a3415049dfa85bbba6f28982 to your computer and use it in GitHub Desktop.
Reverse-engineered: enum DF_DEVICE_TYPE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reverse engineered based on Windows 10 version 21H1 | |
// used in defragsvc.dll, dfrgui.exe, and probably other places | |
// (the specific enum member names seen here were invented by me) | |
enum DF_DEVICE_TYPE | |
{ // CORRESPONDING "MEDIA TYPE" STRING [with string table index from DfrgUI.exe.mui] | |
TYPE_UNKNOWN = 0x0, // 1188 "Unknown" | |
TYPE_HARD_DISK_DRIVE = 0x1, // 1179 "Hard disk drive" | |
TYPE_REMOVABLE_DRIVE = 0x2, // 1180 "Removable drive" | |
TYPE_SOLID_STATE_DRIVE = 0x3, // 1181 "Solid state drive" | |
TYPE_SOLID_STATE_DRIVE__NTFS_OR_REFS = 0x4, // 1181 "Solid state drive" | |
TYPE_THIN_PROVISIONED_DRIVE = 0x5, // 1184 "Thin provisioned drive" | |
TYPE_STORAGE_SPACE = 0x6, // 1182 "Storage space" | |
TYPE_THIN_PROVISIONED_SPACE = 0x7, // 1183 "Thin provisioned space" | |
TYPE_VIRTUAL_HARD_DRIVE = 0x8, // 1187 "Virtual hard drive" | |
TYPE_VIRTUAL_HARD_DRIVE__PARENT = 0x9, // 1185 "Virtual hard drive" | |
TYPE_VIRTUAL_HARD_DRIVE__FULLY_ALLOCATED = 0xA, // 1186 "Virtual hard drive" | |
TYPE_TIERED_SPACE = 0xB, // 1204 "Tiered space" | |
TYPE_STORAGE_SPACE__SSD = 0xC, // 1182 "Storage space" | |
TYPE_STORAGE_SPACE__SSD__NTFS_OR_REFS = 0xD, // 1182 "Storage space" | |
}; | |
// here's the rough logic tree from defragsvc.dll: | |
// | |
// SxQueryVolume | |
// - calls SxIsRemovableFatVolume: | |
// - if GetDriveTypeW(...) == DRIVE_REMOVABLE and GetVolumeInformationW(...) FS type is "FAT32" or "FAT": TYPE_REMOVABLE_DRIVE | |
// - calls SxQueryDeviceType: | |
// - calls DeviceIoControl with IOCTL_STORAGE_QUERY_PROPERTY and StorageAdapterProperty: | |
// - if successful and BusType == BusTypeFileBackedVirtual: calls SxQueryDeviceTypeVirtualDiskSub: | |
// - calls GetStorageDependencyInformation: | |
// - if successful and DependencyTypeFlags has DEPENDENT_DISK_FLAG_PARENT: TYPE_VIRTUAL_HARD_DRIVE__PARENT | |
// - elif successful and DependencyTypeFlags has DEPENDENT_DISK_FLAG_FULLY_ALLOCATED: TYPE_VIRTUAL_HARD_DRIVE__FULLY_ALLOCATED | |
// - elif successful: TYPE_VIRTUAL_HARD_DRIVE | |
// - else: | |
// - if successful and BusType == BusTypeSpaces: this is noted down for later | |
// - calls DeviceIoControl with IOCTL_STORAGE_QUERY_PROPERTY and StorageDeviceLBProvisioningProperty: | |
// - if successful and ThinProvisioningEnabled != 0 and OptimalUnmapGranularity > 0: | |
// - if BusTypeSpaces from earlier: TYPE_THIN_PROVISIONED_SPACE | |
// - else: TYPE_THIN_PROVISIONED_DRIVE | |
// - else: calls DeviceIoControl with IOCTL_STORAGE_QUERY_PROPERTY and StorageSeekPenaltyProperty: | |
// - if successful and IncursSeekPenalty == FALSE: | |
// - if BusTypeSpaces from earlier: TYPE_STORAGE_SPACE__SSD | |
// - else: TYPE_SOLID_STATE_DRIVE | |
// - else: | |
// - if BusTypeSpaces from earlier: TYPE_STORAGE_SPACE | |
// - else: calls DeviceIoControl with IOCTL_ATA_PASS_THROUGH and command IDENTIFY DEVICE: | |
// - if successful and word 217 (NominalMediaRotationRate) == 1: TYPE_SOLID_STATE_DRIVE | |
// - else: calls SxQueryDeviceRandomReadDiskScore (gets WinSAT score): | |
// - if successful and score < 0x20001: TYPE_HARD_DISK_DRIVE | |
// - else: TYPE_SOLID_STATE_DRIVE | |
// - if all volume extents pass SxQueryDeviceDefragAppropriate(...): TYPE_SOLID_STATE_DRIVE | |
// - if type is TYPE_STORAGE_SPACE or TYPE_STORAGE_SPACE__SSD: | |
// - calls DeviceIoControl with FSCTL_QUERY_STORAGE_CLASSES: | |
// - if successful and TotalNumberOfTiers > 1: TYPE_TIERED_SPACE | |
// - if type is TYPE_SOLID_STATE_DRIVE or TYPE_STORAGE_SPACE__SSD: | |
// - if GetVolumeInformationW(...) FS type is "NTFS" or "REFS": | |
// - TYPE_SOLID_STATE_DRIVE becomes TYPE_SOLID_STATE_DRIVE__NTFS_OR_REFS | |
// - TYPE_STORAGE_SPACE__SSD becomes TYPE_STORAGE_SPACE__SSD__NTFS_OR_REFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment