Skip to content

Commit

Permalink
sync to upstream sdparm svn rev 381
Browse files Browse the repository at this point in the history
See ChangeLog file for pre-release sdparm-1.13 [20230517]
  • Loading branch information
doug-gilbert committed May 18, 2023
1 parent 13c30b0 commit 6e2c831
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 60 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 [20230513] [svn: r380]
ChangeLog for pre-release sdparm-1.13 [20230517] [svn: r381]
- add --json[=JO] and --js-file=JFN options
- apart from with a real device, json output can be
requested with --enumerate or --inhex=FN
Expand All @@ -25,7 +25,7 @@ ChangeLog for pre-release sdparm-1.13 [20230513] [svn: r380]
output of further descriptors, override this
truncation with --flexible option
- experimental: add NetBSD support
- point svn:externals to sg3_utils revision 1032
- point svn:externals to sg3_utils revision 1035
- 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
Expand Down
2 changes: 1 addition & 1 deletion include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ scsiinclude_HEADERS = \
sg_cmds_extra.h \
sg_cmds_mmc.h \
sg_json.h \
sg_json_sense.h \
sg_json_sg_lib.h \
sg_pr2serr.h \
sg_unaligned.h \
sg_pt.h \
Expand Down
4 changes: 2 additions & 2 deletions include/sg_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ void sgj_hr_str_out(sgj_state * jsp, const char * sp, int slen);
* 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_js2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status,
FILE * fp);
void sgj_js2file_estr(sgj_state * jsp, sgj_opaque_p jop, int exit_status,
const char * estr, FILE * fp);

/* This function is only needed if the pointer returned from either
* sgj_new_unattached_object_r() or sgj_new_unattached_array_r() has not
Expand Down
11 changes: 11 additions & 0 deletions include/sg_json_sense.h → include/sg_json_sg_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ bool sgj_js_sense(sgj_state * jsp, sgj_opaque_p jop, const uint8_t * sbp,
bool sgj_js_designation_descriptor(sgj_state * jsp, sgj_opaque_p jop,
const uint8_t * ddp, int dd_len);

/* The in-core JSON tree is printed to 'fp' (typically stdout) by this call.
* If jsp is NULL, jsp->pr_as_json is false or jsp->basep is NULL then this
* function does nothing. If jsp->exit_status 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'.
* Uses exit_status to call sg_lib::sg_exit2str() and then calls
* sg_json::xxxxxx */
void sgj_js2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status,
FILE * fp);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion include/sg_pr2serr.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ extern "C" {
* long-winded fprintf(stderr, ....). The second form (i.e. pr2ws() ) is for
* internal library use and may place its output somewhere other than stderr;
* it depends on the external variable sg_warnings_strm which can be set
* with sg_set_warnings_strm(). By default it uses stderr. */
* with sg_set_warnings_strm(). By default it uses stderr.
* Note that this header and its implementation do not depend on sg_lib.[hc]
* or any other sg3_utils components. */

#if __USE_MINGW_ANSI_STDIO -0 == 1
#define __printf(a, b) __attribute__((__format__(gnu_printf, a, b)))
Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
libsgutils2_la_SOURCES = \
sg_lib.c \
sg_json.c \
sg_json_sense.c \
sg_json_sg_lib.c \
sg_pr2serr.c \
sg_lib_data.c \
sg_lib_names.c \
Expand Down
44 changes: 16 additions & 28 deletions lib/sg_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "sg_pr2serr.h"
#include "sg_json.h"
/* Note: does not depend on sg_lib.h or its implementation */

#include "sg_json_builder.h"

Expand Down Expand Up @@ -329,33 +330,32 @@ sgj_start_r(const char * util_name, const char * ver_str, int argc,
}

void
sgj_js2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status, FILE * fp)
sgj_js2file_estr(sgj_state * jsp, sgj_opaque_p jop, int exit_status,
const char * estr, FILE * fp)
{
size_t len;
const char * ccp;
char * b;
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__);
fprintf(fp, "%s: json NULL pointers ??\n", __func__);
return;
}
if ((NULL == jop) && jsp->pr_exit_status) {
char d[80];

#if 0
if (sg_exit2str(exit_status, jsp->verbose, sizeof(d), d)) {
if (0 == strlen(d))
if (estr)
ccp = estr;
else {
if (0 == exit_status)
strncpy(d, "no errors", sizeof(d) - 1);
} else
strncpy(d, "not available", sizeof(d) - 1);
#else
if (0 == exit_status)
strncpy(d, "no errors", sizeof(d) - 1);
else
snprintf(d, sizeof(d), "exit_status=%d", exit_status);
#endif
sgj_js_nv_istr(jsp, jop, "exit_status", exit_status, NULL, d);
else
snprintf(d, sizeof(d), "exit_status=%d", exit_status);
ccp = d;
}
sgj_js_nv_istr(jsp, jop, "exit_status", exit_status, NULL, ccp);
}
memcpy(&out_settings, &def_out_settings, sizeof(out_settings));
if (jsp->pr_indent_size != def_out_settings.indent_size)
Expand Down Expand Up @@ -608,7 +608,7 @@ sgj_js_nv_s_len(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
return NULL;
}

