Skip to content

Commit

Permalink
sync to upstream sdparm svn rev 379
Browse files Browse the repository at this point in the history
See ChangeLog file for pre-release sdparm-1.13 [20230508]
  • Loading branch information
doug-gilbert committed May 10, 2023
1 parent 6dc9cfb commit 6b3dd6c
Show file tree
Hide file tree
Showing 21 changed files with 370 additions and 159 deletions.
11 changes: 5 additions & 6 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ The version number is hardcoded into sdparm.c (in a C string);
the rpm spec file: sdparm.spec ; the debian/changelog file;
and the configure.ac file (in the AC_INIT item).

ChangeLog for pre-release sdparm-1.13 [20230408] [svn: r376]
ChangeLog for pre-release sdparm-1.13 [20230508] [svn: r379]
- add --json[=JO] and --js-file=JFN options
- apart from with a real device, json output can be
requested with --enumerate or --inhex=FN
- change json short option: -j[JO] to -j[=JO]
- control extension mpage: add pwromact, hrdrmact, ssumact
and fmtmact fields
- format presets vpd: expand for schema type 4
Expand All @@ -16,21 +17,19 @@ ChangeLog for pre-release sdparm-1.13 [20230408] [svn: r376]
- zoned block device characteristics vpd: add Zone
alignment method and Zone starting LBA granularity
fields [zbc2r11,zbc2r12]
- add CAPPID bit in device-specific paramter field
- add CAPPID bit in device-specific parameter field
- add --inner-hex option to take overloading from --hex
- use with -j for more searchable mode page names
- device identification VPD page: change IEEE OUI to AOI
- act on LAST bit in App tag mpage descriptors to stop
output of further descriptors, override this
truncation with --flexible option
- experimental: add NetBSD support
- point svn:externals to sg3_utils revision 1021
- autoconf: upgrade version 2.70 to 2.71; automake upgrade
to version 1.16.5
- point svn:externals to sg3_utils revision 1029
- remove the imtermediate files generated by ./autogen.sh
- this reduces size of svn and git repositories but still
plan to have these intermediate files in release tarballs
- add boostrap script that just calls ./autogen.sh
- add bootstrap script that just calls ./autogen.sh

ChangeLog for released sdparm-1.12 [20210421] [svn: r347]
- add Command duration limits T2A and T2B mpages
Expand Down
5 changes: 3 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ command set. Apart form SCSI disks, examples of devices that use SCSI command
sets are ATAPI CD/DVD drives, SCSI and ATAPI tape drives and SCSI enclosures.

This utility was originally written for Linux. It has been ported to FreeBSD,
Solaris, Tru64, and Windows.
NetBSD, Solaris, Tru64, and Windows. There are some tweaks to the Linux port
to support Android.

Relationship to sg3_utils
-------------------------
Expand Down Expand Up @@ -271,4 +272,4 @@ SCSI5:0,112,0 claimed=0 pdt=10h LSI PSEUDO DEVICE 2.34


Douglas Gilbert
21th February 2023
2th April 2023
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ AC_INIT(sdparm, 1.13, [email protected])

AM_INIT_AUTOMAKE([foreign])
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)

# AM_CONFIG_HEADER(config.h)
AC_CONFIG_HEADERS([config.h])

AC_PROG_CC
# AC_PROG_CXX
Expand Down
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sdparm (1.13-0.1) unstable; urgency=low

* see ChangeLog

-- Douglas Gilbert <[email protected]> Sat, 08 Apr 2023 13:00:00 -0400
-- Douglas Gilbert <[email protected]> Mon, 08 May 2023 19:00:00 -0400

sdparm (1.12-0.1) unstable; urgency=low

