From a428bbc8f646e46857077c66c26da4cc6b1349ef Mon Sep 17 00:00:00 2001
From: shattered <shattered@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Fri, 20 Apr 2007 20:41:00 +0000
Subject: [PATCH] Treat CCISS drive number (N in -d cciss,N) as index into
 array of available physical drives (starting at 0).  May help if certain
 drives in an array are not accessible.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@2398 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/CHANGELOG |  4 +++-
 sm5/cciss.cpp | 14 +++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/sm5/CHANGELOG b/sm5/CHANGELOG
index 1282ad089..17173edf8 100644
--- a/sm5/CHANGELOG
+++ b/sm5/CHANGELOG
@@ -1,6 +1,6 @@
 CHANGELOG for smartmontools
 
-$Id: CHANGELOG,v 1.610 2007/04/17 21:10:59 chrfranke Exp $
+$Id: CHANGELOG,v 1.611 2007/04/20 20:41:00 shattered Exp $
 
 The most recent version of this file is:
 http://smartmontools.cvs.sourceforge.net/smartmontools/sm5/CHANGELOG?view=markup
@@ -33,6 +33,8 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [SS] CCISS physical drive enumeration method changed (incompatibly).
+
   [CF] Fixed smartd crash on missing '-s' directive argument.
 
   [SS] Support CCISS on FreeBSD (kernel source is required).
diff --git a/sm5/cciss.cpp b/sm5/cciss.cpp
index b947ca9fe..f81ab2cee 100644
--- a/sm5/cciss.cpp
+++ b/sm5/cciss.cpp
@@ -13,7 +13,10 @@
 #    include <linux/cciss_ioctl.h>
 #    define _HAVE_CCISS
 #  endif
+#  include <asm/byteorder.h>
+#  define be32toh __be32_to_cpu
 #elif defined(__FreeBSD__) && defined(HAVE_DEV_CISS_CISSIO_H)
+#  include <sys/endian.h>
 #  include <dev/ciss/cissio.h>
 #  define _HAVE_CCISS
 #endif
@@ -25,7 +28,7 @@
 
 typedef struct _ReportLUNdata_struct
 {
-  uint8_t LUNListLength[4];
+  uint32_t LUNListLength;	/* always big-endian */
   uint32_t reserved;
   uint8_t LUN[CISS_MAX_LUN][8];
 } ReportLunData_struct;
@@ -209,6 +212,7 @@ static int cciss_getlun(int device, int target, unsigned char *physlun, int repo
       pout("===== [%s] DATA END (%d Bytes) =====\n\n", "LUN DATA", sizeof(_ReportLUNdata_struct));
     }
 
+#if 0
     for (i=0; i<CISS_MAX_LUN; i++) 
     {
         if (luns->LUN[i][6] == target) 
@@ -218,6 +222,14 @@ static int cciss_getlun(int device, int target, unsigned char *physlun, int repo
             return 0;
         }
     }
+#else
+    if (target >= 0 && target < (int) be32toh(luns->LUNListLength) / 8)
+    {
+	memcpy(physlun, luns->LUN[target], 8);
+	free(luns);
+	return 0;
+    }
+#endif
 
     free(luns);
     return 1;
-- 
GitLab