简体   繁体   中英

How to execute SMART Self-Test

I am writing an application based on .NET that checks the heath of a disk or more disks in a system.

I can use the WMI interface for ATAPI to get at the SMART data, followed by link: http://wutils.com/wmi/root/wmi/msstoragedriver_atapismartdata/

But i don't know how to execute SMART Self-Test. Is there any ways to do it by using C#?

I was trying to do the same and found out that it is possible to start the test via WMI. Have a look at the WMI class MSStorageDriver_FailurePredictFunction under the ROOT\\WMI namespace. The class has several different methods you can use. One of them is the ExecuteSelfTest method. Look at this example I created with the WMI Code Creator( WMICodeCreator )

            try
            {
                ManagementObject classInstance = 
                    new ManagementObject("root\\WMI", 
                    "MSStorageDriver_FailurePredictFunction.InstanceName='SCSI\Disk&Ven_Hitachi&Prod_HDS721010CLA632\4&7d4adf0&0&010000_0'",
                    null);

                // Obtain in-parameters for the method
                ManagementBaseObject inParams = 
                    classInstance.GetMethodParameters("ExecuteSelfTest");

                // Add the input parameters.
                inParams["Subcommand"] =  1;

                // Execute the method and obtain the return values.
                ManagementBaseObject outParams = 
                    classInstance.InvokeMethod("ExecuteSelfTest", inParams, null);

                // List outParams
                Console.WriteLine("Out parameters:");
                Console.WriteLine("ReturnCode: " + outParams["ReturnCode"]);
            }
            catch(ManagementException err)
            {
                MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
            }

You have to change the InstanceName in the code above to your diskname. What I also found out is that the "Subcommand" parameter is the factor which determines what test you actually start. If the value is 1 you start the Short Self-test . If the value is 2 you start the Extended Self-test .

As an output Parameter you can receive one of those three values ['0', '1', '2'] while 0 stands for 'Successful Completion' , 1 stands for 'Captive Mode Required' and 2 stands for 'Unsuccessful Completion' . Source( FailurePredictFunction )

Thanks LuXxn,

I already succeed as your guide, but i only succeed to execute Short Selft-test and Extended Selft-test. Even my Hard-disk also supports to test SMART Conveyance self-test routine immediately in off-line mode (value = 03h). But it always return code is 1 'Captive Mode Required'. Do you know how to execute this test ?

I followed ATA/ATAPI Comment Set ACS-3 specification [Table 127, http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf] to know exactly input parameters to excute SMART Selft-test

inParams["Subcommand"] = ?value;

    /* *********************************************************************
        * Table 127 — SMART EXECUTE OFF-LINE IMMEDIATE Subcommands/Draft ATA/ATAPI Comment Set ACS-3
        * http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf 
        * Value    Description of subcommand to be processed
        * 00h      Execute SMART off-line routine immediately in off-line mode
        * 01h      Execute SMART Short self-test routine immediately in off-line mode
        * 02h      Execute SMART Extended self-test routine immediately in off-line mode
        * 03h      Execute SMART Conveyance self-test routine immediately in off-line mode
        * 04h      Execute SMART Selective self-test routine immediately in off-line mode
        * 05h-3Fh  Reserved
        * 40h-7Eh  Vendor specific
        * 7Fh      Abort off-line mode self-test routine
        * 80h      Reserved
        * 81h      Execute SMART Short self-test routine immediately in captive mode
        * 82h      Execute SMART Extended self-test routine immediately in captive mode
        * 83h      Execute SMART Conveyance self-test routine immediately in captive mode
        * 84h      Execute SMART Selective self-test routine immediately in captive mode
        * 85h-8Fh  Reserved
        * 90h-FFh  Vendor specific
        * ********************************************************************/

To know my hard-disk can support execute SMART conveyance selftest in offline mode, I sent SMART command to get the value of OfflineCollectCapability, then return value is 0x73 and followed ATA/ATAPI Comment Set ACS-3 specification [Table 133, http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf]

    /**********************************************************************
     * Table 133 — Offline Data Collection Capabilities
     *  Bit     Description
     *  7       Reserved
     *  6       SELECTIVE SELF-TEST IMPLEMENTED bit – If this bit is cleared to zero, the device does not implement the
     *          Selective self-test routine. If this bit is set to one, the device implements the Selective self-test routine.
     *  5       CONVEYANCE SELF-TEST IMPLEMENTED bit – If this bit is cleared to zero, the device does not implement the
     *          Conveyance self-test routines. If this bit is set to one, the device implements the Conveyance self-test
     *          routines.
     *  4       SELF-TEST IMPLEMENTED bit – If this bit is cleared to zero, the device does not implement the Short and
     *          Extended self-test routines. If this bit is set to one, the device implements the Short and Extended
     *          self-test routines.
     *  3       OFF-LINE READ SCANNING IMPLEMENTED bit – If this bit is cleared to zero, the device does not support
     *          off-line read scanning. If this bit is set to one, the device supports off-line read scanning.
     *  2       ABORT/RESTART OFF-LINE BY HOST bit – If this bit is set to one, then the device shall abort all off-line data
     *          collection activity initiated by a SMART EXECUTE OFF-LINE IMMEDIATE command upon receipt of a
     *          new command within 2 seconds of receiving the new command. If this bit is cleared to zero, the device
     *          shall suspend off-line data collection activity after an interrupting command and resume off-line data
     *          collection activity after some vendor-specified event.
     *  1       Vendor specific.
     *  0       EXECUTE OFF-LINE IMMEDIATE IMPLEMENTED bit – If this bit is set to one, then the SMART EXECUTE
     *          OFF-LINE IMMEDIATE command is implemented by this device. If this bit is cleared to zero, then the
     *          SMART EXECUTE OFF-LINE IMMEDIATE command is not implemented by this device.
     * *******************************************************************/

Thanks for your help,

Bamboo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM