Example #1
0
        /*
         * This part is a mix between Llewellyn Kruger's and derek wilson's code. Modification by Quy Nguyen
         */

        public void GetSmartThreshold(HDD drive)
        {
            // this is the actual physical drive number
            int index = drive.Index;

            _logger.AppendLine($"Drive Number {index} Drive {drive.Id}, {drive.Model}");

            // get wmi access to hdd
            var searcher = new ManagementObjectSearcher("Select * from Win32_DiskDrive");

            //searcher.Scope = new ManagementScope(@"\root\wmi");
            searcher.Scope = scope2;

            // retreive threshold values foreach attribute
            searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictThresholds");
            int iDriveIndex = 0;

            try
            {
                foreach (ManagementObject data in searcher.Get())
                {
                    if (index == iDriveIndex)
                    {
                        Byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
                        for (int i = 0; i < 30; ++i)
                        {
                            try
                            {
                                int id     = bytes[i * 12 + 2];
                                int thresh = bytes[i * 12 + 3];
                                if (id == 0)
                                {
                                    continue;
                                }

                                var attr = drive.Attributes[id];
                                attr.Threshold = thresh;
                            }
                            catch
                            {
                                // given key does not exist in attribute collection (attribute not in the dictionary of attributes)
                            }
                        }
                    }
                    iDriveIndex++;
                }
            }
            catch (System.Management.ManagementException)
            {
                _logger.AppendLine("SMART not supported.");
            }
        }
Example #2
0
        /*
         * This part is modified from Llewellyn Kruger's code. Modification by Quy Nguyen
         */

        public void compileSmartInfo(HDD drive)
        {
            var output = new StringBuilder();

            {
                output.AppendLine("-----------------------------------------------------");
                output.AppendLine(" DRIVE (" + drive.Health + "): " + drive.Serial + " - " + drive.Model + " - " + drive.Type);
                output.AppendLine("-----------------------------------------------------");
                output.AppendLine("");

                output.AppendLine("ID# ATTRIBUTE_NAME                           CURRENT  WORST  THRESHOLD  DATA       STATUS");
                foreach (var attr in drive.Attributes)
                {
                    if (attr.Value.HasData)
                    {
                        output.AppendLine(string.Format("{4,3} {0,-40} {1,-8} {2,-6} {3,-10} {5,-10} {6}", attr.Value.Attribute, attr.Value.Current, attr.Value.Worst, attr.Value.Threshold, attr.Key.ToString(), attr.Value.Data, ((attr.Value.IsOK) ? "ok" : attr.Value.Health)));
                    }
                }
            }
            drive.smart = output.ToString();
        }
Example #3
0
        /*
         * this part is by derek wilson, with some modification by Quy Nguyen to make it work here
         */

        public Dictionary <int, HDD> GetAllDisks()
        {
            // retrieve list of drives on computer (this will return both HDD's and CDROM's and Virtual CDROM's)
            var dicDrives  = new Dictionary <int, HDD>();
            var wdSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

            wdSearcher.Scope = scope;

            // extract model and interface information
            int iDriveIndex = 0;

            foreach (ManagementObject drive in wdSearcher.Get())
            {
                var hdd = new HDD();
                hdd.Id    = drive["DeviceId"].ToString().Trim();
                hdd.Index = Convert.ToInt32(drive["Index"].ToString().Trim());
                hdd.Model = drive["Model"].ToString().Trim();
                hdd.Type  = drive["InterfaceType"].ToString().Trim();
                _logger.AppendLine($"disk drive {hdd.Index} {hdd.Id} {hdd.Model}");
                dicDrives.Add(hdd.Index, hdd); // modified from iDriveIndex to Index
                iDriveIndex++;
            }
            return(dicDrives);
        }
