diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2022-05-02 04:45:28 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2022-05-02 04:45:28 +0000 |
commit | d7f5140b8b84eb9e27509a1c0fb6872a782b1fe8 (patch) | |
tree | de2e3799b32aa5588ba0183a53ecd18971bd9a10 /src | |
parent | 891844a52a28d9c5be86bf055e02180cb2b63275 (diff) | |
download | sg3_utils-d7f5140b8b84eb9e27509a1c0fb6872a782b1fe8.tar.gz |
sg_rep_zones: add experimental --json[=JO] option and generation
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@950 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r-- | src/sg_opcodes.c | 85 | ||||
-rw-r--r-- | src/sg_raw.c | 4 | ||||
-rw-r--r-- | src/sg_rbuf.c | 9 | ||||
-rw-r--r-- | src/sg_rep_zones.c | 179 | ||||
-rw-r--r-- | src/sg_sat_identify.c | 13 | ||||
-rw-r--r-- | src/sg_sat_phy_event.c | 8 | ||||
-rw-r--r-- | src/sg_sat_read_gplog.c | 8 | ||||
-rw-r--r-- | src/sg_sat_set_features.c | 10 | ||||
-rw-r--r-- | src/sg_scan_linux.c | 2 | ||||
-rw-r--r-- | src/sg_turs.c | 4 | ||||
-rw-r--r-- | src/sginfo.c | 4 |
11 files changed, 172 insertions, 154 deletions
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c index ff958f48..f0615612 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.77 20220423"; /* spc6r06 */ +static const char * version_str = "0.78 20220428"; /* spc6r06 */ #define MY_NAME "sg_opcodes" @@ -334,10 +334,7 @@ do_rstmf(struct sg_pt_base * ptvp, bool repd, void * resp, int mx_resp_len, static int new_parse_cmd_line(struct opts_t * op, int argc, char * argv[]) { - bool bad_arg = false; - bool pr_verbose = false; - char bad_ch; - int c, n, k; + int c, n; char * cp; char b[32]; @@ -370,52 +367,10 @@ new_parse_cmd_line(struct opts_t * op, int argc, char * argv[]) op->inhex_fn = optarg; break; case 'j': - sg_json_init_state(&op->json_st); - if (optarg) { - for (k = 0; optarg[k]; ++k) { - switch (optarg[k]) { - case '2': - op->json_st.pr_indent_size = 2; - break; - case '3': - op->json_st.pr_indent_size = 3; - break; - case '4': - op->json_st.pr_indent_size = 4; - break; - case '8': - op->json_st.pr_indent_size = 8; - break; - case 'c': - op->json_st.pr_pretty = false; - break; - case 'g': - op->json_st.pr_format = 'g'; - break; - case 'i': - op->json_st.pr_implemented = true; - break; - case 'o': - op->json_st.pr_output = true; - break; - case 's': - op->json_st.pr_sorted = true; - break; - case 'u': - op->json_st.pr_unimplemented = true; - break; - case 'v': - pr_verbose = true; - break; - case 'y': - op->json_st.pr_format = 'g'; - break; - default: - bad_arg = true; - bad_ch = optarg[k]; - break; - } - } + if (! sgj_init_state(&op->json_st, optarg)) { + pr2serr("bad argument to --json= option, unrecognized " + "character '%c'\n", op->json_st.first_bad_char); + return SG_LIB_SYNTAX_ERROR; } break; case 'm': @@ -527,17 +482,6 @@ new_parse_cmd_line(struct opts_t * op, int argc, char * argv[]) return SG_LIB_SYNTAX_ERROR; } } - if (pr_verbose) { - if (op->verbose_given) - op->json_st.verbose = op->verbose; - else - op->json_st.verbose = 4; - } - if (bad_arg) { - pr2serr("Unrecognized argument character: %c given to --json=\n", - bad_ch); - return SG_LIB_SYNTAX_ERROR; - } return 0; } @@ -569,7 +513,7 @@ old_parse_cmd_line(struct opts_t * op, int argc, char * argv[]) ++op->do_hex; break; case 'j': /* don't accept argument with this old syntax */ - sg_json_init_state(&op->json_st); + sgj_init_state(&op->json_st, NULL); break; case 'm': op->do_mask = true; @@ -1195,7 +1139,7 @@ main(int argc, char * argv[]) as_json = op->json_st.pr_as_json; jsp = &op->json_st; if (as_json) { - jop = sg_json_start(MY_NAME, version_str, argc, argv, &op->json_st); + jop = sgj_start(MY_NAME, version_str, argc, argv, &op->json_st); } #ifdef DEBUG pr2serr("In DEBUG mode, "); @@ -1530,15 +1474,16 @@ err_out: if (sg_fd >= 0) scsi_pt_close_device(sg_fd); } - if (as_json && jop) { - if (0 == op->do_hex) - sgj_pr2file(jop, &op->json_st, stdout); - sg_json_free(jop); - } if ((0 == op->verbose) && (! no_final_msg)) { if (! sg_if_can2stderr("sg_opcodes failed: ", res)) pr2serr("Some error occurred, try again with '-v' " "or '-vv' for more information\n"); } - return (res >= 0) ? res : SG_LIB_CAT_OTHER; + res = (res >= 0) ? res : SG_LIB_CAT_OTHER; + if (as_json) { + if (0 == op->do_hex) + sgj_pr2file(&op->json_st, NULL, res, stdout); + sgj_finish(jsp); + } + return res; } diff --git a/src/sg_raw.c b/src/sg_raw.c index 453a85a4..e0a6ba98 100644 --- a/src/sg_raw.c +++ b/src/sg_raw.c @@ -39,7 +39,7 @@ #include "sg_pr2serr.h" #include "sg_unaligned.h" -#define SG_RAW_VERSION "0.4.38 (2022-01-18)" +#define SG_RAW_VERSION "0.4.39 (2022-04-25)" #define DEFAULT_TIMEOUT 20 #define MIN_SCSI_CDBSZ 6 @@ -542,7 +542,7 @@ main(int argc, char *argv[]) uint16_t sct_sc; uint32_t result; struct sg_pt_base *ptvp = NULL; - uint8_t sense_buffer[32]; + uint8_t sense_buffer[32] = {0}; uint8_t * dinp = NULL; uint8_t * doutp = NULL; uint8_t * free_buf_out = NULL; diff --git a/src/sg_rbuf.c b/src/sg_rbuf.c index 3126ed9b..180c19bc 100644 --- a/src/sg_rbuf.c +++ b/src/sg_rbuf.c @@ -1,5 +1,5 @@ /* A utility program originally written for the Linux OS SCSI subsystem. - * Copyright (C) 1999-2020 D. Gilbert + * Copyright (C) 1999-2022 D. Gilbert * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) @@ -57,7 +57,7 @@ #endif -static const char * version_str = "5.08 20200501"; +static const char * version_str = "5.09 20220425"; static struct option long_options[] = { {"buffer", required_argument, 0, 'b'}, @@ -368,8 +368,8 @@ main(int argc, char * argv[]) struct opts_t * op; uint8_t * rbBuff = NULL; void * rawp = NULL; - uint8_t sense_buffer[32]; - uint8_t rb_cdb [RB_CMD_LEN]; + uint8_t sense_buffer[32] = {0}; + uint8_t rb_cdb [RB_CMD_LEN] = {0}; struct sg_io_hdr io_hdr; struct timeval start_tm, end_tm; struct opts_t opts; @@ -436,7 +436,6 @@ main(int argc, char * argv[]) } rbBuff = (uint8_t *)rawp; - memset(rb_cdb, 0, RB_CMD_LEN); rb_cdb[0] = RB_OPCODE; rb_cdb[1] = op->do_echo ? RB_MODE_ECHO_DESC : RB_MODE_DESC; rb_cdb[8] = RB_DESC_LEN; diff --git a/src/sg_rep_zones.c b/src/sg_rep_zones.c index 93001b50..353c1eda 100644 --- a/src/sg_rep_zones.c +++ b/src/sg_rep_zones.c @@ -40,7 +40,9 @@ * Based on zbc2r12.pdf */ -static const char * version_str = "1.34 20220416"; +static const char * version_str = "1.35 20220501"; + +#define MY_NAME "sg_rep_zones" #define WILD_RZONES_BUFF_LEN (1 << 28) #define MAX_RZONES_BUFF_LEN (2 * 1024 * 1024) @@ -82,6 +84,7 @@ struct opts_t { int vb; uint64_t st_lba; const char * in_fn; + sg_json_state json_st; }; struct zt_num2abbrev_t { @@ -99,6 +102,7 @@ static struct option long_options[] = { {"hex", no_argument, 0, 'H'}, {"in", required_argument, 0, 'i'}, /* silent, same as --inhex= */ {"inhex", required_argument, 0, 'i'}, + {"json", optional_argument, 0, 'j'}, {"locator", required_argument, 0, 'l'}, {"maxlen", required_argument, 0, 'm'}, {"num", required_argument, 0, 'n'}, @@ -156,13 +160,15 @@ usage(int h) pr2serr("Usage: " "sg_rep_zones [--domain] [--find=ZT] [--force] [--help] " "[--hex]\n" - " [--inhex=FN] [--locator=LBA] " - "[--maxlen=LEN]\n" - " [--num=NUM] [--partial] [--raw] " - "[--readonly]\n" - " [--realm] [--report=OPT] [--start=LBA] " - "[--statistics]\n" - " [--verbose] [--version] [--wp] DEVICE\n"); + " [--inhex=FN] [--json[=JO]] " + "[--locator=LBA]\n" + " [--maxlen=LEN] [--num=NUM] [--partial] " + "[--raw]\n" + " [--readonly] [--realm] [--report=OPT] " + "[--start=LBA]\n" + " [--statistics] [--verbose] [--version] " + "[--wp]\n" + " DEVICE\n"); pr2serr(" where:\n" " --domain|-d sends a REPORT ZONE DOMAINS command\n" " --find=ZT|-F ZT find first zone with ZT zone type, " @@ -178,6 +184,10 @@ usage(int h) "twice\n" " shows decoded values in hex\n" " --inhex=FN|-i FN decode contents of FN, ignore DEVICE\n" + " --json[=JO]|-j[JO] output in JSON instead of human " + "readable text.\n" + " Optional argument JO see sg3_utils " + "manpage\n" " --locator=LBA|-l LBA similar to --start= option\n" " --maxlen=LEN|-m LEN max response length (allocation " "length in cdb)\n" @@ -195,7 +205,7 @@ usage(int h) "zones)\n" " --start=LBA|-s LBA report zones from the LBA (def: 0)\n" " need not be a zone starting LBA\n" - " --statistics gather statistics by reviewing zones\n" + " --statistics|-S gather statistics by reviewing zones\n" " --verbose|-v increase verbosity\n" " --version|-V print version string and exit\n" " --wp|-w output write pointer only\n\n" @@ -371,38 +381,52 @@ static const char * same_desc_arr[16] = { }; static uint64_t -prt_a_zn_desc(const uint8_t *bp, const struct opts_t * op) +prt_a_zn_desc(const uint8_t *bp, const struct opts_t * op, + sg_json_state * jsp, sg_json_opaque_p jop) { uint8_t zt, zc; uint64_t lba, len, wp; char b[80]; + jop = jop ? jop : jsp->basep; zt = bp[0] & 0xf; zc = (bp[1] >> 4) & 0xf; - printf(" Zone type: %s\n", sg_get_zone_type_str(zt, sizeof(b), b)); - printf(" Zone condition: %s\n", zone_condition_str(zc, b, - sizeof(b), op->vb)); - printf(" PUEP: %d\n", !!(bp[1] & 0x4)); /* added in zbc2r07 */ - printf(" Non_seq: %d\n", !!(bp[1] & 0x2)); - printf(" Reset: %d\n", bp[1] & 0x1); + 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); + 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_pr_simple_vi(jsp, jop, 3, "PUEP", SG_JSON_SEP_COLON_1_SPACE, + !!(bp[1] & 0x4)); + sgj_pr_simple_vi(jsp, jop, 3, "NON_SEQ", SG_JSON_SEP_COLON_1_SPACE, + !!(bp[1] & 0x2)); + sgj_pr_simple_vi(jsp, jop, 3, "RESET", SG_JSON_SEP_COLON_1_SPACE, + !!(bp[1] & 0x1)); len = sg_get_unaligned_be64(bp + 8); - printf(" Zone Length: 0x%" PRIx64 "\n", len); + sgj_pr_hr(jsp, " Zone Length: 0x%" PRIx64 "\n", len); + sgj_add_name_pair_ihex(jsp, jop, "zone_length", (int64_t)len); lba = sg_get_unaligned_be64(bp + 16); - printf(" Zone start LBA: 0x%" PRIx64 "\n", lba); + sgj_pr_hr(jsp, " Zone start LBA: 0x%" PRIx64 "\n", lba); + sgj_add_name_pair_ihex(jsp, jop, "zone_start_lba", (int64_t)lba); wp = sg_get_unaligned_be64(bp + 24); if (sg_all_ffs((const uint8_t *)&wp, sizeof(wp))) - printf(" Write pointer LBA: -1\n"); + sgj_pr_hr(jsp, " Write pointer LBA: -1\n"); else - printf(" Write pointer LBA: 0x%" PRIx64 "\n", wp); + sgj_pr_hr(jsp, " Write pointer LBA: 0x%" PRIx64 "\n", wp); + sgj_add_name_pair_ihex(jsp, jop, "write_pointer_lba", (int64_t)wp); return lba + len; } static int decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len, - const struct opts_t * op) + const struct opts_t * op, sg_json_state * jsp) { + bool as_json = jsp ? jsp->pr_as_json : false; int k, same, num_zd; uint64_t wp, ul, mx_lba; + sg_json_opaque_p jop = jsp ? jsp->basep : NULL; + sg_json_opaque_p jap = NULL; const uint8_t * bp; if ((uint32_t)act_len < decod_len) { @@ -426,10 +450,16 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len, hex2stdout(rzBuff, 64, -1); printf("\n"); } else { - printf(" Same=%d: %s\n", same, same_desc_arr[same]); - printf(" Maximum LBA: 0x%" PRIx64 "\n\n", mx_lba); - printf(" Reported zone starting LBA granularity: 0x%" PRIx64 "\n\n", - sg_get_unaligned_be64(rzBuff + 16)); /* zbc2r12 */ + uint64_t rzslbag = sg_get_unaligned_be64(rzBuff + 16); + static const char * rzslbag_s = "Reported zone starting LBA " + "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_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); + sgj_add_name_pair_ihex(jsp, jop, rzslbag_s, rzslbag); } if (op->do_num > 0) num_zd = (num_zd > op->do_num) ? op->do_num : num_zd; @@ -450,17 +480,21 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len, } printf("From last descriptor in this response:\n"); printf(" %s%d\n", zn_dnum_s, num_zd - 1); - ul = prt_a_zn_desc(bp, op); + ul = prt_a_zn_desc(bp, op, jsp, jop); if (ul > mx_lba) printf(" >> This zone seems to be the last one\n"); else printf(" >> Probable next Zone start LBA: 0x%" PRIx64 "\n", ul); return 0; } + if (as_json) + jap = sgj_new_named_array(jsp, NULL, "zone_descriptor_list"); for (k = 0, bp = rzBuff + 64; k < num_zd; ++k, bp += REPORT_ZONES_DESC_LEN) { + sg_json_opaque_p jo2p; + if (! op->wp_only) - printf(" %s%d\n", zn_dnum_s, k); + sgj_pr_hr(jsp, " %s%d\n", zn_dnum_s, k); if (op->do_hex) { hex2stdout(bp, 64, -1); continue; @@ -477,7 +511,10 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len, } continue; } - prt_a_zn_desc(bp, op); + jo2p = as_json ? sgj_new_object(jsp) : NULL; + prt_a_zn_desc(bp, op, jsp, jo2p); + if (jo2p) + sgj_add_array_element(jsp, jap, jo2p); } if ((op->do_num == 0) && (! op->wp_only) && (! op->do_hex)) { if ((64 + (REPORT_ZONES_DESC_LEN * (uint32_t)num_zd)) < decod_len) @@ -611,8 +648,9 @@ decode_rep_zdomains(const uint8_t * rzBuff, int act_len, static int find_report_zones(int sg_fd, uint8_t * rzBuff, const char * cmd_name, - struct opts_t * op) + struct opts_t * op, sg_json_state * jsp) { + bool as_json = (jsp && (0 == op->do_hex)) ? jsp->pr_as_json : false; bool found = false; uint8_t zt; int k, res, resid, rlen, num_zd, num_rem; @@ -669,25 +707,35 @@ find_report_zones(int sg_fd, uint8_t * rzBuff, const char * cmd_name, break; } /* end of outer for loop */ if (res == 0) { + sg_json_opaque_p jo2p = as_json ? + sgj_new_named_object(jsp, NULL, "find_condition") : NULL; + if (found) { if (op->do_hex) { hex2stdout(rzBuff, 64, -1); printf("\n"); hex2stdout(bp, 64, -1); } else { - printf("Condition met at:\n"); - printf(" %s: %d\n", zn_dnum_s, zn_dnum); - prt_a_zn_desc(bp, op); + 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); + prt_a_zn_desc(bp, op, jsp, jo2p); } } else { if (op->do_hex) { memset(b, 0xff, 64); hex2stdout((const uint8_t *)b, 64, -1); - } else if (num_rem < 1) - printf("Condition NOT met, checked %d zones; next %s%u\n", - op->do_num, zn_dnum_s, zn_dnum); - else - printf("Condition NOT met; next %s%u\n", zn_dnum_s, zn_dnum); + } else { + sgj_add_name_vb(jsp, jo2p, "met", false); + sgj_add_name_vi(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); + else + sgj_pr_hr(jsp, "Condition NOT met; next %s%u\n", + zn_dnum_s, zn_dnum); + } } } return res; @@ -1037,6 +1085,7 @@ int main(int argc, char * argv[]) { bool no_final_msg = false; + bool as_json; int res, c, act_len, rlen, in_len, off; int sg_fd = -1; int resid = 0; @@ -1047,6 +1096,8 @@ main(int argc, char * argv[]) uint8_t * rzBuff = NULL; uint8_t * free_rzbp = NULL; const char * cmd_name = "Report zones"; + sg_json_state * jsp; + sg_json_opaque_p jop = NULL; char b[80]; struct opts_t opts = {0}; struct opts_t * op = &opts; @@ -1055,7 +1106,7 @@ main(int argc, char * argv[]) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "bdefF:hHi:l:m:n:o:prRs:SvVw", + c = getopt_long(argc, argv, "bdefF:hHi:j::l:m:n:o:prRs:SvVw", long_options, &option_index); if (c == -1) break; @@ -1110,6 +1161,13 @@ main(int argc, char * argv[]) case 'i': op->in_fn = optarg; break; + case 'j': + if (! sgj_init_state(&op->json_st, optarg)) { + pr2serr("bad argument to --json= option, unrecognized " + "character '%c'\n", op->json_st.first_bad_char); + return SG_LIB_SYNTAX_ERROR; + } + break; /* case 'l': is under case 's': */ case 'm': op->maxlen = sg_get_num(optarg); @@ -1213,6 +1271,11 @@ main(int argc, char * argv[]) usage(op->do_help); return 0; } + as_json = op->json_st.pr_as_json; + jsp = &op->json_st; + if (as_json) + jop = sgj_start(MY_NAME, version_str, argc, argv, jsp); + if (op->do_zdomains && op->do_realms) { pr2serr("Can't have both --domain and --realm\n"); return SG_LIB_SYNTAX_ERROR; @@ -1220,6 +1283,8 @@ main(int argc, char * argv[]) cmd_name = "Report zone domains"; else if (op->do_realms) cmd_name = "Report realms"; + if (as_json) + sgj_add_name_vs(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; @@ -1260,6 +1325,15 @@ main(int argc, char * argv[]) goto the_end; } res = 0; + if (op->find_zt) { /* so '-F none' will drop through */ + op->maxlen = in_len; + ret = find_report_zones(sg_fd, rzBuff, cmd_name, op, jsp); + goto the_end; + } else if (op->statistics) { + op->maxlen = in_len; + ret = gather_statistics(sg_fd, rzBuff, cmd_name, op); + goto the_end; + } goto start_response; } else { pr2serr("missing device name!\n\n"); @@ -1273,7 +1347,8 @@ main(int argc, char * argv[]) if (op->do_raw) { if (sg_set_binary_mode(STDOUT_FILENO) < 0) { perror("sg_set_binary_mode"); - return SG_LIB_FILE_ERROR; + ret = SG_LIB_FILE_ERROR; + goto the_end; } } @@ -1287,7 +1362,7 @@ main(int argc, char * argv[]) } if (op->find_zt) { /* so '-F none' will drop through */ - ret = find_report_zones(sg_fd, rzBuff, cmd_name, op); + ret = find_report_zones(sg_fd, rzBuff, cmd_name, op, jsp); goto the_end; } else if (op->statistics) { ret = gather_statistics(sg_fd, rzBuff, cmd_name, op); @@ -1310,15 +1385,16 @@ start_response: if (! op->do_force) { pr2serr("decode length [%u bytes] seems wild, use --force " "override\n", decod_len); - return SG_LIB_CAT_MALFORMED; + ret = SG_LIB_CAT_MALFORMED; + goto the_end; } } if (decod_len > (uint32_t)rlen) { if ((REPORT_ZONES_SA == op->serv_act) && (! op->do_partial)) { - printf("%u zones starting from LBA 0x%" PRIx64 " available " - "but only %d zones returned\n", - (decod_len - 64) / REPORT_ZONES_DESC_LEN, op->st_lba, - (rlen - 64) / REPORT_ZONES_DESC_LEN); + pr2serr("%u zones starting from LBA 0x%" PRIx64 " available " + "but only %d zones returned\n", + (decod_len - 64) / REPORT_ZONES_DESC_LEN, op->st_lba, + (rlen - 64) / REPORT_ZONES_DESC_LEN); decod_len = rlen; act_len = rlen; } else { @@ -1343,7 +1419,8 @@ start_response: goto the_end; } if (! op->wp_only && (! op->do_hex)) - printf("%s response:\n", cmd_name); + sgj_pr_hr(jsp, "%s response:\n", cmd_name); + if (act_len < 64) { pr2serr("Zone length [%d] too short (perhaps after truncation\n)", act_len); @@ -1351,7 +1428,7 @@ start_response: goto the_end; } if (REPORT_ZONES_SA == op->serv_act) - ret = decode_rep_zones(rzBuff, act_len, decod_len, op); + ret = decode_rep_zones(rzBuff, act_len, decod_len, op, jsp); else if (op->do_realms) ret = decode_rep_realms(rzBuff, act_len, op); else if (op->do_zdomains) @@ -1379,5 +1456,11 @@ the_end: pr2serr("Some error occurred, try again with '-v' " "or '-vv' for more information\n"); } - return (ret >= 0) ? ret : SG_LIB_CAT_OTHER; + ret = (ret >= 0) ? ret : SG_LIB_CAT_OTHER; + if (as_json) { + if (0 == op->do_hex) + sgj_pr2file(&op->json_st, NULL, ret, stdout); + sgj_finish(jsp); + } + return ret; } diff --git a/src/sg_sat_identify.c b/src/sg_sat_identify.c index 92cad466..ef9b3197 100644 --- a/src/sg_sat_identify.c +++ b/src/sg_sat_identify.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021 Douglas Gilbert. + * Copyright (c) 2006-2022 Douglas Gilbert. * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. @@ -54,7 +54,7 @@ #define EBUFF_SZ 256 -static const char * version_str = "1.18 20210630"; +static const char * version_str = "1.19 20220425"; static struct option long_options[] = { {"ck-cond", no_argument, 0, 'c'}, @@ -136,21 +136,18 @@ do_identify_dev(int sg_fd, bool do_packet, int cdb_len, bool ck_cond, uint64_t ull; struct sg_scsi_sense_hdr ssh; uint8_t inBuff[ID_RESPONSE_LEN]; - uint8_t sense_buffer[64]; - uint8_t ata_return_desc[16]; + uint8_t sense_buffer[64] = {0}; + uint8_t ata_return_desc[16] = {0}; uint8_t apt_cdb[SAT_ATA_PASS_THROUGH16_LEN] = {SAT_ATA_PASS_THROUGH16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t apt12_cdb[SAT_ATA_PASS_THROUGH12_LEN] = {SAT_ATA_PASS_THROUGH12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - uint8_t apt32_cdb[SAT_ATA_PASS_THROUGH32_LEN]; + uint8_t apt32_cdb[SAT_ATA_PASS_THROUGH32_LEN] = {0}; const unsigned short * usp; sb_sz = sizeof(sense_buffer); - memset(sense_buffer, 0, sb_sz); - memset(apt32_cdb, 0, sizeof(apt32_cdb)); - memset(ata_return_desc, 0, sizeof(ata_return_desc)); ok = false; switch (cdb_len) { case SAT_ATA_PASS_THROUGH32_LEN: /* SAT-4 revision 5 or later */ diff --git a/src/sg_sat_phy_event.c b/src/sg_sat_phy_event.c index 090ecf75..55230b84 100644 --- a/src/sg_sat_phy_event.c +++ b/src/sg_sat_phy_event.c @@ -28,7 +28,7 @@ #include "sg_cmds_extra.h" #include "sg_pr2serr.h" -static const char * version_str = "1.14 20220118"; +static const char * version_str = "1.15 20220425"; /* This program uses a ATA PASS-THROUGH SCSI command. This usage is * defined in the SCSI to ATA Translation (SAT) drafts and standards. @@ -177,8 +177,8 @@ do_read_log_ext(int sg_fd, int log_addr, int page_in_log, int feature, int resid = 0; int sb_sz; struct sg_scsi_sense_hdr ssh; - uint8_t sense_buffer[64]; - uint8_t ata_return_desc[16]; + uint8_t sense_buffer[64] = {0}; + uint8_t ata_return_desc[16] = {0}; uint8_t apt_cdb[SAT_ATA_PASS_THROUGH16_LEN] = {SAT_ATA_PASS_THROUGH16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -187,8 +187,6 @@ do_read_log_ext(int sg_fd, int log_addr, int page_in_log, int feature, 0, 0, 0, 0}; sb_sz = sizeof(sense_buffer); - memset(sense_buffer, 0, sb_sz); - memset(ata_return_desc, 0, sizeof(ata_return_desc)); ok = false; if (SAT_ATA_PASS_THROUGH16_LEN == cdb_len) { /* Prepare ATA PASS-THROUGH COMMAND (16) command */ diff --git a/src/sg_sat_read_gplog.c b/src/sg_sat_read_gplog.c index 0c5ecce6..7006563d 100644 --- a/src/sg_sat_read_gplog.c +++ b/src/sg_sat_read_gplog.c @@ -54,7 +54,7 @@ #define DEF_TIMEOUT 20 -static const char * version_str = "1.21 20220118"; +static const char * version_str = "1.22 20220425"; struct opts_t { bool ck_cond; @@ -139,8 +139,8 @@ do_read_gplog(int sg_fd, int ata_cmd, uint8_t *inbuff, int resid = 0; int sb_sz; struct sg_scsi_sense_hdr ssh; - uint8_t sense_buffer[64]; - uint8_t ata_return_desc[16]; + uint8_t sense_buffer[64] = {0}; + uint8_t ata_return_desc[16] = {0}; uint8_t apt_cdb[SAT_ATA_PASS_THROUGH16_LEN] = {SAT_ATA_PASS_THROUGH16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -157,8 +157,6 @@ do_read_gplog(int sg_fd, int ata_cmd, uint8_t *inbuff, protocol = 4; /* PIO Data-In */ } sb_sz = sizeof(sense_buffer); - memset(sense_buffer, 0, sb_sz); - memset(ata_return_desc, 0, sizeof(ata_return_desc)); memset(inbuff, 0, op->count * 512); if (op->verbose > 1) pr2serr("Building ATA READ LOG%s EXT command; la=0x%x, pn=0x%x\n", diff --git a/src/sg_sat_set_features.c b/src/sg_sat_set_features.c index e873fe60..e914b23a 100644 --- a/src/sg_sat_set_features.c +++ b/src/sg_sat_set_features.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2018 Douglas Gilbert. + * Copyright (c) 2006-2022 Douglas Gilbert. * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. @@ -52,7 +52,7 @@ #define DEF_TIMEOUT 20 -static const char * version_str = "1.18 20180628"; +static const char * version_str = "1.19 20220425"; static struct option long_options[] = { {"count", required_argument, 0, 'c'}, @@ -125,8 +125,8 @@ do_set_features(int sg_fd, int feature, int count, uint64_t lba, int resid = 0; int sb_sz; struct sg_scsi_sense_hdr ssh; - uint8_t sense_buffer[64]; - uint8_t ata_return_desc[16]; + uint8_t sense_buffer[64] = {0}; + uint8_t ata_return_desc[16] = {0}; uint8_t apt_cdb[SAT_ATA_PASS_THROUGH16_LEN] = {SAT_ATA_PASS_THROUGH16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -135,8 +135,6 @@ do_set_features(int sg_fd, int feature, int count, uint64_t lba, 0, 0, 0, 0}; sb_sz = sizeof(sense_buffer); - memset(sense_buffer, 0, sb_sz); - memset(ata_return_desc, 0, sizeof(ata_return_desc)); if (16 == cdb_len) { /* Prepare ATA PASS-THROUGH COMMAND (16) command */ apt_cdb[14] = ATA_SET_FEATURES; diff --git a/src/sg_scan_linux.c b/src/sg_scan_linux.c index 9fa3374a..b0bc52dd 100644 --- a/src/sg_scan_linux.c +++ b/src/sg_scan_linux.c @@ -399,7 +399,7 @@ int sg3_inq(int sg_fd, uint8_t * inqBuff, bool do_extra) { bool ok; int err, sg_io; - uint8_t sense_buffer[32]; + uint8_t sense_buffer[32] = {0}; struct sg_io_hdr io_hdr; memset(&io_hdr, 0, sizeof(struct sg_io_hdr)); diff --git a/src/sg_turs.c b/src/sg_turs.c index 3c7c7a1f..e665fe44 100644 --- a/src/sg_turs.c +++ b/src/sg_turs.c @@ -45,7 +45,7 @@ #include "sg_pr2serr.h" -static const char * version_str = "3.50 20220418"; +static const char * version_str = "3.51 20220425"; #define DEF_PT_TIMEOUT 60 /* 60 seconds */ @@ -386,7 +386,7 @@ loop_turs(struct sg_pt_base * ptvp, struct loop_res_t * resp, int packet_id = 0; int vb = op->verbose; char b[80]; - uint8_t sense_b[32]; + uint8_t sense_b[32] = {0}; if (op->do_low) { int rs, n, sense_cat; diff --git a/src/sginfo.c b/src/sginfo.c index 51a312af..0225ab5f 100644 --- a/src/sginfo.c +++ b/src/sginfo.c @@ -124,7 +124,7 @@ #define _GNU_SOURCE 1 #endif -static const char * version_str = "2.44 [20211114]"; +static const char * version_str = "2.45 [20220425]"; #include <stdio.h> #include <string.h> @@ -3056,7 +3056,7 @@ print_hex_page(struct mpage_info * mpi, const char * prefix, { char nm[8]; - snprintf(nm, sizeof(nm), "0x%02x", k); + snprintf(nm, sizeof(nm), "0x%02x", (unsigned char)k); hexdatafield(pagestart + k, 1, nm); } printf("\n"); |