#if 1
/* Local copy of sg_lib:sg_has_control_char() */
static bool
has_control_char(const uint8_t * up, int len)
{
Expand All @@ -622,21 +622,15 @@ has_control_char(const uint8_t * up, int len)
}
return false;
}
#endif

sgj_opaque_p
sgj_js_nv_s_len_chk(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
const uint8_t * value, int vlen)
{
sgj_opaque_p res = NULL;

#if 0
if (value && (vlen > 0) &&
sg_has_control_char(value, vlen))
#else
if (value && (vlen > 0) &&
has_control_char(value, vlen))
#endif
{
const int n = vlen * 4 + 4;
char * p = (char *)malloc(n);
Expand Down Expand Up @@ -825,7 +819,7 @@ sgj_js_nv_s_nex(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
}
}

#if 1
/* Simplified version of sg_lib::hex2str() */
static void
h2str(const uint8_t * byte_arr, int num_bytes, char * bp, int blen)
{
Expand All @@ -845,7 +839,6 @@ h2str(const uint8_t * byte_arr, int num_bytes, char * bp, int blen)
if ((j > 0) && (' ' == bp[j - 1]))
bp[j - 1] = '\0'; /* chop off trailing space */
}
#endif

/* Add hex byte strings irrespective of jsp->pr_hex setting. */
void
Expand All @@ -859,11 +852,7 @@ sgj_js_nv_hex_bytes(sgj_state * jsp, sgj_opaque_p jop, const char * sn_name,
return;
bp = (char *)calloc(blen + 4, 1);
if (bp) {
#if 0
hex2str(byte_arr, num_bytes, NULL, 2, blen, bp);
#else
h2str(byte_arr, num_bytes, bp, blen);
#endif
sgj_js_nv_s(jsp, jop, sn_name, bp);
free(bp);
}
Expand Down Expand Up @@ -1402,4 +1391,3 @@ sgj_conv2json_string(const uint8_t * cup, int ulen, char * op, int olen_max)
}
return j;
}

3 changes: 2 additions & 1 deletion lib/sg_json_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
* This header file is in this 'lib' directory so its interface is _not_
* published with sg3_utils other header files found in the 'include'
* directory. Currently only this header's implementation (i.e.
* sg_json_builder.c) and sg_pr2serr.c are the only users of this header. */
* sg_json_builder.c), sg_json.c and sg_json_sglib.c are the only users of
* this header. */

