2

Can someone explain technically how Windows identify the type of drive plugged into a computer?

I'm asking this question because I'm about to create a program that will only write data into a specific type of storage drive...and I'm curious how it happens behind the scenes.

  • Do you want to know how Windows gets the drive type or do you want to know how you(r program) can detect the drive type? – Werner Henze Nov 7 '13 at 8:19
  • Just wanted to know how Windows does the whole disk identification thing technically. – ducktapes Nov 7 '13 at 12:39
2

You can get this information from two places: wmic diskdrive and wmic logicaldrive - (and of course, their wmi bindings for equivilents).

The output of wmic diskdrive - note the capability descriptions and media type

Availability  BytesPerSector  Capabilities  CapabilityDescriptions                 Caption                       CompressionMethod  ConfigManagerErrorCode  ConfigManagerUserConfig  CreationClassName  DefaultBlockSize  Description  DeviceID            ErrorCleared  ErrorDescription  ErrorMethodology  FirmwareRevision  Index  InstallDate  InterfaceType  LastErrorCode  Manufacturer            MaxBlockSize  MaxMediaSize  MediaLoaded  MediaType              MinBlockSize  Model                         Name                NeedsCleaning  NumberOfMediaSupported  Partitions  PNPDeviceID                                                                  PowerManagementCapabilities  PowerManagementSupported  SCSIBus  SCSILogicalUnit  SCSIPort  SCSITargetId  SectorsPerTrack  SerialNumber      Signature   Size           Status  StatusInfo  SystemCreationClassName  SystemName  TotalCylinders  TotalHeads  TotalSectors  TotalTracks  TracksPerCylinder  
              512             {3, 4}        {"Random Access", "Supports Writing"}  Hitachi HDS723030ALA640                          0                       FALSE                    Win32_DiskDrive                      Disk drive   \\.\PHYSICALDRIVE0                                                    MKAO              0                   IDE                           (Standard disk drives)                              TRUE         Fixed hard disk media                Hitachi HDS723030ALA640       \\.\PHYSICALDRIVE0                                         1           IDE\DISKHITACHI_HDS723030ALA640_________________MKAOAA10\4&15828421&0&0.0.0                                                         0        0                0         0             63               KM3010HYNKXXGW                3000590369280  OK                  Win32_ComputerSystem     NYX         364801          255         5860528065    93024255     255                
                                                                                   HTC Android Phone USB Device                     0                       FALSE                    Win32_DiskDrive                      Disk drive   \\.\PHYSICALDRIVE4                                                    0000              4                   USB                           (Standard disk drives)                              TRUE                                              HTC Android Phone USB Device  \\.\PHYSICALDRIVE4                                         0           USBSTOR\DISK&VEN_HTC&PROD_ANDROID_PHONE&REV_0000\HT24YTV03821&0                                                                     0        0                0         0                              HT24YTV03820      0                          OK                  Win32_ComputerSystem     NYX                                                                                   
              512             {3, 4}        {"Random Access", "Supports Writing"}  Samsung SSD 840 Series                           0                       FALSE                    Win32_DiskDrive                      Disk drive   \\.\PHYSICALDRIVE1                                                    DXT0              1                   IDE                           (Standard disk drives)                              TRUE         Fixed hard disk media                Samsung SSD 840 Series        \\.\PHYSICALDRIVE1                                         2           IDE\DISKSAMSUNG_SSD_840_SERIES__________________DXT08B0Q\4&15828421&0&0.1.0                                                         0        0                0         1             63               1SG4ENCA4A8251 J  3142097946  250056737280   OK                  Win32_ComputerSystem     NYX         30401           255         488392065     7752255      255                
              512             {3, 4}        {"Random Access", "Supports Writing"}  ST92503010AS                                     0                       FALSE                    Win32_DiskDrive                      Disk drive   \\.\PHYSICALDRIVE3                                                    0005              3                   IDE                           (Standard disk drives)                              TRUE         Fixed hard disk media                ST92503010AS                  \\.\PHYSICALDRIVE3                                         1           IDE\DISKST92503010AS____________________________0005LVM1\4&15828421&0&0.3.0                                                         0        0                0         3             63               Y50HBBJ8          1668369528  250056737280   OK                  Win32_ComputerSystem     NYX         30401           255         488392065     7752255      255                
              512             {3, 4}        {"Random Access", "Supports Writing"}  FUJITSU MHW2040BH                                0                       FALSE                    Win32_DiskDrive                      Disk drive   \\.\PHYSICALDRIVE2                                                    0000              2                   IDE                           (Standard disk drives)                              TRUE         Fixed hard disk media                FUJITSU MHW2040BH             \\.\PHYSICALDRIVE2                                         2           IDE\DISKFUJITSU_MHW2040BH_______________________0000001C\4&15828421&0&0.2.0                                                         0        0                0         2             63               1KX07T2B57FL      976588      40007761920    OK                  Win32_ComputerSystem     NYX         4864            255         78140160      1240320      255                
                                                                                   HTC Android Phone USB Device                     0                       FALSE                    Win32_DiskDrive                      Disk drive   \\.\PHYSICALDRIVE5                                                    0000              5                   USB                           (Standard disk drives)                              TRUE                                              HTC Android Phone USB Device  \\.\PHYSICALDRIVE5                                         0           USBSTOR\DISK&VEN_HTC&PROD_ANDROID_PHONE&REV_0000\HT24YTV03821&1                                                                     0        1                0         0                              HT24YTV03821      0                          OK                  Win32_ComputerSystem     NYX                                                                                   

