From fa6914dd0e8d68827a5d6551a300adf01780c545 Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Tue, 29 Oct 2002 10:06:20 +0000
Subject: [PATCH] smartctl would previously print the LBA of a self-test if it
 completed, and the LBA was not 0 or 0xff...f

However according to the specs this is not correct.  According to the specs, if
the self-test completed without error then LBA is undefined.  This version fixes that.


// T13/1321D revision 1c: (Data structure Rev #1)

      //The failing LBA shall be the LBA of the uncorrectable sector
      //that caused the test to fail. If the device encountered more
      //than one uncorrectable sector during the test, this field
      //shall indicate the LBA of the first uncorrectable sector
      //encountered. If the test passed or the test failed for some
      //reason other than an uncorrectable sector, the value of this
      //field is undefined.

      // This is true in ALL ATA-5 specs


git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@151 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/VERSION      |  2 +-
 sm5/ataprint.c   | 24 ++++++++++++++++++------
 sm5/ataprint.cpp | 24 ++++++++++++++++++------
 sm5/smartd.c     |  6 +++---
 sm5/smartd.cpp   |  6 +++---
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/sm5/VERSION b/sm5/VERSION
index 98d9bcb75..3c032078a 100644
--- a/sm5/VERSION
+++ b/sm5/VERSION
@@ -1 +1 @@
-17
+18
diff --git a/sm5/ataprint.c b/sm5/ataprint.c
index e2e471fce..44407a06d 100644
--- a/sm5/ataprint.c
+++ b/sm5/ataprint.c
@@ -29,7 +29,7 @@
 #include "smartctl.h"
 #include "extern.h"
 
-const char *CVSid2="$Id: ataprint.c,v 1.35 2002/10/28 23:46:59 ballen4705 Exp $"
+const char *CVSid2="$Id: ataprint.c,v 1.36 2002/10/29 10:06:20 ballen4705 Exp $"
 CVSID1 CVSID2 CVSID3 CVSID6;
 
 // for passing global control variables
