Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get S.M.A.R.T. information for external drives

Tags:

c#

.net

wmi

I am trying to get SMART information for external USB drives. I am using the following query to get the temperature of the drive, however the query always return a single object in the collection which is my internal HDD.

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI",
"SELECT * FROM MSStorageDriver_ATAPISmartData");

foreach (ManagementObject queryObj in searcher.Get())
{
   if (queryObj["VendorSpecific"] != null)
   {
       byte[] arrVendorSpecific = (byte[])(queryObj["VendorSpecific"]);
       string temp = arrVendorSpecific[115].ToString();
    }
 }

So far I have tried 3 different drives from different vendors but all my attempts at getting the information failed.

What am I doing wrong and how can I get the SMART information for external drives through WMI?

EDIT: I tried PassMarks's DiskCheckup and it is able to get the SMART information for all drives.

EDIT2:

Digging deeper I found this paragraph in SmartMonTools INSTALL file under Windows:

SCSI and USB devices are accessed through SPTI. Special driver support is not required.

Now I think all I need is to put that into an WMI query, can someone help?

like image 408
Zaid Amir Avatar asked Jul 22 '14 12:07

Zaid Amir


People also ask

Why is my computer not reading my external hard drive?

Common issues include: Outdated drivers – Your existing drivers may be corrupted. Or, they may need updating to establish communication between the external hard drive and your system. Faulty connection – Try plugging the external hard drive into a different port to see if it's a port-related issue.

Does smart work over USB?

Yes (maybe). There's an open-source kernel driver OS-X-SAT-SMART-Driver for Mac OS X that will work for some USB and Firewire enclosures. It uses SAT (SCSI ATA Translation) to pass the SMART commands through to the hard drive, so only works if your enclosure supports SAT.

How do I get Windows 10 to recognize my external hard drive?

Simply plug it in, go to Computer Managent and to Disk Management. There, select the external HDD and right-click to assign a drive letter. Very often this solves issues with HDDs showing up in the device manager but not in file explorer.


1 Answers

SMART is part of the ATA standard. Even the name of the WMI class reflects that.

When you plug in a device through USB, it communicates with your system with the USB mass storage protocol. It simply doesn't support SMART. Generally, an USB attached hard disk is no different than a USB attached pendrive or SD card, so SMART makes no sense here. Same goes for SCSI, Firewire, etc, they are different protocols. You don't know what sits on the other end, it may not speak ATA at all.

Some protocols, like the one used by USB hard disks, allow ATA commands to be passed through different protocol layers, as you said, SPTI is one of those methods. Although it is supported by many devices, it's kind of a hack and may not be supported by every USB disk controller, or may even cause problems (any ATA packet may be passed through, which can be dangerous). RAID devices may use other proprietary protocols to pass through ATA commands.

So basically, there is no general protocol to speak to those devices, and even though I cannot be absolutely positive, I'm pretty sure it is just not supported by WMI, because it's a very complex task.

Smartmontools has a huge database of devices, disks and controllers alike (check out drivedb.h for an insight, it's massive), it is tested and regularly updated, and that's how it knows how to communicate with each of those devices. Low-level device voodoo magic, basically. OS'es in general don't need to know all that stuff, they just know enough how to speak USB, Firewire, RAID devices, etc., with the respective drivers. Crossing protocol boundaries is not something these drivers generally do.

So I suggest that you use smartmontools and parse its output, it will save you from a lot of pain.

like image 99
fejesjoco Avatar answered Oct 01 '22 23:10

fejesjoco