aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-05-12 18:37:08 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-05-12 18:37:08 +0000
commit404cd7cc68c42c49076623e3ec13bb1f42f74ec7 (patch)
treef164f678be7a236aeb87874e1fa6890b37c2c6b3
parent3e056f675f51f14a5209efe1b491ba897e7873ce (diff)
downloadsg3_utils-404cd7cc68c42c49076623e3ec13bb1f42f74ec7.tar.gz
sg_lib: document internal json interface in include/sg_pr2serr.h; codespell fixes
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@952 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog6
-rw-r--r--doc/rescan-scsi-bus.sh.84
-rw-r--r--doc/sg3_utils_json.8120
-rw-r--r--doc/sg_dd.86
-rw-r--r--doc/sg_opcodes.812
-rw-r--r--doc/sg_referrals.82
-rw-r--r--doc/sg_rep_zones.82
-rw-r--r--examples/sgq_dd.c2
-rw-r--r--examples/transport_ids.txt2
-rw-r--r--include/sg_pr2serr.h147
-rw-r--r--inhex/nvme_read_ctl.hex4
-rw-r--r--inhex/nvme_read_oob_ctl.hex4
-rw-r--r--inhex/nvme_write_ctl.hex2
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/Makefile.in1
-rw-r--r--lib/sg_lib.c4
-rw-r--r--lib/sg_lib_data.c8
-rw-r--r--lib/sg_lib_names.c2
-rw-r--r--lib/sg_pr2serr.c386
-rw-r--r--src/sg_inq.c2
-rw-r--r--src/sg_logs.c4
-rw-r--r--src/sg_opcodes.c82
-rw-r--r--src/sg_read.c2
-rw-r--r--src/sg_read_buffer.c2
-rw-r--r--src/sg_rep_zones.c35
-rw-r--r--src/sg_sanitize.c2
-rw-r--r--src/sg_scan_win32.c2
-rw-r--r--src/sg_stpg.c2
-rw-r--r--src/sginfo.c2
-rw-r--r--testing/sg_scat_gath.cpp2
-rw-r--r--testing/sg_take_snap.c2
-rw-r--r--testing/sgh_dd.cpp2
32 files changed, 531 insertions, 326 deletions
diff --git a/ChangeLog b/ChangeLog
index 29b4b258..f1290f82 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 [20220505] [svn: r951]
+Changelog for pre-release sg3_utils-1.48 [20220512] [svn: r952]
- sg_z_act_query: new utility for sending either a
Zone activate or Zone query command
- sg_rep_density: new utility for decoding the response of
@@ -57,6 +57,7 @@ Changelog for pre-release sg3_utils-1.48 [20220505] [svn: r951]
- add hex2fp(), similar to hex2str() but outputs to FILE
- cleanup masks for PDT [0x1f] and group_number [0x3f]
- new sg_json_builder.[hc] files local to lib folder
+ - document internal json interface in include/sg_pr2serr.h
- initialize all sense buffers to 0
- rework main README file
- rev 921+922 are bugfix revs on release 1.47 [r919,920]
@@ -68,6 +69,7 @@ Changelog for pre-release sg3_utils-1.48 [20220505] [svn: r951]
- round of coverity identified issue fixes (and non-issues)
- autoconf: upgrade version 2.70 to 2.71; automake upgrade
to version 1.16.5
+ - codespell fixes
Changelog for released sg3_utils-1.47 [20211110] [svn: r919]
- sg_rep_zones: add support for REPORT ZONE DOMAINS and
@@ -1166,7 +1168,7 @@ Changelog for sg3_utils-1.25 [20071016] [svn: r115]
Makefiles
Changelog for sg3_utils-1.24 [20070507] [svn: r77]
- - sg_raw: new utility to send arbirary SCSI commands
+ - sg_raw: new utility to send arbitrary SCSI commands
- sg_luns: increase number of luns that can be fetched
- fix length of raw and hex output
- add '--quiet' option to output only ASCII hex
diff --git a/doc/rescan-scsi-bus.sh.8 b/doc/rescan-scsi-bus.sh.8
index c91b1f38..1533791d 100644
--- a/doc/rescan-scsi-bus.sh.8
+++ b/doc/rescan-scsi-bus.sh.8
@@ -1,4 +1,4 @@
-.TH RESCAN\-SCSI\-BUS.SH "1" "Aprile 2022" "rescan\-scsi\-bus.sh" "User Commands"
+.TH RESCAN\-SCSI\-BUS.SH "1" "May 2022" "rescan\-scsi\-bus.sh" "User Commands"
.SH NAME
rescan-scsi-bus.sh \- script to add and remove SCSI devices without rebooting
.SH SYNOPSIS
@@ -43,7 +43,7 @@ flush failed multipath devices [default: disabled]
remove stale devices (DANGEROUS)
.TP
\fB\-\-forcerescan\fR
-remove and readd existing devices (DANGEROUS)
+remove and re\-add existing devices (DANGEROUS)
.TP
\fB\-h\fR, \fB\-\-help\fR
print usage message then exit
diff --git a/doc/sg3_utils_json.8 b/doc/sg3_utils_json.8
new file mode 100644
index 00000000..161c3583
--- /dev/null
+++ b/doc/sg3_utils_json.8
@@ -0,0 +1,120 @@
+.TH SG3_UTILS "8" "May 2022" "sg3_utils\-1.48" SG3_UTILS
+.SH NAME
+sg3_utils \- JSON output for some utilities
+.SH SYNOPSIS
+.B sg_*
+\fI\-\-json[=JO]\fR [\fIOTHER_OPTIONS\fR] \fIDEVICE\fR
+.SH DESCRIPTION
+.\" Add any additional description here
+.PP
+sg3_utils is a package of utilities that send SCSI commands to the given
+\fIDEVICE\fR via a SCSI pass through interface provided by the host
+operating system. Some utilities, mainly those decoding structured data
+returned by SCSI commands (e.g. sg_vpd) can optionally provide JSON
+output, rather than simple, human-readable output. The default remains
+human-readable output.
+.PP
+JSON is an open standard file format that can be used for data exchange
+between systems. See https://en.wikipedia.org/wiki/JSON . JSON comes in
+many flavours and this one uses the json-builder C implementation found
+at https://github.com/json-parser/json-builder which implements four simple
+JSON data types: string, integer, boolean and null. Its other data types
+are JSON object and JSON array. This project uses the "snake" convention
+for JSON object names: all in lower case with separate words joined with
+a single underscore (e.g. "starting_lba"). The json-builder library uses
+the SPDX-License-Identifier: BSD-2-Clause which is the same license as the
+bulk of the utilities in the sg3_utils package.
+.PP
+The json-builder library is relatively lightweight (700 lines of C code) and
+is "hidden" fully within the sg3_utils library so that its function interface
+and data types are not available (directly) to the utilities in the sg3_utils
+package. That is why the json-builder interface (a file named
+sg_json_builder.h) is in the lib directory and not in the include directory.
+As presented on github, json-builder shares some header files with its
+companion json-parser. The author has modified the json-builder header to
+include what is needed from the json-parser header so that only the builder
+and not the parser are built. The parser could be added later, but currently
+there seems to be no need for it.
+.PP
+The user interface to JSON functionality in the sg3_utils package is heavily
+based on what has been done by Christian Franke and others in smartctl, a
+utility in the smartmontools package for getting S.M.A.R.T. information
+from disks (and other storage devices).
+.PP
+This manpage discusses the \fI\-\-json\fR option which may or may not itself
+have an optional argument. In its shorter form it may either be \fI\-j\fR or
+\fI\-J\fR (lower case preferred if not already in use). The shorter form may
+also take an argument but there must not be a space (or whitespace) between
+\fI\-j\fR and that argument.
+.SH ENVIRONMENT VARIABLES
+The SG3_UTILS_JSON_OPTS environment variable
+yyyyyyyy
+ is explained in the previous
+section. It is only for backward compatibility of the command line options
+for older utilities.
+.PP
+The SG3_UTILS_DSENSE environment variable may be set to a number. It is
+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
+variable is non\-zero then then the returned SCSI sense will be in 'descriptor'
+format.
+.PP
+Several utilities have their own environment variable setting (e.g.
+sg_persist has SG_PERSIST_IN_RDONLY). See individual utility man pages
+for more information.
+.PP
+There is a Linux specific environment variable called SG3_UTILS_LINUX_NANO
+that if defined and the sg driver in the system is 4.0.30 or later, will
+show command durations in nanoseconds rather than the default milliseconds.
+Command durations are typically only shown if \-\-verbose is used 3 or more
+times. Due to an interface problem (a 32 bit integer that should be 64 bits
+with the benefit of hindsight) the maximum duration that can be represented
+in nanoseconds is about 4.2 seconds. If longer durations may occur then
+don't define this environment variable (or undefine it).
+.SH OPTIONS
+Since the argument to \fI\-\-json[=JO]\fR is optional, in the shorter form
+there can be no space(s) between the option and its argument.
+.TP
+\fB\-j[JO]\fR, \fB\-\-json\fR\fI[=JO]\fR
+yyyyyyyyy
+utilities that can cause lots of user data to be lost or overwritten
+sometimes have a \fI\-\-dry\-run\fR option. Device modifying actions are
+typically bypassed (or skipped) to implement a policy of "do no harm".
+This allows complex command line invocations to be tested before the
+action required (e.g. format a disk) is performed. The \fI\-\-dry\-run\fR
+option has become a common feature of many command line utilities (e.g.
+the Unix 'patch' command), not just those from this package.
+.br
+Note that most hyphenated option names in this package also can be given
+with an underscore rather than a hyphen (e.g. \fI\-\-dry_run\fR).
+.SH WEB SITE
+There is a web page discussing this package at
+https://sg.danny.cz/sg/sg3_utils.html . The device naming used by this
+package on various operating systems is discussed at:
+https://sg.danny.cz/sg/device_name.html . There is a git code mirror at
+https://github.com/hreinecke/sg3_utils . The principle code repository
+uses subversion and is on the author's equipment. The author keeps track
+of this via the subversion revision number which is an ascending integer
+(currently at 922 for this package). The github mirror gets updated
+periodically from the author's repository. Depending on the time of
+update, the above Downloads section at sg.danny.cz may be more up to
+date than the github mirror.
+.SH AUTHORS
+Written by Douglas Gilbert. Some utilities have been contributed, see the
+CREDITS file and individual source files (in the 'src' directory).
+.SH "REPORTING BUGS"
+Report bugs to <dgilbert at interlog dot com>.
+.SH COPYRIGHT
+Copyright \(co 2022 Douglas Gilbert
+.br
+Some utilities are distributed under a GPL version 2 license while
+others, usually more recent ones, are under a FreeBSD license. The files
+that are common to almost all utilities and thus contain the most reusable
+code, namely sg_lib.[hc], sg_cmds_basic.[hc] and sg_cmds_extra.[hc] are
+under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.
+.SH "SEE ALSO"
+.B sg3_utils(sg3_utils), smartctl(smartmontools)
diff --git a/doc/sg_dd.8 b/doc/sg_dd.8
index 14290e07..ffe8f13f 100644
--- a/doc/sg_dd.8
+++ b/doc/sg_dd.8
@@ -1,4 +1,4 @@
-.TH SG_DD "8" "August 2021" "sg3_utils\-1.47" SG3_UTILS
+.TH SG_DD "8" "May 2022" "sg3_utils\-1.48" SG3_UTILS
.SH NAME
sg_dd \- copy data to and from files and devices, especially SCSI
devices
@@ -98,7 +98,7 @@ values are given, the first applies to \fIIFILE\fR while the second applies
to \fIOFILE\fR. The value may be from 0 to 7 where 0 is the default and means
there are no command duration limits. Command duration limits are only
supported by 16 byte READ and WRITE commands (plus READ(32), WRITE(32) and
-the WRITE SCATTERED command, bit thay are used by this utility). If the
+the WRITE SCATTERED command, bit they are used by this utility). If the
cdbsz operand is not given and would have a value less than 16, then if
\fICDL\fR is greater than 0, the cdbsz is increased to 16.
.br
@@ -581,7 +581,7 @@ Written by Douglas Gilbert and Peter Allworth.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2000\-2021 Douglas Gilbert
+Copyright \(co 2000\-2022 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/doc/sg_opcodes.8 b/doc/sg_opcodes.8
index e7a1f19d..d3305589 100644
--- a/doc/sg_opcodes.8
+++ b/doc/sg_opcodes.8
@@ -131,12 +131,12 @@ the \fIDEVICE\fR will be queried for the given operation code (i.e. the
\fIOP\fR value) which is the first byte of a SCSI command. Optionally, if
a \fISA\fR value is given, it will be used as that SCSI command's service
action. Note that \fIOP\fR and \fIOP,0\fR are not the same thing, as SCSI
-does allow the service action to be 0 (but it is not comman). \fIOP\fR and
-\fISA\fR are decimal unless prefixed by "0x" or they have a trailing "h".
-\fIOP\fR should be in the range 0 to 255 (0xff) inclusive. \fISA\fR should
-be in the range 0 to 65535 (0xffff) inclusive. When this option is not
-given then all available SCSI commands supported by the \fIDEVICE\fR are
-listed.
+does allow the service action to be 0 (but not in this command). \fIOP\fR
+and \fISA\fR are decimal unless prefixed by "0x" or they have a
+trailing "h". \fIOP\fR should be in the range 0 to 255 (0xff) inclusive.
+\fISA\fR should be in the range 0 to 65535 (0xffff) inclusive. When this
+option is not given then all available SCSI commands supported by the
+\fIDEVICE\fR are listed.
.TP
\fB\-p\fR, \fB\-\-pdt\fR=\fIDT\fR
where \fIDT\fR is the peripheral device type. This is used together with
diff --git a/doc/sg_referrals.8 b/doc/sg_referrals.8
index cabb8359..f1371794 100644
--- a/doc/sg_referrals.8
+++ b/doc/sg_referrals.8
@@ -36,7 +36,7 @@ the cdb's "allocation length" field. If not given then 256 is used. 256 is
enough space for the response header and user data segment descriptors.
.TP
\fB\-s\fR, \fB\-\-one-segment\fR
-report the user data segment of the segment spefified by the \fILBA\fR
+report the user data segment of the segment specified by the \fILBA\fR
parameter only.
.TP
\fB\-r\fR, \fB\-\-raw\fR
diff --git a/doc/sg_rep_zones.8 b/doc/sg_rep_zones.8
index 68fecee2..0f76ee4d 100644
--- a/doc/sg_rep_zones.8
+++ b/doc/sg_rep_zones.8
@@ -60,7 +60,7 @@ or the number of zones is exhausted.
.br
The \fIZT\fR numbers and abbreviations are listed when the \fI\-\-help\fR
option is given twice. Warning: using '!' for inverting the condition may
-not be so practical as the shell (e.g. bash) may interprete '!' as having
+not be so practical as the shell (e.g. bash) may interpret '!' as having
special meaning. Placing single quotes around \fIZT\fR fixes the problem
for the bash shell (e.g. \-\-find='!c' meaning find the first zone whose
type is not conventional).
diff --git a/examples/sgq_dd.c b/examples/sgq_dd.c
index 2f163ef1..3f8ffa27 100644
--- a/examples/sgq_dd.c
+++ b/examples/sgq_dd.c
@@ -70,7 +70,7 @@ static char * version_str = "0.63 20190324";
#define MAX_NUM_THREADS 1024
#ifndef RAW_MAJOR
-#define RAW_MAJOR 255 /*unlikey value */
+#define RAW_MAJOR 255 /*unlikely value */
#endif
#define FT_OTHER 0 /* filetype other than sg or raw device */
diff --git a/examples/transport_ids.txt b/examples/transport_ids.txt
index b61581d8..2657af25 100644
--- a/examples/transport_ids.txt
+++ b/examples/transport_ids.txt
@@ -1,6 +1,6 @@
# This file is an example for the sg_persist utility.
# It discusses using "TransportID"s which are defined (most recently)
-# in SPC-4 revison 20 section 7.5.4 titled: "TransportID identifiers".
+# in SPC-4 revision 20 section 7.5.4 titled: "TransportID identifiers".
#
# The sg_persist utility can take one or more "transportID"s from stdin when
# either the '--transport-id=-" or "-X -" option is given on the command
diff --git a/include/sg_pr2serr.h b/include/sg_pr2serr.h
index b29c7e34..d5a4809c 100644
--- a/include/sg_pr2serr.h
+++ b/include/sg_pr2serr.h
@@ -67,24 +67,28 @@ typedef void * sgj_opaque_p;
* they initialized as shown. */
typedef struct sgj_state_t {
bool pr_as_json; /* = false */
- bool pr_pretty; /* = true */
- bool pr_header; /* = true */
- bool pr_sorted; /* = false (ignored) */
- bool pr_output; /* = false */
- bool pr_implemented;
- bool pr_unimplemented;
- char pr_format; /* = '\0' */
- int pr_indent_size; /* = 4 */
- int first_bad_char; /* = '\0' */
- int verbose; /* = 0 */
+ bool pr_hex; /* 'h' (def: true) */
+ bool pr_leadin; /* 'l' (def: true) */
+ bool pr_output; /* 'o' (def: false) */
+ bool pr_pretty; /* 'p' (def: true) */
+ bool pr_trailer; /* 't' (def: true) */
+ char pr_format; /* (def: '\0') */
+ int pr_indent_size; /* digit (def: 4) */
+ int verbose; /* 'v' (def: 0) incremented each appearance */
/* the following hold state information */
+ int first_bad_char; /* = '\0' */
sgj_opaque_p basep; /* base JSON object pointer */
sgj_opaque_p outputp; /* 'output' named JSON array pointer */
sgj_opaque_p userp; /* for temporary usage */
} sgj_state;
-/* Prints to stdout like printf(fmt, ...). Further if --json=o option is
- * given that output line is also placed in the JSON 'output' array. */
+/* If jsp in non-NULL and jsp->pr_as_json is true then this call is ignored
+ * unless jsp->pr_output is true. Otherwise this function prints to stdout
+ * like printf(fmt, ...); note that no LF is added. In the jsp->pr_output
+ * is true case, nothing is printed to stdout but instead is placed into the
+ * JSON 'output" array (jsp->outputp) after some preprocessing. That
+ * preprocessing involves removing a leading LF from 'fmt' (if present) and
+ * up to two trailing LF characters. */
void sgj_pr_hr(sgj_state * jsp, const char * fmt, ...) __printf(2, 3);
/* Initializes the state object pointed to by jsp based on the argument
@@ -100,11 +104,11 @@ bool sgj_init_state(sgj_state * jsp, const char * j_optarg);
* sgj_finish() to clean up (i.e. remove all heap allocations) all the
* elements (i.e. JSON objects and arrays) that have been placed in that
* in-core tree. If jsp is NULL nothing further happens. Otherwise the pointer
- * to be returned is placed in jsp->basep. If jsp->pr_header is true and
+ * to be returned is placed in jsp->basep. If jsp->pr_leadin is true and
* util_name is non-NULL then a "utility_invoked" JSON object is made with
* "name", and "version_date" object fields. If the jsp->pr_output field is
* true a named array called "output" is added to the "utility_invoked" object
- * (creating it in the case when jsp->pr_header is false) and a pointer to
+ * (creating it in the case when jsp->pr_leadin is false) and a pointer to
* that array object is placed in jsp->objectp . The returned pointer is not
* usually needed but if it is NULL then a heap allocation has failed. */
sgj_opaque_p sgj_start(const char * util_name, const char * ver_str,
@@ -136,56 +140,113 @@ sgj_opaque_p sgj_new_named_object(sgj_state * jsp, sgj_opaque_p jop,
sgj_opaque_p sgj_new_named_array(sgj_state * jsp, sgj_opaque_p jop,
const char * name);
-/* If jsp is NULL or jsp->pr_as_json is false or ua_jop is NULL nothing
- * happens and NULL is returned. Otherwise it adds a new array element
- * (ua_jop) to the array ('jap') that was returned by sgj_new_named_array().
- * ua_jop is assumed to not been part of the main JSON in-core tree before
- * this call, and it is after this call. This means that ua_jop must have
- * been created by sgj_new_unattached_object() or similar. */
-sgj_opaque_p sgj_add_array_element(sgj_state * jsp, sgj_opaque_p jap,
- sgj_opaque_p ua_jop);
-
-sgj_opaque_p sgj_add_name_vs(sgj_state * jsp, sgj_opaque_p jop,
- const char * name, const char * value);
-
-sgj_opaque_p sgj_add_name_vi(sgj_state * jsp, sgj_opaque_p jop,
- const char * name, int64_t value);
-
-sgj_opaque_p sgj_add_name_vb(sgj_state * jsp, sgj_opaque_p jop,
- const char * name, bool value);
-
-sgj_opaque_p sgj_add_name_obj(sgj_state * jsp, sgj_opaque_p jop,
- const char * name, sgj_opaque_p ua_jop);
-
+/* If either jsp or value is NULL or jsp->pr_as_json is false then nothing
+ * happens and NULL is returned. The insertion point is at jop but if it is
+ * NULL jsp->basep is used. If 'name' is non-NULL a new named JSON object is
+ * added using 'name' and the associated value is a JSON string formed from
+ * 'value'. If 'name' is NULL then 'jop' is assumed to be a JSON array and
+ * a JSON string formed from 'value' is added. If successful returns a
+ * a pointer newly formed JSON string. */
+sgj_opaque_p sgj_add_val_s(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, const char * value);
+
+/* If either jsp is NULL or jsp->pr_as_json is false then nothing happens and
+ * NULL is returned. The insertion point is at jop but if it is NULL
+ * jsp->basep is used. If 'name' is non-NULL a new named JSON object is
+ * added using 'name' and the associated value is a JSON integer formed from
+ * 'value'. If 'name' is NULL then 'jop' is assumed to be a JSON array and
+ * a JSON integer formed from 'value' is added. If successful returns a
+ * a pointer newly formed JSON integer. */
+sgj_opaque_p sgj_add_val_i(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, int64_t value);
+
+/* If either jsp is NULL or jsp->pr_as_json is false then nothing happens and
+ * NULL is returned. The insertion point is at jop but if it is NULL
+ * jsp->basep is used. If 'name' is non-NULL a new named JSON object is
+ * added using 'name' and the associated value is a JSON boolean formed from
+ * 'value'. If 'name' is NULL then 'jop' is assumed to be a JSON array and
+ * a JSON boolean formed from 'value' is added. If successful returns a
+ * a pointer newly formed JSON boolean. */
+sgj_opaque_p sgj_add_val_b(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, bool value);
+
+/* If jsp is NULL, jsp->pr_as_json is false or ua_jop is NULL nothing then
+ * happens and NULL is returned. 'jop' is the insertion point but if it is
+ * NULL jsp->basep is used instead. If 'name' is non-NULL a new named JSON
+ * object is added using 'name' and the associated value is ua_jop. If 'name'
+ * is NULL then 'jop' is assumed to be a JSON array and ua_jop is added to
+ * it. If successful returns ua_jop . The "ua_" prefix stands for unattached.
+ * Tha should be the case before invocation and it will be attached to jop
+ * after a successful invocation. This means that ua_jop must have been
+ * created by sgj_new_unattached_object() or similar. */
+sgj_opaque_p sgj_add_val_o(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, sgj_opaque_p ua_jop);
+
+/* The '_twin_' refers to generating output both for human readable and/or
+ * JSON with a single invocation. If jsp is non_NULL and jsp->pr_output is
+ * true then both JSON and human readable output is formed (and the latter is
+ * placed in the jsp->outputp JSON array). The human readable form will have
+ * leadin_sp spaces followed by 'name' then a separator, then 'value' with a
+ * trailing LF. If 'name' is NULL then it and the separator are ignored. If
+ * there is JSON output, then leadin_sp and sep are ignored. If 'jop' is NULL
+ * then basep->basep is used. If 'name' is NULL then a JSON string object,
+ * made from 'value' is added to the JSON array pointed to by 'jop'.
+ * Otherwise a 'name'-d JSON object whose value is a JSON string object made
+ * from 'value' is added at 'jop'. */
void sgj_pr_twin_vs(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
const char * name, enum sgj_separator_t sep,
const char * value);
+/* Similar to sgj_pr_twin_vs()'s description with 'JSON string object'
+ * replaced by 'JSON integer object'. */
void sgj_pr_twin_vi(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
const char * name, enum sgj_separator_t sep,
int64_t value);
+/* Similar to sgj_pr_twin_vs()'s description with 'JSON string object'
+ * replaced by 'JSON boolean object'. */
void sgj_pr_twin_vb(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
const char * name, enum sgj_separator_t sep, bool value);
+/* This function only produces JSON output if jsp is non-NULL and
+ * jsp->pr_as_json is true. It adds a named object at 'jop' (or jop->basep
+ * if jop is NULL) along with a value. If jsp->pr_hex is true then that
+ * value is two sub-objects, one named 'i' with a 'value' as a JSON integer,
+ * the other one named 'hex' with 'value' rendered as hex in a JSON string.
+ * If jsp->pr_hex is false the there are no sub-objects and the 'value' is
+ * rendered as JSON integer. */
void sgj_add_name_pair_ihex(sgj_state * jsp, sgj_opaque_p jop,
const char * name, uint64_t value);
+/* This function only produces JSON output if jsp is non-NULL and
+ * jsp->pr_as_json is true. It adds a named object at 'jop' (or jop->basep
+ * if jop is NULL) along with a value that has two sub-objects. One is
+ * named "i" with 'val_i' rendered as a JSON integer. The other is named
+ * 'str_name' (or "string" if that is NULL) with 'val_s' randered as a
+ * JSON string. */
void sgj_add_name_pair_istr(sgj_state * jsp, sgj_opaque_p jop,
const char * name, int64_t val_i,
- const char * val_s);
-
-#if 0
-void sgj_pr_hr_line_vs(sgj_state * jsp, sgj_opaque_p jop,
- const char * hr_line, const char * name,
- const char * value);
-#endif
-
+ const char * str_name, const char * val_s);
+
+/* Nothing in the in-core JSON tree is actually printed to 'fp' (typically
+ * stdout) until this call is made. If jsp is NULL, jsp->pr_as_json is false
+ * or jsp->basep is NULL then this function does nothing. If jsp->trailer is
+ * true then a new JSON object named "exit_status" and the 'exit_status'
+ * value rendered as a JSON integer is appended to jsp->basep. The in-core
+ * JSON tree with jsp->basep as its root is streamed to 'fp'. */
void sgj_pr2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status,
FILE * fp);
+/* This function is only needed if the pointer returned from either
+ * sgj_new_unattached_object() or sgj_new_unattached_array() has not been
+ * attached into the in-core JSON tree whose root is jsp->basep . */
void sgj_free_unattached(sgj_opaque_p jop);
+/* If jsp is NULL or jsp->basep is NULL then this function does nothing.
+ * This function does bottom up, heap freeing of all the in-core JSON
+ * objects and arrays attached to the root JSON object assumed to be
+ * found at jsp->basep . After this call jsp->basep, jsp->outputp and
+ * jsp->userp will all be set to NULL. */
void sgj_finish(sgj_state * jsp);
diff --git a/inhex/nvme_read_ctl.hex b/inhex/nvme_read_ctl.hex
index 1473d410..7996a1ae 100644
--- a/inhex/nvme_read_ctl.hex
+++ b/inhex/nvme_read_ctl.hex
@@ -13,7 +13,7 @@
#
# 512 byte logical block size is assumed. Read 4 blocks hence 2048 bytes.
# The first LBA read is 0x12345 and the namespace is 1. If successful
-# the four blocks will be read into the data-in buffer. Submission queu
+# the four blocks will be read into the data-in buffer. Submission queue
# 0 is used (the same queue that Admin commands use). The NVM opcode for
# the Read command is 0x2 and appears in the first command byte.
@@ -30,7 +30,7 @@
# --outfile=t.bin /dev/nvme0n1
# In FreeBSD the device name would be /dev/nvme0ns1
#
-# Notice the '--nvm' option which is needed to distiguish a NVM
+# Notice the '--nvm' option which is needed to distinguish a NVM
# command from an Admin command as Admin commands are the default
# in this utility.
#
diff --git a/inhex/nvme_read_oob_ctl.hex b/inhex/nvme_read_oob_ctl.hex
index 13b0b118..81d7a305 100644
--- a/inhex/nvme_read_oob_ctl.hex
+++ b/inhex/nvme_read_oob_ctl.hex
@@ -21,7 +21,7 @@
#
# 512 byte logical block size is assumed. Read 4 blocks hence 2048 bytes.
# The first LBA read is 0xabcd012345 and the namespace is 1. If successful
-# the four blocks will be read into the data-in buffer. Submission queu
+# the four blocks will be read into the data-in buffer. Submission queue
# 0 is used (the same queue that Admin commands use). The NVM opcode for
# the Read command is 0x2 and appears in the first command byte.
@@ -38,7 +38,7 @@
# --outfile=t.bin /dev/nvme0n1
# In FreeBSD the device name would be /dev/nvme0ns1
#
-# Notice the '--nvm' option which is needed to distiguish a NVM
+# Notice the '--nvm' option which is needed to distinguish a NVM
# command from an Admin command as Admin commands are the default
# in this utility.
#
diff --git a/inhex/nvme_write_ctl.hex b/inhex/nvme_write_ctl.hex
index 02b5a377..9e6c1123 100644
--- a/inhex/nvme_write_ctl.hex
+++ b/inhex/nvme_write_ctl.hex
@@ -29,7 +29,7 @@
# sg_raw --cmdfile=nvme_write_ctl.hex --nvm -s 2048
# --infile=t.bin /dev/nvme0
#
-# Notice the '--nvm' option which is needed to distiguish a NVM
+# Notice the '--nvm' option which is needed to distinguish a NVM
# command from an Admin command as Admin commands are the default
# in this utility.
#
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 274ee667..77e56408 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -77,7 +77,7 @@ endif
# For C++/clang testing
## CC = gcc-9
-CXX = g++
+## CXX = g++
## CC = clang
## CXX = clang++
## CC = clang++
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 010cd3c6..45b464fc 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -394,7 +394,6 @@ libsgutils2_la_SOURCES = sg_lib.c sg_pr2serr.c sg_lib_data.c \
@DEBUG_TRUE@DBG_CPPFLAGS = -DDEBUG
# For C++/clang testing
-CXX = g++
# -std=<s> can be c99, c11, gnu11, etc. Default is gnu11 for C code
# -Wall is no longer all warnings. Add -W (since renamed to -Wextra) for more
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index 850b5c02..8922d323 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -1435,7 +1435,7 @@ static const char * dd_usage_reason_str_arr[] = {
"Unknown",
"resend this and further commands to:",
"resend this command to:",
- "new subsiduary lu added to this administrative lu:",
+ "new subsidiary lu added to this administrative lu:",
"administrative lu associated with a preferred binding:",
};
@@ -2610,7 +2610,7 @@ sg_get_sfs_str(uint16_t sfs_code, int peri_type, int buff_len, char * buff,
* structures that are sent across the wire. The FIS register structure is
* used to move a command from a SATA host to device, but the ATA 'command'
* is not the first byte. So it is harder to say what will happen if a
- * FIS structure is presented as a SCSI command, hopfully there is a low
+ * FIS structure is presented as a SCSI command, hopefully there is a low
* probability this function will yield true in that case. */
bool
sg_is_scsi_cdb(const uint8_t * cdbp, int clen)
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index f6c9b3ac..d0931eb7 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -1438,7 +1438,7 @@ struct sg_lib_asc_ascq_t sg_lib_asc_ascq[] =
{0x74,0x04,"Cryptographic integrity validation failed"},
{0x74,0x05,"Error decrypting data"},
{0x74,0x06,"Unknown signature verification key"},
- {0x74,0x07,"Encryption parameters not useable"},
+ {0x74,0x07,"Encryption parameters not usable"},
{0x74,0x08,"Digital signature validation failure"},
{0x74,0x09,"Encryption mode mismatch on read"},
{0x74,0x0a,"Encrypted block not raw read enabled"},
@@ -1645,7 +1645,7 @@ struct sg_lib_value_name_t sg_lib_nvme_cmd_status_arr[] =
{0x2, 2, "Invalid field in command"},
{0x3, 2, "Command id conflict"},
{0x4, 3, "Data transfer error"},
- {0x5, 4, "Command aborted due to power loss notication"},
+ {0x5, 4, "Command aborted due to power loss notification"},
{0x6, 5, "Internal error"},
{0x7, 6, "Command abort requested"},
{0x8, 6, "Command aborted due to SQ deletion"},
@@ -1656,7 +1656,7 @@ struct sg_lib_value_name_t sg_lib_nvme_cmd_status_arr[] =
{0xd, 5, "Invalid SGL segment descriptor"},
{0xe, 5, "Invalid number of SGL descriptors"},
{0xf, 5, "Data SGL length invalid"},
- {0x10, 5, "Matadata SGL length invalid"},
+ {0x10, 5, "Metadata SGL length invalid"},
{0x11, 5, "SGL descriptor type invalid"},
{0x12, 5, "Invalid use of controller memory buffer"},
{0x13, 5, "PRP offset invalid"},
@@ -1843,7 +1843,7 @@ struct sg_value_2names_t sg_exit_str_arr[] = {
{17, "Illegal request with Info field", NULL},
{18, "Medium or hardware error with Info", NULL},
{20, "No sense key", "type: probably additional sense code"},
- {21, "Recovered error (warning)", "tye: sense key"},
+ {21, "Recovered error (warning)", "type: sense key"},
/* N.B. this is a warning not error */
{22, "LBA out of range", NULL},
{24, "Reservation conflict", "type: SCSI status"},
diff --git a/lib/sg_lib_names.c b/lib/sg_lib_names.c
index 2543f2ab..19ffa441 100644
--- a/lib/sg_lib_names.c
+++ b/lib/sg_lib_names.c
@@ -35,7 +35,7 @@ struct sg_lib_simple_value_name_t sg_lib_names_mode_arr[] = {
{0x0900, "Peripheral device (obsolete)"}, /* SPC */
{0x0a00, "Control"}, /* SPC */
{0x0a01, "Control extension"}, /* SPC */
- {0x0a02, "Application tage"}, /* SBC */
+ {0x0a02, "Application tag"}, /* SBC */
{0x0a03, "Command duration limit A"}, /* SPC */
{0x0a04, "Command duration limit B"}, /* SPC */
{0x0a05, "IO Advice Hints Grouping"}, /* SBC */
diff --git a/lib/sg_pr2serr.c b/lib/sg_pr2serr.c
index 70807671..8acfa278 100644
--- a/lib/sg_pr2serr.c
+++ b/lib/sg_pr2serr.c
@@ -66,98 +66,106 @@ scnpr(char * cp, int cp_max_len, const char * fmt, ...)
return (n < cp_max_len) ? n : (cp_max_len - 1);
}
-bool
-sgj_init_state(sgj_state * jstp, const char * j_optarg)
+static bool
+sgj_parse_opts(sgj_state * jsp, const char * j_optarg)
{
bool bad_arg = false;
- bool prev_exclam = false;
+ bool prev_negate = false;
bool negate;
int k, c;
- jstp->pr_as_json = true;
- jstp->pr_pretty = true;
- jstp->pr_header = true;
- jstp->pr_sorted = false;
- jstp->pr_output = false;
- jstp->pr_implemented = false;
- jstp->pr_unimplemented = false;
- jstp->pr_format = 0;
- jstp->first_bad_char = 0;
- jstp->verbose = 0;
- jstp->pr_indent_size = 4;
- jstp->basep = NULL;
- jstp->outputp = NULL;
- jstp->userp = NULL;
-
- if (j_optarg) {
- for (k = 0; j_optarg[k]; ++k) {
- c = j_optarg[k];
- negate = false;
- switch (c) {
- case '!':
- negate = true;
- break;
- case '~':
- negate = true;
- break;
- case 'N':
- negate = true;
- break;
- case '0':
- case '2':
- jstp->pr_indent_size = 2;
- break;
- case '3':
- jstp->pr_indent_size = 3;
- break;
- case '4':
- jstp->pr_indent_size = 4;
- break;
- case '8':
- jstp->pr_indent_size = 8;
- break;
- case 'c':
- jstp->pr_pretty = false;
- break;
- case 'g':
- jstp->pr_format = 'g';
- break;
- case 'h':
- jstp->pr_header = ! prev_exclam;
- break;
- case 'i':
- jstp->pr_implemented = true;
- break;
- case 'o':
- jstp->pr_output = true;
- break;
- case 's':
- jstp->pr_sorted = true;
- break;
- case 'u':
- jstp->pr_unimplemented = true;
- break;
- case 'v':
- ++jstp->verbose;
- break;
- case 'y':
- jstp->pr_format = 'g';
- break;
- default:
- bad_arg = true;
- if (0 == jstp->first_bad_char)
- jstp->first_bad_char = c;
- break;
- }
- prev_exclam = negate ? !prev_exclam : false;
+ for (k = 0; j_optarg[k]; ++k) {
+ c = j_optarg[k];
+ negate = false;
+ switch (c) {
+ case '=':
+ case ' ':
+ if (0 == k)
+ break; /* allow and ignore leading '=' or ' ' */
+ bad_arg = true;
+ if (0 == jsp->first_bad_char)
+ jsp->first_bad_char = c;
+ break;
+ case '!':
+ negate = true;
+ break;
+ case '~':
+ negate = true;
+ break;
+ case 'N':
+ negate = true;
+ break;
+ case '0':
+ case '2':
+ jsp->pr_indent_size = 2;
+ break;
+ case '3':
+ jsp->pr_indent_size = 3;
+ break;
+ case '4':
+ jsp->pr_indent_size = 4;
+ break;
+ case '8':
+ jsp->pr_indent_size = 8;
+ break;
+ case 'g':
+ jsp->pr_format = 'g';
+ break;
+ case 'h':
+ jsp->pr_hex = ! prev_negate;
+ break;
+ case 'l':
+ jsp->pr_leadin = ! prev_negate;
+ break;
+ case 'o':
+ jsp->pr_output = ! prev_negate;
+ break;
+ case 'p':
+ jsp->pr_pretty = ! prev_negate;
+ break;
+ case 't':
+ jsp->pr_trailer = ! prev_negate;
+ break;
+ case 'v':
+ ++jsp->verbose;
+ break;
+ case 'y':
+ jsp->pr_format = 'g';
+ break;
+ default:
+ bad_arg = true;
+ if (0 == jsp->first_bad_char)
+ jsp->first_bad_char = c;
+ break;
}
+ prev_negate = negate ? ! prev_negate : false;
}
return ! bad_arg;
}
+bool
+sgj_init_state(sgj_state * jsp, const char * j_optarg)
+{
+ jsp->pr_as_json = true;
+ jsp->pr_hex = false;
+ jsp->pr_leadin = true;
+ jsp->pr_output = false;
+ jsp->pr_pretty = true;
+ jsp->pr_trailer = true;
+ jsp->pr_format = 0;
+ jsp->first_bad_char = 0;
+ jsp->verbose = 0;
+ jsp->pr_indent_size = 4;
+ jsp->basep = NULL;
+ jsp->outputp = NULL;
+ jsp->userp = NULL;
+
+ return j_optarg ? sgj_parse_opts(jsp, j_optarg) : true;
+}
+
sgj_opaque_p
sgj_start(const char * util_name, const char * ver_str, int argc,
- char *argv[], sgj_state * jstp)
+ char *argv[], sgj_state * jsp)
{
int k;
json_value * jvp = json_object_new(0);
@@ -167,78 +175,82 @@ sgj_start(const char * util_name, const char * ver_str, int argc,
if (NULL == jvp)
return NULL;
- if (NULL == jstp)
+ if (NULL == jsp)
return jvp;
- jstp->basep = jvp;
- if (jstp->pr_header) {
+ jsp->basep = jvp;
+ if (jsp->pr_leadin) {
jap = json_array_new(0);
if (NULL == jap) {
- json_builder_free(jvp);
+ json_builder_free((json_value *)jvp);
return NULL;
}
/* assume rest of json_*_new() calls succeed */
- json_array_push(jap, json_integer_new(1));
- json_array_push(jap, json_integer_new(0));
- json_object_push(jvp, "json_format_version", jap);
+ json_array_push((json_value *)jap, json_integer_new(1));
+ json_array_push((json_value *)jap, json_integer_new(0));
+ json_object_push((json_value *)jvp, "json_format_version",
+ (json_value *)jap);
if (util_name) {
jap = json_array_new(0);
for (k = 0; k < argc; ++k)
- json_array_push(jap, json_string_new(argv[k]));
- jv2p = json_object_push(jvp, "utility_invoked",
+ json_array_push((json_value *)jap, json_string_new(argv[k]));
+ jv2p = json_object_push((json_value *)jvp, "utility_invoked",
json_object_new(0));
- json_object_push(jv2p, "name", json_string_new(util_name));
+ json_object_push((json_value *)jv2p, "name",
+ json_string_new(util_name));
if (ver_str)
- json_object_push(jv2p, "version_date",
+ json_object_push((json_value *)jv2p, "version_date",
json_string_new(ver_str));
else
- json_object_push(jv2p, "version_date", json_string_new("0.0"));
- json_object_push(jv2p, "argv", jap);
+ json_object_push((json_value *)jv2p, "version_date",
+ json_string_new("0.0"));
+ json_object_push((json_value *)jv2p, "argv", jap);
}
} else {
- if (jstp->pr_output && util_name)
- jv2p = json_object_push(jvp, "utility_invoked",
+ if (jsp->pr_output && util_name)
+ jv2p = json_object_push((json_value *)jvp, "utility_invoked",
json_object_new(0));
}
- if (jstp->pr_output && jv2p)
- jstp->outputp = json_object_push(jv2p, "output", json_array_new(0));
+ if (jsp->pr_output && jv2p)
+ jsp->outputp = json_object_push((json_value *)jv2p, "output",
+ json_array_new(0));
return jvp;
}
void
-sgj_pr2file(sgj_state * jstp, sgj_opaque_p jop, int exit_status, FILE * fp)
+sgj_pr2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status, FILE * fp)
{
size_t len;
char * b;
- json_value * jvp = (json_value *)(jop ? jop : jstp->basep);
+ json_value * jvp = (json_value *)(jop ? jop : jsp->basep);
json_serialize_opts out_settings;
if (NULL == jvp) {
fprintf(fp, "%s: all NULL pointers ??\n", __func__);
return;
}
- if ((NULL == jop) && jstp->pr_header)
+ if ((NULL == jop) && jsp->pr_leadin)
json_object_push(jvp, "exit_status", json_integer_new(exit_status));
memcpy(&out_settings, &def_out_settings, sizeof(out_settings));
- if (jstp->pr_indent_size != def_out_settings.indent_size)
- out_settings.indent_size = jstp->pr_indent_size;
- if (! jstp->pr_pretty)
+ if (jsp->pr_indent_size != def_out_settings.indent_size)
+ out_settings.indent_size = jsp->pr_indent_size;
+ if (! jsp->pr_pretty)
out_settings.mode = json_serialize_mode_single_line;
len = json_measure_ex(jvp, out_settings);
if (len < 1)
return;
- if (jstp->verbose > 3)
+ if (jsp->verbose > 3)
fprintf(fp, "%s: serialization length: %zu bytes\n", __func__, len);
- b = calloc(len, 1);
+ b = (char *)calloc(len, 1);
if (NULL == b) {
- if (jstp->verbose > 3)
+ if (jsp->verbose > 3)
pr2serr("%s: unable to get %zu bytes on heap\n", __func__, len);
return;
}
json_serialize_ex(b, jvp, out_settings);
- if (jstp->verbose > 3)
+ if (jsp->verbose > 3)
fprintf(fp, "json serialized:\n");
fprintf(fp, "%s\n", b);
}
@@ -247,7 +259,7 @@ void
sgj_finish(sgj_state * jsp)
{
if (jsp && jsp->basep) {
- json_builder_free(jsp->basep);
+ json_builder_free((json_value *)jsp->basep);
jsp->basep = NULL;
jsp->outputp = NULL;
jsp->userp = NULL;
@@ -258,7 +270,7 @@ void
sgj_free_unattached(sgj_opaque_p jop)
{
if (jop)
- json_builder_free(jop);
+ json_builder_free((json_value *)jop);
}
void
@@ -285,7 +297,7 @@ sgj_pr_hr(sgj_state * jsp, const char * fmt, ...)
/* remove leading linefeed, if present */
if ((len > 0) && ('\n' == b[0]))
++cp;
- json_array_push(jsp->outputp, json_string_new(cp));
+ json_array_push((json_value *)jsp->outputp, json_string_new(cp));
}
va_end(args);
} else if (jsp->pr_as_json) {
@@ -304,8 +316,8 @@ sgj_new_named_object(sgj_state * jsp, sgj_opaque_p jop, const char * name)
{
sgj_opaque_p resp = NULL;
- if (jsp && jsp->pr_as_json)
- resp = json_object_push((jop ? jop : jsp->basep), name,
+ if (jsp && jsp->pr_as_json && name)
+ resp = json_object_push((json_value *)(jop ? jop : jsp->basep), name,
json_object_new(0));
return resp;
}
@@ -316,22 +328,12 @@ sgj_new_named_array(sgj_state * jsp, sgj_opaque_p jop, const char * name)
{
sgj_opaque_p resp = NULL;
- if (jsp && jsp->pr_as_json)
- resp = json_object_push((jop ? jop : jsp->basep), name,
+ if (jsp && jsp->pr_as_json && name)
+ resp = json_object_push((json_value *)(jop ? jop : jsp->basep), name,
json_array_new(0));
return resp;
}
-/* jap will 'own' ua_jop (if returned value is non-NULL) */
-sgj_opaque_p
-sgj_add_array_element(sgj_state * jsp, sgj_opaque_p jap, sgj_opaque_p ua_jop)
-{
- if (jsp && ua_jop && jsp->pr_as_json)
- return json_array_push(jap, ua_jop);
- else
- return NULL;
-}
-
/* Newly created object is un-attached to jsp->basep tree */
sgj_opaque_p
sgj_new_unattached_object(sgj_state * jsp)
@@ -347,45 +349,64 @@ sgj_new_unattached_array(sgj_state * jsp)
}
sgj_opaque_p
-sgj_add_name_vs(sgj_state * jsp, sgj_opaque_p jop, const char * name,
+sgj_add_val_s(sgj_state * jsp, sgj_opaque_p jop, const char * name,
const char * value)
{
- if (jsp && jsp->pr_as_json)
- return json_object_push((jop ? jop : jsp->basep), name,
- json_string_new(value));
- else
+ if (jsp && jsp->pr_as_json && value) {
+ if (name)
+ return json_object_push((json_value *)(jop ? jop : jsp->basep),
+ name, json_string_new(value));
+ else
+ return json_array_push((json_value *)(jop ? jop : jsp->basep),
+ json_string_new(value));
+ } else
return NULL;
}
sgj_opaque_p
-sgj_add_name_vi(sgj_state * jsp, sgj_opaque_p jop, const char * name,
+sgj_add_val_i(sgj_state * jsp, sgj_opaque_p jop, const char * name,
int64_t value)
{
- if (jsp && jsp->pr_as_json)
- return json_object_push((jop ? jop : jsp->basep), name,
- json_integer_new(value));
+ if (jsp && jsp->pr_as_json) {
+ if (name)
+ return json_object_push((json_value *)(jop ? jop : jsp->basep),
+ name, json_integer_new(value));
+ else
+ return json_array_push((json_value *)(jop ? jop : jsp->basep),
+ json_integer_new(value));
+ }
else
return NULL;
}
sgj_opaque_p
-sgj_add_name_vb(sgj_state * jsp, sgj_opaque_p jop, const char * name,
+sgj_add_val_b(sgj_state * jsp, sgj_opaque_p jop, const char * name,
bool value)
{
- if (jsp && jsp->pr_as_json)
- return json_object_push((jop ? jop : jsp->basep), name,
- json_boolean_new(value));
- else
+ if (jsp && jsp->pr_as_json) {
+ if (name)
+ return json_object_push((json_value *)(jop ? jop : jsp->basep),
+ name, json_boolean_new(value));
+ else
+ return json_array_push((json_value *)(jop ? jop : jsp->basep),
+ json_boolean_new(value));
+ } else
return NULL;
}
+/* jop will 'own' ua_jop (if returned value is non-NULL) */
sgj_opaque_p
-sgj_add_name_obj(sgj_state * jsp, sgj_opaque_p jop, const char * name,
- sgj_opaque_p ua_jop)
+sgj_add_val_o(sgj_state * jsp, sgj_opaque_p jop, const char * name,
+ sgj_opaque_p ua_jop)
{
- if (jsp && jsp->pr_as_json && ua_jop)
- return json_object_push((jop ? jop : jsp->basep), name, ua_jop);
- else
+ if (jsp && jsp->pr_as_json && ua_jop) {
+ if (name)
+ return json_object_push((json_value *)(jop ? jop : jsp->basep),
+ name, (json_value *)ua_jop);
+ else
+ return json_array_push((json_value *)(jop ? jop : jsp->basep),
+ (json_value *)ua_jop);
+ } else
return NULL;
}
@@ -393,24 +414,26 @@ void
sgj_add_name_pair_ihex(sgj_state * jsp, sgj_opaque_p jop, const char * name,
uint64_t value)
{
- if ((NULL == jsp) || (! jsp->pr_as_json))
+ if ((NULL == jsp) || (NULL == name) || (! jsp->pr_as_json))
return;
- else {
+ else if (jsp->pr_hex) {
sgj_opaque_p jo2p =
sgj_new_named_object(jsp, (jop ? jop : jsp->basep), name);
char b[64];
if (NULL == jo2p)
return;
- sgj_add_name_vi(jsp, jo2p, "i", (int64_t)value);
+ sgj_add_val_i(jsp, jo2p, "i", (int64_t)value);
snprintf(b, sizeof(b), "%" PRIx64, value);
- sgj_add_name_vs(jsp, jo2p, "hex", b);
- }
+ sgj_add_val_s(jsp, jo2p, "hex", b);
+ } else
+ sgj_add_val_i(jsp, jop, name, (int64_t)value);
}
void
sgj_add_name_pair_istr(sgj_state * jsp, sgj_opaque_p jop,
- const char * name, int64_t value, const char * str)
+ const char * name, int64_t value,
+ const char * str_name, const char * str)
{
if ((NULL == jsp) || (! jsp->pr_as_json))
return;
@@ -419,9 +442,9 @@ sgj_add_name_pair_istr(sgj_state * jsp, sgj_opaque_p jop,
sgj_new_named_object(jsp, (jop ? jop : jsp->basep), name);
if (NULL == jo2p)
return;
- sgj_add_name_vi(jsp, jo2p, "i", (int64_t)value);
+ sgj_add_val_i(jsp, jo2p, "i", (int64_t)value);
if (str)
- sgj_add_name_vs(jsp, jo2p, "string", str);
+ sgj_add_val_s(jsp, jo2p, str_name ? str_name : "string", str);
}
}
@@ -482,34 +505,39 @@ sgj_pr_twin_xx(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
b[n] = ' ';
b[n] = '\0';
if (NULL == name) {
- switch (jtype) {
- case json_string:
- scnpr(b + n, blen - n, "%s", jvp->u.string.ptr);
- break;
- case json_integer:
- scnpr(b + n, blen - n, "%" PRIi64, jvp->u.integer);
- break;
- case json_boolean:
- scnpr(b + n, blen - n, "%s", jvp->u.boolean ? "true" : "false");
- break;
- case json_none:
- default:
- break;
+ if ((! as_json) || (jsp && jsp->pr_output)) {
+ switch (jtype) {
+ case json_string:
+ scnpr(b + n, blen - n, "%s", jvp->u.string.ptr);
+ break;
+ case json_integer:
+ scnpr(b + n, blen - n, "%" PRIi64, jvp->u.integer);
+ break;
+ case json_boolean:
+ scnpr(b + n, blen - n, "%s",
+ jvp->u.boolean ? "true" : "false");
+ break;
+ case json_none:
+ default:
+ break;
+ }
+ printf("%s\n", b);
}
- printf("%s\n", b);
if (NULL == jop) {
if (as_json && jsp->pr_output) {
eaten = true;
- json_array_push(jsp->outputp, jvp ? jvp : json_null_new());
+ json_array_push((json_value *)jsp->outputp,
+ jvp ? jvp : json_null_new());
}
} else { /* assume jop points to named array */
if (as_json) {
eaten = true;
- json_array_push(jop, jvp ? jvp : json_null_new());
+ json_array_push((json_value *)jop,
+ jvp ? jvp : json_null_new());
}
}
if (jvp && (! eaten))
- json_builder_free(jvp);
+ json_builder_free((json_value *)jvp);
return;
}
n += scnpr(b + n, blen - n, "%s", name);
@@ -521,7 +549,8 @@ sgj_pr_twin_xx(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
k = sgj_jsonify_name(name, jname, sizeof(jname));
if (k > 0) {
eaten = true;
- json_object_push(jop, jname, jvp ? jvp : json_null_new());
+ json_object_push((json_value *)jop, jname,
+ jvp ? jvp : json_null_new());
}
}
if (jvp && ((as_json && jsp->pr_output) || (! as_json))) {
@@ -557,14 +586,13 @@ sgj_pr_twin_xx(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
}
switch (jtype) {
case json_string:
- n += scnpr(b + n, blen - n, "%s", jvp->u.string.ptr);
+ scnpr(b + n, blen - n, "%s", jvp->u.string.ptr);
break;
case json_integer:
- n += scnpr(b + n, blen - n, "%" PRIi64, jvp->u.integer);
+ scnpr(b + n, blen - n, "%" PRIi64, jvp->u.integer);
break;
case json_boolean:
- n += scnpr(b + n, blen - n, "%s",
- jvp->u.boolean ? "true" : "false");
+ scnpr(b + n, blen - n, "%s", jvp->u.boolean ? "true" : "false");
break;
case json_none:
default:
@@ -572,11 +600,11 @@ sgj_pr_twin_xx(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
}
}
if (as_json && jsp->pr_output)
- json_array_push(jsp->outputp, json_string_new(b));
+ json_array_push((json_value *)jsp->outputp, json_string_new(b));
else if (! as_json)
printf("%s\n", b);
if (jvp && (! eaten))
- json_builder_free(jvp);
+ json_builder_free((json_value *)jvp);
}
void
@@ -610,11 +638,3 @@ sgj_pr_twin_vb(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
jvp = json_boolean_new(value);
sgj_pr_twin_xx(jsp, jop, leadin_sp, name, sep, jvp);
}
-
-#if 0
-void
-sgj_pr_hr_line_vs(sgj_state * jsp, sgj_opaque_p jop, const char * hr_line,
- const char * name, const char * value)
-{
-}
-#endif
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 8e3b8c6f..3a098774 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -1631,7 +1631,7 @@ decode_dev_ids(const char * leadin, uint8_t * buff, int len, int do_hex,
printf(" [or device number: 0x%x, function number: "
"0x%x]\n", (0x1f & (ip[1] >> 3)), 0x7 & ip[1]);
} else
- printf(" >>>> unexpected protocol indentifier: %s\n"
+ printf(" >>>> unexpected protocol identifier: %s\n"
" with Protocol specific port "
"identifier\n",
sg_get_trans_proto_str(p_id, sizeof(b), b));
diff --git a/src/sg_logs.c b/src/sg_logs.c
index 051ea7fc..358b7222 100644
--- a/src/sg_logs.c
+++ b/src/sg_logs.c
@@ -426,7 +426,7 @@ static struct log_elem log_arr[] = {
{STATS_LPAGE, CACHE_STATS_SUBPG, 0, -1, MVP_STD, /* 0x19, 0x20 */
"Cache memory statistics", "cms", show_cache_stats_page},
{STATS_LPAGE, CMD_DUR_LIMITS_SUBPG, 0, -1, MVP_STD, /* 0x19, 0x21 */
- "Commmand duration limits statistics", "cdl",
+ "Command duration limits statistics", "cdl",
show_cmd_dur_limits_page /* spc6r01 */ },
{PCT_LPAGE, 0, 0, -1, MVP_STD, "Power condition transitions", "pct",
show_power_condition_transitions_page}, /* 0x1a, 0 */
@@ -3506,7 +3506,7 @@ show_sas_phy_event_info(int pes, unsigned int val, unsigned int thresh_val)
printf(" Received retry-class OPEN_REJECT count: %u\n", val);
break;
case 0x25:
- printf(" Received AIP (WATING ON PARTIAL) count: %u\n", val);
+ printf(" Received AIP (WAITING ON PARTIAL) count: %u\n", val);
break;
case 0x26:
printf(" Received AIP (WAITING ON CONNECTION) count: %u\n", val);
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index cf343a18..aba72afe 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.80 20220505"; /* spc6r06 */
+static const char * version_str = "0.81 20220506"; /* spc6r06 */
#define MY_NAME "sg_opcodes"
@@ -852,22 +852,22 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
}
if (jsp->pr_as_json) {
snprintf(b, blen, "0x%x", opcode);
- sgj_add_name_vs(jsp, jop, "operation_code", b);
+ sgj_add_val_s(jsp, jop, "operation_code", b);
if (sa_v) {
snprintf(b, blen, "0x%x", serv_act);
- sgj_add_name_vs(jsp, jop, "service_action", b);
+ sgj_add_val_s(jsp, jop, "service_action", b);
}
if (name_buff[0])
- sgj_add_name_vs(jsp, jop, "name", name_buff);
- sgj_add_name_vi(jsp, jop, "rwcdlp", (byt5 >> 6) & 0x1);
- sgj_add_name_vi(jsp, jop, "mlu", (byt5 >> 4) & 0x3);
- sgj_add_name_vi(jsp, jop, "cdlp", (byt5 >> 2) & 0x3);
- sgj_add_name_vi(jsp, jop, "ctdp", (byt5 >> 1) & 0x1);
- sgj_add_name_vi(jsp, jop, "servactv", byt5 & 0x1);
- sgj_add_name_vi(jsp, jop, "cdb_length",
- sg_get_unaligned_be16(bp + 6));
-
- sgj_add_array_element(jsp, jap, jop);
+ sgj_add_val_s(jsp, jop, "name", name_buff);
+ sgj_add_val_i(jsp, jop, "rwcdlp", (byt5 >> 6) & 0x1);
+ sgj_add_val_i(jsp, jop, "mlu", (byt5 >> 4) & 0x3);
+ sgj_add_val_i(jsp, jop, "cdlp", (byt5 >> 2) & 0x3);
+ sgj_add_val_i(jsp, jop, "ctdp", (byt5 >> 1) & 0x1);
+ sgj_add_val_i(jsp, jop, "servactv", byt5 & 0x1);
+ sgj_add_val_i(jsp, jop, "cdb_length",
+ sg_get_unaligned_be16(bp + 6));
+
+ sgj_add_val_o(jsp, jap, NULL /* implies an array add */, jop);
}
if (op->do_mask && ptvp) {
@@ -903,8 +903,8 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
l = strlen(b2p);
if ((l > 0) && (' ' == b2p[l - 1]))
b2p[l - 1] = '\0';
- sgj_add_name_vi(jsp, jo2p, "cdb_size", cdb_sz);
- sgj_add_name_vs(jsp, jo2p, "cdb_usage_data", b2p);
+ sgj_add_val_i(jsp, jo2p, "cdb_size", cdb_sz);
+ sgj_add_val_s(jsp, jo2p, "cdb_usage_data", b2p);
}
}
} else
@@ -942,9 +942,9 @@ decode_cmd_timeout_desc(uint8_t * dp, int max_b_len, char * b,
else
snprintf(b, max_b_len, "nominal timeout: %u secs, ", timeout);
if (jsp->pr_as_json) {
- sgj_add_name_vi(jsp, jsp->userp, "command_specific", dp[3]);
- sgj_add_name_vi(jsp, jsp->userp,
- "nominal_command_processing_timeout", timeout);
+ sgj_add_val_i(jsp, jsp->userp, "command_specific", dp[3]);
+ sgj_add_val_i(jsp, jsp->userp,
+ "nominal_command_processing_timeout", timeout);
}
len = strlen(b);
max_b_len -= len;
@@ -955,8 +955,8 @@ decode_cmd_timeout_desc(uint8_t * dp, int max_b_len, char * b,
else
snprintf(b, max_b_len, "recommended timeout: %u secs", timeout);
if (jsp->pr_as_json)
- sgj_add_name_vi(jsp, jsp->userp,
- "recommended_command_timeout", timeout);
+ sgj_add_val_i(jsp, jsp->userp,
+ "recommended_command_timeout", timeout);
return;
}
@@ -1072,25 +1072,25 @@ list_one(uint8_t * rsoc_buff, int cd_len, int rep_opts,
int l;
snprintf(b, blen, "0x%x", op->opcode);
- sgj_add_name_vs(jsp, jop, "operation_code", b);
+ sgj_add_val_s(jsp, jop, "operation_code", b);
if (rep_opts > 1) {
snprintf(b, blen, "0x%x", op->servact);
- sgj_add_name_vs(jsp, jop, "service_action", b);
+ sgj_add_val_s(jsp, jop, "service_action", b);
}
- sgj_add_name_vi(jsp, jop, "rwcdlp", rwcdlp);
- sgj_add_name_vi(jsp, jop, "ctdp", ctdp);
- sgj_add_name_vi(jsp, jop, "mlu", mlu);
- sgj_add_name_vi(jsp, jop, "cdlp", cdlp);
- sgj_add_name_vi(jsp, jop, "support", support);
- sgj_add_name_vs(jsp, jop, "support_str", cp);
- sgj_add_name_vi(jsp, jop, "cdb_size", cd_len);
+ sgj_add_val_i(jsp, jop, "rwcdlp", rwcdlp);
+ sgj_add_val_i(jsp, jop, "ctdp", ctdp);
+ sgj_add_val_i(jsp, jop, "mlu", mlu);
+ sgj_add_val_i(jsp, jop, "cdlp", cdlp);
+ sgj_add_val_i(jsp, jop, "support", support);
+ sgj_add_val_s(jsp, jop, "support_str", cp);
+ sgj_add_val_i(jsp, jop, "cdb_size", cd_len);
n = 0;
for (k = 0; k < cd_len; ++k)
n += sg_scnpr(b + n, blen - n, "%.2x ", rsoc_buff[k + 4]);
l = strlen(b);
if ((l > 0) && (' ' == b[l - 1]))
b[l - 1] = '\0';
- sgj_add_name_vs(jsp, jop, "cdb_usage_data", b);
+ sgj_add_val_s(jsp, jop, "cdb_usage_data", b);
}
if (ctdp) {
jsp->userp = sgj_new_named_object(jsp, jsp->basep,
@@ -1364,17 +1364,17 @@ start_response:
goto fini;
}
if (jsp->pr_as_json) {
- sgj_add_name_vb(jsp, jop, "ats", rsoc_buff[0] & 0x80);
- sgj_add_name_vb(jsp, jop, "atss", rsoc_buff[0] & 0x40);
- sgj_add_name_vb(jsp, jop, "cacas", rsoc_buff[0] & 0x20);
- sgj_add_name_vb(jsp, jop, "ctss", rsoc_buff[0] & 0x10);
- sgj_add_name_vb(jsp, jop, "lurs", rsoc_buff[0] & 0x8);
- sgj_add_name_vb(jsp, jop, "qts", rsoc_buff[0] & 0x4);
- sgj_add_name_vb(jsp, jop, "trs", rsoc_buff[0] & 0x2);
- sgj_add_name_vb(jsp, jop, "ws", rsoc_buff[0] & 0x1);
- sgj_add_name_vb(jsp, jop, "qaes", rsoc_buff[1] & 0x4);
- sgj_add_name_vb(jsp, jop, "qtss", rsoc_buff[1] & 0x2);
- sgj_add_name_vb(jsp, jop, "itnrs", rsoc_buff[1] & 0x1);
+ sgj_add_val_b(jsp, jop, "ats", rsoc_buff[0] & 0x80);
+ sgj_add_val_b(jsp, jop, "atss", rsoc_buff[0] & 0x40);
+ sgj_add_val_b(jsp, jop, "cacas", rsoc_buff[0] & 0x20);
+ sgj_add_val_b(jsp, jop, "ctss", rsoc_buff[0] & 0x10);
+ sgj_add_val_b(jsp, jop, "lurs", rsoc_buff[0] & 0x8);
+ sgj_add_val_b(jsp, jop, "qts", rsoc_buff[0] & 0x4);
+ sgj_add_val_b(jsp, jop, "trs", rsoc_buff[0] & 0x2);
+ sgj_add_val_b(jsp, jop, "ws", rsoc_buff[0] & 0x1);
+ sgj_add_val_b(jsp, jop, "qaes", rsoc_buff[1] & 0x4);
+ sgj_add_val_b(jsp, jop, "qtss", rsoc_buff[1] & 0x2);
+ sgj_add_val_b(jsp, jop, "itnrs", rsoc_buff[1] & 0x1);
if (! jsp->pr_output)
goto fini;
}
diff --git a/src/sg_read.c b/src/sg_read.c
index a4f7ceec..52304970 100644
--- a/src/sg_read.c
+++ b/src/sg_read.c
@@ -202,7 +202,7 @@ usage()
" fua 1-> set force unit access (FUA) in SCSI READs\n"
" if an sg, block or raw device, or a seekable file (not "
"stdin)\n"
- " mmap 1->perform mmaped IO on sg device, 0->indirect IO "
+ " mmap 1->perform mmap-ed IO on sg device, 0->indirect IO "
"(def)\n"
" no_dxfer 1->DMA to kernel buffers only, not user space, "
"0->normal(def)\n"
diff --git a/src/sg_read_buffer.c b/src/sg_read_buffer.c
index cbc5023b..232b94cd 100644
--- a/src/sg_read_buffer.c
+++ b/src/sg_read_buffer.c
@@ -63,7 +63,7 @@ static const char * version_str = "1.35 20220217"; /* spc6r06 */
#define MAX_DEF_INHEX_LEN 8192
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
#define DEF_PT_TIMEOUT 60 /* 60 seconds */
-#define DEF_RESPONSE_LEN 4 /* increased to 64 fo MODE_ERR_HISTORY */
+#define DEF_RESPONSE_LEN 4 /* increased to 64 for MODE_ERR_HISTORY */
static struct option long_options[] = {
diff --git a/src/sg_rep_zones.c b/src/sg_rep_zones.c
index faa89d29..0866cd8d 100644
--- a/src/sg_rep_zones.c
+++ b/src/sg_rep_zones.c
@@ -40,7 +40,7 @@
* Based on zbc2r12.pdf
*/
-static const char * version_str = "1.36 20220505";
+static const char * version_str = "1.38 20220511";
#define MY_NAME "sg_rep_zones"
@@ -134,6 +134,8 @@ static struct zt_num2abbrev_t zt_num2abbrev[] = {
static const char * zn_dnum_s = "zone descriptor number: ";
+static const char * meaning_s = "meaning";
+
static void
prn_zone_type_abbrevs(void)
@@ -393,10 +395,10 @@ prt_a_zn_desc(const uint8_t *bp, const struct opts_t * op,
zc = (bp[1] >> 4) & 0xf;
sg_get_zone_type_str(zt, sizeof(b), b);
sgj_pr_hr(jsp, " Zone type: %s\n", b);
- sgj_add_name_pair_istr(jsp, jop, "zone_type", zt, b);
+ sgj_add_name_pair_istr(jsp, jop, "zone_type", zt, meaning_s, b);
zone_condition_str(zc, b, sizeof(b), op->vb);
sgj_pr_hr(jsp, " Zone condition: %s\n", b);
- sgj_add_name_pair_istr(jsp, jop, "zone_condition", zc, b);
+ sgj_add_name_pair_istr(jsp, jop, "zone_condition", zc, meaning_s, b);
sgj_pr_twin_vi(jsp, jop, 3, "PUEP", SGJ_SEP_COLON_1_SPACE,
!!(bp[1] & 0x4));
sgj_pr_twin_vi(jsp, jop, 3, "NON_SEQ", SGJ_SEP_COLON_1_SPACE,
@@ -455,7 +457,8 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
"granularity";
sgj_pr_hr(jsp, " Same=%d: %s\n", same, same_desc_arr[same]);
- sgj_add_name_pair_istr(jsp, jop, "same", same, same_desc_arr[same]);
+ sgj_add_name_pair_istr(jsp, jop, "same", same, meaning_s,
+ same_desc_arr[same]);
sgj_pr_hr(jsp, " Maximum LBA: 0x%" PRIx64 "\n\n", mx_lba);
sgj_add_name_pair_ihex(jsp, jop, "maximum_lba", mx_lba);
sgj_pr_hr(jsp, " %s: 0x%" PRIx64 "\n\n", rzslbag_s, rzslbag);
@@ -480,7 +483,7 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
}
sgj_pr_hr(jsp, "From last descriptor in this response:\n");
sgj_pr_hr(jsp, " %s%d\n", zn_dnum_s, num_zd - 1);
- sgj_add_name_vi(jsp, jop, "zone_descriptor_index", num_zd - 1);
+ sgj_add_val_i(jsp, jop, "zone_descriptor_index", num_zd - 1);
ul = prt_a_zn_desc(bp, op, jsp, jop);
if (ul > mx_lba)
sgj_pr_hr(jsp, " >> This zone seems to be the last one\n");
@@ -513,13 +516,13 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
jo2p = sgj_new_unattached_object(jsp);
sgj_add_name_pair_ihex(jsp, jo2p, "write_pointer_lba",
(int64_t)wp);
- sgj_add_array_element(jsp, jap, jo2p);
+ sgj_add_val_o(jsp, jap, NULL /* name */, jo2p);
}
continue;
}
jo2p = sgj_new_unattached_object(jsp);
prt_a_zn_desc(bp, op, jsp, jo2p);
- sgj_add_array_element(jsp, jap, jo2p);
+ sgj_add_val_o(jsp, jap, NULL /* name */, jo2p);
}
if ((op->do_num == 0) && (! op->wp_only) && (! op->do_hex)) {
if ((64 + (REPORT_ZONES_DESC_LEN * (uint32_t)num_zd)) < decod_len)
@@ -615,7 +618,7 @@ decode_rep_realms(const uint8_t * rzBuff, int act_len,
jo3p = sgj_new_unattached_object(jsp);
sgj_pr_hr(jsp, " zone_domain=%u\n", j);
- sgj_add_name_vi(jsp, jo3p, "corresponding_zone_domain_id", j);
+ sgj_add_val_i(jsp, jo3p, "corresponding_zone_domain_id", j);
lba = sg_get_unaligned_be64(zp + 0);
sgj_pr_hr(jsp, " starting_lba=0x%" PRIx64 "\n", lba);
sgj_add_name_pair_ihex(jsp, jo3p, "realm_starting_lba",
@@ -624,9 +627,9 @@ decode_rep_realms(const uint8_t * rzBuff, int act_len,
sgj_pr_hr(jsp, " ending_lba=0x%" PRIx64 "\n", lba);
sgj_add_name_pair_ihex(jsp, jo3p, "realm_ending_lba",
(int64_t)lba);
- sgj_add_array_element(jsp, ja2p, jo3p);
+ sgj_add_val_o(jsp, ja2p, NULL /* name */, jo3p);
}
- sgj_add_array_element(jsp, jap, jo2p);
+ sgj_add_val_o(jsp, jap, NULL /* name */, jo2p);
}
return 0;
}
@@ -694,7 +697,7 @@ decode_rep_zdomains(const uint8_t * rzBuff, int act_len,
!!(0x2 & bp[42]));
sgj_pr_twin_vi(jsp, jo2p, 5, "SRB", SGJ_SEP_EQUAL_NO_SPACE,
!!(0x1 & bp[42]));
- sgj_add_array_element(jsp, jap, jo2p);
+ sgj_add_val_o(jsp, jap, NULL /* name */, jo2p);
}
return 0;
}
@@ -771,8 +774,8 @@ find_report_zones(int sg_fd, uint8_t * rzBuff, const char * cmd_name,
} else {
sgj_pr_hr(jsp, "Condition met at:\n");
sgj_pr_hr(jsp, " %s: %d\n", zn_dnum_s, zn_dnum);
- sgj_add_name_vb(jsp, jo2p, "met", true);
- sgj_add_name_vi(jsp, jo2p, "zone_descriptor_index", zn_dnum);
+ sgj_add_val_b(jsp, jo2p, "met", true);
+ sgj_add_val_i(jsp, jo2p, "zone_descriptor_index", zn_dnum);
prt_a_zn_desc(bp, op, jsp, jo2p);
}
} else {
@@ -780,8 +783,8 @@ find_report_zones(int sg_fd, uint8_t * rzBuff, const char * cmd_name,
memset(b, 0xff, 64);
hex2stdout((const uint8_t *)b, 64, -1);
} else {
- sgj_add_name_vb(jsp, jo2p, "met", false);
- sgj_add_name_vi(jsp, jo2p, "zone_descriptor_index", zn_dnum);
+ sgj_add_val_b(jsp, jo2p, "met", false);
+ sgj_add_val_i(jsp, jo2p, "zone_descriptor_index", zn_dnum);
if (num_rem < 1)
sgj_pr_hr(jsp, "Condition NOT met, checked %d zones; "
"next %s%u\n", op->do_num, zn_dnum_s, zn_dnum);
@@ -1337,7 +1340,7 @@ main(int argc, char * argv[])
else if (op->do_realms)
cmd_name = "Report realms";
if (as_json)
- sgj_add_name_vs(jsp, jop, "scsi_command_name", cmd_name);
+ sgj_add_val_s(jsp, jop, "scsi_command_name", cmd_name);
if ((op->serv_act != REPORT_ZONES_SA) && op->do_partial) {
pr2serr("Can only use --partial with REPORT ZONES\n");
return SG_LIB_SYNTAX_ERROR;
diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c
index 147898fe..41db4bba 100644
--- a/src/sg_sanitize.c
+++ b/src/sg_sanitize.c
@@ -138,7 +138,7 @@ usage()
"field\n"
" (def: clear 'desc' field)\n"
" --dry-run|-D to preparation but bypass SANITIZE "
- "commnd\n"
+ "command\n"
" --early|-e exit once sanitize started (IMMED set "
"in cdb)\n"
" user can monitor progress with REQUEST "
diff --git a/src/sg_scan_win32.c b/src/sg_scan_win32.c
index 06851497..d39212c7 100644
--- a/src/sg_scan_win32.c
+++ b/src/sg_scan_win32.c
@@ -103,7 +103,7 @@ usage()
"scan after\n"
" device scan; default: show no "
"adapters;\n"
- " used twice: show only adapaters\n"
+ " used twice: show only adapters\n"
" --verbose|-v increase verbosity\n"
" --version|-V print version string and exit\n\n"
"Scan for storage and related device names\n");
diff --git a/src/sg_stpg.c b/src/sg_stpg.c
index a12b5cac..ce21c9c1 100644
--- a/src/sg_stpg.c
+++ b/src/sg_stpg.c
@@ -284,7 +284,7 @@ encode_tpgs_states(uint8_t *buff, struct tgtgrp *tgtState, int numgrp)
}
/* Read numbers (up to 32 bits in size) from command line (comma separated
- * list). Assumed decimal unless prefixed by '0x', '0X' or contains traling
+ * list). Assumed decimal unless prefixed by '0x', '0X' or contains trailing
* 'h' or 'H' (which indicate hex). Returns 0 if ok, else error code. */
static int
build_port_arr(const char * inp, int * port_arr, int * port_arr_len,
diff --git a/src/sginfo.c b/src/sginfo.c
index 0225ab5f..0fb85904 100644
--- a/src/sginfo.c
+++ b/src/sginfo.c
@@ -3012,7 +3012,7 @@ spi4_report_xfer(struct mpage_info * mpi, const char * prefix)
mpi->subpage);
printf("--------------------------------------------\n");
}
- intfield(pagestart + 6, 1, "Mimimum transfer period factor");
+ intfield(pagestart + 6, 1, "Minimum transfer period factor");
intfield(pagestart + 8, 1, "Maximum REQ/ACK offset");
intfield(pagestart + 9, 1, "Maximum transfer width exponent");
bitfield(pagestart + 10, "Protocol option bits supported", 0xff, 0);
diff --git a/testing/sg_scat_gath.cpp b/testing/sg_scat_gath.cpp
index e9aa633d..56752718 100644
--- a/testing/sg_scat_gath.cpp
+++ b/testing/sg_scat_gath.cpp
@@ -347,7 +347,7 @@ err_out:
* is non-NULL). Assumed decimal (and may have suffix multipliers) when
* def_hex==false; if a number is prefixed by '0x', '0X' or contains trailing
* 'h' or 'H' that denotes a hex number. When def_hex==true all numbers are
- * assumed to be hex (ignored '0x' prefixes and 'h' suffixes) and multiplers
+ * assumed to be hex (ignored '0x' prefixes and 'h' suffixes) and multipliers
* are not permitted. Heap allocates an array just big enough to hold all
* elements if the file is countable. Pipes and stdin are not considered
* countable. In the non-countable case an array of MAX_FIXED_SGL_ELEMS
diff --git a/testing/sg_take_snap.c b/testing/sg_take_snap.c
index 852d3be6..c714a409 100644
--- a/testing/sg_take_snap.c
+++ b/testing/sg_take_snap.c
@@ -133,7 +133,7 @@ int main(int argc, char * argv[])
dev_arr[next_vacant_dev_idx] = argv[optind];
++next_vacant_dev_idx;
} else if (next_vacant_dev_idx == SG_TAKE_MAX_DEVS) {
- pr2serr("Maximim of %d DEVICEs on command line\n",
+ pr2serr("Maximum of %d DEVICEs on command line\n",
next_vacant_dev_idx);
usage();
return SG_LIB_SYNTAX_ERROR;
diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp
index 2c1f2433..90577f88 100644
--- a/testing/sgh_dd.cpp
+++ b/testing/sgh_dd.cpp
@@ -674,7 +674,7 @@ page4:
"example,\nit has been observed that both the read- and write- "
"sides of a request\nshare show they are in 'active' state "
"which should not be possible.\nIt occurs because the read-"
- "sie probably jumped out of active state and\nthe write-side "
+ "side probably jumped out of active state and\nthe write-side "
"request entered it while some other nodes were being "
"printed.\n\n");
pr2serr("Busy state:\n"