And here, the output of wmic logical drive - description here is what's mainly of interest.

Access  Availability  BlockSize  Caption  Compressed  ConfigManagerErrorCode  ConfigManagerUserConfig  CreationClassName  Description       DeviceID  DriveType  ErrorCleared  ErrorDescription  ErrorMethodology  FileSystem  FreeSpace      InstallDate  LastErrorCode  MaximumComponentLength  MediaType  Name  NumberOfBlocks  PNPDeviceID  PowerManagementCapabilities  PowerManagementSupported  ProviderName  Purpose  QuotasDisabled  QuotasIncomplete  QuotasRebuilding  Size           Status  StatusInfo  SupportsDiskQuotas  SupportsFileBasedCompression  SystemCreationClassName  SystemName  VolumeDirty  VolumeName               VolumeSerialNumber  
0                                C:       FALSE                                                        Win32_LogicalDisk  Local Fixed Disk  C:        3                                                            NTFS        139243769856                               255                     12         C:                                                                                                                                                                   249690058752                       FALSE               TRUE                          Win32_ComputerSystem     NYX                                               24FCB3E2            
0                                D:       FALSE                                                        Win32_LogicalDisk  Local Fixed Disk  D:        3                                                            NTFS        2459783610368                              255                     12         D:                                                                                                                                                                   3000457228288                      FALSE               TRUE                          Win32_ComputerSystem     NYX                      New Volume               C6DFE01A            
                                 G:                                                                    Win32_LogicalDisk  Removable Disk    G:        2                                                                                                                                                      G:                                                                                                                                                                                                                                                        Win32_ComputerSystem     NYX                                                                   
                                 H:                                                                    Win32_LogicalDisk  Removable Disk    H:        2                                                                                                                                                      H:                                                                                                                                                                                                                                                        Win32_ComputerSystem     NYX                                                                   
0                                Q:                                                                    Win32_LogicalDisk  Local Fixed Disk  Q:        3                                                                                                                                           12         Q:                                                                                                                                                                                                                                                        Win32_ComputerSystem     NYX                                                                   
0                                Y:       FALSE                                                        Win32_LogicalDisk  Local Fixed Disk  Y:        3                                                            NTFS        77826355200                                255                     12         Y:                                                                                                                                                                   250057060352                       FALSE               TRUE                          Win32_ComputerSystem     NYX                      Drive of Impending Doom  CCC0980F            

As for where this information is from - the disks themselves should have that information in smart (from what I can tell from smartmontools, some of the values reported are different , ssd's wouldn't have spin up time, for example). On linux hdparm gives you detailed information, the same way using wmic would (but much more conveniently)

Removable vs non removable drive is set on a flag on the drive - this is actually switchable with the right tools.

In short, it asks the disk

  • Wouldn't VID/PID play a role in this? I believe this is how the OS finds the correct drivers for a device and what it is, no? Agree that USB thumb drives have an identified bit that shows the OS that it is removable storage. – Carl B Nov 7 '13 at 5:42
  • It could, I'm actually working through my answer through tools I know work. In addition, you'd need to compare the VID/PID to a known list - it makes more sense to use the data off the drive itself for unknown, semi-generic devices. – Journeyman Geek Nov 7 '13 at 5:47
  • Thanks for the answer. The only tricky thing here I think is how Windows could tell if my local disk is an HDD or an SSD. – ducktapes Nov 7 '13 at 12:43
  • I don't think windows does - it wouldn't need to. What's more important is what commands it supports (like trim), which can be queried using the ATA command set I believe – Journeyman Geek Nov 7 '13 at 13:01
1

Well, here’s the technical details:

Windows 7 detects SSDs by using ATA8-ACS identify word 217: Nominal media rotation rate, with value 0001h as Non-rotating media like solid state devices. But not all SSDs adhere to the ATA8-ACS1 spec section 7.16.7.77, some may need firmware updates

Source

Canonical documentation is available here, (PDF) page 175. As such, it’s a mandatory field and not related to SMART.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.