From 246c1d673a346a602ce9119319b68e1e788e03b8 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Tue, 21 Jul 2009 19:55:08 +0000
Subject: [PATCH] Require to specify PORT parameter of '-d usbjmicron' if two
 disks are connected.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@2855 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG     |  3 +++
 smartmontools/scsiata.cpp   | 22 +++++++++++++---------
 smartmontools/smartctl.8.in |  5 +++--
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index 75c203eef..fcd9f60f1 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -42,6 +42,9 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] Require to specify PORT parameter of '-d usbjmicron' if two disks
+       are connected.
+
   [CF] smartctl: Limit default number of printed entries for
        '-l xerror' to 8, for '-l xselftest' to 25.
 
diff --git a/smartmontools/scsiata.cpp b/smartmontools/scsiata.cpp
index fc0919936..ff46c0f2f 100644
--- a/smartmontools/scsiata.cpp
+++ b/smartmontools/scsiata.cpp
@@ -51,8 +51,8 @@
 #include "dev_ata_cmd_set.h" // ata_device_with_command_set
 #include "dev_tunnelled.h" // tunnelled_device<>
 
-const char *scsiata_c_cvsid="$Id$"
-CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID SCSICMDS_H_CVSID SCSIATA_H_CVSID UTILITY_H_CVSID;
+const char * scsiata_cpp_cvsid = "$Id$"
+                                 SCSIATA_H_CVSID;
 
 /* for passing global control variables */
 extern smartmonctrl *con;
@@ -873,13 +873,17 @@ bool usbjmicron_device::open()
       return false;
     }
 
-    if (regbuf[0] & 0x04)
-      m_port = 0;
-    else if (regbuf[0] & 0x40)
-      m_port = 1;
-    else {
-      close();
-      return set_err(ENODEV, "No device connected");
+    switch (regbuf[0] & 0x44) {
+      case 0x04:
+        m_port = 0; break;
+      case 0x40:
+        m_port = 1; break;
+      case 0x44:
+        close();
+        return set_err(EINVAL, "Two devices connected, try '-d usbjmicron,[01]'");
+      default:
+        close();
+        return set_err(ENODEV, "No device connected");
     }
   }
 
diff --git a/smartmontools/smartctl.8.in b/smartmontools/smartctl.8.in
index d9cf68b1f..b8638d9f4 100644
--- a/smartmontools/smartctl.8.in
+++ b/smartmontools/smartctl.8.in
@@ -254,8 +254,9 @@ all of these bridges and are therefore disabled by default. These commands
 can be enabled by \'\-d usbjmicron,x\'. CAUTION: Specifying \',x\' for a
 device which do not support it results in I/O errors and may disconnect
 the drive. The port can be specified by \'\-d usbjmicron[,x],PORT\' where
-PORT is 0 (master) or 1 (slave). If no PORT is specified, it is auto-detected.
-If both ports are connected, 0 takes precedence.
+PORT is 0 (master) or 1 (slave). This is not necessary if only one disk is
+connected to the USB bridge. If two disks are connected, an error message
+is printed if no PORT is specified.
 
 [NEW EXPERIMENTAL SMARTCTL FEATURE] The \'usbsunplus\' device type is for
 SATA disks that are behind a SunplusIT USB to SATA bridge.
-- 
GitLab