]> git.proxmox.com Git - mirror_smartmontools-debian.git/commitdiff
Imported Upstream version 5.38+svn2920
authorGiuseppe Iuculano <giuseppe@iuculano.it>
Sun, 20 Sep 2009 12:45:58 +0000 (14:45 +0200)
committerGiuseppe Iuculano <giuseppe@iuculano.it>
Sun, 20 Sep 2009 12:45:58 +0000 (14:45 +0200)
16 files changed:
CHANGELOG
cciss.cpp
configure.in
dev_interface.cpp
dev_interface.h
dev_legacy.cpp
os_freebsd.cpp
os_freebsd.h
os_generic.cpp
os_linux.cpp
os_win32.cpp
scsiata.cpp
smartctl.8.in
smartctl.cpp
smartd.cpp
utility.cpp

index c9f682922a8d1275e6d1488be3d5d8730a3b6119..bf20752d0274a4b6da1c0ba5c20cae8fbeb1d5fd 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,11 +1,12 @@
 CHANGELOG for smartmontools
 
-$Id: CHANGELOG 2879 2009-08-29 17:19:00Z chrfranke $
+$Id: CHANGELOG 2918 2009-09-20 11:51:42Z samm2 $
 
 The most recent version of this file is:
 http://smartmontools.svn.sourceforge.net/viewvc/smartmontools/trunk/smartmontools/CHANGELOG?view=markup
 
 Maintainers / Developers Key (alphabetic order):
+[AS]  Alex Samorukov
 [BA]  Bruce Allen
 [OB]  Oliver Bock
 [EB]  Erik Inge Bolsø
@@ -42,6 +43,42 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [AS] FreeBSD: fix FTBFS on GNU/kFreeBSD (reported by derevko).
+
+  [AS] FreeBSD: Add USB autodetection to smartd DEVICESCAN directive.
+
+  [CF] Add USB ID of Myson Century CS8818, add some comments.
+
+  [CF] Return info strings from 'smart_interface::get_*()' functions as
+       'std::string' instead of 'const char *'. Static buffers are no
+       longer needed.
+
+  [SZ] FreeBSD: Fix highpoint type detection and ioctl failed for parameter
+       error.
+
+  [CF] Linux: Add USB autodetection to smartd DEVICESCAN directive.
+
+  [CF] Add USB IDs of Maxtor Basics Desktop and ISD-300A1.
+
+  [AS] Use malloc() to ensure that the read buffer lands on a single
+       page.  This avoids some bugs seen on LSI controlers under
+       FreeBSD.
+
+  [CF] Add missing help text for '-d usb*' options.
+
+  [CF] Linux: Dereference '/dev/disk/by-*/*' symlink before device type
+       autodetection.
+
+  [AS] FreeBSD: Support SATA disks attached to a SAS controller (based on
+       patch from freebsd ports tree).
+
+  [AS] FreeBSD: Added FreeBSD 8 libusb2 device autodetecion, new
+       configure check for -lusb.
+
+  [AS] FreeBSD: Added USB device autodetection and fixed -d switch behavior.
+
+  [AS] FreeBSD: Migrate os_freebsd.cpp to new interface.
+
   [CF] Fix max number of 3ware devices, 128 devices are supported again.
        Regression was introduced during migration to new interface.
        Thanks to Michael Holweg for the problem report.
index 3c32585659d3eb67b703694b2317f5872590b4e3..fca75ac206a07a9fbbf00048c8e7bb1a17f8a5a5 100644 (file)
--- a/cciss.cpp
+++ b/cciss.cpp
 #  include <sys/endian.h>
 #  include <dev/ciss/cissio.h>
 #  define _HAVE_CCISS
+#elif defined(__FreeBSD_kernel__) && defined(HAVE_DEV_CISS_CISSIO_H)
+#  include <endian.h>
+#  include <dev/ciss/cissio.h>
+#  define _HAVE_CCISS
 #endif
 
 #ifdef _HAVE_CCISS
index dd9ee6232ca6785a50bef2c92f4b0fb2a9d6973a..5c88a58c87d915f79f560fd4e7fecd51ae025e7e 100644 (file)
@@ -1,5 +1,5 @@
 #
-# $Id: configure.in 2870 2009-08-02 20:38:30Z manfred99 $
+# $Id: configure.in 2890 2009-09-03 14:47:38Z samm2 $
 #
 dnl Process this file with autoconf to produce a configure script.
 AC_PREREQ(2.50)
@@ -7,7 +7,7 @@ AC_INIT(smartmontools, 5.39, smartmontools-support@lists.sourceforge.net)
 AC_CONFIG_SRCDIR(smartctl.cpp)
 
 smartmontools_configure_date=`date -u +"%Y/%m/%d %T %Z"`
-smartmontools_cvs_tag=`echo '$Id: configure.in 2870 2009-08-02 20:38:30Z manfred99 $'`
+smartmontools_cvs_tag=`echo '$Id: configure.in 2890 2009-09-03 14:47:38Z samm2 $'`
 smartmontools_release_date=2008/03/10
 smartmontools_release_time="10:44:07 GMT"
 
@@ -227,7 +227,9 @@ case "${host}" in
                fi;;
        *-*-freebsd*|*-*-dragonfly*|*-*-kfreebsd*-gnu*)
                AC_SUBST([os_deps], ['os_freebsd.o cciss.o']) 
-               AC_SUBST([os_libs], ['-lcam']);;
+               AC_SUBST([os_libs], ['-lcam'])
+               AC_CHECK_LIB(usb, libusb20_dev_get_device_desc)
+               ;;
        sparc-*-solaris*) 
                AC_DEFINE_UNQUOTED(DEFAULT_MAILER, "mailx", [use mailx as default mailer])
                AC_DEFINE_UNQUOTED(NEED_SOLARIS_ATA_CODE, "os_solaris_ata.s", [need assembly code os_solaris_ata.s])
index f19aff7ef218dd01147040723f3250fe2882968a..9f5ea792232ee01ef27ad38340e03f8c09978862 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Home page of code is: http://smartmontools.sourceforge.net
  *
- * Copyright (C) 2008 Christian Franke <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2008-9 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
@@ -25,7 +25,7 @@
 
 #include <stdexcept>
 
-const char * dev_interface_cpp_cvsid = "$Id: dev_interface.cpp,v 1.5 2009/01/30 18:34:55 chrfranke Exp $"
+const char * dev_interface_cpp_cvsid = "$Id: dev_interface.cpp 2915 2009-09-18 21:17:37Z chrfranke $"
   DEV_INTERFACE_H_CVSID;
 
 /////////////////////////////////////////////////////////////////////////////
@@ -217,29 +217,27 @@ void tunnelled_device_base::release(const smart_device * dev)
 // Pointer to (usually singleton) interface object returned by ::smi()
 smart_interface * smart_interface::s_instance;
 
-const char * smart_interface::get_os_version_str()
+std::string smart_interface::get_os_version_str()
 {
   return SMARTMONTOOLS_BUILD_HOST;
 }
 
-const char * smart_interface::get_valid_dev_types_str()
+std::string smart_interface::get_valid_dev_types_str()
 {
-  static std::string buf;
-  if (!buf.empty())
-    return buf.c_str();
   // default
-  buf = "ata, scsi, sat[,N][+TYPE]";
+  std::string s =
+    "ata, scsi, sat[,N][+TYPE], usbcypress[,X], usbjmicron[,x][,N], usbsunplus";
   // append custom
-  const char * add = get_valid_custom_dev_types_str();
-  if (!add || !*add)
-    return buf.c_str();
-  buf += ", "; buf += add;
-  return buf.c_str();
+  std::string s2 = get_valid_custom_dev_types_str();
+  if (!s2.empty()) {
+    s += ", "; s += s2;
+  }
+  return s;
 }
 
-const char * smart_interface::get_app_examples(const char * /*appname*/)
+std::string smart_interface::get_app_examples(const char * /*appname*/)
 {
-  return 0;
+  return "";
 }
 
 void smart_interface::set_err(int no, const char * msg, ...)
@@ -342,7 +340,7 @@ smart_device * smart_interface::get_custom_smart_device(const char * /*name*/, c
   return 0;
 }
 
-const char * smart_interface::get_valid_custom_dev_types_str()
+std::string smart_interface::get_valid_custom_dev_types_str()
 {
-  return 0;
+  return "";
 }
index 7550c3aa3476ae6e42f2bcbc93a7d92f7db4ab4a..960a069af154af33b36045e9fc1325c86e474fcb 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef DEV_INTERFACE_H
 #define DEV_INTERFACE_H
 
-#define DEV_INTERFACE_H_CVSID "$Id: dev_interface.h,v 1.9 2009/03/12 20:31:12 chrfranke Exp $\n"
+#define DEV_INTERFACE_H_CVSID "$Id: dev_interface.h 2915 2009-09-18 21:17:37Z chrfranke $\n"
 
 #include <stdarg.h>
 #include <string>
@@ -590,20 +590,21 @@ public:
   virtual ~smart_interface() throw()
     { }
 
-  /// Return build host and OS version as static string
-  virtual const char * get_os_version_str();
+  /// Return info string about build host and/or OS version.
+  /// Default implementation returns SMARTMONTOOLS_BUILD_HOST.
+  virtual std::string get_os_version_str();
 
   /// Return valid args for device type option/directive.
-  /// Default implementation returns "ata, scsi" concatenated
-  /// with result from get_valid_custom_dev_types_str() below.
-  virtual const char * get_valid_dev_types_str();
+  /// Default implementation returns "ata, scsi, sat, usb*..."
+  /// concatenated with result from get_valid_custom_dev_types_str().
+  virtual std::string get_valid_dev_types_str();
 
   /// Return example string for program 'appname'.
-  /// Default implementation returns 0.
+  /// Default implementation returns empty string.
   /// For the migration of print_smartctl_examples(),
   /// function is allowed to print examples to stdout.
   /// TODO: Remove this hack.
-  virtual const char * get_app_examples(const char * appname);
+  virtual std::string get_app_examples(const char * appname);
 
   ///////////////////////////////////////////////
   // Last error information
@@ -674,8 +675,8 @@ protected:
 
   /// Return valid 'type' args accepted by above.
   /// This is called in get_valid_dev_types_str().
-  /// Default implementation returns 0.
-  virtual const char * get_valid_custom_dev_types_str();
+  /// Default implementation returns empty string.
+  virtual std::string get_valid_custom_dev_types_str();
 
   /// Return ATA->SCSI filter for SAT or USB.
   /// Override only if platform needs special handling.
index 76ed9479f1b379f75726d9313a069291ae98ac02..8b39d3fc6b248eb131e15e7fa1b8468516fbec9d 100644 (file)
@@ -24,7 +24,7 @@
 #include "dev_interface.h"
 #include "dev_ata_cmd_set.h"
 
-const char * dev_legacy_cpp_cvsid = "$Id: dev_legacy.cpp 2879 2009-08-29 17:19:00Z chrfranke $"
+const char * dev_legacy_cpp_cvsid = "$Id: dev_legacy.cpp 2915 2009-09-18 21:17:37Z chrfranke $"
   DEV_INTERFACE_H_CVSID;
 
 extern smartmonctrl * con; // con->reportscsiioctl
@@ -457,10 +457,10 @@ class legacy_smart_interface
 {
 public:
 #ifdef HAVE_GET_OS_VERSION_STR
-  virtual const char * get_os_version_str();
+  virtual std::string get_os_version_str();
 #endif
 
-  virtual const char * get_app_examples(const char * appname);
+  virtual std::string get_app_examples(const char * appname);
 
   virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
     const char * pattern = 0);
@@ -474,24 +474,24 @@ protected:
 
   virtual smart_device * get_custom_smart_device(const char * name, const char * type);
 
-  virtual const char * get_valid_custom_dev_types_str();
+  virtual std::string get_valid_custom_dev_types_str();
 };
 
 
 //////////////////////////////////////////////////////////////////////
 
 #ifdef HAVE_GET_OS_VERSION_STR
-const char * legacy_smart_interface::get_os_version_str()
+std::string legacy_smart_interface::get_os_version_str()
 {
   return ::get_os_version_str();
 }
 #endif
 
-const char * legacy_smart_interface::get_app_examples(const char * appname)
+std::string legacy_smart_interface::get_app_examples(const char * appname)
 {
   if (!strcmp(appname, "smartctl"))
     ::print_smartctl_examples(); // this prints to stdout ...
-  return 0; // ... so don't print again.
+  return ""; // ... so don't print again.
 }
 
 ata_device * legacy_smart_interface::get_ata_device(const char * name, const char * type)
