diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sg_logs.c | 154 | ||||
-rw-r--r-- | src/sg_opcodes.c | 2 | ||||
-rw-r--r-- | src/sg_rep_zones.c | 13 | ||||
-rw-r--r-- | src/sg_rtpg.c | 28 |
4 files changed, 80 insertions, 117 deletions
diff --git a/src/sg_logs.c b/src/sg_logs.c index 9c44d6be..051ea7fc 100644 --- a/src/sg_logs.c +++ b/src/sg_logs.c @@ -37,7 +37,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.97 20220309"; /* spc6r06 + sbc5r01 */ +static const char * version_str = "1.98 20220310"; /* spc6r06 + sbc5r01 */ #define MX_ALLOC_LEN (0xfffc) #define MX_INLEN_ALLOC_LEN (0x800000) @@ -1575,7 +1575,7 @@ show_supported_pgs_page(const uint8_t * resp, int len, int pg_code = bp[k]; const struct log_elem * lep; - snprintf(b, sizeof(b) - 1, " 0x%02x ", pg_code); + snprintf(b, sizeof(b) - 1, " 0x%02x ", pg_code); lep = pg_subpg_pdt_search(pg_code, 0, op->dev_pdt, -1); if (lep) { if (op->do_brief > 1) @@ -1622,9 +1622,9 @@ show_supported_pgs_sub_page(const uint8_t * resp, int len, /* formerly ignored [pg, 0xff] when pg > 0, don't know why */ if (NOT_SPG_SUBPG == subpg_code) - snprintf(b, sizeof(b) - 1, " 0x%02x ", pg_code); + snprintf(b, sizeof(b) - 1, " 0x%02x ", pg_code); else - snprintf(b, sizeof(b) - 1, " 0x%02x,0x%02x ", pg_code, + snprintf(b, sizeof(b) - 1, " 0x%02x,0x%02x ", pg_code, subpg_code); if ((pg_code > 0) && (subpg_code == 0xff)) printf("%s\n", b); @@ -3196,13 +3196,13 @@ show_app_client_page(const uint8_t * resp, int len, const struct opts_t * op) if (op->verbose || ((! op->do_raw) && (op->do_hex == 0))) printf("Application client page [0xf]\n"); if (0 == op->filter_given) { - if ((len > 128) && (0 == op->do_hex)) { - hex2stdout(resp, 64, op->dstrhex_no_ascii); - printf(" ..... [truncated after 64 of %d bytes (use '-H' to " + if ((len > 128) && (0 == op->do_hex) && (0 == op->undefined_hex)) { + hex2fp(resp, 64, " ", 0 != op->dstrhex_no_ascii, stdout); + printf(" ..... [truncated after 64 of %d bytes (use '-H' to " "see the rest)]\n", len); } else - hex2stdout(resp, len, op->dstrhex_no_ascii); + hex2fp(resp, len, " ", 0 != op->dstrhex_no_ascii, stdout); return true; } /* only here if filter_given set */ @@ -4329,8 +4329,7 @@ show_format_status_page(const uint8_t * resp, int len, default: printf(" Unknown Format parameter code = 0x%x\n", pc); is_count = false; - hex2str(bp, pl, " ", 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, pl, " ", 0 != op->dstrhex_no_ascii, stdout); break; } if (is_count) { @@ -4785,9 +4784,7 @@ show_dt_device_status_page(const uint8_t * resp, int len, pl); break; } - hex2str(bp + 4, 8, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, 8, " ", 0 != op->dstrhex_no_ascii, stdout); break; case 0x3: printf(" Key management error data (hex only now):\n"); @@ -4800,9 +4797,7 @@ show_dt_device_status_page(const uint8_t * resp, int len, pl); break; } - hex2str(bp + 4, 12, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, 12, " ", 0 != op->dstrhex_no_ascii, stdout); break; default: if ((pc >= 0x101) && (pc <= 0x1ff)) { @@ -4819,9 +4814,8 @@ show_dt_device_status_page(const uint8_t * resp, int len, sg_get_unaligned_be64(bp + 8)); } else { printf(" non-SAS transport, in hex:\n"); - hex2str(bp + 4, ((pl < num) ? pl : num) - 4, " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, ((pl < num) ? pl : num) - 4, " ", + 0 != op->dstrhex_no_ascii, stdout); } } else if (pc >= 0x8000) { if (op->exclude_vendor) { @@ -4833,15 +4827,13 @@ show_dt_device_status_page(const uint8_t * resp, int len, } } else { printf(" Vendor specific [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } } else { printf(" Reserved [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } break; } @@ -4866,7 +4858,6 @@ show_tapealert_response_page(const uint8_t * resp, int len, int num, pl, pc, k, mod, div; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("TapeAlert response page (ssc-3, adc-3) [0x12]\n"); @@ -4907,9 +4898,8 @@ show_tapealert_response_page(const uint8_t * resp, int len, default: if (pc <= 0x8000) { printf(" Reserved [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } else { if (op->exclude_vendor) { if ((op->verbose > 0) && (0 == op->do_brief) && @@ -4920,9 +4910,8 @@ show_tapealert_response_page(const uint8_t * resp, int len, } } else { printf(" Vendor specific [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } } break; @@ -4971,7 +4960,6 @@ show_requested_recovery_page(const uint8_t * resp, int len, int num, pl, pc, j, k; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("Requested recovery page (ssc-3) [0x13]\n"); @@ -5007,9 +4995,8 @@ show_requested_recovery_page(const uint8_t * resp, int len, default: if (pc <= 0x8000) { printf(" Reserved [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } else { if (op->exclude_vendor) { if ((op->verbose > 0) && (0 == op->do_brief) && @@ -5020,9 +5007,8 @@ show_requested_recovery_page(const uint8_t * resp, int len, } } else { printf(" Vendor specific [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } } break; @@ -5048,7 +5034,6 @@ show_ata_pt_results_page(const uint8_t * resp, int len, const uint8_t * bp; const uint8_t * dp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("ATA pass-through results page (sat-2) [0x16]\n"); @@ -5086,15 +5071,13 @@ show_ata_pt_results_page(const uint8_t * resp, int len, printf(" device=0x%x status=0x%x\n", dp[12], dp[13]); } else if (pl > 17) { printf(" Reserved [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } else { printf(" short parameter length: %d [parameter_code=0x%x]:\n", pl, pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } if (op->do_pcb) printf(" <%s>\n", get_pcb_str(bp[2], str, sizeof(str))); @@ -5145,7 +5128,6 @@ show_background_scan_results_page(const uint8_t * resp, int len, int j, m, num, pl, pc; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("Background scan results page [0x15]\n"); @@ -5223,11 +5205,9 @@ show_background_scan_results_page(const uint8_t * resp, int len, "reserved\n", pc, pc); if (skip_out) skip_out = false; - else { - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); - } + else + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); break; } else printf(" Medium scan parameter # %d [0x%x]\n", pc, pc); @@ -5291,7 +5271,6 @@ show_zoned_block_dev_stats(const uint8_t * resp, int len, int num, pl, pc; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("Zoned block device statistics page [0x14,0x1]\n"); @@ -5438,9 +5417,8 @@ show_zoned_block_dev_stats(const uint8_t * resp, int len, break; default: printf(" Reserved [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); break; } if (trunc) @@ -5545,7 +5523,6 @@ show_background_op_page(const uint8_t * resp, int len, int num, pl, pc; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("Background operation page [0x15,0x2]\n"); @@ -5581,9 +5558,8 @@ show_background_op_page(const uint8_t * resp, int len, break; default: printf(" Reserved [parameter_code=0x%x]:\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); break; } if (op->do_pcb) @@ -5607,7 +5583,6 @@ show_lps_misalignment_page(const uint8_t * resp, int len, int num, pl, pc; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("LPS misalignment page [0x15,0x3]\n"); @@ -5647,9 +5622,8 @@ show_lps_misalignment_page(const uint8_t * resp, int len, pc, bp[4]); } else { printf("<unexpected pc=0x%x>\n", pc); - hex2str(bp, ((pl < num) ? pl : num), " ", - 0 != op->dstrhex_no_ascii, sizeof(b), b); - printf("%s", b); + hex2fp(bp, ((pl < num) ? pl : num), " ", + 0 != op->dstrhex_no_ascii, stdout); } break; } @@ -5674,7 +5648,6 @@ show_service_buffer_info_page(const uint8_t * resp, int len, int num, pl, pc; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("Service buffer information page (adc-3) [0x15]\n"); @@ -5705,9 +5678,7 @@ show_service_buffer_info_page(const uint8_t * resp, int len, } else if (pc < 0x8000) { printf(" parameter_code=0x%x, Reserved, parameter in hex:\n", pc); - hex2str(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, stdout); } else { if (op->exclude_vendor) { if ((op->verbose > 0) && (0 == op->do_brief) && @@ -5719,9 +5690,8 @@ show_service_buffer_info_page(const uint8_t * resp, int len, } else { printf(" parameter_code=0x%x, Vendor-specific, parameter in " "hex:\n", pc); - hex2str(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, + stdout); } } if (op->do_pcb) @@ -5869,7 +5839,6 @@ show_device_stats_page(const uint8_t * resp, int len, int num, pl, pc; const uint8_t * bp; char str[PCB_STR_LEN]; - char b[512]; if (op->verbose || ((! op->do_raw) && (0 == op->do_hex))) printf("Device statistics page (ssc-3 and adc)\n"); @@ -6001,9 +5970,8 @@ show_device_stats_page(const uint8_t * resp, int len, default: vl_num = false; printf(" Reserved parameter code [0x%x] data in hex:\n", pc); - hex2str(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, + stdout); break; } if (vl_num) @@ -6034,9 +6002,8 @@ show_device_stats_page(const uint8_t * resp, int len, "hex:\n", pc); } else { printf(" Reserved parameter [0x%x], dump in hex:\n", pc); - hex2str(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, + stdout); } break; } @@ -6405,16 +6372,12 @@ show_mchanger_diag_data_page(const uint8_t * resp, int len, printf(" Destination address: 0x%x\n", v); if (pl > 91) { printf(" Volume tag information:\n"); - hex2str(bp + 56, 36, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 56, 36, " ", 0 != op->dstrhex_no_ascii, stdout); } if (pl > 99) { printf(" Timestamp origin: 0x%x\n", bp[92] & 0xf); printf(" Timestamp:\n"); - hex2str(bp + 94, 6, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); + hex2fp(bp + 94, 6, " ", 0 != op->dstrhex_no_ascii, stdout); } if (op->do_pcb) printf(" <%s>\n", get_pcb_str(bp[2], str, sizeof(str))); @@ -6733,11 +6696,9 @@ show_volume_stats_pages(const uint8_t * resp, int len, pc); if (skip_out) skip_out = false; - else { - hex2str(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); - } + else + hex2fp(bp + 4, pl - 4, " ", 0 != op->dstrhex_no_ascii, + stdout); break; } if (op->do_pcb) @@ -7078,7 +7039,6 @@ decode_page_contents(const uint8_t * resp, int len, struct opts_t * op) bool spf; bool done = false; const struct log_elem * lep; - char b[512]; if (len < 3) { pr2serr("%s: response has bad length: %d\n", __func__, len); @@ -7114,17 +7074,13 @@ decode_page_contents(const uint8_t * resp, int len, struct opts_t * op) printf("%s%x, here is hex:\n", unable_s, pg_code); } if ((len > 128) && (0 == op->do_hex)) { - hex2str(resp, 64, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); - printf(" ..... [truncated after 64 of %d bytes (use '-H' to " + hex2fp(resp, 64, " ", 0 != op->dstrhex_no_ascii, stdout); + printf(" ..... [truncated after 64 of %d bytes (use '-H' to " "see the rest)]\n", len); } else { - if (0 == op->do_hex) { - hex2str(resp, len, " ", 0 != op->dstrhex_no_ascii, - sizeof(b), b); - printf("%s", b); - } else + if (0 == op->do_hex) + hex2fp(resp, len, " ", 0 != op->dstrhex_no_ascii, stdout); + else hex2stdout(resp, len, op->dstrhex_no_ascii); } } diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c index 944a3e76..55530511 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.73 20220127"; /* spc6r06 */ +static const char * version_str = "0.74 20220312"; /* spc6r06 */ #define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */ diff --git a/src/sg_rep_zones.c b/src/sg_rep_zones.c index 1eca3a8d..93001b50 100644 --- a/src/sg_rep_zones.c +++ b/src/sg_rep_zones.c @@ -37,10 +37,10 @@ * * This program issues the SCSI REPORT ZONES, REPORT ZONE DOMAINS or REPORT * REALMS command to the given SCSI device and decodes the response. - * Based on zbc2r10.pdf + * Based on zbc2r12.pdf */ -static const char * version_str = "1.33 20220224"; +static const char * version_str = "1.34 20220416"; #define WILD_RZONES_BUFF_LEN (1 << 28) #define MAX_RZONES_BUFF_LEN (2 * 1024 * 1024) @@ -117,6 +117,7 @@ static struct option long_options[] = { {0, 0, 0, 0}, }; +/* Zone types */ static struct zt_num2abbrev_t zt_num2abbrev[] = { {0, "none"}, {1, "c"}, /* conventionial */ @@ -157,11 +158,11 @@ usage(int h) "[--hex]\n" " [--inhex=FN] [--locator=LBA] " "[--maxlen=LEN]\n" - " [--partial] [--only] [--raw] " + " [--num=NUM] [--partial] [--raw] " "[--readonly]\n" " [--realm] [--report=OPT] [--start=LBA] " - "[--verbose]\n" - " [--version] DEVICE\n"); + "[--statistics]\n" + " [--verbose] [--version] [--wp] 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, " @@ -183,8 +184,6 @@ usage(int h) " (def: 0 -> 8192 bytes)\n" " --num=NUM|-n NUM number of zones to output (def: 0 -> " "all)\n" - " --only|-o output header and starting LBA of " - "next\n" " --partial|-p sets PARTIAL bit in cdb (def: 0 -> " "zone list\n" " length not altered by allocation length " diff --git a/src/sg_rtpg.c b/src/sg_rtpg.c index 48ee4a02..d83bf363 100644 --- a/src/sg_rtpg.c +++ b/src/sg_rtpg.c @@ -153,11 +153,11 @@ main(int argc, char * argv[]) bool extended = false; bool verbose_given = false; bool version_given = false; - int k, j, off, res, c, report_len, tgt_port_count; + int k, j, off, res, c, report_len, buff_len, tgt_port_count; int sg_fd = -1; int ret = 0; int verbose = 0; - uint8_t reportTgtGrpBuff[REPORT_TGT_GRP_BUFF_LEN]; + uint8_t * reportTgtGrpBuff = NULL; uint8_t * bp; const char * device_name = NULL; @@ -255,20 +255,26 @@ main(int argc, char * argv[]) goto err_out; } - memset(reportTgtGrpBuff, 0x0, sizeof(reportTgtGrpBuff)); - /* trunc = 0; */ + buff_len = REPORT_TGT_GRP_BUFF_LEN; + +retry: + reportTgtGrpBuff = (uint8_t *)malloc(buff_len); + if (NULL == reportTgtGrpBuff) { + pr2serr(" Out of memory (ram)\n"); + goto err_out; + } + memset(reportTgtGrpBuff, 0x0, buff_len); res = sg_ll_report_tgt_prt_grp2(sg_fd, reportTgtGrpBuff, - sizeof(reportTgtGrpBuff), + buff_len, extended, true, verbose); ret = res; if (0 == res) { report_len = sg_get_unaligned_be32(reportTgtGrpBuff + 0) + 4; - if (report_len > (int)sizeof(reportTgtGrpBuff)) { - /* trunc = 1; */ - pr2serr(" <<report too long for internal buffer, output " - "truncated\n"); - report_len = (int)sizeof(reportTgtGrpBuff); + if (report_len > buff_len) { + free(reportTgtGrpBuff); + buff_len = report_len; + goto retry; } if (raw) { dStrRaw(reportTgtGrpBuff, report_len); @@ -354,6 +360,8 @@ err_out: ret = sg_convert_errno(-res); } } + if (reportTgtGrpBuff) + free(reportTgtGrpBuff); if (0 == verbose) { if (! sg_if_can2stderr("sg_rtpg failed: ", ret)) pr2serr("Some error occurred, try again with '-v' " |