/*
* Used to require json.h from json-parser but what was needed as been
Expand Down
16 changes: 15 additions & 1 deletion lib/sg_json_sense.c → lib/sg_json_sg_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <string.h>
#include <ctype.h>

#include "sg_json_sense.h"
#include "sg_json_sg_lib.h"
#include "sg_pr2serr.h"

#include "sg_lib.h"
Expand Down Expand Up @@ -828,3 +828,17 @@ sgj_js_sense(sgj_state * jsp, sgj_opaque_p jop, const uint8_t * sbp,
sgj_js_nv_s(jsp, jop, "sense_decode_error", ebp);
return ret;
}

void
sgj_js2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status, FILE * fp)
{
const char * estr = NULL;
char d[128];
static const int dlen = sizeof(d);

if (sg_exit2str(exit_status, jsp->verbose, dlen, d)) {
if (strlen(d) > 0)
estr = d;
}
sgj_js2file_estr(jsp, jop, exit_status, estr, fp);
}
24 changes: 12 additions & 12 deletions lib/sg_pt_linux_nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* MA 02110-1301, USA.
*/

/* sg_pt_linux_nvme version 1.18 20210601 */
/* sg_pt_linux_nvme version 1.19 20230514 */

/* This file contains a small "SPC-only" SNTL to support the SES pass-through
* of SEND DIAGNOSTIC and RECEIVE DIAGNOSTIC RESULTS through NVME-MI
Expand Down Expand Up @@ -300,9 +300,9 @@ mk_sense_invalid_fld(struct sg_pt_linux_scsi * ptp, bool in_cdb, int in_byte,
* absence of a Unix error. If time_secs is negative it is treated as
* a timeout in milliseconds (of abs(time_secs) ). */
static int
sg_nvme_admon_cmd_f(struct sg_pt_linux_scsi * ptp,
sg_nvme_admin_cmd_f(struct sg_pt_linux_scsi * ptp,
struct sg_nvme_passthru_cmd *cmdp, void * dp,
bool is_read, int time_secs, int vb)
bool is_read, int time_secs, int vb)
{
const uint32_t cmd_len = sizeof(struct sg_nvme_passthru_cmd);
int res;
Expand Down Expand Up @@ -460,7 +460,7 @@ sntl_do_identify(struct sg_pt_linux_scsi * ptp, int cns, int nsid,
cmd.cdw10 = cns;
cmd.addr = (uint64_t)(sg_uintptr_t)up;
cmd.data_len = u_len;
return sg_nvme_admon_cmd_f(ptp, &cmd, up, true, time_secs, vb);
return sg_nvme_admin_cmd_f(ptp, &cmd, up, true, time_secs, vb);
}

/* Currently only caches associated identify controller response (4096 bytes).
Expand Down Expand Up @@ -506,7 +506,7 @@ sntl_get_features(struct sg_pt_linux_scsi * ptp, int feature_id, int select,
if (din_addr)
cmdp->addr = din_addr;
cmdp->timeout_ms = (time_secs < 0) ? 0 : (1000 * time_secs);
res = sg_nvme_admon_cmd_f(ptp, cmdp, NULL, false, time_secs, vb);
res = sg_nvme_admin_cmd_f(ptp, cmdp, NULL, false, time_secs, vb);
if (res)
return res;
ptp->os_err = 0;
Expand Down Expand Up @@ -899,7 +899,7 @@ sntl_mode_ss(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp,
cmdp->cdw10 |= (1U << 31);
cmdp->cdw11 = (uint32_t)ptp->dev_stat.wce;
cmdp->timeout_ms = (time_secs < 0) ? 0 : (1000 * time_secs);
res = sg_nvme_admon_cmd_f(ptp, cmdp, NULL, false, time_secs, vb);
res = sg_nvme_admin_cmd_f(ptp, cmdp, NULL, false, time_secs, vb);
if (0 != res) {
if (SG_LIB_NVME_STATUS == res) {
mk_sense_from_nvme_status(ptp, vb);
Expand Down Expand Up @@ -983,7 +983,7 @@ sntl_senddiag(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp,
return 0;
}
sg_put_unaligned_le32(nvme_dst, cmd_up + SG_NVME_PT_CDW10);
res = sg_nvme_admon_cmd_f(ptp, &cmd, NULL, false, time_secs, vb);
res = sg_nvme_admin_cmd_f(ptp, &cmd, NULL, false, time_secs, vb);
if (0 != res) {
if (SG_LIB_NVME_STATUS == res) {
mk_sense_from_nvme_status(ptp, vb);
Expand Down Expand Up @@ -1041,7 +1041,7 @@ sntl_senddiag(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp,
cmd.cdw10 = 0x0804; /* NVMe Message Header */
cmd.cdw11 = 0x9; /* nvme_mi_ses_send; (0x8 -> mi_ses_recv) */
cmd.cdw13 = n;
res = sg_nvme_admon_cmd_f(ptp, &cmd, dop, false, time_secs, vb);
res = sg_nvme_admin_cmd_f(ptp, &cmd, dop, false, time_secs, vb);
if (0 != res) {
if (SG_LIB_NVME_STATUS == res) {
mk_sense_from_nvme_status(ptp, vb);
Expand Down Expand Up @@ -1097,7 +1097,7 @@ sntl_recvdiag(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp,
cmd.cdw11 = 0x8; /* nvme_mi_ses_receive */
cmd.cdw12 = dpg_cd;
cmd.cdw13 = n;
res = sg_nvme_admon_cmd_f(ptp, &cmd, dip, true, time_secs, vb);
res = sg_nvme_admin_cmd_f(ptp, &cmd, dip, true, time_secs, vb);
if (0 != res) {
if (SG_LIB_NVME_STATUS == res) {
mk_sense_from_nvme_status(ptp, vb);
Expand Down Expand Up @@ -1839,15 +1839,15 @@ sg_do_nvme_pt(struct sg_pt_base * vp, int fd, int time_secs, int vb)
cmd.addr = (uint64_t)(sg_uintptr_t)ptp->io_hdr.dout_xferp;
is_read = false;
}
return sg_nvme_admon_cmd_f(ptp, &cmd, dp, is_read, time_secs, vb);
return sg_nvme_admin_cmd_f(ptp, &cmd, dp, is_read, time_secs, vb);
}

#else /* (HAVE_NVME && (! IGNORE_NVME)) [around line 140] */

int
sg_do_nvme_pt(struct sg_pt_base * vp, int fd, int time_secs, int vb)
{
static const int inapprop_errno = ENOTTY; /* inappropriate ioctl */
static const int inapprop_errno = ENOTTY; /* inappropriate ioctl */

if (vb) {
pr2ws("%s: not supported, ", __func__);
Expand All @@ -1867,7 +1867,7 @@ sg_do_nvme_pt(struct sg_pt_base * vp, int fd, int time_secs, int vb)
if (vp) {
struct sg_pt_linux_scsi * ptp = &vp->impl;

ptp->os_err = inapprop_errno;
ptp->os_err = inapprop_errno;
}
if (fd) { ; } /* suppress warning */
if (time_secs) { ; } /* suppress warning */
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ sglib_SOURCES = ../lib/sg_lib.c \
../include/sg_pr2serr.h \
../lib/sg_json.c \
../include/sg_json.h \
../lib/sg_json_sense.c \
../include/sg_json_sense.h \
../lib/sg_json_sg_lib.c \
../include/sg_json_sg_lib.h \
../lib/sg_json_builder.c \
../lib/sg_json_builder.h \
../include/sg_pt.h \
Expand Down
2 changes: 1 addition & 1 deletion src/sdparm.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int map_if_lk24(int sg_fd, const char * device_name, bool rw,
#include "sg_pr2serr.h"
#include "sdparm.h"

static const char * version_str = "1.17 20230513 [svn: r380]";
static const char * version_str = "1.17 20230517 [svn: r381]";

static const char * my_name = "sdparm: ";

Expand Down
2 changes: 1 addition & 1 deletion src/sdparm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdbool.h>
#include <stdint.h>

#include "sg_json.h"
#include "sg_json_sg_lib.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Loading

0 comments on commit 6e2c831

Please sign in to comment.