@@ -518,7 +518,7 @@ smart_device * legacy_smart_interface::autodetect_smart_device(const char * name
 
 static void free_devnames(char * * devnames, int numdevs)
 {
-  static const char version[] = "$Id: dev_legacy.cpp 2879 2009-08-29 17:19:00Z chrfranke $";
+  static const char version[] = "$Id: dev_legacy.cpp 2915 2009-09-18 21:17:37Z chrfranke $";
   for (int i = 0; i < numdevs; i++)
     FreeNonZero(devnames[i], -1,__LINE__, version);
   FreeNonZero(devnames, (sizeof (char*) * numdevs),__LINE__, version);
@@ -651,7 +651,7 @@ smart_device * legacy_smart_interface::get_custom_smart_device(const char * name
   return 0;
 }
 
-const char * legacy_smart_interface::get_valid_custom_dev_types_str()
+std::string legacy_smart_interface::get_valid_custom_dev_types_str()
 {
   return "marvell, areca,N, 3ware,N, hpt,L/M/N, cciss,N";
 }
index 445238ee78830219677eb70925a03d0362008bf2..f92ab489791ab027753c4db054e4802ff87f2bc9 100644 (file)
@@ -23,7 +23,6 @@
 #include <camlib.h>
 #include <cam/scsi/scsi_message.h>
 #include <cam/scsi/scsi_pass.h>
-#include <dev/usb/usb.h>
 #if defined(__DragonFly__)
 #include <sys/nata.h>
 #else
 #include "dev_ata_cmd_set.h"
 
 #define USBDEV "/dev/usb"
+#if defined(__FreeBSD_version)
+
+// This way we define one variable for the GNU/kFreeBSD and FreeBSD 
+#define FREEBSDVER __FreeBSD_version
+#else
+#define FREEBSDVER __FreeBSD_kernel_version
+#endif
+
+#if (FREEBSDVER >= 800000)
+#include <libusb20_desc.h>
+#include <libusb20.h>
+#else
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+#endif
 
 #define CONTROLLER_UNKNOWN              0x00
 #define CONTROLLER_ATA                  0x01
 #define CONTROLLER_SCSI                 0x02
-#define CONTROLLER_3WARE                0x03  // set by -d option, but converted to one of three types below
 #define CONTROLLER_3WARE_678K           0x04  // NOT set by guess_device_type()
 #define CONTROLLER_3WARE_9000_CHAR      0x05  // set by guess_device_type()
 #define CONTROLLER_3WARE_678K_CHAR      0x06  // set by guess_device_type()
-#define CONTROLLER_MARVELL_SATA         0x07  // SATA drives behind Marvell controllers
-#define CONTROLLER_SAT                         0x08  // SATA device behind a SCSI ATA Translation (SAT) layer
 #define CONTROLLER_HPT                  0x09  // SATA drives behind HighPoint Raid controllers
-#define CONTROLLER_CCISS               0x10  // CCISS controller 
-#define CONTROLLER_PARSEDEV             0x11  // "smartctl -r ataioctl,2 ..." output parser pseudo-device
-#define CONTROLLER_USBCYPRESS          0x12  // ATA device behind Cypress USB bridge
-#define CONTROLLER_ARECA                0x13  // Areca controller
+#define CONTROLLER_CCISS  0x10  // CCISS controller 
 
-static __unused const char *filenameandversion="$Id: os_freebsd.cpp 2879 2009-08-29 17:19:00Z chrfranke $";
+static __unused const char *filenameandversion="$Id: os_freebsd.cpp 2920 2009-09-20 12:22:41Z samm2 $";
 
-const char *os_XXXX_c_cvsid="$Id: os_freebsd.cpp 2879 2009-08-29 17:19:00Z chrfranke $" \
+const char *os_XXXX_c_cvsid="$Id: os_freebsd.cpp 2920 2009-09-20 12:22:41Z samm2 $" \
 ATACMDS_H_CVSID CCISS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_FREEBSD_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
 
 extern smartmonctrl * con;
@@ -76,21 +84,17 @@ extern smartmonctrl * con;
 // part of static data.
 struct freebsd_dev_channel *devicetable[FREEBSD_MAXDEV];
 
-// forward declaration
-// static int parse_ata_chan_dev(const char * dev_name, struct freebsd_dev_channel *ch);
-
-
 // Returns 1 if device not available/open/found else 0.  Also shifts fd into valid range.
 static int isnotopen(int *fd, struct freebsd_dev_channel** fdchan) {
   // put valid "file descriptor" into range 0...FREEBSD_MAXDEV-1
   *fd -= FREEBSD_FDOFFSET;
-  
+
   // check for validity of "file descriptor".
   if (*fd<0 || *fd>=FREEBSD_MAXDEV || !((*fdchan)=devicetable[*fd])) {
     errno = ENODEV;
     return 1;
   }
-  
+
   return 0;
 }
 
@@ -105,11 +109,11 @@ void printwarning(int msgNo, const char* extra) {
   static int printed[] = {0,0,0,0};
   static const char* message[]={
     "The SMART RETURN STATUS return value (smartmontools -H option/Directive)\n can not be retrieved with this version of ATAng, please do not rely on this value\nYou should update to at least 5.2\n",
-    
+
     "Error SMART Status command failed\nPlease get assistance from \n" PACKAGE_HOMEPAGE "\nRegister values returned from SMART Status command are:\n",
-    
+
     "You must specify a DISK # for 3ware drives with -d 3ware,<n> where <n> begins with 1 for first disk drive\n",
-    
+
     "ATA support is not provided for this kernel version. Please ugrade to a recent 5-CURRENT kernel (post 09/01/2003 or so)\n"
   };
 
@@ -124,47 +128,20 @@ void printwarning(int msgNo, const char* extra) {
   return;
 }
 
-
 // Interface to ATA devices behind 3ware escalade RAID controller cards.  See os_linux.c
 
 #define BUFFER_LEN_678K_CHAR ( sizeof(struct twe_usercommand) ) // 520
 #define BUFFER_LEN_9000_CHAR ( sizeof(TW_OSLI_IOCTL_NO_DATA_BUF) + sizeof(TWE_Command) ) // 2048
 #define TW_IOCTL_BUFFER_SIZE ( MAX(BUFFER_LEN_678K_CHAR, BUFFER_LEN_9000_CHAR) )
 
-
-
-
-
-
 #ifndef ATA_DEVICE
 #define ATA_DEVICE "/dev/ata"
 #endif
 
-
-
 // global variable holding byte count of allocated memory
 long long bytes;
 
-
-/*
- * dev_legacy.cpp
- *
- * Home page of code is: http://smartmontools.sourceforge.net
- *
- * Copyright (C) 2008 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
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * You should have received a copy of the GNU General Public License
- * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-const char * dev_freebsd_cpp_cvsid = "$Id: os_freebsd.cpp 2879 2009-08-29 17:19:00Z chrfranke $"
+const char * dev_freebsd_cpp_cvsid = "$Id: os_freebsd.cpp 2920 2009-09-20 12:22:41Z samm2 $"
   DEV_INTERFACE_H_CVSID;
 
 extern smartmonctrl * con; // con->reportscsiioctl
@@ -208,6 +185,14 @@ private:
   const char * m_mode; ///< Mode string for deviceopen().
 };
 
+#ifdef __GLIBC__
+static inline void * reallocf(void *ptr, size_t size) {
+   void *rv = realloc(ptr, size);
+   if(rv == NULL)
+     free(ptr);
+   return rv;
+   }
+#endif
 
 freebsd_smart_device::~freebsd_smart_device() throw()
 {
@@ -221,7 +206,7 @@ unsigned char m_controller_port;
 
 // examples for smartctl
 static const char  smartctl_examples[] =
-       "=================================================== SMARTCTL EXAMPLES =====\n\n"
+   "=================================================== SMARTCTL EXAMPLES =====\n\n"
          "  smartctl -a /dev/ad0                       (Prints all SMART information)\n\n"
          "  smartctl --smart=on --offlineauto=on --saveauto=on /dev/ad0\n"
          "                                              (Enables SMART on first disk)\n\n"
@@ -233,6 +218,10 @@ static const char  smartctl_examples[] =
          "  smartctl -a --device=3ware,2 /dev/twe0\n"
          "                              (Prints all SMART information for ATA disk on\n"
          "                                 third port of first 3ware RAID controller)\n"
+  "  smartctl -a --device=cciss,0 /dev/ciss0\n"
+         "                              (Prints all SMART information for first disk \n"
+         "                               on Common Interface for SCSI-3 Support driver)\n"
+
          ;
 
 bool freebsd_smart_device::is_open() const
@@ -244,7 +233,7 @@ bool freebsd_smart_device::is_open() const
 static int hpt_hba(const char* name) {
   int i=0;
   const char *hpt_node[]={"hptmv", "hptmv6", "hptrr", "hptiop", "hptmviop", "hpt32xx", "rr2320",
-                          "rr232x", "rr2310", "rr2310_00", "rr2300", "rr2340", "rr1740", NULL};
+  "rr232x", "rr2310", "rr2310_00", "rr2300", "rr2340", "rr1740", NULL};
   while (hpt_node[i]) {
     if (!strncmp(name, hpt_node[i], strlen(hpt_node[i])))
       return 1;
@@ -255,11 +244,10 @@ static int hpt_hba(const char* name) {
 
 static int get_tw_channel_unit (const char* name, int* unit, int* dev) {
   const char *p;
-
   /* device node sanity check */
   for (p = name + 3; *p; p++)
     if (*p < '0' || *p > '9')
-      return -1;
+    return -1;
   if (strlen(name) > 4 && *(name + 3) == '0')
     return -1;
 
@@ -277,19 +265,19 @@ static int get_ata_channel_unit ( const char* name, int* unit, int* dev) {
 #ifndef ATAREQUEST
   *dev=0;
   *unit=0;
-return 0;
+  return 0;
 #else
   // there is no direct correlation between name 'ad0, ad1, ...' and
   // channel/unit number.  So we need to iterate through the possible
   // channels and check each unit to see if we match names
   struct ata_cmd iocmd;
   int fd,maxunit;
-  
+
   bzero(&iocmd, sizeof(struct ata_cmd));
 
   if ((fd = open(ATA_DEVICE, O_RDWR)) < 0)
     return -errno;
-  
+
   iocmd.cmd = ATAGMAXCHANNEL;
   if (ioctl(fd, IOCATA, &iocmd) < 0) {
     return -errno;
@@ -336,38 +324,52 @@ static const char * fbsd_dev_twe_ctrl = "twe";
 static const char * fbsd_dev_twa_ctrl = "twa";
 static const char * fbsd_dev_cciss = "ciss";
 
-int parse_ata_chan_dev(const char * dev_name, struct freebsd_dev_channel *chan) {
+int parse_ata_chan_dev(const char * dev_name, struct freebsd_dev_channel *chan, const char * type) {
   int len;
   int dev_prefix_len = strlen(fbsd_dev_prefix);
-  
+
+
+  // No Autodetection if device type was specified by user
+  if (*type){
+    if(!strcmp(type,"ata")) return CONTROLLER_ATA;
+    if(!strcmp(type,"cciss")) return CONTROLLER_CCISS;
+    if(!strcmp(type,"scsi") || !strcmp(type,"sat")) goto handlescsi;
+    if(!strcmp(type,"3ware")){
+      return  parse_ata_chan_dev(dev_name,NULL,"");
+    }
+    if(!strcmp(type,"hpt")) return CONTROLLER_HPT;
+    return CONTROLLER_UNKNOWN;
+    // todo - add other types
+  }
+
   // if dev_name null, or string length zero
   if (!dev_name || !(len = strlen(dev_name)))
     return CONTROLLER_UNKNOWN;
-  
+
   // Remove the leading /dev/... if it's there
   if (!strncmp(fbsd_dev_prefix, dev_name, dev_prefix_len)) {
     if (len <= dev_prefix_len) 
       // if nothing else in the string, unrecognized
-      return CONTROLLER_UNKNOWN;
+    return CONTROLLER_UNKNOWN;
     // else advance pointer to following characters
     dev_name += dev_prefix_len;
   }
   // form /dev/ad* or ad*
   if (!strncmp(fbsd_dev_ata_disk_prefix, dev_name,
-               strlen(fbsd_dev_ata_disk_prefix))) {
+    strlen(fbsd_dev_ata_disk_prefix))) {
 #ifndef IOCATAREQUEST
-    if (chan != NULL) {
-      if (get_ata_channel_unit(dev_name,&(chan->channel),&(chan->device))<0) {
-        return CONTROLLER_UNKNOWN;
-      }
+  if (chan != NULL) {
+    if (get_ata_channel_unit(dev_name,&(chan->channel),&(chan->device))<0) {
+      return CONTROLLER_UNKNOWN;
     }
+  }
 #endif
     return CONTROLLER_ATA;
   }
 
   // form /dev/pass* or pass*
   if (!strncmp(fbsd_dev_scsi_pass, dev_name,
-               strlen(fbsd_dev_scsi_pass)))
+    strlen(fbsd_dev_scsi_pass)))
     goto handlescsi;
 
   // form /dev/da* or da*
@@ -377,41 +379,43 @@ int parse_ata_chan_dev(const char * dev_name, struct freebsd_dev_channel *chan)
 
   // form /dev/sa* or sa*
   if (!strncmp(fbsd_dev_scsi_tape1, dev_name,
-              strlen(fbsd_dev_scsi_tape1)))
+    strlen(fbsd_dev_scsi_tape1)))
     goto handlescsi;
 
   // form /dev/nsa* or nsa*
   if (!strncmp(fbsd_dev_scsi_tape2, dev_name,
-              strlen(fbsd_dev_scsi_tape2)))
+    strlen(fbsd_dev_scsi_tape2)))
     goto handlescsi;
 
   // form /dev/esa* or esa*
   if (!strncmp(fbsd_dev_scsi_tape3, dev_name,
-              strlen(fbsd_dev_scsi_tape3)))
+    strlen(fbsd_dev_scsi_tape3)))
     goto handlescsi;
-  
+
   if (!strncmp(fbsd_dev_twa_ctrl,dev_name,
-              strlen(fbsd_dev_twa_ctrl))) {
+    strlen(fbsd_dev_twa_ctrl))) 
+  {
     if (chan != NULL) {
       if (get_tw_channel_unit(dev_name,&(chan->channel),&(chan->device))<0) {
-       return CONTROLLER_UNKNOWN;
+        return CONTROLLER_UNKNOWN;
       }
     }
     else if (get_tw_channel_unit(dev_name,NULL,NULL)<0) {
-       return CONTROLLER_UNKNOWN;
+      return CONTROLLER_UNKNOWN;
     }
     return CONTROLLER_3WARE_9000_CHAR;
   }
 
   if (!strncmp(fbsd_dev_twe_ctrl,dev_name,
-              strlen(fbsd_dev_twe_ctrl))) {
+        strlen(fbsd_dev_twe_ctrl))) 
+  {
     if (chan != NULL) {
       if (get_tw_channel_unit(dev_name,&(chan->channel),&(chan->device))<0) {
-       return CONTROLLER_UNKNOWN;
+        return CONTROLLER_UNKNOWN;
       }
     }
     else if (get_tw_channel_unit(dev_name,NULL,NULL)<0) {
-       return CONTROLLER_UNKNOWN;
+      return CONTROLLER_UNKNOWN;
     }
     return CONTROLLER_3WARE_678K_CHAR;
   }
@@ -421,8 +425,7 @@ int parse_ata_chan_dev(const char * dev_name, struct freebsd_dev_channel *chan)
   }
 
   // form /dev/ciss*
-  if (!strncmp(fbsd_dev_cciss, dev_name,
-               strlen(fbsd_dev_cciss)))
+  if (!strncmp(fbsd_dev_cciss, dev_name, strlen(fbsd_dev_cciss)))
     return CONTROLLER_CCISS;
 
   // we failed to recognize any of the forms
