From 3cb638c54e46ba492e84dbe5e777bc8445215f4b Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Mon, 21 Oct 2002 08:49:23 +0000
Subject: [PATCH] Changed access to Read only from Read/Write. In identify
 command, if WIN_IDENTITY fails, try WIN_PIDENTITY to get some info about
 packet devices.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@71 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/CHANGELOG    |  8 +++++++-
 sm5/atacmds.c    | 16 +++++++++-------
 sm5/atacmds.cpp  | 16 +++++++++-------
 sm5/smartctl.c   |  8 ++++----
 sm5/smartctl.cpp |  8 ++++----
 5 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/sm5/CHANGELOG b/sm5/CHANGELOG
index c9c759af4..8f3699c7a 100644
--- a/sm5/CHANGELOG
+++ b/sm5/CHANGELOG
@@ -1,6 +1,6 @@
 CHANGELOG for smartmontools
 
-$Id: CHANGELOG,v 1.9 2002/10/20 19:40:23 ballen4705 Exp $
+$Id: CHANGELOG,v 1.10 2002/10/21 08:49:23 ballen4705 Exp $
 
 Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
 
@@ -29,6 +29,8 @@ NOTES FOR NEXT RELEASE:
 
 smartmontools-5.0-11
 
+    device opened only in read-only not read-write mode.  Don't need R/W 
+    access to get smart data.
 
     smartctl now handles all possible choices of "multiple options"
     gracefully.  It goes through the following phases of operation,
@@ -37,6 +39,10 @@ smartmontools-5.0-11
     operation.  Control flow through ataPrintMain()
     simplified.
 
+    If reading device identity information fails, try seeing if the info
+    can be accessed using a "DEVICE PACKET" command.  This way we can
+    at least get device info.
+
     Modified Makefile to automatically tag CVS archive on issuance of
     a release
 
