Skip to content

Commit 571a848

Browse files
committed
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. #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
1 parent 463fd7e commit 571a848

File tree

11 files changed

+119
-36
lines changed

11 files changed

+119
-36
lines changed

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
22
some description at the top of its ".c" file. All utilities in the main
33
directory have their own "man" pages. There is also a sg3_utils man page.
44

5-
Changelog for pre-release sg3_utils-1.48 [20220930] [svn: r973]
5+
Changelog for pre-release sg3_utils-1.48 [20221007] [svn: r974]
66
- some utilities: add experimental --json[=JO] option
77
- sg_z_act_query: new utility for sending either a
88
Zone activate or Zone query command
@@ -79,6 +79,9 @@ Changelog for pre-release sg3_utils-1.48 [20220930] [svn: r973]
7979
- document internal json interface in include/sg_pr2serr.h
8080
- add SG_C_CPP_ZERO_INIT to better handle aggregate stack
8181
instance zeroing (C23 adding 'struct T t {};' will help)
82+
- correct fixed format sense data command-specific field
83+
for ata-passthrough (lba field), see:
84+
https://github.com/doug-gilbert/sg3_utils/pull/25
8285
- initialize all sense buffers to 0
8386
- linux: replace references to /proc/scsi/sg with
8487
/sys/module/sg/parameters/

debian/changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sg3-utils (1.48-0.1) unstable; urgency=low
22

33
* New upstream version
44

5-
-- Douglas Gilbert <dgilbert@interlog.com> Fri, 01 Jul 2022 14:00:00 -0400
5+
-- Douglas Gilbert <dgilbert@interlog.com> Fri, 07 Oct 2022 22:00:00 +0200
66

77
sg3-utils (1.47-0.1) unstable; urgency=low
88

doc/Makefile.am

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11

22
man_MANS = \
33
scsi_mandat.8 scsi_readcap.8 scsi_ready.8 scsi_satl.8 scsi_start.8 \
4-
scsi_stop.8 scsi_temperature.8 sg3_utils.8 sg3_utils_json.8
5-
sg_bg_ctl.8 sg_compare_and_write.8 sg_decode_sense.8 sg_format.8
4+
scsi_stop.8 scsi_temperature.8 sg3_utils.8 sg3_utils_json.8 \
5+
sg_bg_ctl.8 sg_compare_and_write.8 sg_decode_sense.8 sg_format.8 \
66
sg_get_config.8 sg_get_elem_status.8 sg_get_lba_status.8 sg_ident.8 \
77
sg_inq.8 sg_logs.8 sg_luns.8 sg_modes.8 sg_opcodes.8 sg_persist.8 \
88
sg_prevent.8 sg_raw.8 sg_rdac.8 sg_read_attr.8 \
99
sg_read_block_limits.8 sg_read_buffer.8 sg_read_long.8 sg_readcap.8 \
10-
sg_reassign.8 sg_referrals.8 sg_rep_density.8 sg_rep_pip.8 \
11-
sg_rep_zones.8 sg_requests.8 sg_reset_wp.8 sg_rmsn.8 sg_rtpg.8 \
12-
sg_safte.8 sg_sanitize.8 sg_sat_identify.8 sg_sat_phy_event.8 \
13-
sg_sat_read_gplog.8 sg_sat_set_features.8 sg_seek.8 sg_senddiag.8 \
14-
sg_ses.8 sg_ses_microcode.8 sg_start.8 sg_stpg.8 sg_stream_ctl.8 \
15-
sg_sync.8 sg_timestamp.8 sg_turs.8 sg_unmap.8 sg_verify.8 sg_vpd.8 \
16-
sg_wr_mode.8 sg_write_buffer.8 sg_write_long.8 sg_write_same.8 \
17-
sg_write_verify.8 sg_write_x.8 sg_zone.8 sg_z_act_query.8
10+
sg_reassign.8 sg_referrals.8 sg_rem_rest_elem.8 sg_rep_density.8 \
11+
sg_rep_pip.8 sg_rep_zones.8 sg_requests.8 sg_reset_wp.8 sg_rmsn.8 \
12+
sg_rtpg.8 sg_safte.8 sg_sanitize.8 sg_sat_identify.8 \
13+
sg_sat_phy_event.8 sg_sat_read_gplog.8 sg_sat_set_features.8 \
14+
sg_seek.8 sg_senddiag.8 sg_ses.8 sg_ses_microcode.8 sg_start.8 \
15+
sg_stpg.8 sg_stream_ctl.8 sg_sync.8 sg_timestamp.8 sg_turs.8 \
16+
sg_unmap.8 sg_verify.8 sg_vpd.8 sg_wr_mode.8 sg_write_buffer.8 \
17+
sg_write_long.8 sg_write_same.8 sg_write_verify.8 sg_write_x.8 \
18+
sg_zone.8 sg_z_act_query.8
1819
CLEANFILES =
1920

