diff --git a/doc/sg_rtpg.8 b/doc/sg_rtpg.8 index 786dd12..0fe3de7 100644 --- a/doc/sg_rtpg.8 +++ b/doc/sg_rtpg.8 @@ -22,6 +22,9 @@ decodes the status code and asymmetric access state from each target port group descriptor returned. The default action is not to decode these values. .TP +\fB\-e\fR, \fB\-\-extended\fR +use extended header format for parameter data. +.TP \fB\-h\fR, \fB\-\-help\fR output the usage message then exit. .TP diff --git a/include/sg_cmds_extra.h b/include/sg_cmds_extra.h index 12ee50f..1d08f77 100644 --- a/include/sg_cmds_extra.h +++ b/include/sg_cmds_extra.h @@ -157,8 +157,8 @@ extern int sg_ll_report_id_info(int sg_fd, int itype, void * resp, * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported, * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND, * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */ -extern int sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, - int mx_resp_len, int noisy, int verbose); +extern int sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len, + int extended, int noisy, int verbose); /* Invokes a SCSI SET TARGET PORT GROUPS command. Return of 0 -> success, * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported, diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c index a4ff3b4..914f3ed 100644 --- a/lib/sg_cmds_extra.c +++ b/lib/sg_cmds_extra.c @@ -169,8 +169,8 @@ sg_ll_get_lba_status(int sg_fd, uint64_t start_llba, void * resp, * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND, * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */ int -sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len, int noisy, - int verbose) +sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len, + int extended, int noisy, int verbose) { int k, res, ret, sense_cat; unsigned char rtpgCmdBlk[MAINTENANCE_IN_CMDLEN] = @@ -179,6 +179,9 @@ sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len, int noisy, unsigned char sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; + if (extended) { + rtpgCmdBlk[1] |= 0x20; + } rtpgCmdBlk[6] = (mx_resp_len >> 24) & 0xff; rtpgCmdBlk[7] = (mx_resp_len >> 16) & 0xff; rtpgCmdBlk[8] = (mx_resp_len >> 8) & 0xff; diff --git a/src/sg_rtpg.c b/src/sg_rtpg.c index 471bc29..af695b6 100644 --- a/src/sg_rtpg.c +++ b/src/sg_rtpg.c @@ -42,29 +42,9 @@ static char * version_str = "1.14 20100312"; #define STATUS_CODE_CHANGED_BY_SET 0x1 #define STATUS_CODE_CHANGED_BY_IMPLICIT 0x2 -/* <<<<<<<<<<<<<<< start of test code */ -/* #define TEST_CODE */ - -#ifdef TEST_CODE - -#warning "<<<< TEST_CODE response compiled in >>>>" - -unsigned char dummy_resp[32] = { - 0, 0, 0, 28, - - 0x80, 0x3, 0, 1, 0, 2, 0, 2, - 0, 0, 0, 1, - 0, 0, 0, 2, - - 0x1, 0x3, 0, 2, 0, 0, 0, 1, - 0, 0, 0, 3, -}; - -#endif -/* <<<<<<<<<<<<<<< end of test code */ - static struct option long_options[] = { {"decode", 0, 0, 'd'}, + {"extended", 0, 0, 'e'}, {"help", 0, 0, 'h'}, {"hex", 0, 0, 'H'}, {"raw", 0, 0, 'r'}, @@ -76,11 +56,12 @@ static struct option long_options[] = { static void usage() { fprintf(stderr, "Usage: " - "sg_rtpg [--decode] [--help] [--hex] [--raw] [--verbose] " - "[--version]\n" + "sg_rtpg [--decode] [--extended] [--help] [--hex] [--raw] " + "[--verbose] [--version]\n" " DEVICE\n" " where:\n" " --decode|-d decode status and asym. access state\n" + " --extended|-e use extended header parameter data format\n" " --help|-h print out usage message\n" " --hex|-H print out response in hex\n" " --raw|-r output response in binary to stdout\n" @@ -158,13 +139,14 @@ int main(int argc, char * argv[]) int hex = 0; int raw = 0; int verbose = 0; + int extended = 0; const char * device_name = NULL; int ret = 0; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "dhHrvV", long_options, + c = getopt_long(argc, argv, "dehHrvV", long_options, &option_index); if (c == -1) break; @@ -173,6 +155,9 @@ int main(int argc, char * argv[]) case 'd': decode = 1; break; + case 'e': + extended = 1; + break; case 'h': case '?': usage(); @@ -231,13 +216,9 @@ int main(int argc, char * argv[]) memset(reportTgtGrpBuff, 0x0, sizeof(reportTgtGrpBuff)); trunc = 0; -#ifndef TEST_CODE res = sg_ll_report_tgt_prt_grp(sg_fd, reportTgtGrpBuff, - sizeof(reportTgtGrpBuff), 1, verbose); -#else - memcpy(reportTgtGrpBuff, dummy_resp, sizeof(dummy_resp)); - res = 0; -#endif + sizeof(reportTgtGrpBuff), + extended, 1, verbose); ret = res; if (0 == res) { report_len = (reportTgtGrpBuff[0] << 24) + @@ -263,8 +244,16 @@ int main(int argc, char * argv[]) goto err_out; } printf("Report target port groups:\n"); - for (k = 4, ucp = reportTgtGrpBuff + 4; k < report_len; - k += off, ucp += off) { + ucp = reportTgtGrpBuff + 4; + if (extended) { + if (!(ucp[0] & 0x10)) { + fprintf(stderr, " <