From efee81447fd7d30d4c15293fb7ad01b8cd12f8d6 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Sat, 16 Jan 2010 15:46:08 +0000
Subject: [PATCH] Windows: Don't return false ATA version info if IDENTIFY data
 is build from IOCTL_STORAGE_QUERY_PROPERTY result or from 3ware CLI output.
 smartctl: Handle missing info about ATA version in '-i' output.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@3034 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG    |  5 +++++
 smartmontools/atacmds.cpp  |  9 +++++----
 smartmontools/ataprint.cpp | 39 ++++++++++++++++++++------------------
 smartmontools/os_win32.cpp |  6 ++----
 4 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index 75597c3d5..ff8308e58 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -43,6 +43,11 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] Windows: Don't return false ATA version info if IDENTIFY data
+       is build from IOCTL_STORAGE_QUERY_PROPERTY result or from 3ware CLI
+       output.
+       smartctl: Handle missing info about ATA version in '-i' output.
+
   [CF] smartctl: Don't print log directory if '-q errorsonly' is specified.
 
   [CF] smartctl: Fix option '-q, --quietmode' (ticket #11).
diff --git a/smartmontools/atacmds.cpp b/smartmontools/atacmds.cpp
index 87810090e..f4c977910 100644
--- a/smartmontools/atacmds.cpp
+++ b/smartmontools/atacmds.cpp
@@ -3,8 +3,8 @@
  * 
  * Home page of code is: http://smartmontools.sourceforge.net
  *
- * Copyright (C) 2002-9 Bruce Allen <smartmontools-support@lists.sourceforge.net>
- * Copyright (C) 2008-9 Christian Franke <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2002-10 Bruce Allen <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2008-10 Christian Franke <smartmontools-support@lists.sourceforge.net>
  * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
  * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
  *
@@ -58,7 +58,8 @@ extern smartmonctrl *con;
 // that SMART was first added into the ATA/ATAPI-3 Standard with
 // Revision 3 of the document, July 25, 1995.  Look at the "Document
 // Status" revision commands at the beginning of
-// http://www.t13.org/project/d2008r6.pdf to see this.
+// http://www.t13.org/Documents/UploadedDocuments/project/d2008r7b-ATA-3.pdf
+// to see this.
 #define NOVAL_0                 0x0000
 #define NOVAL_1                 0xffff
 /* word 81: minor version number */
@@ -859,7 +860,7 @@ int ataVersionInfo(const char ** description, const ata_identify_device * drive,
   // First check if device has ANY ATA version information in it
   if (major==NOVAL_0 || major==NOVAL_1) {
     *description=NULL;
-    return -1;
+    return 0; // No info found
   }
   
   // The minor revision number has more information - try there first
diff --git a/smartmontools/ataprint.cpp b/smartmontools/ataprint.cpp
index 524861258..889a7d278 100644
--- a/smartmontools/ataprint.cpp
+++ b/smartmontools/ataprint.cpp
@@ -490,26 +490,29 @@ static bool PrintDriveInfo(const ata_identify_device * drive, bool fix_swapped_i
   const char *description; unsigned short minorrev;
   int version = ataVersionInfo(&description, drive, &minorrev);
 
-  // unrecognized minor revision code
-  char unknown[64];
-  if (!description){
-    if (!minorrev)
-      sprintf(unknown, "Exact ATA specification draft version not indicated");
-    else
-      sprintf(unknown,"Not recognized. Minor revision code: 0x%02hx", minorrev);
-    description=unknown;
-  }
-  
-  
   // SMART Support was first added into the ATA/ATAPI-3 Standard with
   // Revision 3 of the document, July 25, 1995.  Look at the "Document
   // Status" revision commands at the beginning of
-  // http://www.t13.org/project/d2008r6.pdf to see this.  So it's not
-  // enough to check if we are ATA-3.  Version=-3 indicates ATA-3
-  // BEFORE Revision 3.
-  pout("ATA Version is:   %d\n",(int)abs(version));
-  pout("ATA Standard is:  %s\n",description);
-  
+  // http://www.t13.org/Documents/UploadedDocuments/project/d2008r7b-ATA-3.pdf
+  // to see this.  So it's not enough to check if we are ATA-3.
+  // Version=-3 indicates ATA-3 BEFORE Revision 3.
+  // Version=0 indicates that no info is found. This may happen if
+  // the OS provides only part of the IDENTIFY data.
+
+  std::string majorstr, minorstr;
+  if (version) {
+    majorstr = strprintf("%d", abs(version));
+    if (description)
+      minorstr = description;
+    else if (!minorrev)
+      minorstr = "Exact ATA specification draft version not indicated";
+    else
+      minorstr = strprintf("Not recognized. Minor revision code: 0x%04x", minorrev);
+  }
+
+  pout("ATA Version is:   %s\n", infofound(majorstr.c_str()));
+  pout("ATA Standard is:  %s\n", infofound(minorstr.c_str()));
+
   // print current time and date and timezone
   char timedatetz[DATEANDEPOCHLEN]; dateandtimezone(timedatetz);
   pout("Local Time is:    %s\n", timedatetz);
@@ -518,7 +521,7 @@ static bool PrintDriveInfo(const ata_identify_device * drive, bool fix_swapped_i
   if (dbentry && *dbentry->warningmsg)
     pout("\n==> WARNING: %s\n\n", dbentry->warningmsg);
 
-  if (version>=3)
+  if (!version || version >= 3)
     return !!dbentry;
   
   pout("SMART is only available in ATA Version 3 Revision 3 or greater.\n");
diff --git a/smartmontools/os_win32.cpp b/smartmontools/os_win32.cpp
index 1d2818a92..5d9d90d3c 100644
--- a/smartmontools/os_win32.cpp
+++ b/smartmontools/os_win32.cpp
@@ -3,7 +3,7 @@
  *
  * Home page of code is: http://smartmontools.sourceforge.net
  *
- * Copyright (C) 2004-9 Christian Franke <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2004-10 Christian Franke <smartmontools-support@lists.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1635,7 +1635,6 @@ bool win_tw_cli_device::open()
     id->words047_079[60-47] = (unsigned short)(nblocks    ); // secs_16
     id->words047_079[61-47] = (unsigned short)(nblocks>>16); // secs_32
   }
-  id->major_rev_num = 0x1<<3; // ATA-3
   id->command_set_1 = 0x0001; id->command_set_2 = 0x4000; // SMART supported, words 82,83 valid
   id->cfs_enable_1  = 0x0001; id->csf_default   = 0x4000; // SMART enabled, words 85,87 valid
 
@@ -1983,7 +1982,6 @@ static int get_identify_from_device_property(HANDLE hdevice, ata_identify_device
     copy_swapped(id->model, data.raw+data.desc.ProductIdOffset, sizeof(id->model));
   if (data.desc.ProductRevisionOffset)
     copy_swapped(id->fw_rev, data.raw+data.desc.ProductRevisionOffset, sizeof(id->fw_rev));
-  id->major_rev_num = 0x1<<3; // ATA-3
   id->command_set_1 = 0x0001; id->command_set_2 = 0x4000; // SMART supported, words 82,83 valid
   id->cfs_enable_1  = 0x0001; id->csf_default   = 0x4000; // SMART enabled, words 85,87 valid
   return 0;
@@ -3612,7 +3610,7 @@ bool win_scsi_device::scsi_pass_through(struct scsi_cmnd_io * iop)
       sb.spt.DataTransferLength = iop->dxfer_len;
       sb.spt.DataBuffer = iop->dxferp;
       // IOCTL_SCSI_PASS_THROUGH_DIRECT does not support single byte
-      // transfers (needed for SMART STATUS check of JMicron USB briges)
+      // transfers (needed for SMART STATUS check of JMicron USB bridges)
       if (sb.spt.DataTransferLength == 1)
         direct = false;
       break;
-- 
GitLab