2021
if OS_LINUX

doc/Makefile.in

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,22 @@ top_builddir = @top_builddir@
288288
top_srcdir = @top_srcdir@
289289
man_MANS = scsi_mandat.8 scsi_readcap.8 scsi_ready.8 scsi_satl.8 \
290290
scsi_start.8 scsi_stop.8 scsi_temperature.8 sg3_utils.8 \
291-
sg3_utils_json.8 $(am__append_1) $(am__append_3) \
291+
sg3_utils_json.8 sg_bg_ctl.8 sg_compare_and_write.8 \
292+
sg_decode_sense.8 sg_format.8 sg_get_config.8 \
293+
sg_get_elem_status.8 sg_get_lba_status.8 sg_ident.8 sg_inq.8 \
294+
sg_logs.8 sg_luns.8 sg_modes.8 sg_opcodes.8 sg_persist.8 \
295+
sg_prevent.8 sg_raw.8 sg_rdac.8 sg_read_attr.8 \
296+
sg_read_block_limits.8 sg_read_buffer.8 sg_read_long.8 \
297+
sg_readcap.8 sg_reassign.8 sg_referrals.8 sg_rem_rest_elem.8 \
298+
sg_rep_density.8 sg_rep_pip.8 sg_rep_zones.8 sg_requests.8 \
299+
sg_reset_wp.8 sg_rmsn.8 sg_rtpg.8 sg_safte.8 sg_sanitize.8 \
300+
sg_sat_identify.8 sg_sat_phy_event.8 sg_sat_read_gplog.8 \
301+
sg_sat_set_features.8 sg_seek.8 sg_senddiag.8 sg_ses.8 \
302+
sg_ses_microcode.8 sg_start.8 sg_stpg.8 sg_stream_ctl.8 \
303+
sg_sync.8 sg_timestamp.8 sg_turs.8 sg_unmap.8 sg_verify.8 \
304+
sg_vpd.8 sg_wr_mode.8 sg_write_buffer.8 sg_write_long.8 \
305+
sg_write_same.8 sg_write_verify.8 sg_write_x.8 sg_zone.8 \
306+
sg_z_act_query.8 $(am__append_1) $(am__append_3) \
292307
$(am__append_5)
293308
CLEANFILES = $(am__append_2) $(am__append_4) $(am__append_6)
294309
all: all-am
@@ -534,19 +549,6 @@ uninstall-man: uninstall-man8
534549

535550
.PRECIOUS: Makefile
536551

537-
sg_bg_ctl.8 sg_compare_and_write.8 sg_decode_sense.8 sg_format.8
538-
sg_get_config.8 sg_get_elem_status.8 sg_get_lba_status.8 sg_ident.8 \
539-
sg_inq.8 sg_logs.8 sg_luns.8 sg_modes.8 sg_opcodes.8 sg_persist.8 \
540-
sg_prevent.8 sg_raw.8 sg_rdac.8 sg_read_attr.8 \
541-
sg_read_block_limits.8 sg_read_buffer.8 sg_read_long.8 sg_readcap.8 \
542-
sg_reassign.8 sg_referrals.8 sg_rep_density.8 sg_rep_pip.8 \
543-
sg_rep_zones.8 sg_requests.8 sg_reset_wp.8 sg_rmsn.8 sg_rtpg.8 \
544-
sg_safte.8 sg_sanitize.8 sg_sat_identify.8 sg_sat_phy_event.8 \
545-
sg_sat_read_gplog.8 sg_sat_set_features.8 sg_seek.8 sg_senddiag.8 \
546-
sg_ses.8 sg_ses_microcode.8 sg_start.8 sg_stpg.8 sg_stream_ctl.8 \
547-
sg_sync.8 sg_timestamp.8 sg_turs.8 sg_unmap.8 sg_verify.8 sg_vpd.8 \
548-
sg_wr_mode.8 sg_write_buffer.8 sg_write_long.8 sg_write_same.8 \
549-
sg_write_verify.8 sg_write_x.8 sg_zone.8 sg_z_act_query.8
550552
@OS_LINUX_TRUE@sg_scan.8: sg_scan.8.linux
551553
@OS_LINUX_TRUE@ cp -p $< $@
552554
@OS_WIN32_MINGW_TRUE@sg_scan.8: sg_scan.8.win32

