aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-10-07 21:18:17 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-10-07 21:18:17 +0000
commit571a84881ebb07e5c307a748b705724ec2d8d3e4 (patch)
treeaa8f87f544d9d9729d2626f67dff5fc20fad5991
parent463fd7e3414eebfaeb541722bea244f4eec32a74 (diff)
downloadsg3_utils-571a84881ebb07e5c307a748b705724ec2d8d3e4.tar.gz
sg3_utils: freestanding sg_pr2serr.c pr_s 25+26
In order to use the new JSON code in pr2serr.[hc] in the lsscsi package, changes were made to remove dependencies on the rest of the sg_lib library. https://github.com/doug-gilbert/sg3_utils/pull/25 and .../pull/26 applied with minor change. More pull requests await the next revision. git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@974 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog5
-rw-r--r--debian/changelog2
-rw-r--r--doc/Makefile.am21
-rw-r--r--doc/Makefile.in30
-rw-r--r--doc/sg3_utils.86
-rw-r--r--doc/sg3_utils_json.82
-rw-r--r--lib/sg_lib.c2
-rw-r--r--lib/sg_lib_data.c2
-rw-r--r--lib/sg_pr2serr.c81
-rw-r--r--sg3_utils.spec2
-rw-r--r--src/sg_opcodes.c2
11 files changed, 119 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index f4ba2b99..ad91c94e 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 pre-release sg3_utils-1.48 [20220930] [svn: r973]
+Changelog for pre-release sg3_utils-1.48 [20221007] [svn: r974]
- some utilities: add experimental --json[=JO] option
- sg_z_act_query: new utility for sending either a
Zone activate or Zone query command
@@ -79,6 +79,9 @@ Changelog for pre-release sg3_utils-1.48 [20220930] [svn: r973]
- document internal json interface in include/sg_pr2serr.h
- add SG_C_CPP_ZERO_INIT to better handle aggregate stack
instance zeroing (C23 adding 'struct T t {};' will help)
+ - correct fixed format sense data command-specific field
+ for ata-passthrough (lba field), see:
+ https://github.com/doug-gilbert/sg3_utils/pull/25
- initialize all sense buffers to 0
- linux: replace references to /proc/scsi/sg with
/sys/module/sg/parameters/
diff --git a/debian/changelog b/debian/changelog
index ac0f4c45..dc024760 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ sg3-utils (1.48-0.1) unstable; urgency=low
* New upstream version
- -- Douglas Gilbert <dgilbert@interlog.com> Fri, 01 Jul 2022 14:00:00 -0400
+ -- Douglas Gilbert <dgilbert@interlog.com> Fri, 07 Oct 2022 22:00:00 +0200
sg3-utils (1.47-0.1) unstable; urgency=low
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 81f4f52c..f816bb87 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,20 +1,21 @@
man_MANS = \
scsi_mandat.8 scsi_readcap.8 scsi_ready.8 scsi_satl.8 scsi_start.8 \
- scsi_stop.8 scsi_temperature.8 sg3_utils.8 sg3_utils_json.8
- sg_bg_ctl.8 sg_compare_and_write.8 sg_decode_sense.8 sg_format.8
+ scsi_stop.8 scsi_temperature.8 sg3_utils.8 sg3_utils_json.8 \
+ sg_bg_ctl.8 sg_compare_and_write.8 sg_decode_sense.8 sg_format.8 \
sg_get_config.8 sg_get_elem_status.8 sg_get_lba_status.8 sg_ident.8 \
sg_inq.8 sg_logs.8 sg_luns.8 sg_modes.8 sg_opcodes.8 sg_persist.8 \
sg_prevent.8 sg_raw.8 sg_rdac.8 sg_read_attr.8 \
sg_read_block_limits.8 sg_read_buffer.8 sg_read_long.8 sg_readcap.8 \
- sg_reassign.8 sg_referrals.8 sg_rep_density.8 sg_rep_pip.8 \
- sg_rep_zones.8 sg_requests.8 sg_reset_wp.8 sg_rmsn.8 sg_rtpg.8 \
- sg_safte.8 sg_sanitize.8 sg_sat_identify.8 sg_sat_phy_event.8 \
- sg_sat_read_gplog.8 sg_sat_set_features.8 sg_seek.8 sg_senddiag.8 \
- sg_ses.8 sg_ses_microcode.8 sg_start.8 sg_stpg.8 sg_stream_ctl.8 \
- sg_sync.8 sg_timestamp.8 sg_turs.8 sg_unmap.8 sg_verify.8 sg_vpd.8 \
- sg_wr_mode.8 sg_write_buffer.8 sg_write_long.8 sg_write_same.8 \
- sg_write_verify.8 sg_write_x.8 sg_zone.8 sg_z_act_query.8
+ sg_reassign.8 sg_referrals.8 sg_rem_rest_elem.8 sg_rep_density.8 \
+ sg_rep_pip.8 sg_rep_zones.8 sg_requests.8 sg_reset_wp.8 sg_rmsn.8 \
+ sg_rtpg.8 sg_safte.8 sg_sanitize.8 sg_sat_identify.8 \
+ sg_sat_phy_event.8 sg_sat_read_gplog.8 sg_sat_set_features.8 \
+ sg_seek.8 sg_senddiag.8 sg_ses.8 sg_ses_microcode.8 sg_start.8 \
+ sg_stpg.8 sg_stream_ctl.8 sg_sync.8 sg_timestamp.8 sg_turs.8 \
+ sg_unmap.8 sg_verify.8 sg_vpd.8 sg_wr_mode.8 sg_write_buffer.8 \
+ sg_write_long.8 sg_write_same.8 sg_write_verify.8 sg_write_x.8 \
+ sg_zone.8 sg_z_act_query.8
CLEANFILES =
if OS_LINUX
diff --git a/doc/Makefile.in b/doc/Makefile.in
index 8a4ba430..63171443 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -288,7 +288,22 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
man_MANS = scsi_mandat.8 scsi_readcap.8 scsi_ready.8 scsi_satl.8 \
scsi_start.8 scsi_stop.8 scsi_temperature.8 sg3_utils.8 \
- sg3_utils_json.8 $(am__append_1) $(am__append_3) \
+ sg3_utils_json.8 sg_bg_ctl.8 sg_compare_and_write.8 \
+ sg_decode_sense.8 sg_format.8 sg_get_config.8 \
+ sg_get_elem_status.8 sg_get_lba_status.8 sg_ident.8 sg_inq.8 \
+ sg_logs.8 sg_luns.8 sg_modes.8 sg_opcodes.8 sg_persist.8 \
+ sg_prevent.8 sg_raw.8 sg_rdac.8 sg_read_attr.8 \
+ sg_read_block_limits.8 sg_read_buffer.8 sg_read_long.8 \
+ sg_readcap.8 sg_reassign.8 sg_referrals.8 sg_rem_rest_elem.8 \
+ sg_rep_density.8 sg_rep_pip.8 sg_rep_zones.8 sg_requests.8 \
+ sg_reset_wp.8 sg_rmsn.8 sg_rtpg.8 sg_safte.8 sg_sanitize.8 \
+ sg_sat_identify.8 sg_sat_phy_event.8 sg_sat_read_gplog.8 \
+ sg_sat_set_features.8 sg_seek.8 sg_senddiag.8 sg_ses.8 \
+ sg_ses_microcode.8 sg_start.8 sg_stpg.8 sg_stream_ctl.8 \
+ sg_sync.8 sg_timestamp.8 sg_turs.8 sg_unmap.8 sg_verify.8 \
+ sg_vpd.8 sg_wr_mode.8 sg_write_buffer.8 sg_write_long.8 \
+ sg_write_same.8 sg_write_verify.8 sg_write_x.8 sg_zone.8 \
+ sg_z_act_query.8 $(am__append_1) $(am__append_3) \
$(am__append_5)
CLEANFILES = $(am__append_2) $(am__append_4) $(am__append_6)
all: all-am
@@ -534,19 +549,6 @@ uninstall-man: uninstall-man8
.PRECIOUS: Makefile
- sg_bg_ctl.8 sg_compare_and_write.8 sg_decode_sense.8 sg_format.8
- sg_get_config.8 sg_get_elem_status.8 sg_get_lba_status.8 sg_ident.8 \
- sg_inq.8 sg_logs.8 sg_luns.8 sg_modes.8 sg_opcodes.8 sg_persist.8 \
- sg_prevent.8 sg_raw.8 sg_rdac.8 sg_read_attr.8 \
- sg_read_block_limits.8 sg_read_buffer.8 sg_read_long.8 sg_readcap.8 \
- sg_reassign.8 sg_referrals.8 sg_rep_density.8 sg_rep_pip.8 \
- sg_rep_zones.8 sg_requests.8 sg_reset_wp.8 sg_rmsn.8 sg_rtpg.8 \
- sg_safte.8 sg_sanitize.8 sg_sat_identify.8 sg_sat_phy_event.8 \
- sg_sat_read_gplog.8 sg_sat_set_features.8 sg_seek.8 sg_senddiag.8 \
- sg_ses.8 sg_ses_microcode.8 sg_start.8 sg_stpg.8 sg_stream_ctl.8 \
- sg_sync.8 sg_timestamp.8 sg_turs.8 sg_unmap.8 sg_verify.8 sg_vpd.8 \
- sg_wr_mode.8 sg_write_buffer.8 sg_write_long.8 sg_write_same.8 \
- sg_write_verify.8 sg_write_x.8 sg_zone.8 sg_z_act_query.8
@OS_LINUX_TRUE@sg_scan.8: sg_scan.8.linux
@OS_LINUX_TRUE@ cp -p $< $@
@OS_WIN32_MINGW_TRUE@sg_scan.8: sg_scan.8.win32
diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8
index 81c10143..ca79b934 100644
--- a/doc/sg3_utils.8
+++ b/doc/sg3_utils.8
@@ -1,4 +1,4 @@
-.TH SG3_UTILS "8" "September 2022" "sg3_utils\-1.48" SG3_UTILS
+.TH SG3_UTILS "8" "October 2022" "sg3_utils\-1.48" SG3_UTILS
.SH NAME
sg3_utils \- a package of utilities for sending SCSI commands
.SH SYNOPSIS
@@ -97,7 +97,7 @@ only used by the embedded SNTL within the library used by the utilities in
this library. SNTL is a SCSI to NVMe Translation Layer. This environment
variable defaults to 0 which will lead to any utility that issues a SCSI
command that is translated to a NVMe command (by the embedded SNTL) that
-fails at the NVMe dvice, to return SCSI sense in 'fixed' format. If this
+fails at the NVMe device, to return SCSI sense in 'fixed' format. If this
variable is non\-zero then then the returned SCSI sense will be in 'descriptor'
format.
.PP
@@ -579,7 +579,7 @@ output the usage message then exit.
for SCSI commands that yield a non\-trivial response, print out that response
in ASCII hexadecimal. When used once, 16 bytes are printed on each line,
prefixed by an relative address, starting at 0 (hex). When used twice, an
-ASCII rendering of the 16 bytes is appended to each line, with non printeble
+ASCII rendering of the 16 bytes is appended to each line, with non printable
characters replaced by a '.' . When used three times only the 16 hex bytes
are printed on each line (hence no address prefix nor ASCII appended). To
produce hexadecimal that can be parsed by other utilities use this option
diff --git a/doc/sg3_utils_json.8 b/doc/sg3_utils_json.8
index 9c6eee2c..690d37eb 100644
--- a/doc/sg3_utils_json.8
+++ b/doc/sg3_utils_json.8
@@ -1,4 +1,4 @@
-.TH SG3_UTILS_JSON "8" "September 2022" "sg3_utils\-1.48" SG3_UTILS
+.TH SG3_UTILS_JSON "8" "October 2022" "sg3_utils\-1.48" SG3_UTILS
.SH NAME
sg3_utils_json \- JSON output for some sg3_utils utilities
.SH SYNOPSIS
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index e1fbea6b..f0ed986f 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -1802,7 +1802,7 @@ sg_get_sense_sat_pt_fixed_str(const char * lip, const uint8_t * sp,
sp[5], sp[6], (count_upper_nz ? '+' : ' '));
n += sg_scnpr(b + n, blen - n, "%s extend=%d, log_index=0x%x, "
"lba_high,mid,low(7:0)=0x%x,0x%x,0x%x%c\n", lip,
- (int)extend, (0xf & sp[8]), sp[9], sp[10], sp[11],
+ (int)extend, (0xf & sp[8]), sp[11], sp[10], sp[9],
(lba_upper_nz ? '+' : ' '));
return n;
}
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index 66c9e98d..944c86c3 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -19,7 +19,7 @@
#include "sg_lib_data.h"
-const char * sg_lib_version_str = "2.93 20220816";
+const char * sg_lib_version_str = "2.94 20221007";
/* spc6r06, sbc5r03, zbc2r13 */
diff --git a/lib/sg_pr2serr.c b/lib/sg_pr2serr.c
index 5112fbfb..79845335 100644
--- a/lib/sg_pr2serr.c
+++ b/lib/sg_pr2serr.c
@@ -18,7 +18,13 @@
#include "sg_pr2serr.h"
#include "sg_json_builder.h"
-/* Comment out next line to remove dependency on sg_lib.h */
+/*
+ * Some users of sg_pr2serr may not need fixed and descriptor sense decoded
+ * for JSON output. If the following define is commented out the effective
+ * compile size of this file is reduced by 800 lines plus dependencies on
+ * other large components of the sg3_utils library.
+ * Comment out the next line to remove dependency on sg_lib.h and its code.
+ */
#define SG_PRSE_SENSE_DECODE 1
#ifdef SG_PRSE_SENSE_DECODE
@@ -65,6 +71,44 @@ pr2serr(const char * fmt, ...)
return n;
}
+#ifndef SG_PRSE_SENSE_DECODE
+
+/* Want safe, 'n += snprintf(b + n, blen - n, ...)' style sequence of
+ * functions. Returns number of chars placed in cp excluding the
+ * trailing null char. So for cp_max_len > 0 the return value is always
+ * < cp_max_len; for cp_max_len <= 1 the return value is 0 and no chars are
+ * written to cp. Note this means that when cp_max_len = 1, this function
+ * assumes that cp[0] is the null character and does nothing (and returns
+ * 0). Linux kernel has a similar function called scnprintf(). Public
+ * declaration in sg_pr2serr.h header */
+int
+sg_scnpr(char * cp, int cp_max_len, const char * fmt, ...)
+{
+ va_list args;
+ int n;
+
+ if (cp_max_len < 2)
+ return 0;
+ va_start(args, fmt);
+ n = vsnprintf(cp, cp_max_len, fmt, args);
+ va_end(args);
+ return (n < cp_max_len) ? n : (cp_max_len - 1);
+}
+
+int
+pr2ws(const char * fmt, ...)
+{
+ va_list args;
+ int n;
+
+ va_start(args, fmt);
+ n = vfprintf(stderr, fmt, args);
+ va_end(args);
+ return n;
+}
+
+#endif
+
static bool
sgj_parse_opts(sgj_state * jsp, const char * j_optarg)
{
@@ -359,11 +403,18 @@ sgj_js2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status, FILE * fp)
if ((NULL == jop) && jsp->pr_exit_status) {
char d[80];
+#ifdef SG_PRSE_SENSE_DECODE
if (sg_exit2str(exit_status, jsp->verbose, sizeof(d), d)) {
if (0 == strlen(d))
strncpy(d, "no errors", sizeof(d) - 1);
} else
strncpy(d, "not available", sizeof(d) - 1);
+#else
+ if (0 == exit_status)
+ strncpy(d, "no errors", sizeof(d) - 1);
+ else
+ snprintf(d, sizeof(d), "exit_status=%d", exit_status);
+#endif
sgj_js_nv_istr(jsp, jop, "exit_status", exit_status, NULL, d);
}
memcpy(&out_settings, &def_out_settings, sizeof(out_settings));
@@ -694,6 +745,28 @@ sgj_js_nv_ihex_nex(sgj_state * jsp, sgj_opaque_p jop, const char * name,
}
}
+#ifndef SG_PRSE_SENSE_DECODE
+static void
+h2str(const uint8_t * byte_arr, int num_bytes, char * bp, int blen)
+{
+ int j, k, n;
+
+ for (k = 0, n = 0; (k < num_bytes) && (n < blen); ) {
+ j = sg_scnpr(bp + n, blen - n, "%02x ", byte_arr[k]);
+ if (j < 2)
+ break;
+ n += j;
+ ++k;
+ if ((0 == (k % 8)) && (k < num_bytes) && (n < blen)) {
+ bp[n++] = ' ';
+ }
+ }
+ j = strlen(bp);
+ if ((j > 0) && (' ' == bp[j - 1]))
+ bp[j - 1] = '\0'; /* chop off trailing space */
+}
+#endif
+
/* Add hex byte strings irrespective of jsp->pr_hex setting. */
void
sgj_js_nv_hex_bytes(sgj_state * jsp, sgj_opaque_p jop, const char * name,
@@ -706,7 +779,11 @@ sgj_js_nv_hex_bytes(sgj_state * jsp, sgj_opaque_p jop, const char * name,
return;
bp = (char *)calloc(blen + 4, 1);
if (bp) {
+#ifdef SG_PRSE_SENSE_DECODE
hex2str(byte_arr, num_bytes, NULL, 2, blen, bp);
+#else
+ h2str(byte_arr, num_bytes, bp, blen);
+#endif
sgj_js_nv_s(jsp, jop, name, bp);
free(bp);
}
@@ -1892,7 +1969,7 @@ sgj_js_sense(sgj_state * jsp, sgj_opaque_p jop, const uint8_t * sbp,
sgj_js_nv_i(jsp, jop, "extend", !! (0x80 & sbp[8]));
sgj_js_nv_i(jsp, jop, "count_upper_nonzero", !! (0x40 & sbp[8]));
sgj_js_nv_i(jsp, jop, "lba_upper_nonzero", !! (0x20 & sbp[8]));
- sgj_js_nv_i(jsp, jop, "log_index", (0x7 & sbp[8]));
+ sgj_js_nv_i(jsp, jop, "log_index", (0xf & sbp[8]));
sgj_js_nv_i(jsp, jop, "lba", sg_get_unaligned_le24(sbp + 9));
} else if (len > 2) { /* fixed format */
sgj_js_nv_i(jsp, jop, "valid", valid_info_fld);
diff --git a/sg3_utils.spec b/sg3_utils.spec
index 81152142..8d31df41 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -83,7 +83,7 @@ fi
%{_libdir}/*.a
%changelog
-* Fri Jul 01 2022 - dgilbert at interlog dot com
+* Fri Oct 07 2022 - dgilbert at interlog dot com
- track t10 changes
* sg3_utils-1.48
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index 41eb274c..9a5e3b83 100644
--- a/src/sg_opcodes.c
+++ b/src/sg_opcodes.c
@@ -33,7 +33,7 @@
#include "sg_pt.h"
-static const char * version_str = "0.85 20220717"; /* spc6r06 */
+static const char * version_str = "0.86 20221005"; /* spc6r06 */
#define MY_NAME "sg_opcodes"