From 2724c7c1b56ccdc4b02f26ff9bb167ae91a7ba3b Mon Sep 17 00:00:00 2001
From: dpgilbert <dpgilbert@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Tue, 2 Dec 2003 03:24:17 +0000
Subject: [PATCH] Add definition of scsiSelfTestInProgress() function

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@1330 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/scsicmds.c   | 27 ++++++++++++++++++++++++++-
 sm5/scsicmds.cpp | 27 ++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/sm5/scsicmds.c b/sm5/scsicmds.c
index 155d3a744..b963f65bf 100644
--- a/sm5/scsicmds.c
+++ b/sm5/scsicmds.c
@@ -46,7 +46,7 @@
 #include "utility.h"
 #include "extern.h"
 
-const char *scsicmds_c_cvsid="$Id: scsicmds.c,v 1.65 2003/11/20 01:02:27 dpgilbert Exp $" EXTERN_H_CVSID SCSICMDS_H_CVSID;
+const char *scsicmds_c_cvsid="$Id: scsicmds.c,v 1.66 2003/12/02 03:24:17 dpgilbert Exp $" EXTERN_H_CVSID SCSICMDS_H_CVSID;
 
 /* for passing global control variables */
 extern smartmonctrl *con;
@@ -1743,6 +1743,31 @@ int scsiCountFailedSelfTests(int fd, int noisy)
     return (fail_hour << 8) + fails;
 }
 
+/* Returns 0 if able to read self test log page; then outputs 1 into
+   *inProgress if self test still in progress, else outputs 0. */
+int scsiSelfTestInProgress(int fd, int * inProgress)
+{
+    int num;
+    UINT8 * ucp;
+    unsigned char resp[LOG_RESP_SELF_TEST_LEN];
+
+    if (scsiLogSense(fd, SELFTEST_RESULTS_LPAGE, resp, 
+                     LOG_RESP_SELF_TEST_LEN, 0))
+        return -1;
+    if (resp[0] != SELFTEST_RESULTS_LPAGE)
+        return -1;
+    // compute page length
+    num = (resp[2] << 8) + resp[3];
+    // Log sense page length 0x190 bytes
+    if (num != 0x190) {
+        return -1;
+    }
+    ucp = resp + 4;
+    if (inProgress)
+        *inProgress = (0xf == (ucp[4] & 0xf)) ? 1 : 0;
+    return 0;
+}
+
 /* Returns a negative value if failed to fetch Contol mode page or it was
    malformed. Returns 0 if GLTSD bit is zero and returns 1 if the GLTSD
    bit is set. Examines default mode page when current==0 else examines
diff --git a/sm5/scsicmds.cpp b/sm5/scsicmds.cpp
index 44177840c..0240767ec 100644
--- a/sm5/scsicmds.cpp
+++ b/sm5/scsicmds.cpp
@@ -46,7 +46,7 @@
 #include "utility.h"
 #include "extern.h"
 
-const char *scsicmds_c_cvsid="$Id: scsicmds.cpp,v 1.65 2003/11/20 01:02:27 dpgilbert Exp $" EXTERN_H_CVSID SCSICMDS_H_CVSID;
+const char *scsicmds_c_cvsid="$Id: scsicmds.cpp,v 1.66 2003/12/02 03:24:17 dpgilbert Exp $" EXTERN_H_CVSID SCSICMDS_H_CVSID;
 
 /* for passing global control variables */
 extern smartmonctrl *con;
@@ -1743,6 +1743,31 @@ int scsiCountFailedSelfTests(int fd, int noisy)
     return (fail_hour << 8) + fails;
 }
 
+/* Returns 0 if able to read self test log page; then outputs 1 into
+   *inProgress if self test still in progress, else outputs 0. */
+int scsiSelfTestInProgress(int fd, int * inProgress)
+{
+    int num;
+    UINT8 * ucp;
+    unsigned char resp[LOG_RESP_SELF_TEST_LEN];
+
+    if (scsiLogSense(fd, SELFTEST_RESULTS_LPAGE, resp, 
+                     LOG_RESP_SELF_TEST_LEN, 0))
+        return -1;
+    if (resp[0] != SELFTEST_RESULTS_LPAGE)
+        return -1;
+    // compute page length
+    num = (resp[2] << 8) + resp[3];
+    // Log sense page length 0x190 bytes
+    if (num != 0x190) {
+        return -1;
+    }
+    ucp = resp + 4;
+    if (inProgress)
+        *inProgress = (0xf == (ucp[4] & 0xf)) ? 1 : 0;
+    return 0;
+}
+
 /* Returns a negative value if failed to fetch Contol mode page or it was
    malformed. Returns 0 if GLTSD bit is zero and returns 1 if the GLTSD
    bit is set. Examines default mode page when current==0 else examines
-- 
GitLab