aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2018-05-02 22:02:05 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2018-05-02 22:02:05 +0000
commita59b767b38f08c0dafc011a58e8791aa06d4feb0 (patch)
tree8be0500cec5edb562779bc41f0ef7ad46b8c86fc /lib
parentf65566c3934a9e22335dee20401cc1cc50865d56 (diff)
downloadsg3_utils-a59b767b38f08c0dafc011a58e8791aa06d4feb0.tar.gz
sg_lib: add sg_ll_inquiry_pt(), sg_ll_test_unit_ready_progress_pt(), sg_ll_request_sense_pt(), sg_ll_send_diag_pt(), sg_ll_receive_diag_pt(); sg_timestamp: add --elapsed, --hex and --no-timestamp options; sg_ses: check for NVMe enclosure bits
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@769 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/Makefile.in5
-rw-r--r--lib/sg_cmds_basic.c168
-rw-r--r--lib/sg_cmds_extra.c83
-rw-r--r--lib/sg_pt_win32.c12
5 files changed, 185 insertions, 86 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2acb18da..c70f47d2 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,7 +35,7 @@ libsgutils2_la_SOURCES += sg_pt_osf1.c
endif
# For C++/clang testing
-## CC = gcc
+## CC = gcc-8
## CC = g++
## CC = clang
## CC = clang++
@@ -49,6 +49,7 @@ AM_CFLAGS = -Wall -W
# AM_CFLAGS = -Wall -W -pedantic -std=c11
# AM_CFLAGS = -Wall -W -pedantic -std=c11 --analyze
# AM_CFLAGS = -Wall -W -pedantic -std=c++14
+# AM_CFLAGS = -Wall -W -pedantic -std=c++1z
lib_LTLIBRARIES = libsgutils2.la
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 4d772e2a..4a8d7678 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.15.1 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2017 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -359,6 +359,7 @@ AM_CFLAGS = -Wall -W
# AM_CFLAGS = -Wall -W -pedantic -std=c11
# AM_CFLAGS = -Wall -W -pedantic -std=c11 --analyze
# AM_CFLAGS = -Wall -W -pedantic -std=c++14
+# AM_CFLAGS = -Wall -W -pedantic -std=c++1z
lib_LTLIBRARIES = libsgutils2.la
libsgutils2_la_LDFLAGS = -version-info 2:0:0 -no-undefined
libsgutils2_la_LIBADD = @GETOPT_O_FILES@
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c
index a31d1834..53014180 100644
--- a/lib/sg_cmds_basic.c
+++ b/lib/sg_cmds_basic.c
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <errno.h>
#include <string.h>
#include <unistd.h>
@@ -36,7 +37,7 @@
#endif
-static const char * const version_str = "1.85 20180302";
+static const char * const version_str = "1.86 20180501";
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
@@ -333,18 +334,19 @@ create_pt_obj(const char * cname)
static const char * const inquiry_s = "inquiry";
+
+
/* Returns 0 on success, while positive values are SG_LIB_CAT_* errors
* (e.g. SG_LIB_CAT_MALFORMED). If OS error, returns negated errno or -1. */
static int
-sg_ll_inquiry_com(int sg_fd, bool cmddt, bool evpd, int pg_op, void * resp,
- int mx_resp_len, int timeout_secs, int * residp,
- bool noisy, int verbose)
+sg_ll_inquiry_com(struct sg_pt_base * ptvp, bool cmddt, bool evpd, int pg_op,
+ void * resp, int mx_resp_len, int timeout_secs,
+ int * residp, bool noisy, int verbose)
{
int res, ret, k, sense_cat, resid;
uint8_t inq_cdb[INQUIRY_CMDLEN] = {INQUIRY_CMD, 0, 0, 0, 0, 0};
uint8_t sense_b[SENSE_BUFF_LEN];
uint8_t * up;
- struct sg_pt_base * ptvp;
if (cmddt)
inq_cdb[1] |= 0x2;
@@ -367,17 +369,10 @@ sg_ll_inquiry_com(int sg_fd, bool cmddt, bool evpd, int pg_op, void * resp,
}
if (timeout_secs <= 0)
timeout_secs = DEF_PT_TIMEOUT;
- ptvp = construct_scsi_pt_obj();
- if (NULL == ptvp) {
- pr2ws("%s: out of memory\n", __func__);
- if (residp)
- *residp = 0;
- return -1;
- }
set_scsi_pt_cdb(ptvp, inq_cdb, sizeof(inq_cdb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_in(ptvp, (uint8_t *)resp, mx_resp_len);
- res = do_scsi_pt(ptvp, sg_fd, timeout_secs, verbose);
+ res = do_scsi_pt(ptvp, -1, timeout_secs, verbose);
ret = sg_cmds_process_resp(ptvp, inquiry_s, res, mx_resp_len, sense_b,
noisy, verbose, &sense_cat);
resid = get_scsi_pt_resid(ptvp);
@@ -401,7 +396,6 @@ sg_ll_inquiry_com(int sg_fd, bool cmddt, bool evpd, int pg_op, void * resp,
ret = SG_LIB_CAT_MALFORMED;
} else
ret = 0;
- destruct_scsi_pt_obj(ptvp);
if (resid > 0) {
if (resid > mx_resp_len) {
@@ -422,8 +416,57 @@ int
sg_ll_inquiry(int sg_fd, bool cmddt, bool evpd, int pg_op, void * resp,
int mx_resp_len, bool noisy, int verbose)
{
- return sg_ll_inquiry_com(sg_fd, cmddt, evpd, pg_op, resp, mx_resp_len,
- 0 /* timeout_sec */, NULL, noisy, verbose);
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_inquiry_com(ptvp, cmddt, evpd, pg_op, resp, mx_resp_len,
+ 0 /* timeout_sec */, NULL, noisy, verbose);
+ destruct_scsi_pt_obj(ptvp);
+ return ret;
+}
+
+/* Invokes a SCSI INQUIRY command and yields the response. Returns 0 when
+ * successful, various SG_LIB_CAT_* positive values or -1 -> other errors.
+ * The CMDDT field is obsolete in the INQUIRY cdb (since spc3r16 in 2003) so
+ * an argument to set it has been removed (use the REPORT SUPPORTED OPERATION
+ * CODES command instead). Adds the ability to set the command abort timeout
+ * and the ability to report the residual count. If timeout_secs is zero
+ * or less the default command abort timeout (60 seconds) is used.
+ * If residp is non-NULL then the residual value is written where residp
+ * points. A residual value of 0 implies mx_resp_len bytes have be written
+ * where resp points. If the residual value equals mx_resp_len then no
+ * bytes have been written. */
+int
+sg_ll_inquiry_v2(int sg_fd, bool evpd, int pg_op, void * resp,
+ int mx_resp_len, int timeout_secs, int * residp,
+ bool noisy, int verbose)
+{
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_inquiry_com(ptvp, false, evpd, pg_op, resp, mx_resp_len,
+ timeout_secs, residp, noisy, verbose);
+ destruct_scsi_pt_obj(ptvp);
+ return ret;
+}
+
+/* Similar to _v2 but takes a pointer to an object (derived from) sg_pt_base.
+ * That object is assumed to be constructed and have a device file descriptor
+ * associated with it. Caller is responsible for lifetime of ptp. */
+int
+sg_ll_inquiry_pt(struct sg_pt_base * ptvp, bool evpd, int pg_op, void * resp,
+ int mx_resp_len, int timeout_secs, int * residp, bool noisy,
+ int verbose)
+{
+ return sg_ll_inquiry_com(ptvp, false, evpd, pg_op, resp, mx_resp_len,
+ timeout_secs, residp, noisy, verbose);
+
}
/* Yields most of first 36 bytes of a standard INQUIRY (evpd==0) response.
@@ -434,15 +477,21 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
bool noisy, int verbose)
{
int ret;
- uint8_t inq_resp[SAFE_STD_INQ_RESP_LEN];
+ uint8_t * inq_resp = NULL;
+ uint8_t * free_irp = NULL;
if (inq_data) {
memset(inq_data, 0, sizeof(* inq_data));
inq_data->peripheral_qualifier = 0x3;
inq_data->peripheral_type = 0x1f;
}
- ret = sg_ll_inquiry_com(sg_fd, false, false, 0, inq_resp,
- sizeof(inq_resp), 0, NULL, noisy, verbose);
+ inq_resp = sg_memalign(SAFE_STD_INQ_RESP_LEN, 0, &free_irp, verbose > 4);
+ if (NULL == inq_resp) {
+ pr2ws("%s: out of memory\n", __func__);
+ return sg_convert_errno(ENOMEM);
+ }
+ ret = sg_ll_inquiry_v2(sg_fd, false, 0, inq_resp, SAFE_STD_INQ_RESP_LEN,
+ 0, NULL, noisy, verbose);
if (inq_data && (0 == ret)) {
inq_data->peripheral_qualifier = (inq_resp[0] >> 5) & 0x7;
@@ -457,29 +506,11 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
memcpy(inq_data->product, inq_resp + 16, 16);
memcpy(inq_data->revision, inq_resp + 32, 4);
}
+ if (free_irp)
+ free(free_irp);
return ret;
}
-/* Invokes a SCSI INQUIRY command and yields the response. Returns 0 when
- * successful, various SG_LIB_CAT_* positive values or -1 -> other errors.
- * The CMDDT field is obsolete in the INQUIRY cdb (since spc3r16 in 2003) so
- * an argument to set it has been removed (use the REPORT SUPPORTED OPERATION
- * CODES command instead). Adds the ability to set the command abort timeout
- * and the ability to report the residual count. If timeout_secs is zero
- * or less the default command abort timeout (60 seconds) is used.
- * If residp is non-NULL then the residual value is written where residp
- * points. A residual value of 0 implies mx_resp_len bytes have be written
- * where resp points. If the residual value equals mx_resp_len then no
- * bytes have been written. */
-int
-sg_ll_inquiry_v2(int sg_fd, bool evpd, int pg_op, void * resp,
- int mx_resp_len, int timeout_secs, int * residp,
- bool noisy, int verbose)
-{
- return sg_ll_inquiry_com(sg_fd, false, evpd, pg_op, resp, mx_resp_len,
- timeout_secs, residp, noisy, verbose);
-}
-
/* Invokes a SCSI TEST UNIT READY command.
* 'pack_id' is just for diagnostics, safe to set to 0.
* Looks for progress indicator if 'progress' non-NULL;
@@ -487,14 +518,13 @@ sg_ll_inquiry_v2(int sg_fd, bool evpd, int pg_op, void * resp,
* Returns 0 when successful, various SG_LIB_CAT_* positive values or
* -1 -> other errors */
int
-sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
- bool noisy, int verbose)
+sg_ll_test_unit_ready_progress_pt(struct sg_pt_base * ptvp, int pack_id,
+ int * progress, bool noisy, int verbose)
{
static const char * const tur_s = "test unit ready";
int res, ret, k, sense_cat;
uint8_t tur_cdb[TUR_CMDLEN] = {TUR_CMD, 0, 0, 0, 0, 0};
uint8_t sense_b[SENSE_BUFF_LEN];
- struct sg_pt_base * ptvp;
if (verbose) {
pr2ws(" %s cdb: ", tur_s);
@@ -503,12 +533,10 @@ sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
pr2ws("\n");
}
- if (NULL == ((ptvp = create_pt_obj(tur_s))))
- return -1;
set_scsi_pt_cdb(ptvp, tur_cdb, sizeof(tur_cdb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_packet_id(ptvp, pack_id);
- res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
+ res = do_scsi_pt(ptvp, -1, DEF_PT_TIMEOUT, verbose);
ret = sg_cmds_process_resp(ptvp, tur_s, res, SG_NO_DATA_IN, sense_b,
noisy, verbose, &sense_cat);
if (-1 == ret)
@@ -531,7 +559,21 @@ sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
}
} else
ret = 0;
+ return ret;
+}
+int
+sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
+ bool noisy, int verbose)
+{
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_test_unit_ready_progress_pt(ptvp, pack_id, progress, noisy,
+ verbose);
destruct_scsi_pt_obj(ptvp);
return ret;
}
@@ -543,22 +585,29 @@ sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
int
sg_ll_test_unit_ready(int sg_fd, int pack_id, bool noisy, int verbose)
{
- return sg_ll_test_unit_ready_progress(sg_fd, pack_id, NULL, noisy,
- verbose);
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_test_unit_ready_progress_pt(ptvp, pack_id, NULL, noisy,
+ verbose);
+ destruct_scsi_pt_obj(ptvp);
+ return ret;
}
/* Invokes a SCSI REQUEST SENSE command. Returns 0 when successful, various
* SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_request_sense(int sg_fd, bool desc, void * resp, int mx_resp_len,
- bool noisy, int verbose)
+sg_ll_request_sense_pt(struct sg_pt_base * ptvp, bool desc, void * resp,
+ int mx_resp_len, bool noisy, int verbose)
{
static const char * const rq_s = "request sense";
int k, ret, res, sense_cat;
uint8_t rs_cdb[REQUEST_SENSE_CMDLEN] =
{REQUEST_SENSE_CMD, 0, 0, 0, 0, 0};
uint8_t sense_b[SENSE_BUFF_LEN];
- struct sg_pt_base * ptvp;
if (desc)
rs_cdb[1] |= 0x1;
@@ -574,12 +623,10 @@ sg_ll_request_sense(int sg_fd, bool desc, void * resp, int mx_resp_len,
pr2ws("\n");
}
- if (NULL == ((ptvp = create_pt_obj(rq_s))))
- return -1;
set_scsi_pt_cdb(ptvp, rs_cdb, sizeof(rs_cdb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_in(ptvp, (uint8_t *)resp, mx_resp_len);
- res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
+ res = do_scsi_pt(ptvp, -1, DEF_PT_TIMEOUT, verbose);
ret = sg_cmds_process_resp(ptvp, rq_s, res, mx_resp_len, sense_b, noisy,
verbose, &sense_cat);
if (-1 == ret)
@@ -603,6 +650,21 @@ sg_ll_request_sense(int sg_fd, bool desc, void * resp, int mx_resp_len,
} else
ret = 0;
}
+ return ret;
+}
+
+int
+sg_ll_request_sense(int sg_fd, bool desc, void * resp, int mx_resp_len,
+ bool noisy, int verbose)
+{
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_request_sense_pt(ptvp, desc, resp, mx_resp_len, noisy,
+ verbose);
destruct_scsi_pt_obj(ptvp);
return ret;
}
diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c
index 6db51f36..579dc464 100644
--- a/lib/sg_cmds_extra.c
+++ b/lib/sg_cmds_extra.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <errno.h>
#include <unistd.h>
#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
@@ -462,16 +463,16 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, bool one_seg,
* value is taken as the timeout value in seconds. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_send_diag(int sg_fd, int st_code, bool pf_bit, bool st_bit,
- bool devofl_bit, bool unitofl_bit, int long_duration,
- void * paramp, int param_len, bool noisy, int verbose)
+sg_ll_send_diag_pt(struct sg_pt_base * ptvp, int st_code, bool pf_bit,
+ bool st_bit, bool devofl_bit, bool unitofl_bit,
+ int long_duration, void * paramp, int param_len,
+ bool noisy, int verbose)
{
static const char * const cdb_name_s = "Send diagnostic";
int k, res, ret, sense_cat, tmout;
uint8_t senddiag_cdb[SEND_DIAGNOSTIC_CMDLEN] =
{SEND_DIAGNOSTIC_CMD, 0, 0, 0, 0, 0};
uint8_t sense_b[SENSE_BUFF_LEN];
- struct sg_pt_base * ptvp;
senddiag_cdb[1] = (uint8_t)(st_code << 5);
if (pf_bit)
@@ -502,12 +503,10 @@ sg_ll_send_diag(int sg_fd, int st_code, bool pf_bit, bool st_bit,
}
}
- if (NULL == ((ptvp = create_pt_obj(cdb_name_s))))
- return -1;
set_scsi_pt_cdb(ptvp, senddiag_cdb, sizeof(senddiag_cdb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (uint8_t *)paramp, param_len);
- res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
+ res = do_scsi_pt(ptvp, -1, tmout, verbose);
ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
noisy, verbose, &sense_cat);
if (-1 == ret)
@@ -525,31 +524,37 @@ sg_ll_send_diag(int sg_fd, int st_code, bool pf_bit, bool st_bit,
} else
ret = 0;
- destruct_scsi_pt_obj(ptvp);
return ret;
}
-/* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success,
- * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_receive_diag(int sg_fd, bool pcv, int pg_code, void * resp,
- int mx_resp_len, bool noisy, int verbose)
+sg_ll_send_diag(int sg_fd, int st_code, bool pf_bit, bool st_bit,
+ bool devofl_bit, bool unitofl_bit, int long_duration,
+ void * paramp, int param_len, bool noisy, int verbose)
{
- return sg_ll_receive_diag_v2(sg_fd, pcv, pg_code, resp, mx_resp_len, 0,
- NULL, noisy, verbose);
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_send_diag_pt(ptvp, st_code, pf_bit, st_bit, devofl_bit,
+ unitofl_bit, long_duration, paramp, param_len,
+ noisy, verbose);
+ destruct_scsi_pt_obj(ptvp);
+ return ret;
}
/* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_receive_diag_v2(int sg_fd, bool pcv, int pg_code, void * resp,
- int mx_resp_len, int timeout_secs, int * residp,
- bool noisy, int verbose)
+sg_ll_receive_diag_pt(struct sg_pt_base * ptvp, bool pcv, int pg_code,
+ void * resp, int mx_resp_len, int timeout_secs,
+ int * residp, bool noisy, int verbose)
{
int resid = 0;
int k, res, ret, sense_cat;
static const char * const cdb_name_s = "Receive diagnostic results";
- struct sg_pt_base * ptvp;
uint8_t rcvdiag_cdb[RECEIVE_DIAGNOSTICS_CMDLEN] =
{RECEIVE_DIAGNOSTICS_CMD, 0, 0, 0, 0, 0};
uint8_t sense_b[SENSE_BUFF_LEN];
@@ -568,15 +573,10 @@ sg_ll_receive_diag_v2(int sg_fd, bool pcv, int pg_code, void * resp,
if (timeout_secs <= 0)
timeout_secs = DEF_PT_TIMEOUT;
- if (NULL == ((ptvp = create_pt_obj(cdb_name_s)))) {
- if (residp)
- *residp = 0;
- return -1;
- }
set_scsi_pt_cdb(ptvp, rcvdiag_cdb, sizeof(rcvdiag_cdb));
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_in(ptvp, (uint8_t *)resp, mx_resp_len);
- res = do_scsi_pt(ptvp, sg_fd, timeout_secs, verbose);
+ res = do_scsi_pt(ptvp, -1, timeout_secs, verbose);
ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, mx_resp_len, sense_b,
noisy, verbose, &sense_cat);
resid = get_scsi_pt_resid(ptvp);
@@ -608,6 +608,41 @@ sg_ll_receive_diag_v2(int sg_fd, bool pcv, int pg_code, void * resp,
}
ret = 0;
}
+ return ret;
+}
+
+
+/* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success,
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
+int
+sg_ll_receive_diag(int sg_fd, bool pcv, int pg_code, void * resp,
+ int mx_resp_len, bool noisy, int verbose)
+{
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_receive_diag_pt(ptvp, pcv, pg_code, resp, mx_resp_len, 0,
+ NULL, noisy, verbose);
+ destruct_scsi_pt_obj(ptvp);
+ return ret;
+}
+
+int
+sg_ll_receive_diag_v2(int sg_fd, bool pcv, int pg_code, void * resp,
+ int mx_resp_len, int timeout_secs, int * residp,
+ bool noisy, int verbose)
+{
+ int ret;
+ struct sg_pt_base * ptvp;
+
+ ptvp = construct_scsi_pt_obj_with_fd(sg_fd, verbose);
+ if (NULL == ptvp)
+ return sg_convert_errno(ENOMEM);
+ ret = sg_ll_receive_diag_pt(ptvp, pcv, pg_code, resp, mx_resp_len,
+ timeout_secs, residp, noisy, verbose);
destruct_scsi_pt_obj(ptvp);
return ret;
}
diff --git a/lib/sg_pt_win32.c b/lib/sg_pt_win32.c
index bdb2808e..1fbb6d2f 100644
--- a/lib/sg_pt_win32.c
+++ b/lib/sg_pt_win32.c
@@ -5,7 +5,7 @@
* license that can be found in the BSD_LICENSE file.
*/
-/* sg_pt_win32 version 1.24 20180309 */
+/* sg_pt_win32 version 1.25 20180427 */
#include <stdio.h>
#include <stdlib.h>
@@ -1536,7 +1536,7 @@ nvme_identify(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA) + n;
buffer = sg_memalign(bufferLength, pg_sz, &free_buffer, false);
if (buffer == NULL) {
- res = SG_LIB_OS_BASE_ERR + ENOMEM;
+ res = sg_convert_errno(ENOMEM);
if (vb > 1)
pr2ws("%s: unable to allocate memory\n", __func__);
psp->os_err = res;
@@ -1626,7 +1626,7 @@ nvme_get_features(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA) + n;
buffer = sg_memalign(bufferLength, pg_sz, &free_buffer, false);
if (buffer == NULL) {
- res = SG_LIB_OS_BASE_ERR + ENOMEM;
+ res = sg_convert_errno(ENOMEM);
if (vb > 1)
pr2ws("%s: unable to allocate memory\n", __func__);
psp->os_err = res;
@@ -1705,7 +1705,7 @@ nvme_get_log_page(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA) + n;
buffer = sg_memalign(bufferLength, pg_sz, &free_buffer, false);
if (buffer == NULL) {
- res = SG_LIB_OS_BASE_ERR + ENOMEM;
+ res = sg_convert_errno(ENOMEM);
if (vb > 1)
pr2ws("%s: unable to allocate memory\n", __func__);
psp->os_err = res;
@@ -1787,7 +1787,7 @@ nvme_real_pt(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
sizeof(NVME_ERROR_INFO_LOG) + n;
buffer = sg_memalign(bufferLength, pg_sz, &free_buffer, false);
if (buffer == NULL) {
- res = SG_LIB_OS_BASE_ERR + ENOMEM;
+ res = sg_convert_errno(ENOMEM);
if (vb > 1)
pr2ws("%s: unable to allocate memory\n", __func__);
psp->os_err = res;
@@ -2014,7 +2014,7 @@ do_nvme_admin_cmd(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
pthru = (NVME_PASS_THROUGH_IOCTL *)sg_memalign(alloc_len, pg_sz,
&free_pthru, false);
if (NULL == pthru) {
- res = SG_LIB_OS_BASE_ERR + ENOMEM;
+ res = sg_convert_errno(ENOMEM);
if (vb > 1)
pr2ws("%s: unable to allocate memory\n", __func__);
psp->os_err = res;