doc/sg3_utils.8

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH SG3_UTILS "8" "September 2022" "sg3_utils\-1.48" SG3_UTILS
1+
.TH SG3_UTILS "8" "October 2022" "sg3_utils\-1.48" SG3_UTILS
22
.SH NAME
33
sg3_utils \- a package of utilities for sending SCSI commands
44
.SH SYNOPSIS
@@ -97,7 +97,7 @@ only used by the embedded SNTL within the library used by the utilities in
9797
this library. SNTL is a SCSI to NVMe Translation Layer. This environment
9898
variable defaults to 0 which will lead to any utility that issues a SCSI
9999
command that is translated to a NVMe command (by the embedded SNTL) that
100-
fails at the NVMe dvice, to return SCSI sense in 'fixed' format. If this
100+
fails at the NVMe device, to return SCSI sense in 'fixed' format. If this
101101
variable is non\-zero then then the returned SCSI sense will be in 'descriptor'
102102
format.
103103
.PP
@@ -579,7 +579,7 @@ output the usage message then exit.
579579
for SCSI commands that yield a non\-trivial response, print out that response
580580
in ASCII hexadecimal. When used once, 16 bytes are printed on each line,
581581
prefixed by an relative address, starting at 0 (hex). When used twice, an
582-
ASCII rendering of the 16 bytes is appended to each line, with non printeble
582+
ASCII rendering of the 16 bytes is appended to each line, with non printable
583583
characters replaced by a '.' . When used three times only the 16 hex bytes
584584
are printed on each line (hence no address prefix nor ASCII appended). To
585585
produce hexadecimal that can be parsed by other utilities use this option

doc/sg3_utils_json.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH SG3_UTILS_JSON "8" "September 2022" "sg3_utils\-1.48" SG3_UTILS
1+
.TH SG3_UTILS_JSON "8" "October 2022" "sg3_utils\-1.48" SG3_UTILS
22
.SH NAME
33
sg3_utils_json \- JSON output for some sg3_utils utilities
44
.SH SYNOPSIS

lib/sg_lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ sg_get_sense_sat_pt_fixed_str(const char * lip, const uint8_t * sp,
18021802
sp[5], sp[6], (count_upper_nz ? '+' : ' '));
18031803
n += sg_scnpr(b + n, blen - n, "%s extend=%d, log_index=0x%x, "
18041804
"lba_high,mid,low(7:0)=0x%x,0x%x,0x%x%c\n", lip,
1805-
(int)extend, (0xf & sp[8]), sp[9], sp[10], sp[11],
1805+
(int)extend, (0xf & sp[8]), sp[11], sp[10], sp[9],
18061806
(lba_upper_nz ? '+' : ' '));
18071807
return n;
18081808
}

lib/sg_lib_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "sg_lib_data.h"
2020

2121

22-
const char * sg_lib_version_str = "2.93 20220816";
22+
const char * sg_lib_version_str = "2.94 20221007";
2323
/* spc6r06, sbc5r03, zbc2r13 */
2424

2525

lib/sg_pr2serr.c

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
#include "sg_pr2serr.h"
1919
#include "sg_json_builder.h"
2020

21-
/* Comment out next line to remove dependency on sg_lib.h */
21+
/*
22+
* Some users of sg_pr2serr may not need fixed and descriptor sense decoded
23+
* for JSON output. If the following define is commented out the effective
24+
* compile size of this file is reduced by 800 lines plus dependencies on
25+
* other large components of the sg3_utils library.
26+
* Comment out the next line to remove dependency on sg_lib.h and its code.
27+
*/
2228
#define SG_PRSE_SENSE_DECODE 1
2329

2430
#ifdef SG_PRSE_SENSE_DECODE
@@ -65,6 +71,44 @@ pr2serr(const char * fmt, ...)
6571
return n;
6672
}
6773