diff --git a/sm5/atacmds.c b/sm5/atacmds.c
index 510cece4d..75e030550 100644
--- a/sm5/atacmds.c
+++ b/sm5/atacmds.c
@@ -1,4 +1,4 @@
-//  $Id: atacmds.c,v 1.10 2002/10/20 19:40:23 ballen4705 Exp $
+//  $Id: atacmds.c,v 1.11 2002/10/21 08:49:23 ballen4705 Exp $
 /*
  * atacmds.c
  * 
@@ -128,7 +128,7 @@ void checksumwarning(const char *string){
 int ataReadHDIdentity ( int device, struct hd_driveid *buf){
   if (ioctl(device, HDIO_GET_IDENTITY, buf)){ 
     perror ("ATA GET HD Failed");
-    return -1; 
+    return -1;
   }
   return 0;
 }
@@ -138,13 +138,15 @@ int ataReadHDIdentity ( int device, struct hd_driveid *buf){
 // Reads current Device Identity info (512 bytes) into buf
 int ataReadHDIdentity (int device, struct hd_driveid *buf){
   unsigned char parms[HDIO_DRIVE_CMD_HDR_SIZE+sizeof(*buf)]=
-    {WIN_IDENTIFY, 0, 0, 1,};
-
+  {WIN_IDENTIFY, 0, 0, 1,};
+  
   if (ioctl(device ,HDIO_DRIVE_CMD,parms)){ 
-    perror ("ATA GET HD Identity Failed");
-    return -1; 
+    parms[0]=WIN_PIDENTIFY;
+    if (ioctl(device ,HDIO_DRIVE_CMD,parms)){
+      perror ("ATA GET HD Identity Failed");
+      return -1; 
+    }
   }
-  
   // copy data into driveid structure
   memcpy(buf,parms+HDIO_DRIVE_CMD_HDR_SIZE,sizeof(*buf));
   
diff --git a/sm5/atacmds.cpp b/sm5/atacmds.cpp
index 088f2c033..58ed944fa 100644
--- a/sm5/atacmds.cpp
+++ b/sm5/atacmds.cpp
@@ -1,4 +1,4 @@
-//  $Id: atacmds.cpp,v 1.10 2002/10/20 19:40:23 ballen4705 Exp $
+//  $Id: atacmds.cpp,v 1.11 2002/10/21 08:49:23 ballen4705 Exp $
 /*
  * atacmds.c
  * 
@@ -128,7 +128,7 @@ void checksumwarning(const char *string){
 int ataReadHDIdentity ( int device, struct hd_driveid *buf){
   if (ioctl(device, HDIO_GET_IDENTITY, buf)){ 
     perror ("ATA GET HD Failed");
-    return -1; 
+    return -1;
   }
   return 0;
 }
@@ -138,13 +138,15 @@ int ataReadHDIdentity ( int device, struct hd_driveid *buf){
 // Reads current Device Identity info (512 bytes) into buf
 int ataReadHDIdentity (int device, struct hd_driveid *buf){
   unsigned char parms[HDIO_DRIVE_CMD_HDR_SIZE+sizeof(*buf)]=
-    {WIN_IDENTIFY, 0, 0, 1,};
-
+  {WIN_IDENTIFY, 0, 0, 1,};
+  
   if (ioctl(device ,HDIO_DRIVE_CMD,parms)){ 
-    perror ("ATA GET HD Identity Failed");
-    return -1; 
+    parms[0]=WIN_PIDENTIFY;
+    if (ioctl(device ,HDIO_DRIVE_CMD,parms)){
+      perror ("ATA GET HD Identity Failed");
+      return -1; 
+    }
   }
-  
   // copy data into driveid structure
   memcpy(buf,parms+HDIO_DRIVE_CMD_HDR_SIZE,sizeof(*buf));
   
diff --git a/sm5/smartctl.c b/sm5/smartctl.c
index c4995adc3..5f94abe9e 100644
--- a/sm5/smartctl.c
+++ b/sm5/smartctl.c
@@ -1,4 +1,4 @@
-//  $Id: smartctl.c,v 1.10 2002/10/20 19:22:02 ballen4705 Exp $
+//  $Id: smartctl.c,v 1.11 2002/10/21 08:49:23 ballen4705 Exp $
 /*
  * smartctl.c
  *
@@ -229,7 +229,7 @@ int main (int argc, char **argv){
     printf("is free software, and you are welcome to redistribute it\n");
     printf("under the terms of the GNU General Public License Version 2.\n");
     printf("See http://www.gnu.org for further details.\n\n");
-    printf("CVS version ID %s\n","$Id: smartctl.c,v 1.10 2002/10/20 19:22:02 ballen4705 Exp $");
+    printf("CVS version ID %s\n","$Id: smartctl.c,v 1.11 2002/10/21 08:49:23 ballen4705 Exp $");
     if (argc==2)
       exit(0);
  }
@@ -240,8 +240,8 @@ int main (int argc, char **argv){
     exit (-1);
   }
     
-  /* open device */
-  fd = open ( device=argv[2], O_RDWR );
+  // open device - read-only mode is enough to issue needed commands
+  fd = open ( device=argv[2], O_RDONLY );
   
   if ( fd < 0) {
     perror ( "Device open failed");
diff --git a/sm5/smartctl.cpp b/sm5/smartctl.cpp
index 1a5bf755d..407eb7a8f 100644
--- a/sm5/smartctl.cpp
+++ b/sm5/smartctl.cpp
@@ -1,4 +1,4 @@
-//  $Id: smartctl.cpp,v 1.10 2002/10/20 19:22:02 ballen4705 Exp $
+//  $Id: smartctl.cpp,v 1.11 2002/10/21 08:49:23 ballen4705 Exp $
 /*
  * smartctl.c
  *
@@ -229,7 +229,7 @@ int main (int argc, char **argv){
     printf("is free software, and you are welcome to redistribute it\n");
     printf("under the terms of the GNU General Public License Version 2.\n");
     printf("See http://www.gnu.org for further details.\n\n");
-    printf("CVS version ID %s\n","$Id: smartctl.cpp,v 1.10 2002/10/20 19:22:02 ballen4705 Exp $");
+    printf("CVS version ID %s\n","$Id: smartctl.cpp,v 1.11 2002/10/21 08:49:23 ballen4705 Exp $");
     if (argc==2)
       exit(0);
  }
@@ -240,8 +240,8 @@ int main (int argc, char **argv){
     exit (-1);
   }
     
-  /* open device */
-  fd = open ( device=argv[2], O_RDWR );
+  // open device - read-only mode is enough to issue needed commands
+  fd = open ( device=argv[2], O_RDONLY );
   
   if ( fd < 0) {
     perror ( "Device open failed");
-- 
GitLab