diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2019-12-27 18:18:48 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2019-12-27 18:18:48 +0000 |
commit | 660ac667940dc7bb188b4e2d0ec9c7f2dd444fc0 (patch) | |
tree | d8a0e36993244d7797f3ab593b0b1945980b8d23 /lib | |
parent | 4b4f37348b25f04b6f2f898aeebc6f5246e56831 (diff) | |
download | sg3_utils-660ac667940dc7bb188b4e2d0ec9c7f2dd444fc0.tar.gz |
sg_lib: add sg_get_command_str() and sg_print_command_len(); sg_verify+sg_write_same: fix and --ff option; sg_dd+sgh_dd: add --verify support
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@837 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sg_cmds_basic.c | 47 | ||||
-rw-r--r-- | lib/sg_cmds_basic2.c | 121 | ||||
-rw-r--r-- | lib/sg_cmds_extra.c | 334 | ||||
-rw-r--r-- | lib/sg_lib.c | 77 | ||||
-rw-r--r-- | lib/sg_lib_data.c | 4 |
5 files changed, 338 insertions, 245 deletions
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c index 470c2f1c..c119c51f 100644 --- a/lib/sg_cmds_basic.c +++ b/lib/sg_cmds_basic.c @@ -42,7 +42,7 @@ #endif -static const char * const version_str = "1.94 20190913"; +static const char * const version_str = "1.95 20191219"; #define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */ @@ -371,7 +371,7 @@ sg_ll_inquiry_com(struct sg_pt_base * ptvp, bool cmddt, bool evpd, int pg_op, void * resp, int mx_resp_len, int timeout_secs, int * residp, bool noisy, int verbose) { - int res, ret, k, sense_cat, resid; + int res, ret, sense_cat, resid; uint8_t inq_cdb[INQUIRY_CMDLEN] = {INQUIRY_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; uint8_t * up; @@ -389,10 +389,11 @@ sg_ll_inquiry_com(struct sg_pt_base * ptvp, bool cmddt, bool evpd, int pg_op, /* 16 bit allocation length (was 8, increased in spc3r09, 200209) */ sg_put_unaligned_be16((uint16_t)mx_resp_len, inq_cdb + 3); if (verbose) { - pr2ws(" %s cdb: ", inquiry_s); - for (k = 0; k < INQUIRY_CMDLEN; ++k) - pr2ws("%02x ", inq_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", inquiry_s, + sg_get_command_str(inq_cdb, INQUIRY_CMDLEN, false, sizeof(b), + b)); } if (resp && (mx_resp_len > 0)) { up = (uint8_t *)resp; @@ -598,15 +599,15 @@ sg_ll_test_unit_ready_progress_pt(struct sg_pt_base * ptvp, int pack_id, int * progress, bool noisy, int verbose) { static const char * const tur_s = "test unit ready"; - int res, ret, k, sense_cat; + int res, ret, sense_cat; uint8_t tur_cdb[TUR_CMDLEN] = {TUR_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; if (verbose) { - pr2ws(" %s cdb: ", tur_s); - for (k = 0; k < TUR_CMDLEN; ++k) - pr2ws("%02x ", tur_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", tur_s, + sg_get_command_str(tur_cdb, TUR_CMDLEN, false, sizeof(b), b)); } clear_scsi_pt_obj(ptvp); @@ -688,7 +689,7 @@ sg_ll_request_sense_com(struct sg_pt_base * ptvp, int sg_fd, bool desc, void * resp, int mx_resp_len, bool noisy, int verbose) { bool ptvp_given = false; - int k, ret, res, sense_cat; + int ret, res, sense_cat; static const char * const rq_s = "request sense"; uint8_t rs_cdb[REQUEST_SENSE_CMDLEN] = {REQUEST_SENSE_CMD, 0, 0, 0, 0, 0}; @@ -702,12 +703,12 @@ sg_ll_request_sense_com(struct sg_pt_base * ptvp, int sg_fd, bool desc, } rs_cdb[4] = mx_resp_len & 0xff; if (verbose) { - pr2ws(" %s cmd: ", rq_s); - for (k = 0; k < REQUEST_SENSE_CMDLEN; ++k) - pr2ws("%02x ", rs_cdb[k]); - pr2ws("\n"); - } + char b[128]; + pr2ws(" %s cdb: %s\n", rq_s, + sg_get_command_str(rs_cdb, REQUEST_SENSE_CMDLEN, false, + sizeof(b), b)); + } if (ptvp) ptvp_given = true; else { @@ -771,7 +772,7 @@ sg_ll_report_luns_com(struct sg_pt_base * ptvp, int sg_fd, int select_report, { static const char * const report_luns_s = "report luns"; bool ptvp_given = false; - int k, ret, res, sense_cat; + int ret, res, sense_cat; uint8_t rl_cdb[REPORT_LUNS_CMDLEN] = {REPORT_LUNS_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -779,12 +780,12 @@ sg_ll_report_luns_com(struct sg_pt_base * ptvp, int sg_fd, int select_report, rl_cdb[2] = select_report & 0xff; sg_put_unaligned_be32((uint32_t)mx_resp_len, rl_cdb + 6); if (verbose) { - pr2ws(" %s cdb: ", report_luns_s); - for (k = 0; k < REPORT_LUNS_CMDLEN; ++k) - pr2ws("%02x ", rl_cdb[k]); - pr2ws("\n"); - } + char b[128]; + pr2ws(" %s cdb: %s\n", report_luns_s, + sg_get_command_str(rl_cdb, REPORT_LUNS_CMDLEN, false, + sizeof(b), b)); + } if (ptvp) ptvp_given = true; else if (NULL == ((ptvp = create_pt_obj(report_luns_s)))) diff --git a/lib/sg_cmds_basic2.c b/lib/sg_cmds_basic2.c index e8536385..c6c8c0bf 100644 --- a/lib/sg_cmds_basic2.c +++ b/lib/sg_cmds_basic2.c @@ -90,7 +90,7 @@ sg_ll_sync_cache_10(int sg_fd, bool sync_nv, bool immed, int group, int verbose) { static const char * const cdb_s = "synchronize cache(10)"; - int res, ret, k, sense_cat; + int res, ret, sense_cat; uint8_t sc_cdb[SYNCHRONIZE_CACHE_CMDLEN] = {SYNCHRONIZE_CACHE_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -109,10 +109,11 @@ sg_ll_sync_cache_10(int sg_fd, bool sync_nv, bool immed, int group, sg_put_unaligned_be16((int16_t)count, sc_cdb + 7); if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SYNCHRONIZE_CACHE_CMDLEN; ++k) - pr2ws("%02x ", sc_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(sc_cdb, SYNCHRONIZE_CACHE_CMDLEN, false, + sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) return -1; @@ -146,7 +147,7 @@ sg_ll_readcap_16(int sg_fd, bool pmi, uint64_t llba, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const cdb_s = "read capacity(16)"; - int k, ret, res, sense_cat; + int ret, res, sense_cat; uint8_t rc_cdb[SERVICE_ACTION_IN_16_CMDLEN] = {SERVICE_ACTION_IN_16_CMD, READ_CAPACITY_16_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -160,10 +161,11 @@ sg_ll_readcap_16(int sg_fd, bool pmi, uint64_t llba, void * resp, /* Allocation length, no guidance in SBC-2 rev 15b */ sg_put_unaligned_be32((uint32_t)mx_resp_len, rc_cdb + 10); if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SERVICE_ACTION_IN_16_CMDLEN; ++k) - pr2ws("%02x ", rc_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rc_cdb, SERVICE_ACTION_IN_16_CMDLEN, false, + sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) return -1; @@ -198,7 +200,7 @@ sg_ll_readcap_10(int sg_fd, bool pmi, unsigned int lba, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const cdb_s = "read capacity(10)"; - int k, ret, res, sense_cat; + int ret, res, sense_cat; uint8_t rc_cdb[READ_CAPACITY_10_CMDLEN] = {READ_CAPACITY_10_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -209,10 +211,11 @@ sg_ll_readcap_10(int sg_fd, bool pmi, unsigned int lba, void * resp, sg_put_unaligned_be32((uint32_t)lba, rc_cdb + 2); } if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < READ_CAPACITY_10_CMDLEN; ++k) - pr2ws("%02x ", rc_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rc_cdb, READ_CAPACITY_10_CMDLEN, false, + sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) return -1; @@ -247,7 +250,7 @@ sg_ll_mode_sense6(int sg_fd, bool dbd, int pc, int pg_code, int sub_pg_code, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const cdb_s = "mode sense(6)"; - int res, ret, k, sense_cat, resid; + int res, ret, sense_cat, resid; uint8_t modes_cdb[MODE_SENSE6_CMDLEN] = {MODE_SENSE6_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -262,10 +265,11 @@ sg_ll_mode_sense6(int sg_fd, bool dbd, int pc, int pg_code, int sub_pg_code, return -1; } if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MODE_SENSE6_CMDLEN; ++k) - pr2ws("%02x ", modes_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(modes_cdb, MODE_SENSE6_CMDLEN, false, + sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) return -1; @@ -340,7 +344,7 @@ sg_ll_mode_sense10_v2(int sg_fd, bool llbaa, bool dbd, int pc, int pg_code, int sub_pg_code, void * resp, int mx_resp_len, int timeout_secs, int * residp, bool noisy, int verbose) { - int res, ret, k, sense_cat, resid; + int res, ret, sense_cat, resid; static const char * const cdb_s = "mode sense(10)"; struct sg_pt_base * ptvp; uint8_t modes_cdb[MODE_SENSE10_CMDLEN] = @@ -356,10 +360,11 @@ sg_ll_mode_sense10_v2(int sg_fd, bool llbaa, bool dbd, int pc, int pg_code, goto gen_err; } if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MODE_SENSE10_CMDLEN; ++k) - pr2ws("%02x ", modes_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(modes_cdb, MODE_SENSE10_CMDLEN, false, + sizeof(b), b)); } if (timeout_secs <= 0) timeout_secs = DEF_PT_TIMEOUT; @@ -425,7 +430,7 @@ sg_ll_mode_select6_v2(int sg_fd, bool pf, bool rtd, bool sp, void * paramp, int param_len, bool noisy, int verbose) { static const char * const cdb_s = "mode select(6)"; - int res, ret, k, sense_cat; + int res, ret, sense_cat; uint8_t modes_cdb[MODE_SELECT6_CMDLEN] = {MODE_SELECT6_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -440,10 +445,11 @@ sg_ll_mode_select6_v2(int sg_fd, bool pf, bool rtd, bool sp, void * paramp, return -1; } if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MODE_SELECT6_CMDLEN; ++k) - pr2ws("%02x ", modes_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(modes_cdb, MODE_SELECT6_CMDLEN, false, + sizeof(b), b)); } if (verbose > 1) { pr2ws(" %s parameter list\n", cdb_s); @@ -492,7 +498,7 @@ sg_ll_mode_select10_v2(int sg_fd, bool pf, bool rtd, bool sp, void * paramp, int param_len, bool noisy, int verbose) { static const char * const cdb_s = "mode select(10)"; - int res, ret, k, sense_cat; + int res, ret, sense_cat; uint8_t modes_cdb[MODE_SELECT10_CMDLEN] = {MODE_SELECT10_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -507,10 +513,11 @@ sg_ll_mode_select10_v2(int sg_fd, bool pf, bool rtd, bool sp, void * paramp, return -1; } if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MODE_SELECT10_CMDLEN; ++k) - pr2ws("%02x ", modes_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(modes_cdb, MODE_SELECT10_CMDLEN, false, + sizeof(b), b)); } if (verbose > 1) { pr2ws(" %s parameter list\n", cdb_s); @@ -787,7 +794,7 @@ sg_ll_log_sense_v2(int sg_fd, bool ppc, bool sp, int pc, int pg_code, bool noisy, int verbose) { static const char * const cdb_s = "log sense"; - int res, ret, k, sense_cat, resid; + int res, ret, sense_cat, resid; uint8_t logs_cdb[LOG_SENSE_CMDLEN] = {LOG_SENSE_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -803,10 +810,11 @@ sg_ll_log_sense_v2(int sg_fd, bool ppc, bool sp, int pc, int pg_code, sg_put_unaligned_be16((int16_t)paramp, logs_cdb + 5); sg_put_unaligned_be16((int16_t)mx_resp_len, logs_cdb + 7); if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < LOG_SENSE_CMDLEN; ++k) - pr2ws("%02x ", logs_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(logs_cdb, LOG_SENSE_CMDLEN, false, + sizeof(b), b)); } if (timeout_secs <= 0) timeout_secs = DEF_PT_TIMEOUT; @@ -867,7 +875,7 @@ sg_ll_log_select(int sg_fd, bool pcr, bool sp, int pc, int pg_code, bool noisy, int verbose) { static const char * const cdb_s = "log select"; - int res, ret, k, sense_cat; + int res, ret, sense_cat; uint8_t logs_cdb[LOG_SELECT_CMDLEN] = {LOG_SELECT_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -882,10 +890,11 @@ sg_ll_log_select(int sg_fd, bool pcr, bool sp, int pc, int pg_code, logs_cdb[3] = (uint8_t)(subpg_code & 0xff); sg_put_unaligned_be16((int16_t)param_len, logs_cdb + 7); if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < LOG_SELECT_CMDLEN; ++k) - pr2ws("%02x ", logs_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(logs_cdb, LOG_SELECT_CMDLEN, false, + sizeof(b), b)); } if ((verbose > 1) && (param_len > 0)) { pr2ws(" %s parameter list\n", cdb_s); @@ -949,7 +958,7 @@ sg_ll_start_stop_unit_pt(struct sg_pt_base * ptvp, bool immed, bool loej, bool start, bool noisy, int verbose) { static const char * const cdb_s = "start stop unit"; - int k, res, ret, sense_cat; + int res, ret, sense_cat; uint8_t ssuBlk[START_STOP_CMDLEN] = {START_STOP_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -964,10 +973,11 @@ sg_ll_start_stop_unit_pt(struct sg_pt_base * ptvp, bool immed, if (start) ssuBlk[4] |= 0x1; if (verbose) { - pr2ws(" %s command:", cdb_s); - for (k = 0; k < (int)sizeof(ssuBlk); ++k) - pr2ws(" %02x", ssuBlk[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(ssuBlk, sizeof(ssuBlk), false, + sizeof(b), b)); } clear_scsi_pt_obj(ptvp); @@ -1001,7 +1011,7 @@ int sg_ll_prevent_allow(int sg_fd, int prevent, bool noisy, int verbose) { static const char * const cdb_s = "prevent allow medium removal"; - int k, res, ret, sense_cat; + int res, ret, sense_cat; uint8_t p_cdb[PREVENT_ALLOW_CMDLEN] = {PREVENT_ALLOW_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -1013,10 +1023,11 @@ sg_ll_prevent_allow(int sg_fd, int prevent, bool noisy, int verbose) } p_cdb[4] |= (prevent & 0x3); if (verbose) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < PREVENT_ALLOW_CMDLEN; ++k) - pr2ws("%02x ", p_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(p_cdb, PREVENT_ALLOW_CMDLEN, false, + sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c index 96558883..71af0358 100644 --- a/lib/sg_cmds_extra.c +++ b/lib/sg_cmds_extra.c @@ -123,7 +123,7 @@ sg_ll_get_lba_status16(int sg_fd, uint64_t start_llba, uint8_t rt, void * resp, int alloc_len, bool noisy, int vb) { static const char * const cdb_s = "Get LBA status(16)"; - int k, res, s_cat, ret; + int res, s_cat, ret; uint8_t getLbaStatCmd[SERVICE_ACTION_IN_16_CMDLEN]; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -136,10 +136,11 @@ sg_ll_get_lba_status16(int sg_fd, uint64_t start_llba, uint8_t rt, sg_put_unaligned_be32((uint32_t)alloc_len, getLbaStatCmd + 10); getLbaStatCmd[14] = rt; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SERVICE_ACTION_IN_16_CMDLEN; ++k) - pr2ws("%02x ", getLbaStatCmd[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(getLbaStatCmd, SERVICE_ACTION_IN_16_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -196,7 +197,7 @@ sg_ll_get_lba_status32(int sg_fd, uint64_t start_llba, uint32_t scan_len, int vb) { static const char * const cdb_s = "Get LBA status(32)"; - int k, res, s_cat, ret; + int res, s_cat, ret; uint8_t gls32_cmd[GLS32_CMD_LEN]; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -211,10 +212,11 @@ sg_ll_get_lba_status32(int sg_fd, uint64_t start_llba, uint32_t scan_len, sg_put_unaligned_be32(element_id, gls32_cmd + 24); sg_put_unaligned_be32((uint32_t)alloc_len, gls32_cmd + 28); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < GLS32_CMD_LEN; ++k) - pr2ws("%02x ", gls32_cmd[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(gls32_cmd, GLS32_CMD_LEN, false, sizeof(b), + b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -269,7 +271,7 @@ sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len, bool extended, bool noisy, int vb) { static const char * const cdb_s = "Report target port groups"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t rtpg_cdb[MAINTENANCE_IN_CMDLEN] = {MAINTENANCE_IN_CMD, REPORT_TGT_PRT_GRP_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -280,10 +282,11 @@ sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len, rtpg_cdb[1] |= 0x20; sg_put_unaligned_be32((uint32_t)mx_resp_len, rtpg_cdb + 6); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MAINTENANCE_IN_CMDLEN; ++k) - pr2ws("%02x ", rtpg_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rtpg_cdb, MAINTENANCE_IN_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -330,7 +333,7 @@ sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, bool noisy, int vb) { static const char * const cdb_s = "Set target port groups"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t stpg_cdb[MAINTENANCE_OUT_CMDLEN] = {MAINTENANCE_OUT_CMD, SET_TGT_PRT_GRP_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -339,10 +342,11 @@ sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, bool noisy, sg_put_unaligned_be32((uint32_t)param_len, stpg_cdb + 6); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MAINTENANCE_OUT_CMDLEN; ++k) - pr2ws("%02x ", stpg_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(stpg_cdb, MAINTENANCE_OUT_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" %s parameter list:\n", cdb_s); hex2stderr((const uint8_t *)paramp, param_len, -1); @@ -382,7 +386,7 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, bool one_seg, int vb) { static const char * const cdb_s = "Report referrals"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t repRef_cdb[SERVICE_ACTION_IN_16_CMDLEN] = {SERVICE_ACTION_IN_16_CMD, REPORT_REFERRALS_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -394,10 +398,11 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, bool one_seg, if (one_seg) repRef_cdb[14] = 0x1; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SERVICE_ACTION_IN_16_CMDLEN; ++k) - pr2ws("%02x ", repRef_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(repRef_cdb, SERVICE_ACTION_IN_16_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -449,7 +454,7 @@ sg_ll_send_diag_pt(struct sg_pt_base * ptvp, int st_code, bool pf_bit, bool noisy, int vb) { static const char * const cdb_s = "Send diagnostic"; - int k, res, ret, s_cat, tmout; + int res, ret, s_cat, tmout; uint8_t senddiag_cdb[SEND_DIAGNOSTIC_CMDLEN] = {SEND_DIAGNOSTIC_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -470,10 +475,11 @@ sg_ll_send_diag_pt(struct sg_pt_base * ptvp, int st_code, bool pf_bit, tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SEND_DIAGNOSTIC_CMDLEN; ++k) - pr2ws("%02x ", senddiag_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(senddiag_cdb, SEND_DIAGNOSTIC_CMDLEN, + false, sizeof(b), b)); if (vb > 1) { if (paramp && param_len) { pr2ws(" %s parameter list:\n", cdb_s); @@ -532,7 +538,7 @@ sg_ll_receive_diag_pt(struct sg_pt_base * ptvp, bool pcv, int pg_code, int * residp, bool noisy, int vb) { int resid = 0; - int k, res, ret, s_cat; + int res, ret, s_cat; static const char * const cdb_s = "Receive diagnostic results"; uint8_t rcvdiag_cdb[RECEIVE_DIAGNOSTICS_CMDLEN] = {RECEIVE_DIAGNOSTICS_CMD, 0, 0, 0, 0, 0}; @@ -544,10 +550,11 @@ sg_ll_receive_diag_pt(struct sg_pt_base * ptvp, bool pcv, int pg_code, sg_put_unaligned_be16((uint16_t)mx_resp_len, rcvdiag_cdb + 3); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < RECEIVE_DIAGNOSTICS_CMDLEN; ++k) - pr2ws("%02x ", rcvdiag_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rcvdiag_cdb, RECEIVE_DIAGNOSTICS_CMDLEN, + false, sizeof(b), b)); } if (timeout_secs <= 0) timeout_secs = DEF_PT_TIMEOUT; @@ -632,7 +639,7 @@ sg_ll_read_defect10(int sg_fd, bool req_plist, bool req_glist, int dl_format, void * resp, int mx_resp_len, bool noisy, int vb) { static const char * const cdb_s = "Read defect(10)"; - int res, k, ret, s_cat; + int res, ret, s_cat; uint8_t rdef_cdb[READ_DEFECT10_CMDLEN] = {READ_DEFECT10_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -649,10 +656,11 @@ sg_ll_read_defect10(int sg_fd, bool req_plist, bool req_glist, int dl_format, return -1; } if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < READ_DEFECT10_CMDLEN; ++k) - pr2ws("%02x ", rdef_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rdef_cdb, READ_DEFECT10_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -699,7 +707,7 @@ sg_ll_read_media_serial_num(int sg_fd, void * resp, int mx_resp_len, bool noisy, int vb) { static const char * const cdb_s = "Read media serial number"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t rmsn_cdb[SERVICE_ACTION_IN_12_CMDLEN] = {SERVICE_ACTION_IN_12_CMD, READ_MEDIA_SERIAL_NUM_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -708,10 +716,11 @@ sg_ll_read_media_serial_num(int sg_fd, void * resp, int mx_resp_len, sg_put_unaligned_be32((uint32_t)mx_resp_len, rmsn_cdb + 6); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SERVICE_ACTION_IN_12_CMDLEN; ++k) - pr2ws("%02x ", rmsn_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rmsn_cdb, SERVICE_ACTION_IN_12_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -759,7 +768,7 @@ sg_ll_report_id_info(int sg_fd, int itype, void * resp, int max_resp_len, bool noisy, int vb) { static const char * const cdb_s = "Report identifying information"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t rii_cdb[MAINTENANCE_IN_CMDLEN] = {MAINTENANCE_IN_CMD, REPORT_IDENTIFYING_INFORMATION_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -770,10 +779,11 @@ sg_ll_report_id_info(int sg_fd, int itype, void * resp, int max_resp_len, rii_cdb[10] |= (itype << 1) & 0xfe; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MAINTENANCE_IN_CMDLEN; ++k) - pr2ws("%02x ", rii_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rii_cdb, MAINTENANCE_IN_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -821,7 +831,7 @@ sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len, bool noisy, int vb) { static const char * const cdb_s = "Set identifying information"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t sii_cdb[MAINTENANCE_OUT_CMDLEN] = {MAINTENANCE_OUT_CMD, SET_IDENTIFYING_INFORMATION_SA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -831,10 +841,11 @@ sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len, sg_put_unaligned_be32((uint32_t)param_len, sii_cdb + 6); sii_cdb[10] |= (itype << 1) & 0xfe; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < MAINTENANCE_OUT_CMDLEN; ++k) - pr2ws("%02x ", sii_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(sii_cdb, MAINTENANCE_OUT_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" %s parameter list:\n", cdb_s); hex2stderr((const uint8_t *)paramp, param_len, -1); @@ -901,7 +912,7 @@ sg_ll_format_unit_v2(int sg_fd, int fmtpinfo, bool longlist, bool fmtdata, bool noisy, int vb) { static const char * const cdb_s = "Format unit"; - int k, res, ret, s_cat, tmout; + int res, ret, s_cat, tmout; uint8_t fu_cdb[FORMAT_UNIT_CMDLEN] = {FORMAT_UNIT_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -921,10 +932,10 @@ sg_ll_format_unit_v2(int sg_fd, int fmtpinfo, bool longlist, bool fmtdata, fu_cdb[4] |= (ffmt & 0x3); tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < 6; ++k) - pr2ws("%02x ", fu_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(fu_cdb, 6, false, sizeof(b), b)); if (vb > 1) { if (param_len > 0) { pr2ws(" %s parameter list:\n", cdb_s); @@ -967,7 +978,7 @@ sg_ll_reassign_blocks(int sg_fd, bool longlba, bool longlist, void * paramp, int param_len, bool noisy, int vb) { static const char * const cdb_s = "Reassign blocks"; - int res, k, ret, s_cat; + int res, ret, s_cat; uint8_t reass_cdb[REASSIGN_BLKS_CMDLEN] = {REASSIGN_BLKS_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -978,10 +989,11 @@ sg_ll_reassign_blocks(int sg_fd, bool longlba, bool longlist, void * paramp, if (longlist) reass_cdb[1] |= 0x1; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < REASSIGN_BLKS_CMDLEN; ++k) - pr2ws("%02x ", reass_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(reass_cdb, REASSIGN_BLKS_CMDLEN, false, + sizeof(b), b)); } if (vb > 1) { pr2ws(" %s parameter list\n", cdb_s); @@ -1022,7 +1034,7 @@ sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, void * resp, int mx_resp_len, bool noisy, int vb) { static const char * const cdb_s = "Persistent reservation in"; - int res, k, ret, s_cat; + int res, ret, s_cat; uint8_t prin_cdb[PERSISTENT_RESERVE_IN_CMDLEN] = {PERSISTENT_RESERVE_IN_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -1033,10 +1045,11 @@ sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, void * resp, sg_put_unaligned_be16((uint16_t)mx_resp_len, prin_cdb + 7); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < PERSISTENT_RESERVE_IN_CMDLEN; ++k) - pr2ws("%02x ", prin_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(prin_cdb, PERSISTENT_RESERVE_IN_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -1085,7 +1098,7 @@ sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope, int param_len, bool noisy, int vb) { static const char * const cdb_s = "Persistent reservation out"; - int res, k, ret, s_cat; + int res, ret, s_cat; uint8_t prout_cdb[PERSISTENT_RESERVE_OUT_CMDLEN] = {PERSISTENT_RESERVE_OUT_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -1097,10 +1110,11 @@ sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope, sg_put_unaligned_be16((uint16_t)param_len, prout_cdb + 7); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < PERSISTENT_RESERVE_OUT_CMDLEN; ++k) - pr2ws("%02x ", prout_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(prout_cdb, PERSISTENT_RESERVE_OUT_CMDLEN, + false, sizeof(b), b)); if (vb > 1) { pr2ws(" %s parameters:\n", cdb_s); hex2stderr((const uint8_t *)paramp, param_len, 0); @@ -1160,7 +1174,7 @@ sg_ll_read_long10(int sg_fd, bool pblock, bool correct, unsigned int lba, int vb) { static const char * const cdb_s = "read long(10)"; - int k, res, s_cat, ret; + int res, s_cat, ret; uint8_t readLong_cdb[READ_LONG10_CMDLEN]; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -1175,10 +1189,11 @@ sg_ll_read_long10(int sg_fd, bool pblock, bool correct, unsigned int lba, sg_put_unaligned_be32((uint32_t)lba, readLong_cdb + 2); sg_put_unaligned_be16((uint16_t)xfer_len, readLong_cdb + 7); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < READ_LONG10_CMDLEN; ++k) - pr2ws("%02x ", readLong_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(readLong_cdb, READ_LONG10_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -1248,7 +1263,7 @@ sg_ll_read_long16(int sg_fd, bool pblock, bool correct, uint64_t llba, int vb) { static const char * const cdb_s = "read long(16)"; - int k, res, s_cat, ret; + int res, s_cat, ret; uint8_t readLong_cdb[SERVICE_ACTION_IN_16_CMDLEN]; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -1264,10 +1279,11 @@ sg_ll_read_long16(int sg_fd, bool pblock, bool correct, uint64_t llba, sg_put_unaligned_be64(llba, readLong_cdb + 2); sg_put_unaligned_be16((uint16_t)xfer_len, readLong_cdb + 12); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SERVICE_ACTION_IN_16_CMDLEN; ++k) - pr2ws("%02x ", readLong_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(readLong_cdb, SERVICE_ACTION_IN_16_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -1337,7 +1353,7 @@ sg_ll_write_long10(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock, int * offsetp, bool noisy, int vb) { static const char * const cdb_s = "write long(10)"; - int k, res, s_cat, ret; + int res, s_cat, ret; uint8_t writeLong_cdb[WRITE_LONG10_CMDLEN]; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -1354,10 +1370,11 @@ sg_ll_write_long10(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock, sg_put_unaligned_be32((uint32_t)lba, writeLong_cdb + 2); sg_put_unaligned_be16((uint16_t)xfer_len, writeLong_cdb + 7); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < (int)sizeof(writeLong_cdb); ++k) - pr2ws("%02x ", writeLong_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(writeLong_cdb, (int)sizeof(writeLong_cdb), + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -1415,7 +1432,7 @@ sg_ll_write_long16(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock, int * offsetp, bool noisy, int vb) { static const char * const cdb_s = "write long(16)"; - int k, res, s_cat, ret; + int res, s_cat, ret; uint8_t writeLong_cdb[SERVICE_ACTION_OUT_16_CMDLEN]; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -1433,10 +1450,11 @@ sg_ll_write_long16(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock, sg_put_unaligned_be64(llba, writeLong_cdb + 2); sg_put_unaligned_be16((uint16_t)xfer_len, writeLong_cdb + 12); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < SERVICE_ACTION_OUT_16_CMDLEN; ++k) - pr2ws("%02x ", writeLong_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(writeLong_cdb, SERVICE_ACTION_OUT_16_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -1510,10 +1528,11 @@ sg_ll_verify10(int sg_fd, int vrprotect, bool dpo, int bytchk, sg_put_unaligned_be32((uint32_t)lba, v_cdb + 2); sg_put_unaligned_be16((uint16_t)veri_len, v_cdb + 7); if (vb > 1) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < VERIFY10_CMDLEN; ++k) - pr2ws("%02x ", v_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(v_cdb, VERIFY10_CMDLEN, + false, sizeof(b), b)); if ((vb > 3) && bytchk && data_out && (data_out_len > 0)) { k = data_out_len > 4104 ? 4104 : data_out_len; pr2ws(" data_out buffer%s\n", @@ -1587,10 +1606,11 @@ sg_ll_verify16(int sg_fd, int vrprotect, bool dpo, int bytchk, uint64_t llba, sg_put_unaligned_be32((uint32_t)veri_len, v_cdb + 10); v_cdb[14] = group_num & 0x1f; if (vb > 1) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < VERIFY16_CMDLEN; ++k) - pr2ws("%02x ", v_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(v_cdb, VERIFY16_CMDLEN, + false, sizeof(b), b)); if ((vb > 3) && bytchk && data_out && (data_out_len > 0)) { k = data_out_len > 4104 ? 4104 : data_out_len; pr2ws(" data_out buffer%s\n", @@ -1716,13 +1736,13 @@ sg_ll_ata_pt(int sg_fd, const uint8_t * cdbp, int cdb_len, slen = sizeof(sense_b); } if (vb) { - pr2ws(" %s cdb: ", cnamep); if (cdb_len < 32) { - for (k = 0; k < cdb_len; ++k) - pr2ws("%02x ", apt_cdb[k]); - pr2ws("\n"); + char d[128]; + + pr2ws(" %s cdb: %s\n", cnamep, + sg_get_command_str(apt_cdb, cdb_len, false, sizeof(d), d)); } else { - pr2ws("\n"); + pr2ws(" %s cdb:\n", cnamep); hex2stderr(apt_cdb, cdb_len, -1); } } @@ -1821,7 +1841,7 @@ sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset, void * resp, int mx_resp_len, bool noisy, int vb) { static const char * const cdb_s = "read buffer(10)"; - int res, k, ret, s_cat; + int res, ret, s_cat; uint8_t rbuf_cdb[READ_BUFFER_CMDLEN] = {READ_BUFFER_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -1832,10 +1852,11 @@ sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset, sg_put_unaligned_be24((uint32_t)buffer_offset, rbuf_cdb + 3); sg_put_unaligned_be24((uint32_t)mx_resp_len, rbuf_cdb + 6); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < READ_BUFFER_CMDLEN; ++k) - pr2ws("%02x ", rbuf_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rbuf_cdb, READ_BUFFER_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -1882,7 +1903,7 @@ sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset, void * paramp, int param_len, bool noisy, int vb) { static const char * const cdb_s = "write buffer"; - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t wbuf_cdb[WRITE_BUFFER_CMDLEN] = {WRITE_BUFFER_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -1893,10 +1914,11 @@ sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset, sg_put_unaligned_be24((uint32_t)buffer_offset, wbuf_cdb + 3); sg_put_unaligned_be24((uint32_t)param_len, wbuf_cdb + 6); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < WRITE_BUFFER_CMDLEN; ++k) - pr2ws("%02x ", wbuf_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(wbuf_cdb, WRITE_BUFFER_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" %s parameter list", cdb_s); if (2 == vb) { @@ -1949,7 +1971,7 @@ sg_ll_write_buffer_v2(int sg_fd, int mode, int m_specific, int buffer_id, uint32_t param_len, int timeout_secs, bool noisy, int vb) { - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t wbuf_cdb[WRITE_BUFFER_CMDLEN] = {WRITE_BUFFER_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -1969,10 +1991,11 @@ sg_ll_write_buffer_v2(int sg_fd, int mode, int m_specific, int buffer_id, sg_put_unaligned_be24(buffer_offset, wbuf_cdb + 3); sg_put_unaligned_be24(param_len, wbuf_cdb + 6); if (vb) { - pr2ws(" Write buffer cdb: "); - for (k = 0; k < WRITE_BUFFER_CMDLEN; ++k) - pr2ws("%02x ", wbuf_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" Write buffer cdb: %s\n", + sg_get_command_str(wbuf_cdb, WRITE_BUFFER_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" Write buffer parameter list%s:\n", ((param_len > 256) ? " (first 256 bytes)" : "")); @@ -2029,7 +2052,7 @@ sg_ll_unmap_v2(int sg_fd, bool anchor, int group_num, int timeout_secs, void * paramp, int param_len, bool noisy, int vb) { static const char * const cdb_s = "unmap"; - int k, res, ret, s_cat, tmout; + int res, ret, s_cat, tmout; uint8_t u_cdb[UNMAP_CMDLEN] = {UNMAP_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -2041,10 +2064,11 @@ sg_ll_unmap_v2(int sg_fd, bool anchor, int group_num, int timeout_secs, u_cdb[6] = group_num & 0x1f; sg_put_unaligned_be16((uint16_t)param_len, u_cdb + 7); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < UNMAP_CMDLEN; ++k) - pr2ws("%02x ", u_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(u_cdb, UNMAP_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" %s parameter list:\n", cdb_s); hex2stderr((const uint8_t *)paramp, param_len, -1); @@ -2083,17 +2107,18 @@ sg_ll_read_block_limits(int sg_fd, void * resp, int mx_resp_len, bool noisy, int vb) { static const char * const cdb_s = "read block limits"; - int k, ret, res, s_cat; + int ret, res, s_cat; uint8_t rl_cdb[READ_BLOCK_LIMITS_CMDLEN] = {READ_BLOCK_LIMITS_CMD, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < READ_BLOCK_LIMITS_CMDLEN; ++k) - pr2ws("%02x ", rl_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(rl_cdb, READ_BLOCK_LIMITS_CMDLEN, + false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) @@ -2140,7 +2165,7 @@ int sg_ll_receive_copy_results(int sg_fd, int sa, int list_id, void * resp, int mx_resp_len, bool noisy, int vb) { - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t rcvcopyres_cdb[THIRD_PARTY_COPY_IN_CMDLEN] = {THIRD_PARTY_COPY_IN_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -2156,10 +2181,11 @@ sg_ll_receive_copy_results(int sg_fd, int sa, int list_id, void * resp, sg_put_unaligned_be32((uint32_t)mx_resp_len, rcvcopyres_cdb + 10); if (vb) { - pr2ws(" %s cdb: ", b); - for (k = 0; k < THIRD_PARTY_COPY_IN_CMDLEN; ++k) - pr2ws("%02x ", rcvcopyres_cdb[k]); - pr2ws("\n"); + char d[128]; + + pr2ws(" %s cdb: %s\n", b, + sg_get_command_str(rcvcopyres_cdb, THIRD_PARTY_COPY_IN_CMDLEN, + false, sizeof(d), d)); } if (NULL == ((ptvp = create_pt_obj(b)))) @@ -2199,7 +2225,7 @@ int sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, bool noisy, int vb) { - int k, res, ret, s_cat; + int res, ret, s_cat; uint8_t xcopy_cdb[THIRD_PARTY_COPY_OUT_CMDLEN] = {THIRD_PARTY_COPY_OUT_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -2210,10 +2236,11 @@ sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, bool noisy, sg_put_unaligned_be32((uint32_t)param_len, xcopy_cdb + 10); if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < THIRD_PARTY_COPY_OUT_CMDLEN; ++k) - pr2ws("%02x ", xcopy_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(xcopy_cdb, THIRD_PARTY_COPY_OUT_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" %s parameter list:\n", cdb_s); hex2stderr((const uint8_t *)paramp, param_len, -1); @@ -2255,7 +2282,7 @@ sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num, int timeout_secs, void * paramp, int param_len, bool noisy, int vb) { - int k, res, ret, s_cat, tmout; + int res, ret, s_cat, tmout; uint8_t xcopy_cdb[THIRD_PARTY_COPY_OUT_CMDLEN] = {THIRD_PARTY_COPY_OUT_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t sense_b[SENSE_BUFF_LEN]; @@ -2286,10 +2313,11 @@ sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num, tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT; if (vb) { - pr2ws(" %s cdb: ", cname); - for (k = 0; k < THIRD_PARTY_COPY_OUT_CMDLEN; ++k) - pr2ws("%02x ", xcopy_cdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cname, + sg_get_command_str(xcopy_cdb, THIRD_PARTY_COPY_OUT_CMDLEN, + false, sizeof(b), b)); if ((vb > 1) && paramp && param_len) { pr2ws(" %s parameter list:\n", cname); hex2stderr((const uint8_t *)paramp, param_len, -1); @@ -2338,7 +2366,7 @@ sg_ll_pre_fetch_x(int sg_fd, bool do_seek10, bool cdb16, bool immed, static const char * const cdb10_name_s = "Pre-fetch(10)"; static const char * const cdb16_name_s = "Pre-fetch(16)"; static const char * const cdb_seek_name_s = "Seek(10)"; - int k, res, s_cat, ret, cdb_len, tmout; + int res, s_cat, ret, cdb_len, tmout; const char *cdb_s; uint8_t preFetchCdb[PRE_FETCH16_CMDLEN]; /* all use longest cdb */ uint8_t sense_b[SENSE_BUFF_LEN]; @@ -2386,10 +2414,10 @@ sg_ll_pre_fetch_x(int sg_fd, bool do_seek10, bool cdb16, bool immed, } tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT; if (vb) { - pr2ws(" %s cdb: ", cdb_s); - for (k = 0; k < cdb_len; ++k) - pr2ws("%02x ", preFetchCdb[k]); - pr2ws("\n"); + char b[128]; + + pr2ws(" %s cdb: %s\n", cdb_s, + sg_get_command_str(preFetchCdb, cdb_len, false, sizeof(b), b)); } if (NULL == ((ptvp = create_pt_obj(cdb_s)))) return -1; diff --git a/lib/sg_lib.c b/lib/sg_lib.c index 2516f450..d688f6eb 100644 --- a/lib/sg_lib.c +++ b/lib/sg_lib.c @@ -157,25 +157,78 @@ sg_set_warnings_strm(FILE * warnings_strm) sg_warnings_strm = warnings_strm; } +/* Take care to minimize printf() parsing delays when printing commands */ +static char bin2hexascii[] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + + +/* Given a SCSI command pointed to by cmdp of sz bytes this function forms + * a SCSI command in ASCII surrounded by square brackets in 'b'. 'b' is at + * least blen bytes long. If cmd_name is true then the command is prefixed + * by its SCSI command name (e.g. "VERIFY(10) [2f ...]". The command is + * shown as spaced separated pairs of hexadecimal digits (i.e. 0-9, a-f). + * Each pair repesents byte. The leftmost pair of digits is cmdp[0] . If + * sz <= 0 then this function tries to guess the length of the command. */ +char * +sg_get_command_str(const uint8_t * cmdp, int sz, bool cmd_name, int blen, + char * b) +{ + int k, j, jj; + + if ((cmdp == NULL) || (b == NULL) || (blen < 1)) + return b; + if (cmd_name && (blen > 16)) { + sg_get_command_name(cmdp, 0, blen, b); + j = (int)strlen(b); + if (j < (blen - 1)) + b[j++] = ' '; + } else + j = 0; + if (j >= blen) + goto fini; + b[j++] = '['; + if (j >= blen) + goto fini; + if (sz <= 0) { + if (SG_VARIABLE_LENGTH_CMD == cmdp[0]) + sz = cmdp[7] + 8; + else + sz = sg_get_command_size(cmdp[0]); + } + jj = j; + for (k = 0; (k < sz) && (j < (blen - 3)); ++k, j += 3, ++cmdp) { + b[j] = bin2hexascii[(*cmdp >> 4) & 0xf]; + b[j + 1] = bin2hexascii[*cmdp & 0xf]; + b[j + 2] = ' '; + } + if (j > jj) + --j; /* don't want trailing space before ']' */ + if (j >= blen) + goto fini; + b[j++] = ']'; +fini: + if (j >= blen) + b[blen - 1] = '\0'; /* truncated string */ + else + b[j] = '\0'; + return b; +} + #define CMD_NAME_LEN 128 void -sg_print_command(const uint8_t * command) +sg_print_command_len(const uint8_t * cmdp, int sz) { - int k, sz; char buff[CMD_NAME_LEN]; - sg_get_command_name(command, 0, CMD_NAME_LEN, buff); - buff[CMD_NAME_LEN - 1] = '\0'; + sg_get_command_str(cmdp, sz, true, sizeof(buff), buff); + pr2ws("%s\n", buff); +} - pr2ws("%s [", buff); - if (SG_VARIABLE_LENGTH_CMD == command[0]) - sz = command[7] + 8; - else - sz = sg_get_command_size(command[0]); - for (k = 0; k < sz; ++k) - pr2ws("%02x ", command[k]); - pr2ws("]\n"); +void +sg_print_command(const uint8_t * cmdp) +{ + sg_print_command_len(cmdp, 0); } /* SCSI Status values */ diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c index 14c009f7..7bec0678 100644 --- a/lib/sg_lib_data.c +++ b/lib/sg_lib_data.c @@ -19,7 +19,7 @@ #include "sg_lib_data.h" -const char * sg_lib_version_str = "2.69 20191204"; +const char * sg_lib_version_str = "2.70 20191226"; /* spc5r22, sbc4r17, zbc2r04 */ @@ -1506,7 +1506,7 @@ const char * sg_lib_pdt_strs[32] = { /* should have 2**5 elements */ const char * sg_lib_transport_proto_strs[] = { - "Fibre Channel Protocol for SCSI (FCP-4)", + "Fibre Channel Protocol for SCSI (FCP-5)", /* now at fcp5r01 */ "SCSI Parallel Interface (SPI-5)", /* obsolete in spc5r01 */ "Serial Storage Architecture SCSI-3 Protocol (SSA-S3P)", "Serial Bus Protocol for IEEE 1394 (SBP-3)", |