Expand Down
13 changes: 7 additions & 6 deletions doc/sdparm.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH SDPARM "8" "April 2023" "sdparm\-1.13" SDPARM
.TH SDPARM "8" "May 2023" "sdparm\-1.13" SDPARM
.SH NAME
sdparm \- access SCSI modes pages; read VPD pages; send simple SCSI commands
.SH SYNOPSIS
Expand Down Expand Up @@ -324,11 +324,12 @@ output.
\fI\-\-page=sinq\fR or \fI\-\-page=\-1\fR given with this option will
output the standard INQUIRY response instead of a VPD page.
.TP
\fB\-j[JO]\fR, \fB\-\-json[=JO]\fR
See the accompanying sdparm_json(8) manpage. Note that the \fIJO\fR argument
is itself optional. The optional argument to the short form is shown here
to stress that in this case there is no space between the "j" and its
optional argument.
\fB\-j\fR[=\fIJO\fR], \fB\-\-json\fR[=\fIJO\fR]
output is in JSON format instead of plain text form. Note that arguments
to the short and long form are themselves optional and if present start
with "=" and no whitespace is permitted around that "=".
.br
See the sdparm_json(8) manpage or use '?' for \fIJO\fR to get a summary.
.TP
\fB\-J\fR, \fB\-\-js\-file\fR=\fIJFN\fR
See the accompanying sdparm_json(8) manpage.
Expand Down
18 changes: 11 additions & 7 deletions doc/sdparm_json.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH SDPARM_JSON "8" "April 2023" "sdparm\-1.13" SDPARM
.TH SDPARM_JSON "8" "May 2023" "sdparm\-1.13" SDPARM
.SH NAME
sdparm_json \- JSON output options for the sdparm utility
.SH SYNOPSIS
Expand Down Expand Up @@ -67,15 +67,19 @@ stderr: 'error parsing SG3_UTILS_JSON_OPTS environment variable, ignore'.
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
\fIJO\fR is a string of 0 or more characters whose order is not significant
\fB\-j[=JO]\fR, \fB\-\-json\fR\fI[=JO]\fR
\fIJO\fR is a string of zero or more characters whose order is not significant
apart from the negation characters ('\-' is preferred). The negation character
must appear immediately before the (boolean) feature it is toggling.
.br
Since the argument to the short form option is itself optional, there can be
no space between the short form option and \fIJO\fR, if it is given. To make
this read a little better on the command line, '=' may be first character of
\fIJO\fR, so for example, this is valid '\-j=av'.
In the short form the option letter may be other than \fI\-j\fR if that letter
has already been used (\fI\-J\fR is preferred next). For example the sg_ses
utility uses \fI\-j\fR for its 'join' operation. Also since the argument to
the short form option is itself optional, there can be no spaces between the
short form option, the "=", and \fIJO\fR, if it is given. Some short form
examples: '-jl' requests JSON output (with no argument option) and whatever
the '-l' short option means in the invoked utility; '-j=h' requests JSON
output with some integers additional rendered as JSON strings of hex.
.TP
\fB\-J\fR, \fB\-\-js\-file\fR=\fIJFN\fR
output is in JSON format and it is sent to a file named \fIJFN\fR. If that
Expand Down
39 changes: 24 additions & 15 deletions include/sg_pr2serr.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ bool sgj_is_snake_name(const char * in_name);
* sgj_ - prefix of all the functions related to (non-)JSON output
* hr - human readable form (same meaning as "plain text")
* js - JSON only output
* haj - human readable and JSON output, hr goes in 'output' array
* haj - human readable and JSON output, if JSON output is selected
* then the normal output goes in 'plain_text_output' array
* pr - has printf() like variadic arguments
* _r - suffix indicating the return value should/must be used
* nv - adds a name-value JSON field (or several)
Expand Down Expand Up @@ -157,10 +158,11 @@ bool sgj_init_state(sgj_state * jsp, const char * j_optarg);
* 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_out_hr field is
* true a named array called "output" is added to the "utility_invoked" object
* (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. */
* true a named array called "plain_text_output" is added to the
* "utility_invoked" object (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_r(const char * util_name, const char * ver_str,
int argc, char *argv[], sgj_state * jsp);

Expand Down Expand Up @@ -281,16 +283,15 @@ void sgj_js_nv_ihexstr(sgj_state * jsp, sgj_opaque_p jop,
const char * sn_name, int64_t val_i,
const char * str_name, const char * val_s);

/* 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_name_ex is true then that
* value is two sub-objects, one named 'i' with a 'val_i' as a JSON integer,
* the other one named "abbreviated_name_expansion" with value nex_s rendered
* as a JSON string. If jsp->pr_hex and 'hex_as_well' are true, then a
* sub-object named 'hex' with a value rendered as a hex string equal to
* val_i. If jsp->pr_name_ex is false and either jsp->pr_hex or hex_as_well are
* false then there are no sub-objects and the 'val_i' is rendered as a JSON
* integer. */
/* This function only produces JSON output if jsp && 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_name_ex is true then that value has two sub-objects,
* one named 'i' with a 'val_i' as a JSON integer, the other one named
* "name_extra" with value nex_s rendered as a JSON string. If jsp->pr_hex
* and 'hex_as_well' are true, then a sub-object named 'hex' with a value
* rendered as a hex string equal to val_i. If jsp->pr_name_ex is false and
* either jsp->pr_hex or hex_as_well are false then there are no sub-objects
* and the 'val_i' is rendered as a JSON integer. */
void sgj_js_nv_ihex_nex(sgj_state * jsp, sgj_opaque_p jop,
const char * sn_name, int64_t val_i, bool hex_as_well,
const char * nex_s);
Expand All @@ -300,6 +301,14 @@ void sgj_js_nv_ihexstr_nex(sgj_state * jsp, sgj_opaque_p jop,
bool hex_as_well, const char * str_name,
const char * val_s, const char * nex_s);

/* String value version of above *_nex() functions. If both 'val_s' and
* 'nex_s' are non-NULL forms sub-object named 'sn_name' with the names
* "s" and "name_extra" and values of the last two arguments. If one of
* the last two arguments is NULL similar to sgj_js_nv_s() using the non-NULL
* argument as the value. */
void sgj_js_nv_s_nex(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
const char * val_s, const char * nex_s);

/* Add named field whose value is a (large) JSON string made up of num_bytes
* ASCII hexadecimal bytes (each two hex digits separated by a space) starting
* at byte_arr. The heap is used for intermediate storage so num_bytes can
Expand Down
5 changes: 3 additions & 2 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ endif
if DEBUG
# This is active if --enable-debug given to ./configure
# removed -Wduplicated-branches because needs gcc-8
DBG_CFLAGS = -Wextra -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference -Wshadow -Wjump-misses-init
DBG_CFLAGS = -Wextra -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference -Wshadow -Wjump-misses-init -Wunused -Wsizeof-array-argument
DBG_CPPFLAGS = -DDEBUG
else
DBG_CFLAGS =
Expand Down Expand Up @@ -97,7 +97,8 @@ AM_CFLAGS = -Wall -W $(DBG_CFLAGS)
# AM_CFLAGS = -Wall -W -pedantic -std=c++14
# AM_CFLAGS = -Wall -W -pedantic -std=c++1z
# AM_CFLAGS = -Wall -W -pedantic -std=c++20 --analyze
# AM_CFLAGS = -Wall -W -pedantic -std=c++23
# AM_CFLAGS = -Wall -W -pedantic -std=c++20 $(DBG_CFLAGS)
# AM_CFLAGS = -Wall -W -pedantic -std=c++23 $(DBG_CFLAGS)

lib_LTLIBRARIES = libsgutils2.la

Expand Down
10 changes: 5 additions & 5 deletions lib/sg_cmds_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ sg_cmds_process_helper(const char * leadin, int req_din_x, int act_din_x,
}
}
}
if (free_b)
free(free_b);
if (free_b)
free(free_b);
}
if (o_sense_cat)
*o_sense_cat = scat;
Expand Down Expand Up @@ -240,10 +240,10 @@ sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin,
if (duration > 0)
pr2ws(" duration=%" PRIu64 " ns\n", duration);
else {
int d = get_scsi_pt_duration_ms(ptvp);
int dur = get_scsi_pt_duration_ms(ptvp);

if (d != -1)
pr2ws(" duration=%u ms\n", (uint32_t)d);
if (dur != -1)
pr2ws(" duration=%u ms\n", (uint32_t)dur);
}
}
get_pt_req_lengths(ptvp, &req_din_x, &req_dout_x);
Expand Down
18 changes: 11 additions & 7 deletions lib/sg_json_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ typedef struct json_builder_value

} json_builder_value;

/* Use this to silence clang --analyze warning about 'unix.MallocSizeof' */
static const int jbv_sz = sizeof (json_builder_value);


static int builderize (json_value * value)
{
if (((json_builder_value *) value)->is_builder_value)
Expand Down Expand Up @@ -134,7 +138,7 @@ static int get_serialize_flags (json_serialize_opts opts)
json_value * json_array_new (size_t length)
{
/* 'value' will be pointer to an instance of the base class json_value */
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand Down Expand Up @@ -186,7 +190,7 @@ json_value * json_array_push (json_value * array, json_value * value)

json_value * json_object_new (size_t length)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand Down Expand Up @@ -304,7 +308,7 @@ json_value * json_string_new_length (unsigned int length, const json_char * buf)

json_value * json_string_new_nocopy (unsigned int length, json_char * buf)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand All @@ -320,7 +324,7 @@ json_value * json_string_new_nocopy (unsigned int length, json_char * buf)

json_value * json_integer_new (json_int_t integer)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand All @@ -335,7 +339,7 @@ json_value * json_integer_new (json_int_t integer)

json_value * json_double_new (double dbl)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand All @@ -350,7 +354,7 @@ json_value * json_double_new (double dbl)

json_value * json_boolean_new (int b)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand All @@ -365,7 +369,7 @@ json_value * json_boolean_new (int b)

json_value * json_null_new (void)
{
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
json_value * value = (json_value *) calloc (1, jbv_sz);

if (!value)
return NULL;
Expand Down
37 changes: 31 additions & 6 deletions lib/sg_pr2serr.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ sgj_parse_opts(sgj_state * jsp, const char * j_optarg)
int k, c;

for (k = 0; j_optarg[k]; ++k) { /* step over leading whitespace */
if (! isspace(j_optarg[k]))
if (! isspace((uint8_t)j_optarg[k]))
break;
}
for ( ; j_optarg[k]; ++k) {
c = j_optarg[k];
negate = false;
switch (c) {
case '=':
if (0 == k)
if (0 == k) /* should remove this, allows '-j==h' */
break; /* allow and ignore leading '=' */
bad_arg = true;
if (0 == jsp->first_bad_char)
Expand Down Expand Up @@ -214,7 +214,7 @@ sg_json_usage(int char_if_not_j, char * b, int blen)
goto fini;
n += sg_scnpr(b + n, blen - n, "JSON option usage:\n");
n += sg_scnpr(b + n, blen - n,
" --json[-JO] | -%c[JO]\n\n", short_opt);
" --json[=JO] | -%c[=JO]\n\n", short_opt);
n += sg_scnpr(b + n, blen - n, " where JO is a string of one or more "
"of:\n");
n += sg_scnpr(b + n, blen - n,
Expand Down Expand Up @@ -248,9 +248,6 @@ sg_json_usage(int char_if_not_j, char * b, int blen)
"'meaning')\n");
n += sg_scnpr(b + n, blen - n,
" v make JSON output more verbose\n");
n += sg_scnpr(b + n, blen - n,
" = ignored if first character, else it's an "
"error\n");
n += sg_scnpr(b + n, blen - n,
" - | ~ | ! toggle next letter setting\n");

Expand Down Expand Up @@ -865,6 +862,34 @@ sgj_js_nv_ihex_nex(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
}
}

void
sgj_js_nv_s_nex(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
const char * val_s, const char * nex_s)
{
bool as_nex;

if ((NULL == jsp) || (! jsp->pr_as_json))
return;
as_nex = jsp->pr_name_ex && nex_s;
if ((NULL == val_s) && (! as_nex))
/* corner case: assume jop is an array */
json_array_push((json_value *)(jop ? jop : jsp->basep),
json_string_new(sn_name));
else if (NULL == val_s)
sgj_js_nv_s(jsp, jop, sn_name, nex_s);
else if (! as_nex)
sgj_js_nv_s(jsp, jop, sn_name, val_s);
else {
sgj_opaque_p jo2p =
sgj_named_subobject_r(jsp, jop, sn_name);

if (NULL == jo2p)
return;
sgj_js_nv_s(jsp, jo2p, "s", val_s);
sgj_js_nv_s(jsp, jo2p, sc_nex_s, nex_s);
}
}

#ifndef SG_PRSE_SENSE_DECODE
static void
h2str(const uint8_t * byte_arr, int num_bytes, char * bp, int blen)
Expand Down
Loading

0 comments on commit 6b3dd6c

Please sign in to comment.