aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2019-09-17 21:53:05 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2019-09-17 21:53:05 +0000
commitbcdf18e4dd92f592617c35edbc9ffbb2817bd36c (patch)
treed408e019b135df92eb3f6860333865b9c9064b5c
parenteaa9d929aba1cc812418582c779731bcde2adf68 (diff)
downloadsg3_utils-bcdf18e4dd92f592617c35edbc9ffbb2817bd36c.tar.gz
sync with fixes from Redhat, via github; remove testing/Makefile.cplus and testing/Makefile.cplus_fb
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@832 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog5
-rw-r--r--README11
-rw-r--r--archive/align_b4_memalign.c9
-rw-r--r--doc/sg_read.814
-rw-r--r--doc/sg_requests.82
-rw-r--r--doc/sg_turs.820
-rw-r--r--examples/sg_compare_and_write.txt2
-rw-r--r--examples/transport_ids.txt2
-rw-r--r--include/sg_lib.h4
-rw-r--r--lib/sg_cmds_basic.c8
-rw-r--r--lib/sg_lib.c14
-rw-r--r--lib/sg_pt_linux_nvme.c5
-rwxr-xr-xscripts/rescan-scsi-bus.sh2
-rw-r--r--src/sg_dd.c22
-rw-r--r--src/sg_format.c12
-rw-r--r--src/sg_get_lba_status.c4
-rw-r--r--src/sg_inq.c3
-rw-r--r--src/sg_logs.c4
-rw-r--r--src/sg_luns.c7
-rw-r--r--src/sg_opcodes.c3
-rw-r--r--src/sg_persist.c6
-rw-r--r--src/sg_rbuf.c6
-rw-r--r--src/sg_sanitize.c11
-rw-r--r--src/sg_ses.c25
-rw-r--r--src/sg_test_rwbuf.c8
-rw-r--r--src/sg_vpd.c83
-rw-r--r--src/sg_vpd_vendor.c2
-rw-r--r--src/sg_write_x.c18
-rw-r--r--src/sginfo.c9
-rw-r--r--testing/Makefile4
-rw-r--r--testing/Makefile.cplus94
-rw-r--r--testing/Makefile.cplus_fb79
-rw-r--r--testing/README9
-rw-r--r--testing/sg_tst_async.cpp18
-rw-r--r--testing/sg_tst_context.cpp12
-rw-r--r--testing/sg_tst_excl.cpp79
-rw-r--r--testing/sg_tst_excl2.cpp17
-rw-r--r--testing/sg_tst_excl3.cpp20
38 files changed, 223 insertions, 430 deletions
diff --git a/ChangeLog b/ChangeLog
index 3546ab8b..eff02277 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.45 [20190905] [svn: r831]
+Changelog for sg3_utils-1.45 [20190917] [svn: r832]
- sg_get_elem_status: new utility [sbc4r16]
- sg_ses: bug: --page= being overridden when --control
and --data= also given; fix
@@ -60,7 +60,7 @@ Changelog for sg3_utils-1.45 [20190905] [svn: r831]
- testing/sg_tst_bidi: for sg 4.0 driver
- testing/sgh_dd: test request sharing, mreqs...
- testing/sgs_dd: back from archive, for testing
- - 'make' now builds both C and C++ programs
+ - testing: 'make' now builds both C and C++ programs
SIGPOLL (SIGIO) and realtime (RT) signals
- sg_pt: add sg_get_opcode_translation() to replace
global pointer to array: sg_opcode_info_arr[]
@@ -77,6 +77,7 @@ Changelog for sg3_utils-1.45 [20190905] [svn: r831]
- gcc-9: suppress (pointless) warnings
- automake: upgrade to version 1.16.1
- autoconf: upgrade to version 2.69
+ - sync with fixes from Redhat, via github
Changelog for sg3_utils-1.44 [20180912] [svn: r791]
- same code as release 1.43 20180911 svn rev 789;
diff --git a/README b/README
index 1a68d8b3..b88dd447 100644
--- a/README
+++ b/README
@@ -305,15 +305,14 @@ a "compliant jitter tolerance pattern" (CJTPAT).
The 'testing' subdirectory contains source and a Makefiles to test
kernel pass-through and associated drivers, mainly for Linux. There is
both C code (with the extension ".c") and C++ code (with the extension
-".cpp"). There is a "Makefile" to build the C code and a "Makefile.cplus"
-to build the C++ code. Both depend on some object files from the "lib"
-subdirectory. So a sequence like this may be required prior to invoking
-one of the Makefiles in the directory: "cd <top_of_package> ;
+".cpp"). There is a "Makefile" to build the C + C++ code. The Makefile
+depends on some object files from the "lib" subdirectory. So a sequence
+like this may be required prior to invoking make: "cd <top_of_package> ;
./configure ; cd lib ; make ; cd ../testing".
Here is a list in alphabetical order of utilities found in the 'testing'
subdirectory:
- - bsg_queue_tst, sg_iovec_tst, sg_queue_tst, sg_sense_tst,
+ - bsg_queue_tst, sgh_dd (C++), sg_iovec_tst, sg_queue_tst, sg_sense_tst,
sg_tst_async (C++), sg_tst_context (C++), sg_tst_excl (C++),
sg_tst_excl2 (C++), sg_tst_excl3 (C++)
@@ -542,4 +541,4 @@ See http://sg.danny.cz/sg/tools.html
Douglas Gilbert
-9th September 2019
+17 September 2019
diff --git a/archive/align_b4_memalign.c b/archive/align_b4_memalign.c
index 87602027..1cd4032d 100644
--- a/archive/align_b4_memalign.c
+++ b/archive/align_b4_memalign.c
@@ -1,5 +1,6 @@
-/* Code fragment of how to get a buffer of heap that has a specific
- * alignment, typically 'page' size which is 4096 bytes. */
+/* Code fragment of how to get a buffer from the heap that has a specific
+ * alignment. The typical alignment is to a "page" whose size is often
+ * 4096 bytes. */
uint8_t * wrkBuff; /* will get pointer to heap allocation */
uint8_t * wrkPos; /* will get aligned pointer within wrkBuff */
@@ -17,3 +18,7 @@
/* perhaps use posix_memalign() instead. Yes but not always available */
wrkBuff = (uint8_t *)malloc(sz_of_aligned + psz);
wrkPos = (uint8_t *)(((sg_uintptr_t)wrkBuff + psz - 1) & (~(psz - 1)));
+
+/* The disadvantage of this approach is that it needs both wrkBuff and wrkPos
+ * to be held by the application. The wrkBuff is only needed for the
+ * corresponding free(), all other uses should be via wrkPos. */
diff --git a/doc/sg_read.8 b/doc/sg_read.8
index 3f011349..c12dd57f 100644
--- a/doc/sg_read.8
+++ b/doc/sg_read.8
@@ -1,4 +1,4 @@
-.TH SG_READ "8" "November 2012" "sg3_utils\-1.35" SG3_UTILS
+.TH SG_READ "8" "September 2019" "sg3_utils\-1.45" SG3_UTILS
.SH NAME
sg_read \- read multiple blocks of data, optionally with SCSI READ commands
.SH SYNOPSIS
@@ -29,6 +29,11 @@ are issued. "Zero block" means "do nothing" for SCSI READ 10, 12 and
16 byte commands (but not for the 6 byte variant). In practice "zero
block" SCSI READ commands have low latency and so are one way to measure
SCSI command overhead.
+.PP
+Please note: this is a very old utility that uses 32 bit integers for
+disk LBAs and the count. Hence it will not be able to address beyond
+2 Terabytes on a disk with logical blocks that are 512 bytes long.
+Alternatives are the sg_dd and ddpt utilities.
.SH OPTIONS
.TP
\fBblk_sgio\fR=0 | 1
@@ -171,14 +176,17 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2000\-2012 Douglas Gilbert
+Copyright \(co 2000\-2019 Douglas Gilbert
.br
This software is distributed under the GPL version 2. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH "SEE ALSO"
To time streaming media read or write time see
.B sg_dd
-is in the sg3_utils package. The lmbench package contains
+is in the sg3_utils package and
+.B ddpt
+in a package of the same name.
+The lmbench package contains
.B lmdd
which is also interesting.
.B raw(8), dd(1)
diff --git a/doc/sg_requests.8 b/doc/sg_requests.8
index 58f30bef..81db55fe 100644
--- a/doc/sg_requests.8
+++ b/doc/sg_requests.8
@@ -57,7 +57,7 @@ is reached or an error occurs. The default value for \fINUM\fR is 1 .
same action as \fI\-\-num=NUM\fR. Added for compatibility with sg_turs.
.TP
\fB\-p\fR, \fB\-\-progress\fR
-show progress indication (a percentage) if available. If \fI\-\-number=NUM\fR
+show progress indication (a percentage) if available. If \fI\-\-num=NUM\fR
is given, \fINUM\fR is greater than 1 and an initial progress indication
was detected then this utility waits 30 seconds before subsequent checks.
Exits when \fINUM\fR is reached or there are no more progress indications.
diff --git a/doc/sg_turs.8 b/doc/sg_turs.8
index 66e6ad3a..8cf909c0 100644
--- a/doc/sg_turs.8
+++ b/doc/sg_turs.8
@@ -1,9 +1,9 @@
-.TH SG_TURS "8" "March 2018" "sg3_utils\-1.43" SG3_UTILS
+.TH SG_TURS "8" "September 2019" "sg3_utils\-1.45" SG3_UTILS
.SH NAME
sg_turs \- send one or more SCSI TEST UNIT READY commands
.SH SYNOPSIS
.B sg_turs
-[\fI\-\-help\fR] [\fI\-\-low\fR] [\fI\-\-number=NUM\fR] [\fI\-\-num=NUM\fR]
+[\fI\-\-help\fR] [\fI\-\-low\fR] [\fI\-\-num=NUM\fR] [\fI\-\-number=NUM\fR]
[\fI\-\-progress\fR] [\fI\-\-time\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
\fIDEVICE\fR
.PP
@@ -34,7 +34,7 @@ calls a library function to do each TUR (sg_ll_test_unit_ready). With this
option it uses the lower level sg_pt interface (see sg_pt.h) to save a
little time on each TUR.
.TP
-\fB\-n\fR, \fB\-\-number\fR=\fINUM\fR
+\fB\-n\fR, \fB\-\-num\fR=\fINUM\fR
performs TEST UNIT READY \fINUM\fR times. If not given defaults to 1.
These suffix multipliers are permitted: c C *1; w W *2; b B *512;
k K KiB *1,024; KB *1,000; m M MiB *1,048,576; MB *1,000,000;
@@ -42,15 +42,17 @@ g G GiB *1,073,741,824; and GB *1,000,000,000 . Also a suffix of the
form "x<n>" multiplies the leading number by <n>. Alternatively a hex
number may be given, prefixed by either '0x' or has a trailing 'h'.
.TP
-\fB\-\-num\fR=\fINUM\fR
-same as \fI\-\-number=NUM\fR. Added for compatibility with sg_requests
-which has taken over the role of polling the progress indication.
+\fB\-\-number\fR=\fINUM\fR
+same as \fI\-\-num=NUM\fR. Added for compatibility with sg_requests and
+other utilities in this package. The sg_request utility has taken over the
+role of polling the progress indication which was originally assigned to
+the TEST UNIT READY command. This is a change by T10.
.TP
\fB\-O\fR, \fB\-\-old\fR
Switch to older style options. Please use as first option.
.TP
\fB\-p\fR, \fB\-\-progress\fR
-show progress indication (a percentage) if available. If \fI\-\-number=NUM\fR
+show progress indication (a percentage) if available. If \fI\-\-num=NUM\fR
is given, \fINUM\fR is greater than 1 and an initial progress indication
was detected then this utility waits 30 seconds before subsequent checks.
Exits when \fINUM\fR is reached or there are no more progress indications.
@@ -101,7 +103,7 @@ force the use of these older command line options.
.TP
\fB\-n\fR=\fINUM\fR
performs TEST UNIT READY \fINUM\fR times. If not given defaults to 1.
-Equivalent to \fI\-\-number=NUM\fR in the main description.
+Equivalent to \fI\-\-num=NUM\fR in the main description.
.TP
\fB-N\fR, \fB\-\-new\fR
Switch to the newer style options.
@@ -128,7 +130,7 @@ using \fI\-\-old\fR (or \fI\-O\fR) as the first command line option.
.SH AUTHORS
Written by D. Gilbert
.SH COPYRIGHT
-Copyright \(co 2000\-2018 Douglas Gilbert
+Copyright \(co 2000\-2019 Douglas Gilbert
.br
This software is distributed under the GPL version 2. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/examples/sg_compare_and_write.txt b/examples/sg_compare_and_write.txt
index 05d72b91..86b166b3 100644
--- a/examples/sg_compare_and_write.txt
+++ b/examples/sg_compare_and_write.txt
@@ -9,7 +9,7 @@
#
# The following example shows initialization, successful and unsuccessful
# compare and write using sg3_utils. I am using caw_buf_zero2one and
-# caw_buf_one2zero as shown bellow.
+# caw_buf_one2zero as shown below.
$ hexdump /tmp/caw_buf_zero2one
0000000 0000 0000 0000 0000 0000 0000 0000 0000
diff --git a/examples/transport_ids.txt b/examples/transport_ids.txt
index 0c604569..a63374da 100644
--- a/examples/transport_ids.txt
+++ b/examples/transport_ids.txt
@@ -9,7 +9,7 @@
# To see transport IDs decoded after they have been read in (e.g. to check
# they are well formed) use the verbose flag 3 times (i.e. "... -vvv ...").
-# Here is a simple example (for SPI) of a comma separted hex list:
+# Here is a simple example (for SPI) of a comma separated hex list:
1,0,0,7,0,0,0,1 # SPI, initiator address=7, relative_port_num=1
# and here is the transport specific format for the same thing:
diff --git a/include/sg_lib.h b/include/sg_lib.h
index c762d3a2..169b0ea5 100644
--- a/include/sg_lib.h
+++ b/include/sg_lib.h
@@ -636,8 +636,8 @@ int sg_get_num_nomult(const char * buf);
* SI and IEC 60027-2)). Main (SI) multipliers supported: K, M, G, T, P
* and E. Ignore leading spaces and tabs; accept comma, hyphen, space, tab
* and hash as terminator. Handles zero and positive values up to 2**63-1 .
- * Experimental: left argument (must in with hexadecimal digit) added
- * to, or multipled by right argument. No embedded spaces.
+ * Experimental: the left argument (must end in with hexadecimal digit)
+ * added to, or multiplied by, the right argument. No embedded spaces.
* Examples: '3+1k' (evaluates to 1027) and '0xf+0x3'. */
int64_t sg_get_llnum(const char * buf);
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c
index 927c92a5..470c2f1c 100644
--- a/lib/sg_cmds_basic.c
+++ b/lib/sg_cmds_basic.c
@@ -42,7 +42,7 @@
#endif
-static const char * const version_str = "1.93 20190128";
+static const char * const version_str = "1.94 20190913";
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
@@ -364,7 +364,6 @@ 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
@@ -377,6 +376,11 @@ sg_ll_inquiry_com(struct sg_pt_base * ptvp, bool cmddt, bool evpd, int pg_op,
uint8_t sense_b[SENSE_BUFF_LEN];
uint8_t * up;
+ if (resp == NULL) {
+ if (verbose)
+ pr2ws("Got NULL `resp` pointer");
+ return SG_LIB_CAT_MALFORMED;
+ }
if (cmddt)
inq_cdb[1] |= 0x2;
if (evpd)
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index f6095f80..2516f450 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -550,7 +550,7 @@ sg_decode_transportid_str(const char * lip, uint8_t * bp, int bplen,
}
if (NULL == lip)
lip = "";
- bump = TRANSPORT_ID_MIN_LEN; /* should be overwritten in all loop paths */
+ /* bump = TRANSPORT_ID_MIN_LEN; // some old compilers insisted on this */
for (k = 0, n = 0; bplen > 0; ++k, bp += bump, bplen -= bump) {
if ((k > 0) && only_one)
break;
@@ -1878,9 +1878,6 @@ sg_get_sense_str(const char * lip, const uint8_t * sbp, int sb_len,
sg_scnpr(b + r, blen - r, "%s lba=0x%x\n", lip,
sg_get_unaligned_be24(sbp + 1) & 0x1fffff);
n += sg_scnpr(cbp + n, cblen - n, "%s\n", b);
- len = sb_len;
- if (len > 32)
- len = 32; /* trim in case there is a lot of rubbish */
}
check_raw:
if (raw_sinfo) {
@@ -2162,14 +2159,11 @@ sg_get_command_size(uint8_t opcode)
switch ((opcode >> 5) & 0x7) {
case 0:
return 6;
- case 1: case 2: case 6: case 7:
- return 10;
case 3: case 5:
return 12;
- break;
case 4:
return 16;
- default:
+ default: /* 1, 2, 6, 7 */
return 10;
}
}
@@ -2306,9 +2300,6 @@ sg_get_opcode_name(uint8_t cmd_byte0, int peri_type, int buff_len,
case 7:
sg_scnpr(buff, buff_len, "Vendor specific [0x%x]", (int)cmd_byte0);
break;
- default:
- sg_scnpr(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0);
- break;
}
}
@@ -2624,6 +2615,7 @@ sg_nvme_status2scsi(uint16_t sct_sc, uint8_t * status_p, uint8_t * sk_p,
return false;
} else if (ind >= k)
return false;
+
mp = sg_lib_scsi_status_sense_arr + ind;
if (status_p)
*status_p = mp->t1;
diff --git a/lib/sg_pt_linux_nvme.c b/lib/sg_pt_linux_nvme.c
index 771dd599..10e176b1 100644
--- a/lib/sg_pt_linux_nvme.c
+++ b/lib/sg_pt_linux_nvme.c
@@ -907,11 +907,6 @@ sntl_senddiag(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp,
return 0;
} else
return 0; /* nothing to do */
- if (dout_len > 0) {
- if (vb)
- pr2ws("%s: dout given but PF clear\n", __func__);
- return SCSI_PT_DO_BAD_PARAMS;
- }
}
if (dout_len < 4) {
if (vb)
diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh
index a708df9a..46fe6c06 100755
--- a/scripts/rescan-scsi-bus.sh
+++ b/scripts/rescan-scsi-bus.sh
@@ -1141,7 +1141,7 @@ if [ "@$1" = @--help ] || [ "@$1" = @-h ] || [ "@$1" = "@-?" ] ; then
echo "--largelun: Tell kernel to support LUNs > 7 even on SCSI2 devs"
echo "--luns=LIST: Scan only lun(s) in LIST"
echo "--multipath: same as -m"
- echo "--nooptscan: don't stop looking for LUNs is 0 is not found"
+ echo "--nooptscan: don't stop looking for LUNs if 0 is not found"
echo "--remove: same as -r"
echo "--reportlun2: Tell kernel to try REPORT_LUN even on SCSI2 devices"
echo "--resize: same as -s"
diff --git a/src/sg_dd.c b/src/sg_dd.c
index 01588669..06d96610 100644
--- a/src/sg_dd.c
+++ b/src/sg_dd.c
@@ -982,7 +982,7 @@ err_out:
}
return may_coe ? 0 : ret;
} else
- return ret ? ret : -1;
+ return ret;
}
@@ -1230,7 +1230,8 @@ static int
open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp,
int * in_typep, int vb)
{
- int infd, flags, fl, t, res;
+ int infd = -1;
+ int flags, fl, t, res;
char ebuff[EBUFF_SZ];
struct sg_simple_inquiry_resp sir;
@@ -1332,7 +1333,7 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp,
#endif
}
}
- if (ifp->flock) {
+ if (ifp->flock && (infd >= 0)) {
res = flock(infd, LOCK_EX | LOCK_NB);
if (res < 0) {
close(infd);
@@ -1345,8 +1346,12 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp,
return infd;
file_err:
+ if (infd >= 0)
+ close(infd);
return -SG_LIB_FILE_ERROR;
other_err:
+ if (infd >= 0)
+ close(infd);
return -SG_LIB_CAT_OTHER;
}
@@ -1358,7 +1363,8 @@ static int
open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp,
int * out_typep, int vb)
{
- int outfd, flags, t, res;
+ int outfd = -1;
+ int flags, t, res;
char ebuff[EBUFF_SZ];
struct sg_simple_inquiry_resp sir;
@@ -1460,21 +1466,25 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp,
"\n", (uint64_t)offset);
}
}
- if (ofp->flock) {
+ if (ofp->flock && (outfd >= 0)) {
res = flock(outfd, LOCK_EX | LOCK_NB);
if (res < 0) {
- close(outfd);
snprintf(ebuff, EBUFF_SZ, ME "flock(LOCK_EX | LOCK_NB) on %s "
"failed", outf);
perror(ebuff);
+ close(outfd);
return -SG_LIB_FLOCK_ERR;
}
}
return outfd;
file_err:
+ if (outfd >= 0)
+ close(outfd);
return -SG_LIB_FILE_ERROR;
other_err:
+ if (outfd >= 0)
+ close(outfd);
return -SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_format.c b/src/sg_format.c
index 12fa78d1..9b29caf9 100644
--- a/src/sg_format.c
+++ b/src/sg_format.c
@@ -40,7 +40,7 @@
#include "sg_pr2serr.h"
#include "sg_pt.h"
-static const char * version_str = "1.58 20190113";
+static const char * version_str = "1.59 20190913";
#define RW_ERROR_RECOVERY_PAGE 1 /* can give alternate with --mode=MP */
@@ -706,15 +706,9 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen,
if (n > (SAFE_STD_INQ_RESP_LEN - 4))
n = (SAFE_STD_INQ_RESP_LEN - 4);
for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) {
- if (VPD_UNIT_SERIAL_NUM == b[4 + k]) {
- if (has_di) {
- if (op->verbose)
- pr2serr("VPD_SUPPORTED_VPDS "
- "dis-ordered\n");
- goto out;
- }
+ if (VPD_UNIT_SERIAL_NUM == b[4 + k])
++has_sn;
- } else if (VPD_DEVICE_ID == b[4 + k]) {
+ else if (VPD_DEVICE_ID == b[4 + k]) {
++has_di;
break;
}
diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c
index 1b9df4de..4feac63b 100644
--- a/src/sg_get_lba_status.c
+++ b/src/sg_get_lba_status.c
@@ -35,7 +35,7 @@
* device.
*/
-static const char * version_str = "1.20 20190822"; /* sbc4r15 */
+static const char * version_str = "1.21 20190913"; /* sbc4r15 */
#ifndef UINT32_MAX
#define UINT32_MAX ((uint32_t)-1)
@@ -391,7 +391,7 @@ main(int argc, char * argv[])
res = sg_ll_get_lba_status16(sg_fd, lba, rt, glbasBuffp, maxlen, true,
verbose);
else if (do_32) /* keep analyser happy since do_32 must be true */
- res = sg_ll_get_lba_status32(sg_fd, lba, element_id, scan_len, rt,
+ res = sg_ll_get_lba_status32(sg_fd, lba, scan_len, element_id, rt,
glbasBuffp, maxlen, true, verbose);
ret = res;
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 5ee6792f..f1df8085 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -51,7 +51,7 @@
#include "sg_pt_nvme.h"
#endif
-static const char * version_str = "2.02 20190815"; /* SPC-5 rev 22 */
+static const char * version_str = "2.03 20190913"; /* SPC-5 rev 22 */
/* INQUIRY notes:
* It is recommended that the initial allocation length given to a
@@ -3246,7 +3246,6 @@ cmddt_process(int sg_fd, const struct opts_t * op)
break;
case 6: desc_p = "vendor specific (6)"; break;
case 7: desc_p = "reserved (7)"; break;
- default: desc_p = "impossible value > 7"; break;
}
if (prnt_cmd) {
printf(" Support field: %s [", desc_p);
diff --git a/src/sg_logs.c b/src/sg_logs.c
index e11e8523..c23a62e5 100644
--- a/src/sg_logs.c
+++ b/src/sg_logs.c
@@ -36,7 +36,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.77 20190822"; /* spc5r22 + sbc4r17 */
+static const char * version_str = "1.78 20190913"; /* spc5r22 + sbc4r17 */
#define MX_ALLOC_LEN (0xfffc)
#define SHORT_RESP_LEN 128
@@ -6980,7 +6980,7 @@ main(int argc, char * argv[])
if (k) {
if (SG_LIB_CAT_NOT_READY == k)
pr2serr("log_select: device not ready\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
+ else if (SG_LIB_CAT_ILLEGAL_REQ == k)
pr2serr("log_select: field in cdb illegal\n");
else if (SG_LIB_CAT_INVALID_OP == k)
pr2serr("log_select: not supported\n");
diff --git a/src/sg_luns.c b/src/sg_luns.c
index d1a5030e..555e14d6 100644
--- a/src/sg_luns.c
+++ b/src/sg_luns.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2018 Douglas Gilbert.
+ * Copyright (c) 2004-2019 Douglas Gilbert.
* All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the BSD_LICENSE file.
@@ -34,7 +34,7 @@
* and decodes the response.
*/
-static const char * version_str = "1.42 20180626";
+static const char * version_str = "1.43 20190913";
#define MAX_RLUNS_BUFF_LEN (1024 * 1024)
#define DEF_RLUNS_BUFF_LEN (1024 * 8)
@@ -308,9 +308,6 @@ decode_lun(const char * leadin, const uint8_t * lunp, bool lu_cong,
}
}
break;
- default:
- printf("%s<<%s: faulty logic>>\n", l_leadin, __func__);
- break;
}
if (next_level)
continue;
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index 52032cd1..f80b79da 100644
--- a/src/sg_opcodes.c
+++ b/src/sg_opcodes.c
@@ -800,7 +800,8 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
printf(" usage: ");
else
printf(" cdb usage: ");
- for (m = 0; m < cdb_sz; ++m)
+ for (m = 0; (m < cdb_sz) && ((4 + m) < (int)sizeof(b));
+ ++m)
printf("%.2x ", b[4 + m]);
printf("\n");
}
diff --git a/src/sg_persist.c b/src/sg_persist.c
index c1324c43..59067f2a 100644
--- a/src/sg_persist.c
+++ b/src/sg_persist.c
@@ -1,5 +1,5 @@
/* A utility program originally written for the Linux OS SCSI subsystem.
- * Copyright (C) 2004-2018 D. Gilbert
+ * Copyright (C) 2004-2019 D. Gilbert
* 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)
@@ -35,7 +35,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "0.66 20180615";
+static const char * version_str = "0.67 20190913";
#define PRIN_RKEY_SA 0x0
@@ -826,7 +826,7 @@ decode_file_tids(const char * fnp, struct opts_t * op)
pr2serr("%s: array length exceeded\n", __func__);
goto bad;
}
- tid_arr[off + k] = h;
+ op->transportid_arr[off + k] = h; /* keep code checker happy */
lcp = strpbrk(lcp, " ,\t");
if (NULL == lcp)
break;
diff --git a/src/sg_rbuf.c b/src/sg_rbuf.c
index 9f5055e8..2f5229f0 100644
--- a/src/sg_rbuf.c
+++ b/src/sg_rbuf.c
@@ -1,5 +1,5 @@
/* A utility program originally written for the Linux OS SCSI subsystem.
- * Copyright (C) 1999-2018 D. Gilbert
+ * Copyright (C) 1999-2019 D. Gilbert
* 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)
@@ -57,7 +57,7 @@
#endif
-static const char * version_str = "5.05 20180627";
+static const char * version_str = "5.06 20190913";
static struct option long_options[] = {
{"buffer", required_argument, 0, 'b'},
@@ -683,5 +683,5 @@ main(int argc, char * argv[])
else
printf("read buffer non-zero\n");
#endif
- return (res >= 0) ? res : SG_LIB_CAT_OTHER;
+ return res;
}
diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c
index 9fc348c8..b4a10682 100644
--- a/src/sg_sanitize.c
+++ b/src/sg_sanitize.c
@@ -33,7 +33,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.12 20190113";
+static const char * version_str = "1.13 20190913";
/* Not all environments support the Unix sleep() */
#if defined(MSC_VER) || defined(__MINGW32__)
@@ -389,14 +389,9 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, int verbose)
if (n > (SAFE_STD_INQ_RESP_LEN - 4))
n = (SAFE_STD_INQ_RESP_LEN - 4);
for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) {
- if (VPD_UNIT_SERIAL_NUM == b[4 + k]) {
- if (has_di) {
- if (verbose)
- pr2serr("VPD_SUPPORTED_VPDS dis-ordered\n");
- return 0;
- }
+ if (VPD_UNIT_SERIAL_NUM == b[4 + k])
++has_sn;
- } else if (VPD_DEVICE_ID == b[4 + k]) {
+ else if (VPD_DEVICE_ID == b[4 + k]) {
++has_di;
break;
}
diff --git a/src/sg_ses.c b/src/sg_ses.c
index 2325b8b4..cc24c13e 100644
--- a/src/sg_ses.c
+++ b/src/sg_ses.c
@@ -38,7 +38,7 @@
* commands tailored for SES (enclosure) devices.
*/
-static const char * version_str = "2.46 20190826"; /* ses4r03 */
+static const char * version_str = "2.47 20190913"; /* ses4r03 */
#define MX_ALLOC_LEN ((64 * 1024) - 4) /* max allowable for big enclosures */
#define MX_ELEM_HDR 1024
@@ -1425,15 +1425,12 @@ parse_cmd_line(struct opts_t *op, int argc, char *argv[])
break;
}
}
- if (n > 1)
- op->many_dpages = true;
- else if (1 == n) {
+ if (1 == n) {
op->page_code_given = true;
op->page_code = pc;
- } else {
- pr2serr("No dpage found --data= argument\n");
- goto err_help;
- }
+ } else /* n must be > 1 */
+ op->many_dpages = true;
+
if (op->verbose > 3) {
int k;
char b[128];
@@ -2454,9 +2451,6 @@ find_sas_connector_type(int conn_type, bool abridged, char * buff,
else if (conn_type < 0x20)
snprintf(buff, buff_len, "unknown internal wide connector type: "
"0x%x", conn_type);
- else if (conn_type < 0x30)
- snprintf(buff, buff_len, "unknown internal connector to end "
- "device, type: 0x%x", conn_type);
else if (conn_type < 0x3f)
snprintf(buff, buff_len, "reserved for internal connector, "
"type: 0x%x", conn_type);
@@ -2660,8 +2654,6 @@ enc_status_helper(const char * pad, const uint8_t * statp, int etype,
printf("%slast 3 bytes (hex): %02x %02x %02x\n", pad, statp[1],
statp[2], statp[3]);
break;
- default:
- break;
}
break;
case UI_POWER_SUPPLY_ETC: /* Uninterruptible power supply */
@@ -4286,8 +4278,7 @@ process_status_dpage(struct sg_pt_base * ptvp, int page_code, uint8_t * resp,
subenc_nickname_sdg(resp, resp_len);
break;
default:
- printf("Cannot decode response from diagnostic "
- "page: %s\n", (cp ? cp : "<unknown>"));
+ printf("Cannot decode response from diagnostic page: %s\n", cp);
hex2stdout(resp, resp_len, 0);
}
@@ -5336,7 +5327,7 @@ ses_cgs(struct sg_pt_base * ptvp, const struct tuple_acronym_val * tavp,
if (op->ind_indiv_last <= op->ind_indiv)
break;
} /* end of loop over join array */
- if ((NULL == jrp->enc_statp) || (k >= MX_JOIN_ROWS)) {
+ if ((k >= MX_JOIN_ROWS || (NULL == jrp->enc_statp))) {
if (op->desc_name)
pr2serr("descriptor name: %s not found (check the 'ed' page "
"[0x7])\n", op->desc_name);
@@ -5907,7 +5898,7 @@ early_out:
pr2serr("Some error occurred, try again with '-v' or '-vv' for "
"more information\n");
else if ((SG_LIB_SYNTAX_ERROR == ret) && (0 == vb))
- pr2serr("Add '-h' to command line for usage infomation\n");
+ pr2serr("Add '-h' to command line for usage information\n");
}
if (op->free_data_arr)
free(op->free_data_arr);
diff --git a/src/sg_test_rwbuf.c b/src/sg_test_rwbuf.c
index 8eb604b0..86d85ca1 100644
--- a/src/sg_test_rwbuf.c
+++ b/src/sg_test_rwbuf.c
@@ -1,7 +1,7 @@
/*
* (c) 2000 Kurt Garloff <garloff at suse dot de>
* heavily based on Douglas Gilbert's sg_rbuf program.
- * (c) 1999-2018 Douglas Gilbert
+ * (c) 1999-2019 Douglas Gilbert
*
* Program to test the SCSI host adapter by issuing
* write and read operations on a device's buffer
@@ -47,7 +47,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "1.18 20180628";
+static const char * version_str = "1.19 20190913";
#define BPI (signed)(sizeof(int))
@@ -388,8 +388,8 @@ void usage ()
int main (int argc, char * argv[])
{
- bool verbose_given = true;
- bool version_given = true;
+ bool verbose_given = false;
+ bool version_given = false;
int sg_fd, res;
const char * device_name = NULL;
int times = 1;
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
index 6e4b21e8..3fdcca84 100644
--- a/src/sg_vpd.c
+++ b/src/sg_vpd.c
@@ -40,7 +40,7 @@
*/
-static const char * version_str = "1.54 20190516"; /* spc5r22 + sbc4r17 */
+static const char * version_str = "1.55 20190913"; /* spc5r22 + sbc4r17 */
/* standard VPD pages, in ascending page number order */
#define VPD_SUPPORTED_VPDS 0x0
@@ -1047,9 +1047,6 @@ decode_x_inq_vpd(uint8_t * b, int len, int do_hex, bool do_long,
case 7:
printf(" [protection types 1, 2 and 3 supported]\n");
break;
- default:
- printf("\n");
- break;
}
} else
printf("\n");
@@ -1775,10 +1772,18 @@ decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt,
printf(" Maximum identified concurrent copies: %u\n", u);
u = sg_get_unaligned_be32(bp + 12);
printf(" Maximum segment length: %u\n", u);
- ull = (1 << bp[16]); /* field is power of 2 */
- printf(" Data segment granularity: %" PRIu64 "\n", ull);
- ull = (1 << bp[17]);
- printf(" Inline data granularity: %" PRIu64 "\n", ull);
+ printf(" Data segment granularity: ");
+ u = bp[16]; /* field is power of 2 */
+ if (u < 64)
+ printf("%" PRIu64 "\n", (uint64_t)1 << u);
+ else
+ printf("too large [2^%u]\n", u);
+ printf(" Inline data granularity: ");
+ u = bp[17]; /* field is power of 2 */
+ if (u < 64)
+ printf("%" PRIu64 "\n", (uint64_t)1 << u);
+ else
+ printf("too large [2^%u]\n", u);
break;
case 0x9101:
printf(" Stream copy operations:\n");
@@ -1832,21 +1837,19 @@ decode_proto_lu_vpd(uint8_t * buff, int len, int do_hex)
}
if (0 == desc_len)
continue;
- if (2 == do_hex)
+ if (2 == do_hex) {
hex2stdout(bp + 8, desc_len, 1);
- else if (do_hex > 2)
- hex2stdout(bp, bump, 1);
- else {
- switch (proto) {
- case TPROTO_SAS:
- printf(" Protocol identifier: SAS\n");
- printf(" TLR control supported: %d\n", !!(bp[8] & 0x1));
- break;
- default:
- pr2serr("Unexpected proto=%d\n", proto);
- hex2stderr(bp, bump, 1);
- break;
- }
+ continue;
+ }
+ switch (proto) {
+ case TPROTO_SAS:
+ printf(" Protocol identifier: SAS\n");
+ printf(" TLR control supported: %d\n", !!(bp[8] & 0x1));
+ break;
+ default:
+ pr2serr("Unexpected proto=%d\n", proto);
+ hex2stderr(bp, bump, 1);
+ break;
}
}
}
@@ -1883,25 +1886,23 @@ decode_proto_port_vpd(uint8_t * buff, int len, int do_hex)
}
if (0 == desc_len)
continue;
- if (2 == do_hex)
+ if (2 == do_hex) {
hex2stdout(bp + 8, desc_len, 1);
- else if (do_hex > 2)
- hex2stdout(bp, bump, 1);
- else {
- switch (proto) {
- case TPROTO_SAS: /* page added in spl3r02 */
- printf(" power disable supported (pwr_d_s)=%d\n",
- !!(bp[3] & 0x1)); /* added spl3r03 */
- pidp = bp + 8;
- for (j = 0; j < desc_len; j += 4, pidp += 4)
- printf(" phy id=%d, SSP persistent capable=%d\n",
- pidp[1], (0x1 & pidp[2]));
- break;
- default:
- pr2serr("Unexpected proto=%d\n", proto);
- hex2stderr(bp, bump, 1);
- break;
- }
+ continue;
+ }
+ switch (proto) {
+ case TPROTO_SAS: /* page added in spl3r02 */
+ printf(" power disable supported (pwr_d_s)=%d\n",
+ !!(bp[3] & 0x1)); /* added spl3r03 */
+ pidp = bp + 8;
+ for (j = 0; j < desc_len; j += 4, pidp += 4)
+ printf(" phy id=%d, SSP persistent capable=%d\n",
+ pidp[1], (0x1 & pidp[2]));
+ break;
+ default:
+ pr2serr("Unexpected proto=%d\n", proto);
+ hex2stderr(bp, bump, 1);
+ break;
}
}
}
@@ -2740,7 +2741,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
dStrRaw(rp, alloc_len);
else if (op->do_hex) {
if (! op->do_quiet && (op->do_hex < 3))
- printf("Standard Inquiry reponse:\n");
+ printf("Standard Inquiry response:\n");
hex2stdout(rp, alloc_len, (1 == op->do_hex) ? 0 : -1);
} else
std_inq_decode(rp, alloc_len, vb);
diff --git a/src/sg_vpd_vendor.c b/src/sg_vpd_vendor.c
index 66be0729..32fc3494 100644
--- a/src/sg_vpd_vendor.c
+++ b/src/sg_vpd_vendor.c
@@ -1431,7 +1431,7 @@ svpd_decode_vendor(int sg_fd, struct opts_t * op, int off)
if (0 == res) {
vnp = svpd_get_v_detail(op->vpd_pn, op->vend_prod_num, 0xf & rp[0]);
if (vnp && vnp->name)
- strcpy(name, vnp->name);
+ snprintf(name, sizeof(name), "%s", vnp->name);
else
snprintf(name, sizeof(name) - 1, "Vendor VPD page=0x%x",
op->vpd_pn);
diff --git a/src/sg_write_x.c b/src/sg_write_x.c
index c610fa00..fca94377 100644
--- a/src/sg_write_x.c
+++ b/src/sg_write_x.c
@@ -38,7 +38,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.20 20190113";
+static const char * version_str = "1.21 20190913";
/* Protection Information refers to 8 bytes of extra information usually
* associated with each logical block and is often abbreviated to PI while
@@ -673,8 +673,10 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num)
if (cp) { /* copy from first non whitespace ... */
memcpy(c, lcp, cp - lcp); /* ... to just prior to first '#' */
c[cp - lcp] = '\0';
- } else
- strcpy(c, lcp); /* ... to end of line, including null */
+ } else {
+ /* ... to end of line, including null */
+ snprintf(c, sizeof(c), "%s", lcp);
+ }
ll = sg_get_llnum(bp);
ok = ((-1 != ll) || all_ascii_f_s(bp, 16));
if (! ok) {
@@ -750,10 +752,6 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num)
} else if (up)
sg_put_unaligned_be16((uint16_t)ll, up + 18);
break;
- default:
- pr2serr("%s: k=%d should not be >= 3\n", __func__, k);
- ok = false;
- break;
}
if (! ok)
break;
@@ -774,13 +772,9 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num)
if (up)
sg_put_unaligned_be16((uint16_t)DEF_TM, up + 18);
break;
- default:
- pr2serr("%s: k=%d should not be >= 3\n", __func__, k);
- ok = false;
- break;
}
}
- return ok ? 0 : SG_LIB_SYNTAX_ERROR;
+ return 0;
}
/* Read pairs or quintets from a scat_file and places them in a T10 scatter
diff --git a/src/sginfo.c b/src/sginfo.c
index 6a514fc1..3529d1fd 100644
--- a/src/sginfo.c
+++ b/src/sginfo.c
@@ -124,7 +124,7 @@
#define _GNU_SOURCE 1
#endif
-static const char * version_str = "2.42 [20180811]";
+static const char * version_str = "2.43 [20190913]";
#include <stdio.h>
#include <string.h>
@@ -1514,12 +1514,11 @@ read_defect_list(int grown_only)
if (defectformat == HEAD_SORT_TOKEN) {
defectformat = 0x04;
sorthead = 1;
- headsp = (unsigned int *)malloc(sizeof(unsigned int) * MAX_HEADS);
+ headsp = (unsigned int *)calloc(MAX_HEADS, sizeof(unsigned int));
if (headsp == NULL) {
perror("malloc failed");
return status;
}
- memset(headsp,0,sizeof(unsigned int) * MAX_HEADS);
}
for (table = grown_only; table < 2; table++) {
if (heapp) {
@@ -1759,6 +1758,7 @@ trytenbyte:
}
else if (!sorthead) printf("|");
}
+ break;
case 5: /* physical sector */
while (len > 0) {
snprintf((char *)cbuffer1, 40, "%6d:%2u:%5d",
@@ -1777,6 +1777,7 @@ trytenbyte:
}
else if (!sorthead) printf("|");
}
+ break;
case 0: /* lba (32 bit) */
while (len > 0) {
printf("%10d", getnbyte(df, 4));
@@ -1790,6 +1791,7 @@ trytenbyte:
else
printf("|");
}
+ break;
case 3: /* lba (64 bit) */
while (len > 0) {
printf("%15" PRId64 , getnbyte_ll(df, 8));
@@ -1825,6 +1827,7 @@ trytenbyte:
printf("%3d: %u\n", i, headsp[i]);
}
}
+ free(headsp);
}
printf("\n");
return status;
diff --git a/testing/Makefile b/testing/Makefile
index 266a960f..34c746c2 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -23,9 +23,9 @@ LARGE_FILE_FLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
## CXX = g++
## CC = clang
## CXX = clang++
-CXXLD = $(CXX)
-LD = $(CC)
+LD = $(CXX)
+CXXLD = $(CXX)
CPPFLAGS = -iquote ../include -iquote .. -D_REENTRANT $(LARGE_FILE_FLAGS) -DHAVE_CONFIG_H -DHAVE_NVME
CXXFLAGS = -std=c++17 -pthread -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
diff --git a/testing/Makefile.cplus b/testing/Makefile.cplus
deleted file mode 100644
index 871136ff..00000000
--- a/testing/Makefile.cplus
+++ /dev/null
@@ -1,94 +0,0 @@
-SHELL = /bin/sh
-
-PREFIX=/usr/local
-INSTDIR=$(DESTDIR)/$(PREFIX)/bin
-MANDIR=$(DESTDIR)/$(PREFIX)/man
-
-## CXX = g++
-## CXX = clang++
-## CXX = clang++-7
-CXXLD = $(CXX)
-
-EXECS = sg_tst_excl sg_tst_excl2 sg_tst_excl3 sg_tst_context sg_tst_async \
- sgh_dd
-
-EXTRAS =
-
-BSG_EXTRAS =
-
-
-MAN_PGS =
-MAN_PREF = man8
-
-LARGE_FILE_FLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
-
-CXXFLAGS = -std=c++17 -pthread -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-# CXXFLAGS = -std=c++11 -pthread -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-# CXXFLAGS = -std=c++11 -pthread -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) -DDEBUG
-## CXXFLAGS = -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-# CXXFLAGS = -g -O2 -Wall -iquote ../include -D_REENTRANT -DSG_KERNEL_INCLUDES $(LARGE_FILE_FLAGS)
-# CXXFLAGS = -g -O2 -Wall -pedantic -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-
-LDFLAGS = -std=c++17 -pthread
-# LDFLAGS = -std=c++11 -pthread
-# LDFLAGS = -pthread
-
-LIBFILESOLD = ../lib/sg_lib.o ../lib/sg_lib_data.o ../lib/sg_io_linux.o
-LIBFILESNEW = ../lib/sg_pt_linux_nvme.o ../lib/sg_lib.o ../lib/sg_lib_data.o \
- ../lib/sg_pt_linux.o ../lib/sg_io_linux.o \
- ../lib/sg_pt_common.o ../lib/sg_cmds_basic.o \
- ../lib/sg_cmds_basic2.o
-
-all: $(EXECS)
-
-extras: $(EXTRAS)
-
-
-depend dep:
- for i in *.c; do $(CC) $(INCLUDES) $(CFLAGS) -M $$i; \
- done > .depend
-
-clean:
- /bin/rm -f *.o $(EXECS) $(EXTRAS) $(BSG_EXTRAS) core .depend
-
-sg_tst_excl: sg_tst_excl.o $(LIBFILESOLD)
- $(CXXLD) -o $@ $(LDFLAGS) $^
-
-sg_tst_excl2: sg_tst_excl2.o $(LIBFILESNEW)
- $(CXXLD) -o $@ $(LDFLAGS) $^
-
-sg_tst_excl3: sg_tst_excl3.o $(LIBFILESNEW)
- $(CXXLD) -o $@ $(LDFLAGS) $^
-
-sg_tst_context: sg_tst_context.o $(LIBFILESNEW)
- $(CXXLD) -o $@ $(LDFLAGS) $^
-
-sg_tst_async: sg_tst_async.o $(LIBFILESNEW)
- $(CXXLD) -o $@ $(LDFLAGS) $^
-
-sgh_dd: sgh_dd.o $(LIBFILESNEW)
- $(CXXLD) -o $@ $(LDFLAGS) -pthread -latomic $^
-
-install: $(EXECS)
- install -d $(INSTDIR)
- for name in $^; \
- do install -s -o root -g root -m 755 $$name $(INSTDIR); \
- done
- install -d $(MANDIR)/$(MAN_PREF)
- for mp in $(MAN_PGS); \
- do install -o root -g root -m 644 $$mp $(MANDIR)/$(MAN_PREF); \
- gzip -9f $(MANDIR)/$(MAN_PREF)/$$mp; \
- done
-
-uninstall:
- dists="$(EXECS)"; \
- for name in $$dists; do \
- rm -f $(INSTDIR)/$$name; \
- done
- for mp in $(MAN_PGS); do \
- rm -f $(MANDIR)/$(MAN_PREF)/$$mp.gz; \
- done
-
-ifeq (.depend,$(wildcard .depend))
-include .depend
-endif
diff --git a/testing/Makefile.cplus_fb b/testing/Makefile.cplus_fb
deleted file mode 100644
index a41c2346..00000000
--- a/testing/Makefile.cplus_fb
+++ /dev/null
@@ -1,79 +0,0 @@
-SHELL = /bin/sh
-
-PREFIX=/usr/local
-INSTDIR=$(DESTDIR)/$(PREFIX)/bin
-MANDIR=$(DESTDIR)/$(PREFIX)/man
-
-## CC = g++
-## LD = g++
-## CC = clang++
-## LD = clang++
-
-## This is just an example FreeBSD Makefile for how to build for clang++
-## All .cpp execs in this directory are Linux specific so there is
-## nothing to do for FreeBSD.
-## Not optimum but it works around 20180715 [dpg]
-
-# EXECS = sg_tst_context
-EXECS =
-
-EXTRAS =
-
-BSG_EXTRAS =
-
-
-MAN_PGS =
-MAN_PREF = man8
-
-LARGE_FILE_FLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
-
-CXXFLAGS = -std=c++11 -pthread -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-# CPPFLAGS = -std=c++11 -pthread -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) -DDEBUG
-## CFLAGS = -g -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-# CFLAGS = -g -O2 -Wall -iquote ../include -D_REENTRANT -DSG_KERNEL_INCLUDES $(LARGE_FILE_FLAGS)
-# CFLAGS = -g -O2 -Wall -pedantic -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS)
-
-LDFLAGS = -std=c++11 -pthread
-
-LIBFILESOLD = ../lib/sg_lib.o ../lib/sg_lib_data.o
-LIBFILESNEW = ../lib/sg_lib.o ../lib/sg_lib_data.o ../lib/sg_pt_freebsd.o ../lib/sg_pt_common.o \
- ../lib/sg_cmds_basic.o
-
-all: $(EXECS)
-
-extras: $(EXTRAS)
-
-
-depend dep:
- for i in $(EXECS).cpp; do $(CXX) $(INCLUDES) $(CXXFLAGS) -M $$i; \
- done > .depend
-
-clean:
- /bin/rm -f *.o $(EXECS) $(EXTRAS) $(BSG_EXTRAS) core .depend
-
-sg_tst_context: sg_tst_async.o $(LIBFILESNEW)
- $(CXX) -o $@ $(LDFLAGS) $^
-
-install: $(EXECS)
- install -d $(INSTDIR)
- for name in $^; \
- do install -s -o root -g root -m 755 $$name $(INSTDIR); \
- done
- install -d $(MANDIR)/$(MAN_PREF)
- for mp in $(MAN_PGS); \
- do install -o root -g root -m 644 $$mp $(MANDIR)/$(MAN_PREF); \
- gzip -9f $(MANDIR)/$(MAN_PREF)/$$mp; \
- done
-
-uninstall:
- dists="$(EXECS)"; \
- for name in $$dists; do \
- rm -f $(INSTDIR)/$$name; \
- done
- for mp in $(MAN_PGS); do \
- rm -f $(MANDIR)/$(MAN_PREF)/$$mp.gz; \
- done
-
-## ifeq (.depend,$(wildcard .depend))
-## include .depend
-## endif
diff --git a/testing/README b/testing/README
index 5a485576..68f82244 100644
--- a/testing/README
+++ b/testing/README
@@ -4,7 +4,7 @@ The utilities in this directory are _not_ built automatically. So:
cd <root_of_sg3_utils_src>
./configure ; make ; make install
will _not_ build and install them. The make command (or some variant
-of it) needs to be run in this directory as outlined before.
+of it) needs to be run in this directory as outlined below.
Building files in this directory depends on several files being already
built in the ../lib directory. So to build files here, the ./configure
@@ -35,14 +35,13 @@ to get more information.
There are both C and C++ files in this directory, they have extensions
'.c' and '.cpp' respectively. Now both are built with rules in Makefile
-(at least in Linux). Formerly the C++ in Linux required:
-'make -f Makefile.cplus'. A gcc/g++ compiler of 4.7.3 vintage or later
+(at least in Linux). A gcc/g++ compiler of 4.7.3 vintage or later
(or a recent clang compiler) will be required. To make them in FreeBSD
-use 'make -f Makefile.cplus_fb'.
+use 'make -f Makefile.freebsd'.
The sgh_dd utility (C++) uses 'libatomic' which may not be installed
on some systems. On Debian based systems 'apt install libatomic1' fixes
this.
Douglas Gilbert
-2nd September 2019
+17th September 2019
diff --git a/testing/sg_tst_async.cpp b/testing/sg_tst_async.cpp
index af7eed87..e8203a10 100644
--- a/testing/sg_tst_async.cpp
+++ b/testing/sg_tst_async.cpp
@@ -89,7 +89,7 @@
#include "sg_pt.h"
#include "sg_cmds.h"
-static const char * version_str = "1.39 20190902";
+static const char * version_str = "1.40 20190917";
static const char * util_name = "sg_tst_async";
/* This is a test program for checking the async usage of the Linux sg
@@ -110,21 +110,17 @@ static const char * util_name = "sg_tst_async";
* which is assumed to be a sibling of this examples directory. Those
* object files in the lib directory can be built with:
* cd <sg3_utils_package_root> ; ./configure ; cd lib; make
- * cd ../examples
- * Then to build sg_tst_async concatenate the next 3 lines:
- * g++ -Wall -std=c++11 -pthread -I ../include ../lib/sg_lib.o
- * ../lib/sg_lib_data.o ../lib/sg_io_linux.o -o sg_tst_async
- * sg_tst_async.cpp
- * or use the C++ Makefile in that directory:
- * make -f Makefile.cplus sg_tst_async
+ * cd ../testing
+ * make sg_tst_async
*
* Currently this utility is Linux only and uses the sg driver. The bsg
* driver is known to be broken (it doesn't match responses to the
- * correct file descriptor that requested them) so this utility won't
- * be extended to bsg until that is fixed.
+ * correct file descriptor that requested them). Around Linux kernel 4.15
+ * the async capability of the bsg driver was removed. So this test code
+ * no longer appiles to the bsg driver.
*
* BEWARE: >>> This utility will modify a logical block (default LBA 1000)
- * on the given device when the '-W' option is given.
+ * on the given device _when_ the '-W' option is given.
*
*/
diff --git a/testing/sg_tst_context.cpp b/testing/sg_tst_context.cpp
index 89b7a7d2..a6948c0e 100644
--- a/testing/sg_tst_context.cpp
+++ b/testing/sg_tst_context.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2018 Douglas Gilbert.
+ * Copyright (c) 2013-2019 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,7 @@
#include "sg_lib.h"
#include "sg_pt.h"
-static const char * version_str = "1.04 20181207";
+static const char * version_str = "1.05 20190917";
static const char * util_name = "sg_tst_context";
/* This is a test program for checking that file handles keep their
@@ -68,11 +68,9 @@ static const char * util_name = "sg_tst_context";
* which is assumed to be a sibling of this examples directory. Those
* object files in the lib directory can be built with:
* cd <sg3_utils> ; ./configure ; cd lib; make
- * Then to build sg_tst_context concatenate the next 3 lines:
- * g++ -Wall -std=c++11 -pthread -I ../include ../lib/sg_lib.o
- * ../lib/sg_lib_data.o ../lib/sg_pt_linux.o -o sg_tst_context
- * sg_tst_context.cpp
- * Alternatively use 'make -f Makefile.cplus sg_tst_context'
+ * Then:
+ * cd ../testing
+ * make sg_tst_context
*
*/
diff --git a/testing/sg_tst_excl.cpp b/testing/sg_tst_excl.cpp
index 84f83892..b5a344d6 100644
--- a/testing/sg_tst_excl.cpp
+++ b/testing/sg_tst_excl.cpp
@@ -73,7 +73,7 @@
#include "sg_io_linux.h"
#include "sg_unaligned.h"
-static const char * version_str = "1.11 20190121";
+static const char * version_str = "1.12 20190917";
static const char * util_name = "sg_tst_excl";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -95,12 +95,9 @@ static const char * util_name = "sg_tst_excl";
* which is assumed to be a sibling of this examples directory. Those
* object files in the lib directory can be built with:
* cd <sg3_utils> ; ./configure ; cd lib; make
- * Then to build sg_tst_excl concatenate the next 3 lines:
- * g++ -Wall -std=c++11 -pthread -I ../include ../lib/sg_lib.o
- * ../lib/sg_lib_data.o ../lib/sg_io_linux.o -o sg_tst_excl
- * sg_tst_excl.cpp
- * or use the C++ Makefile in that directory:
- * make -f Makefile.cplus sg_tst_excl
+ * Then:
+ * cd ../testing
+ * make sg_tst_excl
*
* Currently this utility is Linux only and assumes the SG_IO v3 interface
* which is supported by sg and block devices (but not bsg devices which
@@ -220,7 +217,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block,
}
if (sg_fd < 0) {
snprintf(ebuff, EBUFF_SZ, "%s: error opening file: %s", __func__,
- dev_name);
+ dev_name);
perror(ebuff);
return -1;
}
@@ -333,7 +330,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block,
lock_guard<mutex> lg(console_mutex);
fprintf(stderr, "%s: Recovered error on READ_16, "
- "continuing 2\n", __func__);
+ "continuing 2\n", __func__);
}
ok = 1;
break;
@@ -398,7 +395,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block,
lock_guard<mutex> lg(console_mutex);
fprintf(stderr, "%s: Recovered error on WRITE_16, "
- "continuing\n", __func__);
+ "continuing\n", __func__);
}
ok = 1;
break;
@@ -462,7 +459,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
}
if (sg_fd < 0) {
snprintf(ebuff, EBUFF_SZ, "%s: error opening file: %s", __func__,
- dev_name);
+ dev_name);
perror(ebuff);
return -1;
}
@@ -479,7 +476,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
pt.request = (uint64_t)(sg_uintptr_t)r16CmdBlk;
pt.response = (uint64_t)(sg_uintptr_t)sense_buffer;
pt.timeout = 20000; /* 20000 millisecs == 20 seconds */
- pt.request_extra = id; /* pack_id field */
+ pt.request_extra = id; /* pack_id field */
// queue up two READ_16s to same LBA
if (ioctl(sg_fd, SG_IOSUBMIT, &pt) < 0) {
@@ -523,8 +520,8 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
}
/* now for the error processing */
ok = 0;
- switch (sg_err_category_new(pt.device_status, pt.transport_status,
- pt.driver_status, sense_buffer, pt.response_len)) {
+ switch (sg_err_category_new(pt.device_status, pt.transport_status,
+ pt.driver_status, sense_buffer, pt.response_len)) {
case SG_LIB_CAT_CLEAN:
ok = 1;
break;
@@ -540,10 +537,10 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
{
lock_guard<mutex> lg(console_mutex);
- sg_linux_sense_print("READ_16 command error",
- pt.device_status, pt.transport_status,
- pt.driver_status, sense_buffer,
- pt.response_len, true);
+ sg_linux_sense_print("READ_16 command error",
+ pt.device_status, pt.transport_status,
+ pt.driver_status, sense_buffer,
+ pt.response_len, true);
// sg_chk_n_print3("READ_16 command error", &pt, 1);
}
break;
@@ -571,8 +568,8 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
pt = pt2;
/* now for the error processing */
ok = 0;
- switch (sg_err_category_new(pt.device_status, pt.transport_status,
- pt.driver_status, sense_buffer, pt.response_len)) {
+ switch (sg_err_category_new(pt.device_status, pt.transport_status,
+ pt.driver_status, sense_buffer, pt.response_len)) {
case SG_LIB_CAT_CLEAN:
ok = 1;
break;
@@ -581,7 +578,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
lock_guard<mutex> lg(console_mutex);
fprintf(stderr, "%s: Recovered error on READ_16, "
- "continuing 2\n", __func__);
+ "continuing 2\n", __func__);
}
ok = 1;
break;
@@ -589,11 +586,11 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
{
lock_guard<mutex> lg(console_mutex);
- sg_linux_sense_print("READ_16 command error 2",
- pt.device_status,
- pt.transport_status,
- pt.driver_status, sense_buffer,
- pt.response_len, true);
+ sg_linux_sense_print("READ_16 command error 2",
+ pt.device_status,
+ pt.transport_status,
+ pt.driver_status, sense_buffer,
+ pt.response_len, true);
// sg_chk_n_print3("READ_16 command error 2", &pt, 1);
}
break;
@@ -629,7 +626,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
pt.request = (uint64_t)(sg_uintptr_t)w16CmdBlk;
pt.response = (uint64_t)(sg_uintptr_t)sense_buffer;
pt.timeout = 20000; /* 20000 millisecs == 20 seconds */
- pt.request_extra = id; /* pack_id field */
+ pt.request_extra = id; /* pack_id field */
if (ioctl(sg_fd, SG_IO, &pt) < 0) {
{
@@ -652,7 +649,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
lock_guard<mutex> lg(console_mutex);
fprintf(stderr, "%s: Recovered error on WRITE_16, "
- "continuing\n", __func__);
+ "continuing\n", __func__);
}
ok = 1;
break;
@@ -660,10 +657,10 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block,
{
lock_guard<mutex> lg(console_mutex);
- sg_linux_sense_print("WRITE_16 command error",
- pt.device_status, pt.transport_status,
- pt.driver_status, sense_buffer,
- pt.response_len, true);
+ sg_linux_sense_print("WRITE_16 command error",
+ pt.device_status, pt.transport_status,
+ pt.driver_status, sense_buffer,
+ pt.response_len, true);
}
break;
}
@@ -785,18 +782,18 @@ work_thread(const char * dev_name, unsigned int lba, int id, int block,
<< block << endl;
}
for (k = 0; k < num; ++k) {
- if (sg_ifc_ver == 3)
+ if (sg_ifc_ver == 3)
res = do_rd_inc_wr_twice_v3(dev_name, lba, block, excl, wait_ms,
- k, thr_ebusy_count, thr_eagain_count);
- else if (sg_ifc_ver == 4)
+ k, thr_ebusy_count, thr_eagain_count);
+ else if (sg_ifc_ver == 4)
res = do_rd_inc_wr_twice_v4(dev_name, lba, block, excl, wait_ms,
- k, thr_ebusy_count, thr_eagain_count);
- else {
- lock_guard<mutex> lg(console_mutex);
+ k, thr_ebusy_count, thr_eagain_count);
+ else {
+ lock_guard<mutex> lg(console_mutex);
- cerr << "sg_ifc_ver=" << sg_ifc_ver << " not supported" << endl;
- res = -1;
- }
+ cerr << "sg_ifc_ver=" << sg_ifc_ver << " not supported" << endl;
+ res = -1;
+ }
if (res < 0)
break;
if (res)
diff --git a/testing/sg_tst_excl2.cpp b/testing/sg_tst_excl2.cpp
index 491d7fc6..b4ae9582 100644
--- a/testing/sg_tst_excl2.cpp
+++ b/testing/sg_tst_excl2.cpp
@@ -47,7 +47,7 @@
#include "sg_pt.h"
#include "sg_unaligned.h"
-static const char * version_str = "1.09 20190321";
+static const char * version_str = "1.10 20190917";
static const char * util_name = "sg_tst_excl2";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -69,20 +69,13 @@ static const char * util_name = "sg_tst_excl2";
* which is assumed to be a sibling of this examples directory. Those
* object files in the lib directory can be built with:
* cd <sg3_utils> ; ./configure ; cd lib; make
- * Then to build sg_tst_excl2 concatenate the next 3 lines:
- * g++ -Wall -std=c++11 -pthread -I ../include ../lib/sg_lib.o
- * ../lib/sg_lib_data.o ../lib/sg_pt_linux.o -o sg_tst_excl2
- * sg_tst_excl2.cpp
- * Alternatively use 'make -f Makefile.cplus sg_tst_excl2'
+ * Then:
+ * cd ../testing
+ * make sg_tst_excl2
*
* BEWARE: this utility modifies a logical block (default LBA 1000) on the
* given device.
*
- * Test breaks sg driver in lk 3.10.4 but works with proposed fix so should
- * work soon thereafter. Works on standard block driver (e.g. /dev/sdc) in
- * lk 3.10.4 . Fails on bsg driver in lk 3.10.4 because it ignores the
- * O_EXCL flag (and that is unlikely to change).
- *
*/
using namespace std;
@@ -271,7 +264,7 @@ do_rd_inc_wr_twice(const char * dev_name, unsigned int lba, int block,
if (0 == k)
odd = (1 == (u % 2));
++u;
- sg_put_unaligned_be32(u, lb);
+ sg_put_unaligned_be32(u, lb);
if (wait_ms > 0) /* allow daylight for bad things ... */
this_thread::sleep_for(milliseconds{wait_ms});
diff --git a/testing/sg_tst_excl3.cpp b/testing/sg_tst_excl3.cpp
index 6d32a4fb..f511dd66 100644
--- a/testing/sg_tst_excl3.cpp
+++ b/testing/sg_tst_excl3.cpp
@@ -48,7 +48,7 @@
#include "sg_pt.h"
#include "sg_unaligned.h"
-static const char * version_str = "1.07 20190321";
+static const char * version_str = "1.10 20190917";
static const char * util_name = "sg_tst_excl3";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -71,21 +71,13 @@ static const char * util_name = "sg_tst_excl3";
* which is assumed to be a sibling of this examples directory. Those
* object files in the lib directory can be built with:
* cd <sg3_utils> ; ./configure ; cd lib; make
- * Then to build sg_tst_excl3 concatenate the next 3 lines:
- * g++ -Wall -std=c++11 -pthread -I ../include ../lib/sg_lib.o
- * ../lib/sg_lib_data.o ../lib/sg_pt_linux.o -o sg_tst_excl3
- * sg_tst_excl3.cpp
- * Alternatively use 'make -f Makefile.cplus sg_tst_excl3'
+ * Then:
+ * cd ../testing
+ * make sg_tst_excl3
*
* BEWARE: this utility modifies a logical block (default LBA 1000) on the
* given device.
*
- * Test breaks sg driver in lk 3.10.4 but works with proposed fix so should
- * work soon thereafter. It works on standard block driver (e.g. /dev/sdc)
- * in lk 3.10.4 (most of the time). It fails on bsg driver in lk 3.10.4
- * because it ignores the O_EXCL flag (and that is unlikely to change in
- * the short term).
- *
*/
using namespace std;
@@ -273,7 +265,7 @@ do_rd_inc_wr_twice(const char * dev_name, int read_only, unsigned int lba,
goto err;
}
- u = sg_get_unaligned_be32(lb);
+ u = sg_get_unaligned_be32(lb);
// Assuming u starts test as even (probably 0), expect it to stay even
if (0 == k)
odd = (1 == (u % 2));
@@ -288,7 +280,7 @@ do_rd_inc_wr_twice(const char * dev_name, int read_only, unsigned int lba,
if (read_only)
break;
++u;
- sg_put_unaligned_be32(u, lb);
+ sg_put_unaligned_be32(u, lb);
/* Prepare WRITE_16 command */
clear_scsi_pt_obj(ptp);