From 07c2f93b8804d4191cc8a8a9caedfe9e0a8f5da5 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Sat, 17 Oct 2009 20:14:17 +0000
Subject: [PATCH] Add missing check for log page 0x11 support to smartctl '-l
 sataphy' option.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@2960 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG    |  9 ++++++---
 smartmontools/ataprint.cpp | 30 ++++++++++++++++++++----------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index 049afebed..15b99d0fd 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -43,10 +43,13 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] Add missing check for log page 0x11 support to smartctl
+       '-l sataphy' option.
+
   [CF] Add USB ID of Freecom Hard Drive XS.
 
-  [AS] Linux: Autodetect DELL PERC and MegaRAID controllers. 
-       Hiding debug messages coming from megaraid code.  
+  [AS] Linux: Autodetect DELL PERC and MegaRAID controllers.
+       Hiding debug messages coming from megaraid code.
 
   [AS] Linux: Fixed SATA drives support on megaraid device (see ticket #15).
 
@@ -59,7 +62,7 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
   [AS] FreeBSD: cam_get_umassno rewritten using XPT_PATH_INQ
 
-  [AS] FreeBSD: do not open/close cam device on every request for SCSI 
+  [AS] FreeBSD: do not open/close cam device on every request for SCSI
        disks. Use com->camdev both for SCSI and ATAPICAM.
 
   [AS] FreeBSD: added support for the ada disks, based on agapon patch
diff --git a/smartmontools/ataprint.cpp b/smartmontools/ataprint.cpp
index 9276e6a67..78ad54945 100644
--- a/smartmontools/ataprint.cpp
+++ b/smartmontools/ataprint.cpp
@@ -2051,10 +2051,12 @@ int ataPrintMain (ata_device * device, const ata_print_options & options)
   ata_smart_log_directory smartlogdir_buf, gplogdir_buf;
   const ata_smart_log_directory * smartlogdir = 0, * gplogdir = 0;
 
-  if (   options.gp_logdir || options.smart_logdir
-      || options.sataphy || options.smart_ext_error_log
+  if (   options.gp_logdir
+      || options.smart_logdir
+      || options.smart_ext_error_log
       || options.smart_ext_selftest_log
-      || !options.log_requests.empty()                 ) {
+      || options.sataphy
+      || !options.log_requests.empty() ) {
     PRINT_ON(con);
     if (isGeneralPurposeLoggingCapable(&drive))
       pout("General Purpose Logging (GPL) feature set supported\n");
@@ -2063,7 +2065,8 @@ int ataPrintMain (ata_device * device, const ata_print_options & options)
     bool need_smart_logdir = options.smart_logdir;
     bool need_gp_logdir    = (   options.gp_logdir
                               || options.smart_ext_error_log
-                              || options.smart_ext_selftest_log);
+                              || options.smart_ext_selftest_log
+                              || options.sataphy               );
     unsigned i;
     for (i = 0; i < options.log_requests.size(); i++) {
       if (options.log_requests[i].gpl)
@@ -2323,12 +2326,19 @@ int ataPrintMain (ata_device * device, const ata_print_options & options)
 
   // Print SATA Phy Event Counters
   if (options.sataphy) {
-    unsigned char log_11[512] = {0, };
-    unsigned char features = (options.sataphy_reset ? 0x01 : 0x00);
-    if (!ataReadLogExt(device, 0x11, features, 0, log_11, 1))
-      failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
-    else
-      PrintSataPhyEventCounters(log_11, options.sataphy_reset);
+    unsigned nsectors = GetNumLogSectors(gplogdir, 0x11, true);
+    if (!nsectors)
+      pout("SATA Phy Event Counters (GP Log 0x11) not supported\n");
+    else if (nsectors != 1)
+      pout("SATA Phy Event Counters with %u sectors not supported\n", nsectors);
+    else {
+      unsigned char log_11[512] = {0, };
+      unsigned char features = (options.sataphy_reset ? 0x01 : 0x00);
+      if (!ataReadLogExt(device, 0x11, features, 0, log_11, 1))
+        failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
+      else
+        PrintSataPhyEventCounters(log_11, options.sataphy_reset);
+    }
   }
 
   // START OF THE TESTING SECTION OF THE CODE.  IF NO TESTING, RETURN
-- 
GitLab