@@ -432,18 +435,17 @@ int parse_ata_chan_dev(const char * dev_name, struct freebsd_dev_channel *chan)
   if (chan != NULL) {
     if (!(chan->devname = (char *)calloc(1,DEV_IDLEN+1)))
       return CONTROLLER_UNKNOWN;
-    
     if (cam_get_device(dev_name,chan->devname,DEV_IDLEN,&(chan->unitnum)) == -1)
       return CONTROLLER_UNKNOWN;
   }
   return CONTROLLER_SCSI;
-  
+
 }
 
 
 bool freebsd_smart_device::open()
 {
-       
+
   const char *dev = get_dev_name();
   struct freebsd_dev_channel *fdchan;
   int parse_ok, i;
@@ -451,8 +453,8 @@ bool freebsd_smart_device::open()
   // Search table for a free entry
   for (i=0; i<FREEBSD_MAXDEV; i++)
     if (!devicetable[i])
-      break;
-  
+    break;
+
   // If no free entry found, return error.  We have max allowed number
   // of "file descriptors" already allocated.
   if (i == FREEBSD_MAXDEV) {
@@ -466,8 +468,8 @@ bool freebsd_smart_device::open()
     return false;
   }
 
-  parse_ok = parse_ata_chan_dev(dev,fdchan);
-  
+  parse_ok = parse_ata_chan_dev(dev,fdchan,get_req_type());
+
   if (parse_ok == CONTROLLER_UNKNOWN) {
     free(fdchan);
     errno = ENOTTY;
@@ -480,7 +482,7 @@ bool freebsd_smart_device::open()
 #else
     if ((fdchan->atacommand = ::open("/dev/ata",O_RDWR))<0) {
 #endif
-      int myerror = errno;     // preserve across free call
+      int myerror = errno; // preserve across free call
       free(fdchan);
       errno = myerror;
       return false;
@@ -495,7 +497,7 @@ bool freebsd_smart_device::open()
 #else
     if ((fdchan->atacommand = ::open(buf,O_RDWR))<0) {
 #endif
-      int myerror = errno;     // preserve across free call
+      int myerror = errno; // preserve across free call
       free(fdchan);
       errno = myerror;
       return false;
@@ -510,7 +512,7 @@ bool freebsd_smart_device::open()
 #else
     if ((fdchan->atacommand = ::open(buf,O_RDWR))<0) {
 #endif
-      int myerror = errno;     // preserve across free call
+      int myerror = errno; // preserve across free call
       free(fdchan);
       errno = myerror;
       return false;
@@ -519,7 +521,7 @@ bool freebsd_smart_device::open()
 
   if (parse_ok == CONTROLLER_HPT) {
     if ((fdchan->device = ::open(dev,O_RDWR))<0) {
-      int myerror = errno;     // preserve across free call
+      int myerror = errno; // preserve across free call
       free(fdchan);
       errno = myerror;
       return false;
@@ -528,7 +530,7 @@ bool freebsd_smart_device::open()
 
   if (parse_ok == CONTROLLER_CCISS) {
     if ((fdchan->device = ::open(dev,O_RDWR))<0) {
-      int myerror = errno;     // preserve across free call
+      int myerror = errno; // preserve across free call
       free(fdchan);
       errno = myerror;
       return false;
@@ -539,7 +541,7 @@ bool freebsd_smart_device::open()
     // this is really a NO-OP, as the parse takes care
     // of filling in correct details
   }
-  
+
   // return pointer to "file descriptor" table entry, properly offset.
   devicetable[i]=fdchan;
   m_fd = i+FREEBSD_FDOFFSET;
@@ -560,12 +562,11 @@ bool freebsd_smart_device::close()
   // check for valid file descriptor
   if (isnotopen(&fd, &fdchan))
     return false;
-  
 
   // did we allocate a SCSI device name?
   if (fdchan->devname)
     free(fdchan->devname);
-  
+
   // close device, if open
   if (fdchan->device)
     failed=::close(fdchan->device);
@@ -573,7 +574,7 @@ bool freebsd_smart_device::close()
   if (fdchan->atacommand)
     failed=::close(fdchan->atacommand);
 #endif
-  
+
   // if close succeeded, then remove from device list
   // Eduard, should we also remove it from list if close() fails?  I'm
   // not sure. Here I only remove it from list if close() worked.
@@ -581,8 +582,8 @@ bool freebsd_smart_device::close()
     free(fdchan);
     devicetable[fd]=NULL;
   }
-  
-  return failed;
+  if(failed) return false;
+  else return true;
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -611,201 +612,201 @@ freebsd_ata_device::freebsd_ata_device(smart_interface * intf, const char * dev_
 
 int freebsd_ata_device::ata_command_interface(smart_command_set command, int select, char * data)
 {
      int fd=get_fd();
-       #if !defined(ATAREQUEST) && !defined(IOCATAREQUEST)
      // sorry, but without ATAng, we can't do anything here
      printwarning(BAD_KERNEL,NULL);
      errno = ENOSYS;
      return -1;
-       #else
      struct freebsd_dev_channel* con;
      int retval, copydata=0;
-       #ifdef IOCATAREQUEST
      struct ata_ioc_request request;
-       #else
      struct ata_cmd iocmd;
-       #endif
      unsigned char buff[512];
-       
      // check that "file descriptor" is valid
      if (isnotopen(&fd,&con))
-               return -1;
-       
      bzero(buff,512);
-       
-       #ifdef IOCATAREQUEST
      bzero(&request,sizeof(struct ata_ioc_request));
-       #else
      bzero(&iocmd,sizeof(struct ata_cmd));
-       #endif
      bzero(buff,512);
-       
-       #ifndef IOCATAREQUEST
      iocmd.cmd=ATAREQUEST;
      iocmd.channel=con->channel;
      iocmd.device=con->device;
-       #define request iocmd.u.request
-       #endif
-       
      request.u.ata.command=ATA_SMART_CMD;
      request.timeout=600;
      switch (command){
      case READ_VALUES:
-               request.u.ata.feature=ATA_SMART_READ_VALUES;
-               request.u.ata.lba=0xc24f<<8;
-               request.flags=ATA_CMD_READ;
-               request.data=(char *)buff;
-               request.count=512;
-               copydata=1;
-               break;
      case READ_THRESHOLDS:
-               request.u.ata.feature=ATA_SMART_READ_THRESHOLDS;
-               request.u.ata.count=1;
-               request.u.ata.lba=1|(0xc24f<<8);
-               request.flags=ATA_CMD_READ;
-               request.data=(char *)buff;
-               request.count=512;
-               copydata=1;
-               break;
      case READ_LOG:
-               request.u.ata.feature=ATA_SMART_READ_LOG_SECTOR;
-               request.u.ata.lba=select|(0xc24f<<8);
-               request.u.ata.count=1;
-               request.flags=ATA_CMD_READ;
-               request.data=(char *)buff;
-               request.count=512;
-               copydata=1;
-               break;
      case IDENTIFY:
-               request.u.ata.command=ATA_IDENTIFY_DEVICE;
-               request.flags=ATA_CMD_READ;
-               request.data=(char *)buff;
-               request.count=512;
-               copydata=1;
-               break;
      case PIDENTIFY:
-               request.u.ata.command=ATA_IDENTIFY_PACKET_DEVICE;
-               request.flags=ATA_CMD_READ;
-               request.data=(char *)buff;
-               request.count=512;
-               copydata=1;
-               break;
      case ENABLE:
-               request.u.ata.feature=ATA_SMART_ENABLE;
-               request.u.ata.lba=0xc24f<<8;
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case DISABLE:
-               request.u.ata.feature=ATA_SMART_DISABLE;
-               request.u.ata.lba=0xc24f<<8;
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case AUTO_OFFLINE:
-               // NOTE: According to ATAPI 4 and UP, this command is obsolete
-               request.u.ata.feature=ATA_SMART_AUTO_OFFLINE;
-               request.u.ata.lba=0xc24f<<8;                                                                                                                                         
-               request.u.ata.count=select;                                                                                                                                          
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case AUTOSAVE:
-               request.u.ata.feature=ATA_SMART_AUTOSAVE;
-               request.u.ata.lba=0xc24f<<8;
-               request.u.ata.count=select;
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case IMMEDIATE_OFFLINE:
-               request.u.ata.feature=ATA_SMART_IMMEDIATE_OFFLINE;
-               request.u.ata.lba = select|(0xc24f<<8); // put test in sector
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case STATUS_CHECK: // same command, no HDIO in FreeBSD
      case STATUS:
-               // this command only says if SMART is working.  It could be
-               // replaced with STATUS_CHECK below.
-               request.u.ata.feature=ATA_SMART_STATUS;
-               request.u.ata.lba=0xc24f<<8;
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case CHECK_POWER_MODE:
-               request.u.ata.command=ATA_CHECK_POWER_MODE;
-               request.u.ata.feature=0;
-               request.flags=ATA_CMD_CONTROL;
-               break;
      case WRITE_LOG:
-               memcpy(buff, data, 512);
-               request.u.ata.feature=ATA_SMART_WRITE_LOG_SECTOR;
-               request.u.ata.lba=select|(0xc24f<<8);
-               request.u.ata.count=1;
-               request.flags=ATA_CMD_WRITE;
-               request.data=(char *)buff;
-               request.count=512;
-               break;
      default:
-               pout("Unrecognized command %d in ata_command_interface()\n"
-                       "Please contact " PACKAGE_BUGREPORT "\n", command);
-               errno=ENOSYS;
-               return -1;
      }
-       
      if (command==STATUS_CHECK){
-               unsigned const char normal_lo=0x4f, normal_hi=0xc2;
-               unsigned const char failed_lo=0xf4, failed_hi=0x2c;
-               unsigned char low,high;
-               
-               #ifdef IOCATAREQUEST
-               if ((retval=ioctl(con->device, IOCATAREQUEST, &request)) || request.error)
-                       #else
-               if ((retval=ioctl(con->atacommand, IOCATA, &iocmd)) || request.error)
-                       #endif
-               return -1;
-               
-               #if __FreeBSD_version < 502000
-               printwarning(NO_RETURN,NULL);
-               #endif
-               
-               high = (request.u.ata.lba >> 16) & 0xff;
-               low = (request.u.ata.lba >> 8) & 0xff;
-               
-               // Cyl low and Cyl high unchanged means "Good SMART status"
-               if (low==normal_lo && high==normal_hi)
-                       return 0;
-               
-               // These values mean "Bad SMART status"
-               if (low==failed_lo && high==failed_hi)
-                       return 1;
-               
-               // We haven't gotten output that makes sense; print out some debugging info
-               char buf[512];
-               sprintf(buf,"CMD=0x%02x\nFR =0x%02x\nNS =0x%02x\nSC =0x%02x\nCL =0x%02x\nCH =0x%02x\nRETURN =0x%04x\n",
-                       (int)request.u.ata.command,
-                       (int)request.u.ata.feature,
-                       (int)request.u.ata.count,
-                       (int)((request.u.ata.lba) & 0xff),
-                       (int)((request.u.ata.lba>>8) & 0xff),
-                       (int)((request.u.ata.lba>>16) & 0xff),
-                       (int)request.error);
-               printwarning(BAD_SMART,buf);
-               return 0;   
      }
-       
-       #ifdef IOCATAREQUEST
      if ((retval=ioctl(con->device, IOCATAREQUEST, &request)) || request.error)
-               #else
      if ((retval=ioctl(con->atacommand, IOCATA, &iocmd)) || request.error)
-               #endif
      {
-               return -1;
      }
      // 
      if (command == CHECK_POWER_MODE) {
-               data[0] = request.u.ata.count & 0xff;
-               return 0;
      }
      if (copydata)
-               memcpy(data, buff, 512);
-       
      return 0;
-       #endif
+ int fd=get_fd();
+#if !defined(ATAREQUEST) && !defined(IOCATAREQUEST)
+ // sorry, but without ATAng, we can't do anything here
+ printwarning(BAD_KERNEL,NULL);
+ errno = ENOSYS;
+ return -1;
+#else
+ struct freebsd_dev_channel* con;
+ int retval, copydata=0;
+#ifdef IOCATAREQUEST
+ struct ata_ioc_request request;
+#else
+ struct ata_cmd iocmd;
+#endif
+ unsigned char buff[512];
+
+ // check that "file descriptor" is valid
+ if (isnotopen(&fd,&con))
+  return -1;
+
+ bzero(buff,512);
+
+#ifdef IOCATAREQUEST
+ bzero(&request,sizeof(struct ata_ioc_request));
+#else
+ bzero(&iocmd,sizeof(struct ata_cmd));
+#endif
+ bzero(buff,512);
+
+#ifndef IOCATAREQUEST
+ iocmd.cmd=ATAREQUEST;
+ iocmd.channel=con->channel;
+ iocmd.device=con->device;
+#define request iocmd.u.request
+#endif
+
+ request.u.ata.command=ATA_SMART_CMD;
+ request.timeout=600;
+ switch (command){
+ case READ_VALUES:
+  request.u.ata.feature=ATA_SMART_READ_VALUES;
+  request.u.ata.lba=0xc24f<<8;
+  request.flags=ATA_CMD_READ;
+  request.data=(char *)buff;
+  request.count=512;
+  copydata=1;
+  break;
+ case READ_THRESHOLDS:
+  request.u.ata.feature=ATA_SMART_READ_THRESHOLDS;
+  request.u.ata.count=1;
+  request.u.ata.lba=1|(0xc24f<<8);
+  request.flags=ATA_CMD_READ;
+  request.data=(char *)buff;
+  request.count=512;
+  copydata=1;
+  break;
+ case READ_LOG:
+  request.u.ata.feature=ATA_SMART_READ_LOG_SECTOR;
+  request.u.ata.lba=select|(0xc24f<<8);
+  request.u.ata.count=1;
+  request.flags=ATA_CMD_READ;
+  request.data=(char *)buff;
+  request.count=512;
+  copydata=1;
+  break;
+ case IDENTIFY:
+  request.u.ata.command=ATA_IDENTIFY_DEVICE;
+  request.flags=ATA_CMD_READ;
+  request.data=(char *)buff;
+  request.count=512;
+  copydata=1;
+  break;
+ case PIDENTIFY:
+  request.u.ata.command=ATA_IDENTIFY_PACKET_DEVICE;
+  request.flags=ATA_CMD_READ;
+  request.data=(char *)buff;
+  request.count=512;
+  copydata=1;
+  break;
+ case ENABLE:
+  request.u.ata.feature=ATA_SMART_ENABLE;
+  request.u.ata.lba=0xc24f<<8;
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case DISABLE:
+  request.u.ata.feature=ATA_SMART_DISABLE;
+  request.u.ata.lba=0xc24f<<8;
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case AUTO_OFFLINE:
+  // NOTE: According to ATAPI 4 and UP, this command is obsolete
+  request.u.ata.feature=ATA_SMART_AUTO_OFFLINE;
+  request.u.ata.lba=0xc24f<<8;                                                                                                                                         
+  request.u.ata.count=select;                                                                                                                                          
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case AUTOSAVE:
+  request.u.ata.feature=ATA_SMART_AUTOSAVE;
+  request.u.ata.lba=0xc24f<<8;
+  request.u.ata.count=select;
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case IMMEDIATE_OFFLINE:
+  request.u.ata.feature=ATA_SMART_IMMEDIATE_OFFLINE;
+  request.u.ata.lba = select|(0xc24f<<8); // put test in sector
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case STATUS_CHECK: // same command, no HDIO in FreeBSD
+ case STATUS:
+  // this command only says if SMART is working.  It could be
+  // replaced with STATUS_CHECK below.
+  request.u.ata.feature=ATA_SMART_STATUS;
+  request.u.ata.lba=0xc24f<<8;
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case CHECK_POWER_MODE:
+  request.u.ata.command=ATA_CHECK_POWER_MODE;
+  request.u.ata.feature=0;
+  request.flags=ATA_CMD_CONTROL;
+  break;
+ case WRITE_LOG:
+  memcpy(buff, data, 512);
+  request.u.ata.feature=ATA_SMART_WRITE_LOG_SECTOR;
+  request.u.ata.lba=select|(0xc24f<<8);
+  request.u.ata.count=1;
+  request.flags=ATA_CMD_WRITE;
+  request.data=(char *)buff;
+  request.count=512;
+  break;
+ default:
+  pout("Unrecognized command %d in ata_command_interface()\n"
+   "Please contact " PACKAGE_BUGREPORT "\n", command);
+  errno=ENOSYS;
+  return -1;
+ }
+
+ if (command==STATUS_CHECK){
+  unsigned const char normal_lo=0x4f, normal_hi=0xc2;
+  unsigned const char failed_lo=0xf4, failed_hi=0x2c;
+  unsigned char low,high;
+
+#ifdef IOCATAREQUEST
+  if ((retval=ioctl(con->device, IOCATAREQUEST, &request)) || request.error)
+#else
+  if ((retval=ioctl(con->atacommand, IOCATA, &iocmd)) || request.error)
+#endif
+  return -1;
+
+#if (FREEBSDVER < 502000)
+  printwarning(NO_RETURN,NULL);
+#endif
+
+  high = (request.u.ata.lba >> 16) & 0xff;
+  low = (request.u.ata.lba >> 8) & 0xff;
+
+  // Cyl low and Cyl high unchanged means "Good SMART status"
+  if (low==normal_lo && high==normal_hi)
+   return 0;
+
+  // These values mean "Bad SMART status"
+  if (low==failed_lo && high==failed_hi)
+   return 1;
+
+  // We haven't gotten output that makes sense; print out some debugging info
+  char buf[512];
+  sprintf(buf,"CMD=0x%02x\nFR =0x%02x\nNS =0x%02x\nSC =0x%02x\nCL =0x%02x\nCH =0x%02x\nRETURN =0x%04x\n",
+   (int)request.u.ata.command,
+   (int)request.u.ata.feature,
+   (int)request.u.ata.count,
+   (int)((request.u.ata.lba) & 0xff),
+   (int)((request.u.ata.lba>>8) & 0xff),
+   (int)((request.u.ata.lba>>16) & 0xff),
+   (int)request.error);
+  printwarning(BAD_SMART,buf);
+  return 0;   
+ }
+
+#ifdef IOCATAREQUEST
+ if ((retval=ioctl(con->device, IOCATAREQUEST, &request)) || request.error)
+#else
+ if ((retval=ioctl(con->atacommand, IOCATA, &iocmd)) || request.error)
+#endif
+ {
+  return -1;
+ }
+ // 
+ if (command == CHECK_POWER_MODE) {
+  data[0] = request.u.ata.count & 0xff;
+  return 0;
+ }
+ if (copydata)
+  memcpy(data, buff, 512);
+
+ return 0;
+#endif
 }
 
 #ifdef HAVE_ATA_IDENTIFY_IS_CACHED
@@ -849,8 +850,8 @@ freebsd_escalade_device::freebsd_escalade_device(smart_interface * intf, const c
 
 int freebsd_escalade_device::ata_command_interface(smart_command_set command, int select, char * data)
 {
-    // to hold true file descriptor
-    int fd = get_fd();
+  // to hold true file descriptor
+  int fd = get_fd();
   struct freebsd_dev_channel* con;
 
   // return value and buffer for ioctl()
@@ -869,7 +870,7 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
 
   // check that "file descriptor" is valid
   if (isnotopen(&fd,&con))
-      return -1;
+    return -1;
 
   memset(ioctl_buffer, 0, TW_IOCTL_BUFFER_SIZE);
 
@@ -883,7 +884,7 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
     ata = &cmd_twe->tu_command.ata;
   } else {
     pout("Unrecognized escalade_type %d in freebsd_3ware_command_interface(disk %d)\n"
-         "Please contact " PACKAGE_BUGREPORT "\n", m_escalade_type, m_disknum);
+      "Please contact " PACKAGE_BUGREPORT "\n", m_escalade_type, m_disknum);
     errno=ENOSYS;
     return -1;
   }
@@ -902,10 +903,10 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
   // values from the ATA specifications.
   ata->cylinder_lo   = 0x4F;
   ata->cylinder_hi   = 0xC2;
-  
+
   // SMART ATA COMMAND REGISTER value
   ata->command       = ATA_SMART_CMD;
-  
+
   // Is this a command that reads or returns 512 bytes?
   // passthru->param values are:
   // 0x0 - non data command without TFR write check,
@@ -917,7 +918,8 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
       command == READ_THRESHOLDS ||
       command == READ_LOG        ||
       command == IDENTIFY        ||
-      command == WRITE_LOG ) {
+      command == WRITE_LOG ) 
+  {
     readdata=1;
     if (m_escalade_type==CONTROLLER_3WARE_678K_CHAR) {
       cmd_twe->tu_data = data;
@@ -942,7 +944,7 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
     ata->param        = 0x8;
     ata->sector_count = 0x0;
   }
-  
+
   // Now set ATA registers depending upon command
   switch (command){
   case CHECK_POWER_MODE:
@@ -1039,7 +1041,7 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
       errno=EIO;
     return -1;
   }
-  
+
   // See if the ATA command failed.  Now that we have returned from
   // the ioctl() call, if passthru is valid, then:
   // - ata->status contains the 3ware controller STATUS
@@ -1051,13 +1053,13 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
   // While we *might* decode the ATA ERROR register, at the moment it
   // doesn't make much sense: we don't care in detail why the error
   // happened.
-  
+
   if (ata->status || (ata->command & 0x21)) {
     pout("Command failed, ata.status=(0x%2.2x), ata.command=(0x%2.2x), ata.flags=(0x%2.2x)\n",ata->status,ata->command,ata->flags);
     errno=EIO;
     return -1;
   }
-  
+
   // If this is a read data command, copy data to output buffer
   if (readdata) {
     if (m_escalade_type==CONTROLLER_3WARE_9000_CHAR)
@@ -1066,36 +1068,36 @@ int freebsd_escalade_device::ata_command_interface(smart_command_set command, in
 
   // For STATUS_CHECK, we need to check register values
   if (command==STATUS_CHECK) {
-    
+
     // To find out if the SMART RETURN STATUS is good or failing, we
     // need to examine the values of the Cylinder Low and Cylinder
     // High Registers.
-    
+
     unsigned short cyl_lo=ata->cylinder_lo;
     unsigned short cyl_hi=ata->cylinder_hi;
-    
+
     // If values in Cyl-LO and Cyl-HI are unchanged, SMART status is good.
     if (cyl_lo==0x4F && cyl_hi==0xC2)
       return 0;
-    
+
     // If values in Cyl-LO and Cyl-HI are as follows, SMART status is FAIL
     if (cyl_lo==0xF4 && cyl_hi==0x2C)
       return 1;
-    
+
       errno=EIO;
       return -1;
   }
-  
+
   // copy sector count register (one byte!) to return data
   if (command==CHECK_POWER_MODE)
     *data=*(char *)&(ata->sector_count);
-  
+
   // look for nonexistent devices/ports
   if (command==IDENTIFY && !nonempty((unsigned char *)data, 512)) {
     errno=ENODEV;
     return -1;
   }
-  
+
   return 0;
 }
 
@@ -1130,7 +1132,7 @@ freebsd_highpoint_device::freebsd_highpoint_device(smart_interface * intf, const
 
 int freebsd_highpoint_device::ata_command_interface(smart_command_set command, int select, char * data)
 {
-   int fd=get_fd(); 
+  int fd=get_fd(); 
   int ids[2];
   struct freebsd_dev_channel* fbcon;
   HPT_IOCTL_PARAM param;
@@ -1140,7 +1142,7 @@ int freebsd_highpoint_device::ata_command_interface(smart_command_set command, i
 
   // check that "file descriptor" is valid
   if (isnotopen(&fd, &fbcon))
-      return -1;
+    return -1;
 
   // get internal deviceid
   ids[0] = m_hpt_data[0] - 1;
@@ -1249,7 +1251,8 @@ int freebsd_highpoint_device::ata_command_interface(smart_command_set command, i
     return -1;
   }
 
-  if (command==STATUS_CHECK){
+  if (command==STATUS_CHECK)
+  {
     unsigned const char normal_lo=0x4f, normal_hi=0xc2;
     unsigned const char failed_lo=0xf4, failed_hi=0x2c;
     unsigned char low,high;
@@ -1280,7 +1283,8 @@ int freebsd_highpoint_device::ata_command_interface(smart_command_set command, i
   else if (command==CHECK_POWER_MODE)
     data[0] = pide_pt_hdr_out->sectorcount & 0xff;
   else if (pide_pt_hdr->protocol==HPT_READ)
-    memcpy(data, (unsigned char *)buff + 2 * sizeof(HPT_PASS_THROUGH_HEADER), pide_pt_hdr->sectors * 512);
+    memcpy(data, (unsigned char *)buff + 2 * sizeof(HPT_PASS_THROUGH_HEADER), 
+      pide_pt_hdr->sectors * 512);
   return 0;
 }
 
@@ -1313,32 +1317,31 @@ int do_normal_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report)
   struct freebsd_dev_channel* con = NULL;
   struct cam_device* cam_dev = NULL;
   union ccb *ccb;
-  
-  
-    if (report > 0) {
-        unsigned int k;
-        const unsigned char * ucp = iop->cmnd;
-        const char * np;
-
-        np = scsi_get_opcode_name(ucp[0]);
-        pout(" [%s: ", np ? np : "<unknown opcode>");
-        for (k = 0; k < iop->cmnd_len; ++k)
-            pout("%02x ", ucp[k]);
-        if ((report > 1) && 
-            (DXFER_TO_DEVICE == iop->dxfer_dir) && (iop->dxferp)) {
-            int trunc = (iop->dxfer_len > 256) ? 1 : 0;
-
-            pout("]\n  Outgoing data, len=%d%s:\n", (int)iop->dxfer_len,
-                 (trunc ? " [only first 256 bytes shown]" : ""));
-            dStrHex(iop->dxferp, (trunc ? 256 : iop->dxfer_len) , 1);
-        }
-        else
-            pout("]");
-    }
+
+  if (report > 0) {
+    unsigned int k;
+    const unsigned char * ucp = iop->cmnd;
+    const char * np;
+
+    np = scsi_get_opcode_name(ucp[0]);
+    pout(" [%s: ", np ? np : "<unknown opcode>");
+    for (k = 0; k < iop->cmnd_len; ++k)
+      pout("%02x ", ucp[k]);
+    if ((report > 1) && 
+      (DXFER_TO_DEVICE == iop->dxfer_dir) && (iop->dxferp)) {
+    int trunc = (iop->dxfer_len > 256) ? 1 : 0;
+
+    pout("]\n  Outgoing data, len=%d%s:\n", (int)iop->dxfer_len,
+      (trunc ? " [only first 256 bytes shown]" : ""));
+    dStrHex(iop->dxferp, (trunc ? 256 : iop->dxfer_len) , 1);
+      }
+      else
+        pout("]");
+  }
 
   // check that "file descriptor" is valid
   if (isnotopen(&fd,&con))
-      return -ENOTTY;
+    return -ENOTTY;
 
 
   if (!(cam_dev = cam_open_spec_device(con->devname,con->unitnum,O_RDWR,NULL))) {
@@ -1353,33 +1356,33 @@ int do_normal_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report)
 
   // clear out structure, except for header that was filled in for us
   bzero(&(&ccb->ccb_h)[1],
-        sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+    sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
 
   cam_fill_csio(&ccb->csio,
-                /*retrires*/ 1,
-                /*cbfcnp*/ NULL,
-                /* flags */ (iop->dxfer_dir == DXFER_NONE ? CAM_DIR_NONE :(iop->dxfer_dir == DXFER_FROM_DEVICE ? CAM_DIR_IN : CAM_DIR_OUT)),
-                /* tagaction */ MSG_SIMPLE_Q_TAG,
-                /* dataptr */ iop->dxferp,
-                /* datalen */ iop->dxfer_len,
-                /* senselen */ iop->max_sense_len,
-                /* cdblen */ iop->cmnd_len,
-                /* timout (converted to seconds) */ iop->timeout*1000);
+    /*retrires*/ 1,
+    /*cbfcnp*/ NULL,
+    /* flags */ (iop->dxfer_dir == DXFER_NONE ? CAM_DIR_NONE :(iop->dxfer_dir == DXFER_FROM_DEVICE ? CAM_DIR_IN : CAM_DIR_OUT)),
+    /* tagaction */ MSG_SIMPLE_Q_TAG,
+    /* dataptr */ iop->dxferp,
+    /* datalen */ iop->dxfer_len,
+    /* senselen */ iop->max_sense_len,
+    /* cdblen */ iop->cmnd_len,
+    /* timout (converted to seconds) */ iop->timeout*1000);
   memcpy(ccb->csio.cdb_io.cdb_bytes,iop->cmnd,iop->cmnd_len);
 
   if (cam_send_ccb(cam_dev,ccb) < 0) {
     warn("error sending SCSI ccb");
- #if __FreeBSD_version > 500000
+#if (FREEBSDVER > 500000)
     cam_error_print(cam_dev,ccb,CAM_ESF_ALL,CAM_EPF_ALL,stderr);
- #endif
+#endif
     cam_freeccb(ccb);
     return -EIO;
   }
 
-  if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
- #if __FreeBSD_version > 500000
+  if (((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) && ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR)) {
+#if (FREEBSDVER > 500000)
     cam_error_print(cam_dev,ccb,CAM_ESF_ALL,CAM_EPF_ALL,stderr);
- #endif
+#endif
     cam_freeccb(ccb);
     return -EIO;
   }
@@ -1392,7 +1395,7 @@ int do_normal_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report)
   iop->scsi_status = ccb->csio.scsi_status;
 
   cam_freeccb(ccb);
-  
+
   if (cam_dev)
     cam_close_device(cam_dev);
 
@@ -1401,9 +1404,9 @@ int do_normal_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report)
 
     pout("  status=0\n");
     trunc = (iop->dxfer_len > 256) ? 1 : 0;
-    
+
     pout("  Incoming data, len=%d%s:\n", (int)iop->dxfer_len,
-         (trunc ? " [only first 256 bytes shown]" : ""));
+      (trunc ? " [only first 256 bytes shown]" : ""));
     dStrHex(iop->dxferp, (trunc ? 256 : iop->dxfer_len) , 1);
   }
   return 0;
@@ -1414,33 +1417,35 @@ int do_normal_scsi_cmnd_io(int fd, struct scsi_cmnd_io * iop, int report)
    we can take off this crude way of calling the right interface */
 int do_scsi_cmnd_io(int dev_fd, struct scsi_cmnd_io * iop, int report)
 {
-struct freebsd_dev_channel *fdchan;
-     switch(m_controller_type)
-     {
-         case CONTROLLER_CCISS:
+  struct freebsd_dev_channel *fdchan;
+  switch(m_controller_type)
+  {
+  case CONTROLLER_CCISS:
 #ifdef HAVE_DEV_CISS_CISSIO_H
-            // check that "file descriptor" is valid
-            if (isnotopen(&dev_fd,&fdchan))
-                return -ENOTTY;
-             return cciss_io_interface(fdchan->device, m_controller_port-1, iop, report);
+    // check that "file descriptor" is valid
+    if (isnotopen(&dev_fd,&fdchan))
+      return -ENOTTY;
+
+    return cciss_io_interface(fdchan->device, m_controller_port-1, iop, report);
 #else
-             {
-                 static int warned = 0;
-                 if (!warned) {
-                     pout("CCISS support is not available in this build of smartmontools,\n"
-                          "/usr/src/sys/dev/ciss/cissio.h was not available at build time.\n\n");
-                     warned = 1;
-                 }
-             }
-             return -ENOSYS;
+    {
+      static int warned = 0;
+      if (!warned) {
+        pout("CCISS support is not available in this build of smartmontools,\n"
+          "/usr/src/sys/dev/ciss/cissio.h was not available at build time.\n\n");
+        warned = 1;
+      }
+    }
+    return -ENOSYS;
 #endif
-             // not reached
-             break;
-         default:
-             return do_normal_scsi_cmnd_io(dev_fd, iop, report);
-             // not reached
-             break;
-     }
+// not reached
+    break;
+
+  default:
+    return do_normal_scsi_cmnd_io(dev_fd, iop, report);
+    // not reached
+    break;
+  }
 }
 
 bool freebsd_scsi_device::scsi_pass_through(scsi_cmnd_io * iop)
@@ -1450,8 +1455,8 @@ bool freebsd_scsi_device::scsi_pass_through(scsi_cmnd_io * iop)
   int status = do_scsi_cmnd_io(get_fd(), iop, con->reportscsiioctl);
   m_controller_type = oldtype; m_controller_port = oldport;
   if (status < 0) {
-      set_err(-status);
-      return false;
+    set_err(-status);
+    return false;
   }
   return true;
 }
@@ -1531,7 +1536,7 @@ smart_device * freebsd_scsi_device::autodetect_open()
   int avail_len = req_buff[4] + 5;
   int len = (avail_len < req_len ? avail_len : req_len);
   if (len < 36)
-      return this;
+    return this;
 
   // Use INQUIRY to detect type
   smart_device * newdev = 0;
@@ -1539,12 +1544,8 @@ smart_device * freebsd_scsi_device::autodetect_open()
     // 3ware ?
     if (!memcmp(req_buff + 8, "3ware", 5) || !memcmp(req_buff + 8, "AMCC", 4)) {
       close();
-#if defined(_WIN32) || defined(__CYGWIN__)
-      set_err(EINVAL, "AMCC/3ware controller, please try changing device to %s,N", get_dev_name());
-#else
       set_err(EINVAL, "AMCC/3ware controller, please try adding '-d 3ware,N',\n"
                       "you may need to replace %s with /dev/twaN or /dev/tweN", get_dev_name());
-#endif
       return this;
     }
 
@@ -1572,9 +1573,9 @@ class freebsd_smart_interface
 : public /*implements*/ smart_interface
 {
 public:
-  virtual const char * get_os_version_str();
+  virtual std::string get_os_version_str();
 
-  virtual const char * get_app_examples(const char * appname);
+  virtual std::string get_app_examples(const char * appname);
 
   virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
     const char * pattern = 0);
@@ -1588,26 +1589,24 @@ protected:
 
   virtual smart_device * get_custom_smart_device(const char * name, const char * type);
 
-  virtual const char * get_valid_custom_dev_types_str();
+  virtual std::string get_valid_custom_dev_types_str();
 };
 
 
 //////////////////////////////////////////////////////////////////////
-char sysname[256];
-const char * freebsd_smart_interface::get_os_version_str()
+
+std::string freebsd_smart_interface::get_os_version_str()
 {
- struct utsname osname;
- uname(&osname);
- snprintf(sysname, sizeof(sysname),"%s %s %s",osname.sysname, osname.release,
-        osname.machine);
-  return sysname;
+  struct utsname osname;
+  uname(&osname);
+  return strprintf("%s %s %s", osname.sysname, osname.release, osname.machine);
 }
 
-const char * freebsd_smart_interface::get_app_examples(const char * appname)
+std::string freebsd_smart_interface::get_app_examples(const char * appname)
 {
   if (!strcmp(appname, "smartctl"))
     return smartctl_examples;
-   return 0;
+  return "";
 }
 
 ata_device * freebsd_smart_interface::get_ata_device(const char * name, const char * type)
@@ -1622,105 +1621,106 @@ scsi_device * freebsd_smart_interface::get_scsi_device(const char * name, const
 
 static int 
 cam_getumassno(char * devname) {
-       union ccb ccb;
-       int bufsize, fd;
-       unsigned int i;
-       int error = -1;
-       char devstring[256];
-       
-       if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
-               warn("couldn't open %s", XPT_DEVICE);
-               return(1);
-       }
-       bzero(&ccb, sizeof(union ccb));
-
-       ccb.ccb_h.path_id = CAM_XPT_PATH_ID;
-       ccb.ccb_h.target_id = CAM_TARGET_WILDCARD;
-       ccb.ccb_h.target_lun = CAM_LUN_WILDCARD;
-
-       ccb.ccb_h.func_code = XPT_DEV_MATCH;
-       bufsize = sizeof(struct dev_match_result) * 100;
-       ccb.cdm.match_buf_len = bufsize;
-       ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
-       if (ccb.cdm.matches == NULL) {
-               warnx("can't malloc memory for matches");
-               close(fd);
-               return(1);
-       }
-       ccb.cdm.num_matches = 0;
-       /*
-        * We fetch all nodes, since we display most of them in the default
-        * case, and all in the verbose case.
-        */
-       ccb.cdm.num_patterns = 0;
-       ccb.cdm.pattern_buf_len = 0;
-       /*
-        * We do the ioctl multiple times if necessary, in case there are
-        * more than 100 nodes in the EDT.
-        */
-        
-       do {
-               if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
-                       warn("error sending CAMIOCOMMAND ioctl");
-                       error = -1;
-                       break;
-               }
-               if ((ccb.ccb_h.status != CAM_REQ_CMP)
-                || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
-                   && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
-                       warnx("got CAM error %#x, CDM error %d\n",
-                             ccb.ccb_h.status, ccb.cdm.status);
-                       error = -1;
-                       break;
-               }
-
-               struct bus_match_result *bus_result = 0;
-               for (i = 0; i < ccb.cdm.num_matches; i++) {
-                       switch (ccb.cdm.matches[i].type) {
-                       case DEV_MATCH_BUS: {
-                               // struct bus_match_result *bus_result;
-                               bus_result =
-                                       &ccb.cdm.matches[i].result.bus_result;
-                               break;
-                       }
-                       case DEV_MATCH_DEVICE: {
-                               /* we are not interested in device name */
-                               break;
-                       }
-                       case DEV_MATCH_PERIPH: {
-                               struct periph_match_result *periph_result;
-
-                               periph_result =
-                                     &ccb.cdm.matches[i].result.periph_result;
-
-                               snprintf(devstring,sizeof(devstring),"%s%d",periph_result->periph_name,periph_result->unit_number);
-                               if(strcmp(devstring,devname)==0){ /* found our device */
-                                   if(strcmp(bus_result->dev_name,"umass-sim")) {
-                                       close(fd);
-                                       return -1; /* non usb device found, giving up */
-                                   }
-                                   /* return bus number */
-                                   return  bus_result->unit_number;
-                               }
-                               break;
-                       }
-                       
-                       default:
-                               fprintf(stdout, "WARN: unknown match type\n");
-                               break;
-                       }
-               }
-
-       } while ((ccb.ccb_h.status == CAM_REQ_CMP)
-               && (ccb.cdm.status == CAM_DEV_MATCH_MORE));
-       close(fd);
-       free(ccb.cdm.matches);
-       return(error); /* no device found */
+  union ccb ccb;
+  int bufsize, fd;
+  unsigned int i;
+  int error = -1;
+  char devstring[256];
+
+  if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
+    warn("couldn't open %s", XPT_DEVICE);
+    return(1);
+  }
+  bzero(&ccb, sizeof(union ccb));
+
+  ccb.ccb_h.path_id = CAM_XPT_PATH_ID;
+  ccb.ccb_h.target_id = CAM_TARGET_WILDCARD;
+  ccb.ccb_h.target_lun = CAM_LUN_WILDCARD;
+  ccb.ccb_h.func_code = XPT_DEV_MATCH;
+  bufsize = sizeof(struct dev_match_result) * 100;
+  ccb.cdm.match_buf_len = bufsize;
+  ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
+
+  if (ccb.cdm.matches == NULL) {
+    warnx("can't malloc memory for matches");
+    close(fd);
+    return(1);
+  }
+  ccb.cdm.num_matches = 0;
+  /*
+  * We fetch all nodes, since we display most of them in the default
+  * case, and all in the verbose case.
+  */
+  ccb.cdm.num_patterns = 0;
+  ccb.cdm.pattern_buf_len = 0;
+  /*
+  * We do the ioctl multiple times if necessary, in case there are
+  * more than 100 nodes in the EDT.
+  */
+
+  do {
+    if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
+      warn("error sending CAMIOCOMMAND ioctl");
+      error = -1;
+      break;
+    }
+    if ((ccb.ccb_h.status != CAM_REQ_CMP)
+      || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
+        && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) 
+    {
+      warnx("got CAM error %#x, CDM error %d\n",
+        ccb.ccb_h.status, ccb.cdm.status);
+      error = -1;
+      break;
+    }
+
+    struct bus_match_result *bus_result = 0;
+    for (i = 0; i < ccb.cdm.num_matches; i++) {
+      switch (ccb.cdm.matches[i].type) {
+      case DEV_MATCH_BUS: {
+          // struct bus_match_result *bus_result;
+          bus_result =
+          &ccb.cdm.matches[i].result.bus_result;
+          break;
+      }
+    case DEV_MATCH_DEVICE:   {
+        /* we are not interested in device name */
+        break;
+      }
+    case DEV_MATCH_PERIPH: {
+        struct periph_match_result *periph_result;
+
+        periph_result =
+        &ccb.cdm.matches[i].result.periph_result;
+
+        snprintf(devstring,sizeof(devstring),"%s%d",periph_result->periph_name,periph_result->unit_number);
+        if(strcmp(devstring,devname)==0){ /* found our device */
+          if(strcmp(bus_result->dev_name,"umass-sim")) {
+            close(fd);
+            return -1; /* non usb device found, giving up */
+          }
+          /* return bus number */
+          return  bus_result->unit_number;
+        }
+        break;
+    }
+
+  default:
+    fprintf(stdout, "WARN: unknown match type\n");
+    break;
+      }
+    }
+  } while ((ccb.ccb_h.status == CAM_REQ_CMP)
+    && (ccb.cdm.status == CAM_DEV_MATCH_MORE));
+
+  close(fd);
+  free(ccb.cdm.matches);
+  return(error); /* no device found */
 }
 
 
-// we are using CAM subsystem XPT enumerator to found all SCSI devices on system
-// despite of it's names
+// we are using CAM subsystem XPT enumerator to found all CAM (scsi/usb/ada/...)
+// devices on system despite of it's names
 //
 // If any errors occur, leave errno set as it was returned by the
 // system call, and return <0.
@@ -1729,7 +1729,7 @@ cam_getumassno(char * devname) {
 // -1:   error
 // >=0: number of discovered devices
 
-int get_dev_names_scsi(char*** names) {
+int get_dev_names_cam(char*** names) {
   int n = 0;
   char** mp = NULL;
   unsigned int i;
@@ -1772,13 +1772,12 @@ int get_dev_names_scsi(char*** names) {
   ccb.cdm.match_buf_len = bufsize;
   ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
   if (ccb.cdm.matches == NULL) {
-       serrno = errno;
-       pout("can't malloc memory for matches on line %d\n", __LINE__);
-       n = -1;
-       goto end;
+    serrno = errno;
+    pout("can't malloc memory for matches on line %d\n", __LINE__);
+    n = -1;
+    goto end;
   }
   ccb.cdm.num_matches = 0;
-
   ccb.cdm.num_patterns = 0;
   ccb.cdm.pattern_buf_len = 0;
 
@@ -1795,8 +1794,8 @@ int get_dev_names_scsi(char*** names) {
     }
 
     if ((ccb.ccb_h.status != CAM_REQ_CMP)
-     || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
-        && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
+      || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
+      && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
       pout("got CAM error %#x, CDM error %d\n", ccb.ccb_h.status, ccb.cdm.status);
       serrno = ENXIO;
       n = -1;
@@ -1812,8 +1811,8 @@ int get_dev_names_scsi(char*** names) {
         bus_result = &ccb.cdm.matches[i].result.bus_result;
 
         if (strcmp(bus_result->dev_name,"ata") == 0 /* ATAPICAM devices will be probed as ATA devices, skip'em there */
-         || strcmp(bus_result->dev_name,"xpt") == 0) /* skip XPT bus at all */
-          skip_bus = 1;
+          || strcmp(bus_result->dev_name,"xpt") == 0) /* skip XPT bus at all */
+        skip_bus = 1;
         else
           skip_bus = 0;
         changed = 1;
@@ -1825,13 +1824,13 @@ int get_dev_names_scsi(char*** names) {
         else
           skip_device = 0;
 
-//        /* Shall we skip non T_DIRECT devices ? */
-//        if (dev_result->inq_data.device != T_DIRECT)
-//          skip_device = 1;
+        //        /* Shall we skip non T_DIRECT devices ? */
+        //        if (dev_result->inq_data.device != T_DIRECT)
+        //          skip_device = 1;
         changed = 1;
       } else if (ccb.cdm.matches[i].type == DEV_MATCH_PERIPH && skip_device == 0) { 
         /* One device may be populated as many peripherals (pass0 & da0 for example). 
-         * We are searching for latest name
+        * We are searching for latest name
         */
         periph_result =  &ccb.cdm.matches[i].result.periph_result;
         free(devname);
@@ -1844,7 +1843,7 @@ int get_dev_names_scsi(char*** names) {
         };
         changed = 0;
       };
-      
+
       if (changed == 1 && devname != NULL) {
         mp[n] = devname;
         devname = NULL;
@@ -1906,7 +1905,7 @@ int get_dev_names_ata(char*** names) {
     n = -1;
     goto end;
   };
-  
+
   if (ioctl(fd, IOCATAGMAXCHANNEL, &maxchannel) < 0) {
     serrno = errno;
     pout("ioctl(IOCATAGMAXCHANNEL) on /dev/ata failed: %s\n", strerror(errno));
@@ -1925,7 +1924,7 @@ int get_dev_names_ata(char*** names) {
 
   for (devices.channel = 0; devices.channel < maxchannel && n < MAX_NUM_DEV; devices.channel++) {
     int j;
-    
+
     if (ioctl(fd, IOCATADEVICES, &devices) < 0) {
       if (errno == ENXIO)
         continue; /* such channel not exist */
@@ -1948,7 +1947,7 @@ int get_dev_names_ata(char*** names) {
   };  
   mp = (char **)reallocf(mp,n*(sizeof (char*))); // shrink to correct size
   bytes += (n)*(sizeof(char*)); // and set allocated byte count
-      
+
 end:
   if (fd>=0)
     close(fd);
@@ -1986,7 +1985,7 @@ bool freebsd_smart_interface::scan_smart_devices(smart_device_list & devlist,
 
   char * * scsinames = 0; int numscsi = 0;
   if (!type || !strcmp(type, "scsi")) {
-    numscsi = get_dev_names_scsi(&scsinames);
+    numscsi = get_dev_names_cam(&scsinames);
     if (numscsi < 0) {
       set_err(ENOMEM);
       return false;
@@ -2004,121 +2003,176 @@ bool freebsd_smart_interface::scan_smart_devices(smart_device_list & devlist,
   }
 
   for (i = 0; i < numscsi; i++) {
-    scsi_device * scsidev = get_scsi_device(scsinames[i], type);
-    if (scsidev)
-      devlist.add(scsidev);
+    if(!*type) { // try USB autodetection if no type specified
+      smart_device * smartdev = autodetect_smart_device(scsinames[i]);
+      if(smartdev)
+        devlist.add(smartdev);
+    }
+    else {
+      scsi_device * scsidev = get_scsi_device(scsinames[i], type);
+      if (scsidev)
+        devlist.add(scsidev);
+    }
   }
   return true;
 }
 
 
+#if (FREEBSDVER < 800000) // without this build fail on FreeBSD 8
 static char done[USB_MAX_DEVICES];
-// static unsigned short vendor_id = 0, product_id = 0, version = 0;
 
 static int usbdevinfo(int f, int a, int rec, int busno, unsigned short & vendor_id,
-                       unsigned short & product_id, unsigned short & version)
-{
-       struct usb_device_info di;
-       int e, p, i;
-       char devname[256];
-
-       snprintf(devname, sizeof(devname),"umass%d",busno);
-       
-       di.udi_addr = a;
-       e = ioctl(f, USB_DEVICEINFO, &di);
-       if (e) {
-               if (errno != ENXIO)
-                       printf("addr %d: I/O error\n", a);
-               return 0;
-       }
-       done[a] = 1;
-       
-               // list devices
-               for (i = 0; i < USB_MAX_DEVNAMES; i++) {
-                       if (di.udi_devnames[i][0]) {
-                               if(strcmp(di.udi_devnames[i],devname)==0) {
-                                // device found!
-                                   vendor_id = di.udi_vendorNo;
-                                   product_id = di.udi_productNo;
-                                   version = di.udi_releaseNo;
-                                   return 1;
-                                   // FIXME
-                               }
-                       }
-               }
-       if (!rec)
-               return 0;
-       for (p = 0; p < di.udi_nports; p++) {
-               int s = di.udi_ports[p];
-               if (s >= USB_MAX_DEVICES) {
-                       continue;
-               }
-               if (s == 0)
-                       printf("addr 0 should never happen!\n");
-               else {
-                       if(usbdevinfo(f, s, 1, busno, vendor_id, product_id, version)) return 1;
-               }
-       }
-       return 0;
-}
+  unsigned short & product_id, unsigned short & version)
+{ 
 
+  struct usb_device_info di;
+  int e, p, i;
+  char devname[256];
 
+  snprintf(devname, sizeof(devname),"umass%d",busno);
+
+  di.udi_addr = a;
+  e = ioctl(f, USB_DEVICEINFO, &di);
+  if (e) {
+    if (errno != ENXIO)
+      printf("addr %d: I/O error\n", a);
+    return 0;
+  }
+  done[a] = 1;
+
+  // list devices
+  for (i = 0; i < USB_MAX_DEVNAMES; i++) {
+    if (di.udi_devnames[i][0]) {
+      if(strcmp(di.udi_devnames[i],devname)==0) {
+        // device found!
+        vendor_id = di.udi_vendorNo;
+        product_id = di.udi_productNo;
+        version = di.udi_releaseNo;
+        return 1;
+        // FIXME
+      }
+    }
+  }
+  if (!rec)
+    return 0;
+  for (p = 0; p < di.udi_nports; p++) {
+    int s = di.udi_ports[p];
+    if (s >= USB_MAX_DEVICES) {
+      continue;
+    }
+    if (s == 0)
+      printf("addr 0 should never happen!\n");
+    else {
+      if(usbdevinfo(f, s, 1, busno, vendor_id, product_id, version)) return 1;
+    }
+  }
+  return 0;
+}
+#endif
 
 
 static int usbdevlist(int busno,unsigned short & vendor_id,
-                       unsigned short & product_id, unsigned short & version)
+  unsigned short & product_id, unsigned short & version)
 {
-    int  i, f, a, rc;
-    char buf[50];
-    int ncont;
-
-    for (ncont = 0, i = 0; i < 10; i++) {
-       snprintf(buf, sizeof(buf), "%s%d", USBDEV, i);
-       f = open(buf, O_RDONLY);
-       if (f >= 0) {
-           memset(done, 0, sizeof done);
-           for (a = 1; a < USB_MAX_DEVICES; a++) {
-               if (!done[a]) {
-                   rc = usbdevinfo(f, a, 1, busno,vendor_id, product_id, version);
-                   if(rc) return 1;
-               }
-               
-           }
-       close(f);
-       } else {
-           if (errno == ENOENT || errno == ENXIO)
-               continue;
-           warn("%s", buf);
-       }
-       ncont++;
+#if (FREEBSDVER >= 800000) // libusb2 interface
+  struct libusb20_device *pdev = NULL;
+  struct libusb20_backend *pbe;
+  uint32_t matches = 0;
+  char buf[128]; // do not change!
+  char devname[128];
+  uint8_t n;
+  struct LIBUSB20_DEVICE_DESC_DECODED *pdesc;
+
+  pbe = libusb20_be_alloc_default();
+
+  while ((pdev = libusb20_be_device_foreach(pbe, pdev))) {
+    matches++;
+
+    if (libusb20_dev_open(pdev, 0)) {
+      warnx("libusb20_dev_open: could not open device");
+      return 0;
     }
-    return 0;
+
+    pdesc=libusb20_dev_get_device_desc(pdev);
+
+    snprintf(devname, sizeof(devname),"umass%d:",busno);
+    for (n = 0; n != 255; n++) {
+      if (libusb20_dev_get_iface_desc(pdev, n, buf, sizeof(buf)))
+        break;
+      if (buf[0] == 0)
+        continue;
+      if(strncmp(buf,devname,strlen(devname))==0){
+        // found!
+        vendor_id = pdesc->idVendor;
+        product_id = pdesc->idProduct;
+        version = pdesc->bcdDevice;
+        libusb20_dev_close(pdev);
+        libusb20_be_free(pbe);
+        return 1;
+      }
+    }
+
+    libusb20_dev_close(pdev);
+  }
+
+  if (matches == 0) {
+    printf("No device match or lack of permissions.\n");
+  }
+
+  libusb20_be_free(pbe);
+
+  return false;
+#else // freebsd < 8.0 USB stack, ioctl interface
+
+  int  i, f, a, rc;
+  char buf[50];
+  int ncont;
+
+  for (ncont = 0, i = 0; i < 10; i++) {
+    snprintf(buf, sizeof(buf), "%s%d", USBDEV, i);
+    f = open(buf, O_RDONLY);
+    if (f >= 0) {
+      memset(done, 0, sizeof done);
+      for (a = 1; a < USB_MAX_DEVICES; a++) {
+        if (!done[a]) {
+          rc = usbdevinfo(f, a, 1, busno,vendor_id, product_id, version);
+          if(rc) return 1;
+        }
+
+      }
+      close(f);
+    } else {
+      if (errno == ENOENT || errno == ENXIO)
+        continue;
+      warn("%s", buf);
+    }
+    ncont++;
+  }
+  return 0;
+#endif
 }
 
 // Get USB bridge ID for "/dev/daX"
 static bool get_usb_id(const char * path, unsigned short & vendor_id,
-                       unsigned short & product_id, unsigned short & version)
+  unsigned short & product_id, unsigned short & version)
 {
-  // Only "/dev/daX" supported
-  if (!(!strncmp(path, "/dev/da", 7) && !strchr(path + 7, '/')))
+  if (strlen(path) < 5)
     return false;
-   int bus = cam_getumassno((char *)path+5);
-   
+  int bus = cam_getumassno((char *)path+5);
   if (bus == -1) 
     return false;
 
   usbdevlist(bus,vendor_id,
-                       product_id, version);
-
+    product_id, version);
   return true;
 }
 
 
 smart_device * freebsd_smart_interface::autodetect_smart_device(const char * name)
 {
-  int guess = parse_ata_chan_dev(name,NULL);
+  int guess = parse_ata_chan_dev(name,NULL,"");
   unsigned short vendor_id = 0, product_id = 0, version = 0;
-  
+
   switch (guess) {
   case CONTROLLER_ATA : 
     return new freebsd_ata_device(this, name, "");
@@ -2139,9 +2193,7 @@ smart_device * freebsd_smart_interface::autodetect_smart_device(const char * nam
     set_err(EINVAL, "Option -d cciss,N requires N to be a non-negative integer");
     return 0;
   }
-  
-  
-  // TODO: Test autodetect device here
+  // TODO: Test autodetected device here
   return 0;
 }
 
@@ -2159,10 +2211,10 @@ smart_device * freebsd_smart_interface::get_custom_smart_device(const char * nam
       set_err(EINVAL, "Option -d 3ware,N (N=%d) must have 0 <= N <= 127", disknum);
       return 0;
     }
-    int contr = parse_ata_chan_dev(name,NULL);
+    int contr = parse_ata_chan_dev(name,NULL,"");
     if (contr != CONTROLLER_3WARE_9000_CHAR && contr != CONTROLLER_3WARE_678K_CHAR)
       contr = CONTROLLER_3WARE_678K;
-     return new freebsd_escalade_device(this, name, contr, disknum);
+    return new freebsd_escalade_device(this, name, contr, disknum);
   } 
 
   // Highpoint ?
@@ -2206,15 +2258,13 @@ smart_device * freebsd_smart_interface::get_custom_smart_device(const char * nam
   return 0;
 }
 
-const char * freebsd_smart_interface::get_valid_custom_dev_types_str()
+std::string freebsd_smart_interface::get_valid_custom_dev_types_str()
 {
-  return "marvell, 3ware,N, hpt,L/M/N, cciss,N";
+  return "3ware,N, hpt,L/M/N, cciss,N";
 }
 
-
 } // namespace
 
-
 /////////////////////////////////////////////////////////////////////////////
 /// Initialize platform interface and register with smi()
 
index 6793a43484e112a39b1aa52f61ab96e1e8bb35a1..9a59afb71221debfd6e026458f93bb20a8d7af05 100644 (file)
@@ -587,6 +587,7 @@ typedef struct tw_osli_ioctl_with_payload {
 #define MAXDEV_PER_CHANNEL 2
 #define PMPORT_PER_CHANNEL 15 /* max devices connected to this channel via pmport */
 
+#pragma pack(1)
 typedef struct _HPT_CHANNEL_INFO {
   unsigned int reserve1;
   unsigned int reserve2;
@@ -624,6 +625,7 @@ typedef struct _HPT_PASS_THROUGH_HEADER {
   unsigned char reserve[3];
 }
 HPT_PASS_THROUGH_HEADER, *PHPT_PASS_THROUGH_HEADER;
+#pragma pack()
 
 #ifndef __unused
 #define __unused __attribute__ ((__unused__))
index d57e17f81962ed3b1c9505db72add3ca7346d39e..d733147e22eb35e763b82c4a4ab972336c9dd821 100644 (file)
@@ -82,7 +82,7 @@
 // should have one *_H_CVSID macro appearing below for each file
 // appearing with #include "*.h" above.  Please list these (below) in
 // alphabetic/dictionary order.
-const char *os_XXXX_c_cvsid="$Id: os_generic.cpp,v 1.28 2009/01/20 00:31:17 dlukes Exp $" \
+const char *os_XXXX_c_cvsid="$Id: os_generic.cpp 2915 2009-09-18 21:17:37Z chrfranke $" \
 ATACMDS_H_CVSID CONFIG_H_CVSID OS_GENERIC_H_CVSID UTILITY_H_CVSID;
 
 // This is here to prevent compiler warnings for unused arguments of
@@ -175,7 +175,7 @@ public:
   virtual const char * get_os_version_str();
 #endif
 
-  virtual const char * get_app_examples(const char * appname);
+  virtual std::string get_app_examples(const char * appname);
 
   virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
     const char * pattern = 0);
@@ -189,7 +189,7 @@ protected:
 
   virtual smart_device * get_custom_smart_device(const char * name, const char * type);
 
-  virtual const char * get_valid_custom_dev_types_str();
+  virtual std::string get_valid_custom_dev_types_str();
 };
 
 
@@ -203,11 +203,11 @@ const char * generic_smart_interface::get_os_version_str()
 }
 #endif
 
-const char * generic_smart_interface::get_app_examples(const char * appname)
+std::string generic_smart_interface::get_app_examples(const char * appname)
 {
   if (!strcmp(appname, "smartctl"))
     ::print_smartctl_examples(); // this prints to stdout ...
-  return 0; // ... so don't print again.
+  return ""; // ... so don't print again.
 }
 
 // Return ATA device object for the given device name or NULL
@@ -267,7 +267,7 @@ smart_device * generic_smart_interface::get_custom_smart_device(const char * nam
   return NULL;
 }
 
-const char * generic_smart_interface::get_valid_custom_dev_types_str()
+std::string generic_smart_interface::get_valid_custom_dev_types_str()
 {
   return "";
 }
index a2866eb9613f1a68e5b180da637c7fd9bee6c941..f6d9f2d35f87b0020fd2ddac11ea70fad24f1f43 100644 (file)
@@ -90,7 +90,7 @@
 
 #define ARGUSED(x) ((void)(x))
 
-const char *os_XXXX_c_cvsid="$Id: os_linux.cpp 2879 2009-08-29 17:19:00Z chrfranke $" \
+const char *os_XXXX_c_cvsid="$Id: os_linux.cpp 2915 2009-09-18 21:17:37Z chrfranke $" \
 ATACMDS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_LINUX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
 
 /* for passing global control variables */
@@ -2709,17 +2709,17 @@ static bool read_id(const std::string & path, unsigned short & id)
   return ok;
 }
 
-// Get USB bridge ID for "/dev/sdX"
-static bool get_usb_id(const char * path, unsigned short & vendor_id,
+// Get USB bridge ID for "sdX"
+static bool get_usb_id(const char * name, unsigned short & vendor_id,
                        unsigned short & product_id, unsigned short & version)
 {
-  // Only "/dev/sdX" supported
-  if (!(!strncmp(path, "/dev/sd", 7) && !strchr(path + 7, '/')))
+  // Only "sdX" supported
+  if (!(!strncmp(name, "sd", 2) && !strchr(name, '/')))
     return false;
 
   // Start search at dir referenced by symlink "/sys/block/sdX/device"
   // -> "/sys/devices/.../usb*/.../host*/target*/..."
-  std::string dir = strprintf("/sys/block/%s/device", path + 5);
+  std::string dir = strprintf("/sys/block/%s/device", name);
 
   // Stop search at "/sys/devices"
   struct stat st;
@@ -2755,7 +2755,7 @@ class linux_smart_interface
 : public /*implements*/ smart_interface
 {
 public:
-  virtual const char * get_app_examples(const char * appname);
+  virtual std::string get_app_examples(const char * appname);
 
   virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
     const char * pattern = 0);
@@ -2769,20 +2769,20 @@ protected:
 
   virtual smart_device * get_custom_smart_device(const char * name, const char * type);
 
-  virtual const char * get_valid_custom_dev_types_str();
+  virtual std::string get_valid_custom_dev_types_str();
 
 private:
   bool get_dev_list(smart_device_list & devlist, const char * pattern,
-    bool scan_ata, bool scan_scsi, const char * req_type);
+    bool scan_ata, bool scan_scsi, const char * req_type, bool autodetect);
 
   smart_device * missing_option(const char * opt);
 };
 
-const char * linux_smart_interface::get_app_examples(const char * appname)
+std::string linux_smart_interface::get_app_examples(const char * appname)
 {
   if (!strcmp(appname, "smartctl"))
     return smartctl_examples;
-  return 0;
+  return "";
 }
 
 
@@ -2790,7 +2790,8 @@ const char * linux_smart_interface::get_app_examples(const char * appname)
 // have device entries for devices that exist.  So if we get the equivalent of
 // ls /dev/hd[a-t], we have all the ATA devices on the system
 bool linux_smart_interface::get_dev_list(smart_device_list & devlist,
-  const char * pattern, bool scan_ata, bool scan_scsi, const char * req_type)
+  const char * pattern, bool scan_ata, bool scan_scsi,
+  const char * req_type, bool autodetect)
 {
   // Use glob to look for any directory entries matching the pattern
   glob_t globbuf;
@@ -2867,10 +2868,15 @@ bool linux_smart_interface::get_dev_list(smart_device_list & devlist,
 
     if (name) {
       // Found a name, add device to list.
-      if (is_scsi)
-        devlist.add(new linux_scsi_device(this, name, req_type));
+      smart_device * dev;
+      if (autodetect)
+        dev = autodetect_smart_device(name);
+      else if (is_scsi)
+        dev = new linux_scsi_device(this, name, req_type);
       else
-        devlist.add(new linux_ata_device(this, name, req_type));
+        dev = new linux_ata_device(this, name, req_type);
+      if (dev) // autodetect_smart_device() may return nullptr.
+        devlist.add(dev);
     }
   }
 
@@ -2897,9 +2903,9 @@ bool linux_smart_interface::scan_smart_devices(smart_device_list & devlist,
     return true;
 
   if (scan_ata)
-    get_dev_list(devlist,"/dev/hd[a-t]", true, false, type);
-  if (scan_scsi)
-    get_dev_list(devlist, "/dev/sd[a-z]", false, true, type);
+    get_dev_list(devlist, "/dev/hd[a-t]", true, false, type, false);
+  if (scan_scsi) // Try USB autodetection if no type specifed
+    get_dev_list(devlist, "/dev/sd[a-z]", false, true, type, !*type);
 
   // if we found traditional links, we are done
   if (devlist.size() > 0)
@@ -2907,7 +2913,7 @@ bool linux_smart_interface::scan_smart_devices(smart_device_list & devlist,
 
   // else look for devfs entries without traditional links
   // TODO: Add udev support
-  return get_dev_list(devlist, "/dev/discs/disc*", scan_ata, scan_scsi, type);
+  return get_dev_list(devlist, "/dev/discs/disc*", scan_ata, scan_scsi, type, false);
 }
 
 ata_device * linux_smart_interface::get_ata_device(const char * name, const char * type)
@@ -2926,6 +2932,12 @@ smart_device * linux_smart_interface::missing_option(const char * opt)
   return 0;
 }
 
+// Return true if STR starts with PREFIX.
+static bool str_starts_with(const char * str, const char * prefix)
+{
+  return !strncmp(str, prefix, strlen(prefix));
+}
+
 // Guess device type (ata or scsi) based on device name (Linux
 // specific) SCSI device name in linux can be sd, sr, scd, st, nst,
 // osst, nosst and sg.
@@ -2952,8 +2964,15 @@ smart_device * linux_smart_interface::autodetect_smart_device(const char * name)
   if (!dev_name || !(len = strlen(dev_name)))
     return 0;
 
+  // Dereference if /dev/disk/by-*/* symlink
+  char linkbuf[100];
+  if (   str_starts_with(dev_name, "/dev/disk/by-")
+      && readlink(dev_name, linkbuf, sizeof(linkbuf)) > 0
+      && str_starts_with(linkbuf, "../../")) {
+    dev_name = linkbuf + sizeof("../../")-1;
+  }
   // Remove the leading /dev/... if it's there
-  if (!strncmp(lin_dev_prefix, dev_name, dev_prefix_len)) {
+  else if (!strncmp(lin_dev_prefix, dev_name, dev_prefix_len)) {
     if (len <= dev_prefix_len)
       // if nothing else in the string, unrecognized
       return 0;
@@ -2977,7 +2996,7 @@ smart_device * linux_smart_interface::autodetect_smart_device(const char * name)
 
     // Try to detect possible USB->(S)ATA bridge
     unsigned short vendor_id = 0, product_id = 0, version = 0;
-    if (get_usb_id(name, vendor_id, product_id, version)) {
+    if (get_usb_id(dev_name, vendor_id, product_id, version)) {
       const char * usbtype = get_usb_dev_type_by_id(vendor_id, product_id, version);
       if (!usbtype)
         return 0;
@@ -3124,7 +3143,7 @@ smart_device * linux_smart_interface::get_custom_smart_device(const char * name,
   return 0;
 }
 
-const char * linux_smart_interface::get_valid_custom_dev_types_str()
+std::string linux_smart_interface::get_valid_custom_dev_types_str()
 {
   return "marvell, areca,N, 3ware,N, hpt,L/M/N, megaraid,N"
 #ifdef HAVE_LINUX_CCISS_IOCTL_H
index d9d99e93c406ae28ad71811f93f027597a0cd59b..a0f6c4e70d14c3b0de95eef4a1904f53d1cbb459 100644 (file)
@@ -48,7 +48,7 @@ extern smartmonctrl * con; // con->permissive,reportataioctl
 
 
 // Needed by '-V' option (CVS versioning) of smartd/smartctl
-const char *os_XXXX_c_cvsid="$Id: os_win32.cpp,v 1.75 2009/06/02 19:43:06 chrfranke Exp $"
+const char *os_XXXX_c_cvsid="$Id: os_win32.cpp 2915 2009-09-18 21:17:37Z chrfranke $"
 ATACMDS_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
 
 
@@ -189,9 +189,9 @@ class win_smart_interface
 : public /*implements part of*/ smart_interface
 {
 public:
-  virtual const char * get_os_version_str();
+  virtual std::string get_os_version_str();
 
-  virtual const char * get_app_examples(const char * appname);
+  virtual std::string get_app_examples(const char * appname);
 
   virtual bool scan_smart_devices(smart_device_list & devlist, const char * type,
     const char * pattern = 0);
@@ -259,10 +259,10 @@ static bool is_wow64()
   return !!w64;
 }
 
-// Return build host and OS version as static string
-const char * win_smart_interface::get_os_version_str()
+// Return info string about build host and OS version
+std::string win_smart_interface::get_os_version_str()
 {
-  static char vstr[sizeof(SMARTMONTOOLS_BUILD_HOST)-1+sizeof("-2003r2(64)-sp2.1")+13]
+  char vstr[sizeof(SMARTMONTOOLS_BUILD_HOST)-1+sizeof("-2003r2(64)-sp2.1")+13]
     = SMARTMONTOOLS_BUILD_HOST;
   if (vstr[1] < '6')
     vstr[1] = '6';
@@ -479,13 +479,11 @@ bool win_smart_interface::scan_smart_devices(smart_device_list & devlist,
 
 
 // get examples for smartctl
-const char * win_smart_interface::get_app_examples(const char * appname)
+std::string win_smart_interface::get_app_examples(const char * appname)
 {
   if (strcmp(appname, "smartctl"))
-    return 0;
-  static char buf[2048]; // TODO: Let this function return std::string ?
-  snprintf(buf, sizeof(buf),
-         "=================================================== SMARTCTL EXAMPLES =====\n\n"
+    return "";
+  return "=================================================== SMARTCTL EXAMPLES =====\n\n"
          "  smartctl -a /dev/hda                       (Prints all SMART information)\n\n"
          "  smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n"
          "                                              (Enables SMART on first disk)\n\n"
@@ -510,9 +508,9 @@ const char * win_smart_interface::get_app_examples(const char * appname)
          "  's': SMART_* IOCTLs,         'a': IOCTL_ATA_PASS_THROUGH,\n"
          "  'i': IOCTL_IDE_PASS_THROUGH, 'c': ATA via IOCTL_SCSI_PASS_THROUGH,\n"
          "  'f': IOCTL_STORAGE_*,        'm': IOCTL_SCSI_MINIPORT_*.\n"
+      + strprintf(
          "  The default on this system is /dev/sdX:%s\n", ata_get_def_options()
-  );
-  return buf;
+        );
 }
 
 
index 4ae87022cd6f92c1df1c5ba0613da018a0719d66..64ae81e7d511504c2c23aad2893842237517c8c5 100644 (file)
@@ -48,6 +48,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <ctype.h>
 
 #include "config.h"
@@ -60,7 +61,7 @@
 #include "dev_ata_cmd_set.h" // ata_device_with_command_set
 #include "dev_tunnelled.h" // tunnelled_device<>
 
-const char * scsiata_cpp_cvsid = "$Id: scsiata.cpp 2876 2009-08-20 22:53:18Z dlukes $";
+const char * scsiata_cpp_cvsid = "$Id: scsiata.cpp 2916 2009-09-19 12:46:26Z chrfranke $";
 
 /* for passing global control variables */
 extern smartmonctrl *con;
@@ -432,11 +433,16 @@ bool sat_device::ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out)
 
 static bool has_sat_pass_through(ata_device * dev, bool packet_interface = false)
 {
+    /* Note:  malloc() ensures the read buffer lands on a single
+       page.  This avoids some bugs seen on LSI controlers under
+       FreeBSD */
+    char *data = (char *)malloc(512);
     ata_cmd_in in;
     in.in_regs.command = (packet_interface ? ATA_IDENTIFY_PACKET_DEVICE : ATA_IDENTIFY_DEVICE);
-    char data[512];
     in.set_data_in(data, 1);
-    return dev->ata_pass_through(in);
+    bool ret = dev->ata_pass_through(in);
+    free(data);
+    return ret;
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -1349,32 +1355,47 @@ struct usb_id_entry {
   const char * type;
 };
 
-const char d_sat[]     = "sat";
-const char d_cypress[] = "usbcypress";
-const char d_jmicron[] = "usbjmicron";
+const char d_sat[]       = "sat";
+const char d_cypress[]   = "usbcypress";
+const char d_jmicron[]   = "usbjmicron";
 const char d_jmicron_x[] = "usbjmicron,x";
-const char d_sunplus[] = "usbsunplus";
-const char d_unsup[]   = "unsupported";
+const char d_sunplus[]   = "usbsunplus";
+const char d_unsup[]     = "unsupported";
 
 // Map USB IDs -> '-d type' string
 const usb_id_entry usb_ids[] = {
+  // Cypress
   { 0x04b4, 0x6830, 0x0001, d_unsup   }, // Cypress CY7C68300A (AT2)
   { 0x04b4, 0x6830, 0x0240, d_cypress }, // Cypress CY7C68300B/C (AT2LP)
 //{ 0x04b4, 0x6831,     -1, d_cypress }, // Cypress CY7C68310 (ISD-300LP)
+  // Myson Century
+  { 0x04cf, 0x8818, 0xb007, d_unsup   }, // Myson Century CS8818
+  // Sunplus
   { 0x04fc, 0x0c15, 0xf615, d_sunplus }, // SunPlus SPDIF215
   { 0x04fc, 0x0c25, 0x0103, d_sunplus }, // SunPlus SPDIF225 (USB+SATA->SATA)
+  // Iomega
   { 0x059b, 0x0275, 0x0001, d_unsup   }, // Iomega MDHD500-U
+  // LaCie
   { 0x059f, 0x0651,     -1, d_unsup   }, // LaCie hard disk (FA Porsche design)
   { 0x059f, 0x1018,     -1, d_sat     }, // LaCie hard disk (Neil Poulton design)
+  // In-System Design
+  { 0x05ab, 0x0060, 0x1101, d_cypress }, // In-System/Cypress ISD-300A1
+  // Prolific
   { 0x067b, 0x3507, 0x0001, d_unsup   }, // Prolific PL3507
-  { 0x0930, 0x0b09,     -1, d_sunplus }, // Toshiba PX1396E-3T01 (similar to Dura Micro)
+  // Toshiba
+  { 0x0930, 0x0b09,     -1, d_sunplus }, // Toshiba PX1396E-3T01 (similar to Dura Micro 501)
+  // Seagate
   { 0x0bc2, 0x2000,     -1, d_sat     }, // Seagate FreeAgent Go
   { 0x0bc2, 0x2100,     -1, d_sat     }, // Seagate FreeAgent Go
   { 0x0bc2, 0x3001,     -1, d_sat     }, // Seagate FreeAgent Desk
-  { 0x0c0b, 0xb159, 0x0103, d_sunplus }, // Dura Micro (Sunplus USB-bridge)
+  // Dura Micro
+  { 0x0c0b, 0xb159, 0x0103, d_sunplus }, // Dura Micro 509
+  // Maxtor
   { 0x0d49, 0x7310, 0x0125, d_sat     }, // Maxtor OneTouch 4
   { 0x0d49, 0x7350, 0x0125, d_sat     }, // Maxtor OneTouch 4 Mini
+  { 0x0d49, 0x7410, 0x0122, d_sat     }, // Maxtor Basics Desktop
   { 0x0d49, 0x7450, 0x0122, d_sat     }, // Maxtor Basics Portable
+  // Western Digital
   { 0x1058, 0x0704, 0x0175, d_sat     }, // WD My Passport Essential
   { 0x1058, 0x0705, 0x0175, d_sat     }, // WD My Passport Elite
   { 0x1058, 0x0906, 0x0012, d_sat     }, // WD My Book ES
@@ -1383,13 +1404,17 @@ const usb_id_entry usb_ids[] = {
   { 0x1058, 0x1010, 0x0105, d_sat     }, // WD Elements
   { 0x1058, 0x1100, 0x0165, d_sat     }, // WD My Book Essential
   { 0x1058, 0x1102, 0x1028, d_sat     }, // WD My Book
+  // Initio
   { 0x13fd, 0x1240, 0x0104, d_sat     }, // Initio ? (USB->SATA)
   { 0x13fd, 0x1340, 0x0208, d_sat     }, // Initio ? (USB+SATA->SATA)
+  // JMicron
   { 0x152d, 0x2329, 0x0100, d_jmicron }, // JMicron JM20329 (USB->SATA)
   { 0x152d, 0x2336, 0x0100, d_jmicron_x},// JMicron JM20336 (USB+SATA->SATA, USB->2xSATA)
   { 0x152d, 0x2338, 0x0100, d_jmicron }, // JMicron JM20337/8 (USB->SATA+PATA, USB+SATA->PATA)
   { 0x152d, 0x2339, 0x0100, d_jmicron_x},// JMicron JM20339 (USB->SATA)
+  // Verbatim
   { 0x18a5, 0x0215, 0x0001, d_sat     }, // Verbatim FW/USB160 - Oxford OXUF934SSA-LQAG (USB+IEE1394->SATA)
+  // SunplusIT
   { 0x1bcf, 0x0c31,     -1, d_sunplus }  // SunplusIT
 };
 
index 348972ea55b4cd53604d2be3825f39d1acf1ecec..b4a62b613fcf417f2ffedc7d344eb33283690cbd 100644 (file)
@@ -1,7 +1,7 @@
 .ig
  Copyright (C) 2002-9 Bruce Allen <smartmontools-support@lists.sourceforge.net>
 
- $Id: smartctl.8.in 2855 2009-07-21 19:55:08Z chrfranke $
+ $Id: smartctl.8.in 2883 2009-09-02 12:38:39Z samm2 $
  
  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 the Free
@@ -405,7 +405,7 @@ of the HighPoint RocketRAID controller.
 
 .B HighPoint RocketRAID controllers are currently ONLY supported under Linux and FreeBSD.
 
-.B cciss controllers are currently ONLY supported under Linux.
+.B cciss controllers are currently ONLY supported under Linux and FreeBSD.
 
 .TP
 .B \-T TYPE, \-\-tolerance=TYPE
@@ -1769,7 +1769,7 @@ these documents may be found in the References section of the
 
 .SH
 SVN ID OF THIS PAGE:
-$Id: smartctl.8.in 2855 2009-07-21 19:55:08Z chrfranke $
+$Id: smartctl.8.in 2883 2009-09-02 12:38:39Z samm2 $
 .\" Local Variables:            
 .\" mode: nroff         
 .\" End:
index 549dd957c9f06168f266f63096aa5cc7695db9d6..7da7a0b1c5adc2b4042571ad362a77901a78eac4 100644 (file)
@@ -56,7 +56,7 @@
 #include "smartctl.h"
 #include "utility.h"
 
-const char * smartctl_cpp_cvsid = "$Id: smartctl.cpp 2854 2009-07-21 19:23:20Z chrfranke $"
+const char * smartctl_cpp_cvsid = "$Id: smartctl.cpp 2915 2009-09-18 21:17:37Z chrfranke $"
                                   CONFIG_H_CVSID EXTERN_H_CVSID SMARTCTL_H_CVSID;
 
 // This is a block containing all the "control variables".  We declare
@@ -73,7 +73,7 @@ void UsageSummary(){
   return;
 }
 
-static const char *getvalidarglist(char opt);
+static std::string getvalidarglist(char opt);
 
 /*  void prints help information for command syntax */
 void Usage (void){
@@ -105,7 +105,7 @@ void Usage (void){
 "         Report transactions (see man page)\n\n"
 "  -n MODE, --nocheck=MODE                                             (ATA)\n"
 "         No check if: never, sleep, standby, idle (see man page)\n\n",
-  getvalidarglist('d')); // TODO: Use this function also for other options ?
+  getvalidarglist('d').c_str()); // TODO: Use this function also for other options ?
   printf(
 "============================== DEVICE FEATURE ENABLE/DISABLE COMMANDS =====\n\n"
 "  -s VALUE, --smart=VALUE\n"
@@ -153,24 +153,20 @@ void Usage (void){
 "  -X, --abort\n"
 "        Abort any non-captive test on device\n\n"
 );
-  const char * examples = smi()->get_app_examples("smartctl");
-  if (examples)
-    printf("%s\n", examples);
+  std::string examples = smi()->get_app_examples("smartctl");
+  if (!examples.empty())
+    printf("%s\n", examples.c_str());
 }
 
-/* Returns a pointer to a static string containing a formatted list of the valid
-   arguments to the option opt or NULL on failure. Note 'v' case different */
-static const char *getvalidarglist(char opt)
+/* Returns a string containing a formatted list of the valid arguments
+   to the option opt or empty on failure. Note 'v' case different */
+static std::string getvalidarglist(char opt)
 {
   switch (opt) {
   case 'q':
     return "errorsonly, silent, noserial";
   case 'd':
-    { // TODO: let this function return std::string ?
-      static std::string buf = smi()->get_valid_dev_types_str();
-      buf += ", test";
-      return buf.c_str();
-    }
+    return smi()->get_valid_dev_types_str() + ", test";
   case 'T':
     return "normal, conservative, permissive, verypermissive";
   case 'b':
@@ -195,7 +191,7 @@ static const char *getvalidarglist(char opt)
     return "never, sleep, standby, idle";
   case 'v':
   default:
-    return NULL;
+    return "";
   }
 }
 
@@ -210,9 +206,9 @@ void printvalidarglistmessage(char opt) {
   else {
   // getvalidarglist() might produce a multiline or single line string.  We
   // need to figure out which to get the formatting right.
-    const char * s = getvalidarglist(opt);
-    char separator = strchr(s, '\n') ? '\n' : ' ';
-    pout("=======> VALID ARGUMENTS ARE:%c%s%c<=======\n", separator, s, separator);
+    std::string s = getvalidarglist(opt);
+    char separator = strchr(s.c_str(), '\n') ? '\n' : ' ';
+    pout("=======> VALID ARGUMENTS ARE:%c%s%c<=======\n", separator, s.c_str(), separator);
   }
 
   return;
index 1e63dc9226391a94502fd249fe037cd6756ca41a..efaa226d31c17d942daa79c02f31e3da1d10bcf7 100644 (file)
@@ -122,7 +122,7 @@ extern "C" int getdomainname(char *, int); // no declaration in header files!
 
 #define ARGUSED(x) ((void)(x))
 
-const char * smartd_cpp_cvsid = "$Id: smartd.cpp 2870 2009-08-02 20:38:30Z manfred99 $"
+const char * smartd_cpp_cvsid = "$Id: smartd.cpp 2915 2009-09-18 21:17:37Z chrfranke $"
                                 CONFIG_H_CVSID EXTERN_H_CVSID;
 
 extern const char *reportbug;
@@ -1412,7 +1412,7 @@ void Directives() {
            "Attribute ID is a decimal integer 1 <= ID <= 255\n"
           "Use ID = 0 to turn off -C and/or -U Directives\n"
            "Example: /dev/hda -a\n", 
-           configfile, smi()->get_valid_dev_types_str());
+           configfile, smi()->get_valid_dev_types_str().c_str());
   return;
 }
 
@@ -3009,7 +3009,7 @@ void printoutvaliddirectiveargs(int priority, char d) {
     PrintOut(priority, "valid_regular_expression");
     break;
   case 'd':
-    PrintOut(priority, "%s", smi()->get_valid_dev_types_str());
+    PrintOut(priority, "%s", smi()->get_valid_dev_types_str().c_str());
     break;
   case 'T':
     PrintOut(priority, "normal, permissive");
index 670df9e7ad9b5c67f9451ea73561fb95d9101ecf..511adc5f105dfed67a6d730331aa168f17741461 100644 (file)
@@ -50,7 +50,7 @@
 #include "atacmds.h"
 #include "dev_interface.h"
 
-const char * utility_cpp_cvsid = "$Id: utility.cpp 2848 2009-07-18 20:14:38Z chrfranke $"
+const char * utility_cpp_cvsid = "$Id: utility.cpp 2915 2009-09-18 21:17:37Z chrfranke $"
                                  UTILITY_H_CVSID INT64_H_CVSID;
 
 const char * packet_types[] = {
@@ -91,7 +91,7 @@ std::string format_version_info(const char * prog_name, bool full /*= false*/)
     "%s "PACKAGE_VERSION" "SMARTMONTOOLS_SVN_DATE" r"SMARTMONTOOLS_SVN_REV
       " [%s] "BUILD_INFO"\n"
     "Copyright (C) 2002-9 by Bruce Allen, http://smartmontools.sourceforge.net\n",
-    prog_name, smi()->get_os_version_str()
+    prog_name, smi()->get_os_version_str().c_str()
   );
   if (!full)
     return info;