@@ -376,8 +376,8 @@ void PrintSmartAttribWithThres (struct ata_smart_values data,
       int failednow,failedever;
       char attributename[64];
 
-      failednow =disk->current <= thre->threshold;
-      failedever=disk->worst   <= thre->threshold;
+      failednow = (disk->current <= thre->threshold);
+      failedever= (disk->worst   <= thre->threshold);
       
       // These break out of the loop if we are only printing certain entries...
       if (onlyfailed==1 && (!disk->status.flag.prefailure || !failednow))
@@ -650,11 +650,23 @@ int ataPrintSmartSelfTestlog(struct ata_smart_selftestlog data,int allentries){
       case 15:msgstat="Test in progress             "; break;
       default:msgstat="Unknown test status          ";
       }
-      
-      retval+=errorfound;
 
+      retval+=errorfound;
       sprintf(percent,"%1d0%%",(log->selfteststatus)&0xf);
-      if (log->lbafirstfailure==0xffffffff || log->lbafirstfailure==0x00000000)
+
+      // T13/1321D revision 1c: (Data structure Rev #1)
+
+      //The failing LBA shall be the LBA of the uncorrectable sector
+      //that caused the test to fail. If the device encountered more
+      //than one uncorrectable sector during the test, this field
+      //shall indicate the LBA of the first uncorrectable sector
+      //encountered. If the test passed or the test failed for some
+      //reason other than an uncorrectable sector, the value of this
+      //field is undefined.
+
+      // This is true in ALL ATA-5 specs
+      
+      if (!errorfound || log->lbafirstfailure==0xffffffff || log->lbafirstfailure==0x00000000)
 	sprintf(firstlba,"%s","");
       else	
 	sprintf(firstlba,"0x%08x",log->lbafirstfailure);
diff --git a/sm5/ataprint.cpp b/sm5/ataprint.cpp
index 2e332784c..15cde024f 100644
--- a/sm5/ataprint.cpp
+++ b/sm5/ataprint.cpp
@@ -29,7 +29,7 @@
 #include "smartctl.h"
 #include "extern.h"
 
-const char *CVSid2="$Id: ataprint.cpp,v 1.35 2002/10/28 23:46:59 ballen4705 Exp $"
+const char *CVSid2="$Id: ataprint.cpp,v 1.36 2002/10/29 10:06:20 ballen4705 Exp $"
 CVSID1 CVSID2 CVSID3 CVSID6;
 
 // for passing global control variables
@@ -376,8 +376,8 @@ void PrintSmartAttribWithThres (struct ata_smart_values data,
       int failednow,failedever;
       char attributename[64];
 
-      failednow =disk->current <= thre->threshold;
-      failedever=disk->worst   <= thre->threshold;
+      failednow = (disk->current <= thre->threshold);
+      failedever= (disk->worst   <= thre->threshold);
       
       // These break out of the loop if we are only printing certain entries...
       if (onlyfailed==1 && (!disk->status.flag.prefailure || !failednow))
@@ -650,11 +650,23 @@ int ataPrintSmartSelfTestlog(struct ata_smart_selftestlog data,int allentries){
       case 15:msgstat="Test in progress             "; break;
       default:msgstat="Unknown test status          ";
       }
-      
-      retval+=errorfound;
 
+      retval+=errorfound;
       sprintf(percent,"%1d0%%",(log->selfteststatus)&0xf);
-      if (log->lbafirstfailure==0xffffffff || log->lbafirstfailure==0x00000000)
+
+      // T13/1321D revision 1c: (Data structure Rev #1)
+
+      //The failing LBA shall be the LBA of the uncorrectable sector
+      //that caused the test to fail. If the device encountered more
+      //than one uncorrectable sector during the test, this field
+      //shall indicate the LBA of the first uncorrectable sector
+      //encountered. If the test passed or the test failed for some
+      //reason other than an uncorrectable sector, the value of this
+      //field is undefined.
+
+      // This is true in ALL ATA-5 specs
+      
+      if (!errorfound || log->lbafirstfailure==0xffffffff || log->lbafirstfailure==0x00000000)
 	sprintf(firstlba,"%s","");
       else	
 	sprintf(firstlba,"0x%08x",log->lbafirstfailure);
diff --git a/sm5/smartd.c b/sm5/smartd.c
index dfdad3c63..0e42d282e 100644
--- a/sm5/smartd.c
+++ b/sm5/smartd.c
@@ -43,7 +43,7 @@
 
 // CVS ID strings
 extern const char *CVSid1, *CVSid2;
-const char *CVSid6="$Id: smartd.c,v 1.38 2002/10/29 00:02:43 ballen4705 Exp $" 
+const char *CVSid6="$Id: smartd.c,v 1.39 2002/10/29 10:06:20 ballen4705 Exp $" 
 CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
 
 // global variable used for control of printing, passing arguments, etc.
@@ -516,7 +516,7 @@ int ataCheckDevice(atadevices_t *drive){
 	    while (*loc && *loc==' ') loc++;
 	    
 	    // warning message
-	    printout(LOG_CRIT,"Device: %s, Failed SMART usage attribute: %s. Use smartctl -v %s.\n", name, loc, name);
+	    printout(LOG_CRIT,"Device: %s, Failed SMART usage attribute: %s.\n", name, loc, name);
 	  }
 	}
 	
@@ -1098,7 +1098,7 @@ int main (int argc, char **argv){
   
   // if there was no config file, create needed entries
   if (!entries){
-    printout(LOG_INFO,"smartctl: file %s not found. Searching for devices.\n",CONFIGFILE);
+    printout(LOG_INFO,"smartd: file %s not found. Searching for devices.\n",CONFIGFILE);
     entries+=makeconfigentries(MAXATADEVICES,"/dev/hda",1,entries);
     entries+=makeconfigentries(MAXSCSIDEVICES,"/dev/sda",0,entries);
   }
diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp
index 6269b613f..f0e6fe996 100644
--- a/sm5/smartd.cpp
+++ b/sm5/smartd.cpp
@@ -43,7 +43,7 @@
 
 // CVS ID strings
 extern const char *CVSid1, *CVSid2;
-const char *CVSid6="$Id: smartd.cpp,v 1.38 2002/10/29 00:02:43 ballen4705 Exp $" 
+const char *CVSid6="$Id: smartd.cpp,v 1.39 2002/10/29 10:06:20 ballen4705 Exp $" 
 CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
 
 // global variable used for control of printing, passing arguments, etc.
@@ -516,7 +516,7 @@ int ataCheckDevice(atadevices_t *drive){
 	    while (*loc && *loc==' ') loc++;
 	    
 	    // warning message
-	    printout(LOG_CRIT,"Device: %s, Failed SMART usage attribute: %s. Use smartctl -v %s.\n", name, loc, name);
+	    printout(LOG_CRIT,"Device: %s, Failed SMART usage attribute: %s.\n", name, loc, name);
 	  }
 	}
 	
@@ -1098,7 +1098,7 @@ int main (int argc, char **argv){
   
   // if there was no config file, create needed entries
   if (!entries){
-    printout(LOG_INFO,"smartctl: file %s not found. Searching for devices.\n",CONFIGFILE);
+    printout(LOG_INFO,"smartd: file %s not found. Searching for devices.\n",CONFIGFILE);
     entries+=makeconfigentries(MAXATADEVICES,"/dev/hda",1,entries);
     entries+=makeconfigentries(MAXSCSIDEVICES,"/dev/sda",0,entries);
   }
-- 
GitLab