Example #4
0
        /*
         * This part by Quy Nguyen
         * Check some specific attributes to see if the drive is still good
         */

        public void AnalyseSmartData(HDD drive)
        {
            /*
             * warning health if at least one of these attributes have value over 0
             * Critical attribute according to wikipedia
             * https://en.wikipedia.org/wiki/S.M.A.R.T.#Known_ATA_S.M.A.R.T._attributes
             * 0x05 "Reallocated sector count"
             * 0xC4 "Reallocation count"
             * 0xC5 "Current pending sector count"
             * 0xC6 "Offline scan uncorrectable count"
             * 0xC7 "UDMA CRC error rate"
             * 0x0A Spin Retry Count
             * 0xB8 End-to-End error
             * 0xBB Reported Uncorrectable Errors
             * 0xBC Command Timeout
             * 0xC9 Soft Read Error Rate
             */
            bool warning = false;
            bool unknown = true;

            foreach (var attr in drive.Attributes)
            {
                if (attr.Value.HasData)
                {
                    unknown = false;
                    int id = attr.Key;
                    if ((id == 0x05 || id == 0xC4 || id == 0xC5 || id == 0xC6 || id == 0xC7 ||
                         id == 0x0A || id == 0xB8 || id == 0xBB || id == 0xBC || id == 0xC9) &&
                        attr.Value.Data != 0)
                    {
                        warning           = true;
                        attr.Value.IsOK   = false;
                        attr.Value.Health = "warning";
                    }
                }
            }

            /*
             * failed health if any attribute is equal to or lower than its threshold
             */
            bool failed = false;

            foreach (var attr in drive.Attributes)
            {
                if (attr.Value.HasData)
                {
                    if (attr.Value.Worst <= attr.Value.Threshold)
                    {
                        failed            = true;
                        attr.Value.IsOK   = false;
                        attr.Value.Health = "failed";
                    }
                }
            }

            if (unknown)
            {
                drive.IsOK   = null;
                drive.Health = "UNKNOWN";
            }
            else if (failed)
            {
                drive.IsOK   = false;
                drive.Health = "FAILED";
            }
            else if (warning)
            {
                drive.IsOK   = false;
                drive.Health = "WARNING";
            }
            else
            {
                drive.IsOK   = true;
                drive.Health = "GOOD";
            }
        }
Example #5
0
        public void GetSmartInformation(HDD drive)
        {
            // this is the actual physical drive number
            int index = drive.Index;

            _logger.AppendLine($"Drive Number {index} Drive {drive.Id}, {drive.Model}");

            // get wmi access to hdd
            var searcher = new ManagementObjectSearcher("Select * from Win32_DiskDrive");

            //searcher.Scope = new ManagementScope(@"\root\wmi");
            searcher.Scope = scope2;

            // retrieve attribute flags, value worst and vendor data information
            searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictData");
            int iDriveIndex = 0;

            try
            {
                foreach (ManagementObject data in searcher.Get())
                {
                    if (index == iDriveIndex)
                    {
                        Byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
                        for (int i = 0; i < 30; ++i)
                        {
                            int id = 0;
                            try
                            {
                                id = bytes[i * 12 + 2];

                                int flags = bytes[i * 12 + 4];     // least significant status byte, +3 most significant byte, but not used so ignored.
                                                                   //bool advisory = (flags & 0x1) == 0x0;
                                bool failureImminent = (flags & 0x1) == 0x1;
                                //bool onlineDataCollection = (flags & 0x2) == 0x2;

                                int value      = bytes[i * 12 + 5];
                                int worst      = bytes[i * 12 + 6];
                                int vendordata = BitConverter.ToInt32(bytes, i * 12 + 7);
                                if (id == 0)
                                {
                                    continue;
                                }

                                var attr = drive.Attributes[id];
                                attr.Current = value;
                                attr.Worst   = worst;
                                attr.Data    = vendordata;
                                attr.IsOK    = !failureImminent;
                            }
                            catch
                            {
                                // given key does not exist in attribute collection (attribute not in the dictionary of attributes)
                                _logger.AppendLine($"SMART Key Not found {id}");
                            }
                        }
                    }
                    iDriveIndex++;
                }
            }
            catch (System.Management.ManagementException)
            {
                _logger.AppendLine("SMART not supported.");
            }
        }