74+
#ifndef SG_PRSE_SENSE_DECODE
75+
76+
/* Want safe, 'n += snprintf(b + n, blen - n, ...)' style sequence of
77+
* functions. Returns number of chars placed in cp excluding the
78+
* trailing null char. So for cp_max_len > 0 the return value is always
79+
* < cp_max_len; for cp_max_len <= 1 the return value is 0 and no chars are
80+
* written to cp. Note this means that when cp_max_len = 1, this function
81+
* assumes that cp[0] is the null character and does nothing (and returns
82+
* 0). Linux kernel has a similar function called scnprintf(). Public
83+
* declaration in sg_pr2serr.h header */
84+
int
85+
sg_scnpr(char * cp, int cp_max_len, const char * fmt, ...)
86+
{
87+
va_list args;
88+
int n;
89+
90+
if (cp_max_len < 2)
91+
return 0;
92+
va_start(args, fmt);
93+
n = vsnprintf(cp, cp_max_len, fmt, args);
94+
va_end(args);
95+
return (n < cp_max_len) ? n : (cp_max_len - 1);
96+
}
97+
98+
int
99+
pr2ws(const char * fmt, ...)
100+
{
101+
va_list args;
102+
int n;
103+
104+
va_start(args, fmt);
105+
n = vfprintf(stderr, fmt, args);
106+
va_end(args);
107+
return n;
108+
}
109+
110+
#endif
111+
68112
static bool
69113
sgj_parse_opts(sgj_state * jsp, const char * j_optarg)
70114
{
@@ -359,11 +403,18 @@ sgj_js2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status, FILE * fp)
359403
if ((NULL == jop) && jsp->pr_exit_status) {
360404
char d[80];
361405

406+
#ifdef SG_PRSE_SENSE_DECODE
362407
if (sg_exit2str(exit_status, jsp->verbose, sizeof(d), d)) {
363408
if (0 == strlen(d))
364409
strncpy(d, "no errors", sizeof(d) - 1);
365410
} else
366411
strncpy(d, "not available", sizeof(d) - 1);
412+
#else
413+
if (0 == exit_status)
414+
strncpy(d, "no errors", sizeof(d) - 1);
415+
else
416+
snprintf(d, sizeof(d), "exit_status=%d", exit_status);
417+
#endif
367418
sgj_js_nv_istr(jsp, jop, "exit_status", exit_status, NULL, d);
368419
}
369420
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,
694745
}
695746
}
696747

748+
#ifndef SG_PRSE_SENSE_DECODE
749+
static void
750+
h2str(const uint8_t * byte_arr, int num_bytes, char * bp, int blen)
751+
{
752+
int j, k, n;
753+
754+
for (k = 0, n = 0; (k < num_bytes) && (n < blen); ) {
755+
j = sg_scnpr(bp + n, blen - n, "%02x ", byte_arr[k]);
756+
if (j < 2)
757+
break;
758+
n += j;
759+
++k;
760+
if ((0 == (k % 8)) && (k < num_bytes) && (n < blen)) {
761+
bp[n++] = ' ';
762+
}
763+
}
764+
j = strlen(bp);
765+
if ((j > 0) && (' ' == bp[j - 1]))
766+
bp[j - 1] = '\0'; /* chop off trailing space */
767+
}
768+
#endif
769+
697770
/* Add hex byte strings irrespective of jsp->pr_hex setting. */
698771
void
699772
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,
706779
return;
707780
bp = (char *)calloc(blen + 4, 1);
708781
if (bp) {
782+
#ifdef SG_PRSE_SENSE_DECODE
709783
hex2str(byte_arr, num_bytes, NULL, 2, blen, bp);
784+
#else
785+
h2str(byte_arr, num_bytes, bp, blen);
786+
#endif
710787
sgj_js_nv_s(jsp, jop, name, bp);
711788
free(bp);
712789
}
@@ -1892,7 +1969,7 @@ sgj_js_sense(sgj_state * jsp, sgj_opaque_p jop, const uint8_t * sbp,
18921969
sgj_js_nv_i(jsp, jop, "extend", !! (0x80 & sbp[8]));
18931970
sgj_js_nv_i(jsp, jop, "count_upper_nonzero", !! (0x40 & sbp[8]));
18941971
sgj_js_nv_i(jsp, jop, "lba_upper_nonzero", !! (0x20 & sbp[8]));
1895-
sgj_js_nv_i(jsp, jop, "log_index", (0x7 & sbp[8]));
1972+
sgj_js_nv_i(jsp, jop, "log_index", (0xf & sbp[8]));
18961973
sgj_js_nv_i(jsp, jop, "lba", sg_get_unaligned_le24(sbp + 9));
18971974
} else if (len > 2) { /* fixed format */
18981975
sgj_js_nv_i(jsp, jop, "valid", valid_info_fld);

sg3_utils.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fi
8383
%{_libdir}/*.a
8484

8585
%changelog
86-
* Fri Jul 01 2022 - dgilbert at interlog dot com
86+
* Fri Oct 07 2022 - dgilbert at interlog dot com
8787
- track t10 changes
8888
* sg3_utils-1.48
8989

0 commit comments

Comments
 (0)