aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--include/sg_lib.h10
-rw-r--r--lib/sg_lib.c1339
-rw-r--r--lib/sg_lib_data.c4
-rw-r--r--src/sg_inq.c135
-rw-r--r--src/sg_inq_data.c6
-rw-r--r--src/sg_persist.c136
-rw-r--r--src/sg_vpd.c135
8 files changed, 782 insertions, 990 deletions
diff --git a/ChangeLog b/ChangeLog
index 530fc436..c34dcfd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.43 [20160423] [svn: r693]
+Changelog for sg3_utils-1.43 [20160426] [svn: r694]
- sg_senddiag: add --timeout=SEC option
- sg_sanitize: add --timeout=SEC option
- sg_format: add --timeout=SEC option
@@ -16,6 +16,7 @@ Changelog for sg3_utils-1.43 [20160423] [svn: r693]
Service buffer information lpages
- add '--pdt=DT' option
- sg_inq: fix potential unbounded loop in --export
+ - update version descriptor list to 20160420
- sg_reassign+sg_write_same: fix ULONG_MAX problem
- sg_turs+sg_requests: make both accept '--num=NUM'
and '--number=NUM' for mutual compatibility
@@ -23,7 +24,9 @@ Changelog for sg3_utils-1.43 [20160423] [svn: r693]
- sg_opcode: add '--enumerate' and '--pdt=' options
- sg_raw: add '--enumerate' option
- sg_lib: add SSC maintenance in/out sa names
- - add read buffer(16) mode names
+ - add read buffer(16) command mode names
+ - add sg_decode_transportid_str()
+ - sg_lib_data: sync asc/ascq codes with T10 20160425
- rescan-scsi-bus.sh: harden code
- clang --analyze static checker clean ups
- shellcheck cleanup on scripts
diff --git a/include/sg_lib.h b/include/sg_lib.h
index 86273eaa..71e73c5e 100644
--- a/include/sg_lib.h
+++ b/include/sg_lib.h
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
@@ -98,7 +99,7 @@ extern "C" {
#define TPROTO_SPI 1
#define TPROTO_SSA 2
#define TPROTO_1394 3
-#define TPROTO_SRP 4
+#define TPROTO_SRP 4 /* SCSI over RDMA */
#define TPROTO_ISCSI 5
#define TPROTO_SAS 6
#define TPROTO_ADT 7
@@ -244,6 +245,13 @@ int sg_lib_pdt_decay(int pdt);
* 'buff'. If 'tpi' out of range yields "bad tpi" string. */
char * sg_get_trans_proto_str(int tpi, int buff_len, char * buff);
+/* Decode TransportID pointed to by 'bp' of length 'bplen'. Place decoded
+ * string output in 'buff' which is also the return value. Each new line
+ * is prefixed by 'leadin'. If leadin NULL treat as "". */
+char * sg_decode_transportid_str(const char * leadin, unsigned char * bp,
+ int bplen, bool only_one, int buff_len,
+ char * buff);
+
/* Returns a designator's type string given 'val' (0 to 15 inclusive),
* otherwise returns NULL. */
const char * sg_get_desig_type_str(int val);
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index a80634c4..675b99e0 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -71,21 +71,21 @@ pr2ws(const char * fmt, ...)
}
#if defined(__GNUC__) || defined(__clang__)
-static int my_snprintf(char * cp, int cp_max_len, const char * fmt, ...)
- __attribute__ ((format (printf, 3, 4)));
+static int scnpr(char * cp, int cp_max_len, const char * fmt, ...)
+ __attribute__ ((format (printf, 3, 4)));
#else
-static int my_snprintf(char * cp, int cp_max_len, const char * fmt, ...);
+static int scnpr(char * cp, int cp_max_len, const char * fmt, ...);
#endif
/* Want safe, 'n += snprintf(b + n, blen - n, ...)' style sequence of
* functions. Returns number number of chars placed in cp excluding the
* trailing null char. So for cp_max_len > 0 the return value is always
- * < cp_max_len; for cp_max_len <= 1 the return value is 0 and no chars
- * are written to cp. Note this means that when cp_max_len = 1, this
- * function assumes that cp[0] is the null character and does nothing
- * (and returns 0). */
+ * < cp_max_len; for cp_max_len <= 1 the return value is 0 and no chars are
+ * written to cp. Note this means that when cp_max_len = 1, this function
+ * assumes that cp[0] is the null character and does nothing (and returns
+ * 0). Linux kernel has a similar function called scnprintf(). */
static int
-my_snprintf(char * cp, int cp_max_len, const char * fmt, ...)
+scnpr(char * cp, int cp_max_len, const char * fmt, ...)
{
va_list args;
int n;
@@ -185,9 +185,9 @@ sg_get_scsi_status_str(int scsi_status, int buff_len, char * buff)
break;
}
if (unknown)
- my_snprintf(buff, buff_len, "Unknown status [0x%x]", scsi_status);
+ scnpr(buff, buff_len, "Unknown status [0x%x]", scsi_status);
else
- my_snprintf(buff, buff_len, "%s", ccp);
+ scnpr(buff, buff_len, "%s", ccp);
}
void
@@ -203,17 +203,17 @@ sg_print_scsi_status(int scsi_status)
/* Get sense key from sense buffer. If successful returns a sense key value
* between 0 and 15. If sense buffer cannot be decode, returns -1 . */
int
-sg_get_sense_key(const unsigned char * sensep, int sense_len)
+sg_get_sense_key(const unsigned char * sbp, int sb_len)
{
- if ((NULL == sensep) || (sense_len < 2))
+ if ((NULL == sbp) || (sb_len < 2))
return -1;
- switch (sensep[0] & 0x7f) {
+ switch (sbp[0] & 0x7f) {
case 0x70:
case 0x71:
- return (sense_len < 3) ? -1 : (sensep[2] & 0xf);
+ return (sb_len < 3) ? -1 : (sbp[2] & 0xf);
case 0x72:
case 0x73:
- return sensep[1] & 0xf;
+ return sbp[1] & 0xf;
default:
return -1;
}
@@ -228,9 +228,9 @@ sg_get_sense_key_str(int sense_key, int buff_len, char * buff)
return buff;
}
if ((sense_key >= 0) && (sense_key < 16))
- my_snprintf(buff, buff_len, "%s", sg_lib_sense_key_desc[sense_key]);
+ scnpr(buff, buff_len, "%s", sg_lib_sense_key_desc[sense_key]);
else
- my_snprintf(buff, buff_len, "invalid value: 0x%x", sense_key);
+ scnpr(buff, buff_len, "invalid value: 0x%x", sense_key);
return buff;
}
@@ -253,10 +253,9 @@ sg_get_asc_ascq_str(int asc, int ascq, int buff_len, char * buff)
(ascq >= ei2p->ascq_min) &&
(ascq <= ei2p->ascq_max)) {
found = true;
- num = my_snprintf(buff, buff_len, "Additional sense: ");
+ num = scnpr(buff, buff_len, "Additional sense: ");
rlen = buff_len - num;
- my_snprintf(buff + num, ((rlen > 0) ? rlen : 0), ei2p->text,
- ascq);
+ scnpr(buff + num, ((rlen > 0) ? rlen : 0), ei2p->text, ascq);
}
}
if (found)
@@ -267,19 +266,18 @@ sg_get_asc_ascq_str(int asc, int ascq, int buff_len, char * buff)
if (eip->asc == asc &&
eip->ascq == ascq) {
found = true;
- my_snprintf(buff, buff_len, "Additional sense: %s", eip->text);
+ scnpr(buff, buff_len, "Additional sense: %s", eip->text);
}
}
if (! found) {
if (asc >= 0x80)
- my_snprintf(buff, buff_len, "vendor specific ASC=%02x, "
- "ASCQ=%02x (hex)", asc, ascq);
+ scnpr(buff, buff_len, "vendor specific ASC=%02x, ASCQ=%02x "
+ "(hex)", asc, ascq);
else if (ascq >= 0x80)
- my_snprintf(buff, buff_len, "ASC=%02x, vendor specific "
- "qualification ASCQ=%02x (hex)", asc, ascq);
+ scnpr(buff, buff_len, "ASC=%02x, vendor specific qualification "
+ "ASCQ=%02x (hex)", asc, ascq);
else
- my_snprintf(buff, buff_len, "ASC=%02x, ASCQ=%02x (hex)", asc,
- ascq);
+ scnpr(buff, buff_len, "ASC=%02x, ASCQ=%02x (hex)", asc, ascq);
}
return buff;
}
@@ -288,19 +286,18 @@ sg_get_asc_ascq_str(int asc, int ascq, int buff_len, char * buff)
* given 'desc_type'. If found return pointer to start of sense data
* descriptor; otherwise (including fixed format sense data) returns NULL. */
const unsigned char *
-sg_scsi_sense_desc_find(const unsigned char * sensep, int sense_len,
+sg_scsi_sense_desc_find(const unsigned char * sbp, int sb_len,
int desc_type)
{
int add_sb_len, add_d_len, desc_len, k;
const unsigned char * descp;
- if ((sense_len < 8) || (0 == (add_sb_len = sensep[7])))
+ if ((sb_len < 8) || (0 == (add_sb_len = sbp[7])))
return NULL;
- if ((sensep[0] < 0x72) || (sensep[0] > 0x73))
+ if ((sbp[0] < 0x72) || (sbp[0] > 0x73))
return NULL;
- add_sb_len = (add_sb_len < (sense_len - 8)) ?
- add_sb_len : (sense_len - 8);
- descp = &sensep[8];
+ add_sb_len = (add_sb_len < (sb_len - 8)) ? add_sb_len : (sb_len - 8);
+ descp = &sbp[8];
for (desc_len = 0, k = 0; k < add_sb_len; k += desc_len) {
descp += desc_len;
add_d_len = (k < (add_sb_len - 1)) ? descp[1]: -1;
@@ -317,7 +314,7 @@ sg_scsi_sense_desc_find(const unsigned char * sensep, int sense_len,
* information field is written out via 'info_outp' (except when it is
* NULL). Handles both fixed and descriptor sense formats. */
int
-sg_get_sense_info_fld(const unsigned char * sensep, int sb_len,
+sg_get_sense_info_fld(const unsigned char * sbp, int sb_len,
uint64_t * info_outp)
{
const unsigned char * bp;
@@ -327,15 +324,15 @@ sg_get_sense_info_fld(const unsigned char * sensep, int sb_len,
*info_outp = 0;
if (sb_len < 7)
return 0;
- switch (sensep[0] & 0x7f) {
+ switch (sbp[0] & 0x7f) {
case 0x70:
case 0x71:
if (info_outp)
- *info_outp = sg_get_unaligned_be32(sensep + 3);
- return (sensep[0] & 0x80) ? 1 : 0;
+ *info_outp = sg_get_unaligned_be32(sbp + 3);
+ return (sbp[0] & 0x80) ? 1 : 0;
case 0x72:
case 0x73:
- bp = sg_scsi_sense_desc_find(sensep, sb_len, 0 /* info desc */);
+ bp = sg_scsi_sense_desc_find(sbp, sb_len, 0 /* info desc */);
if (bp && (0xa == bp[1])) {
ull = sg_get_unaligned_be64(bp + 4);
if (info_outp)
@@ -353,30 +350,30 @@ sg_get_sense_info_fld(const unsigned char * sensep, int sb_len,
* then returns 0. Writes 1 or 0 corresponding to these bits to the
* last three arguments if they are non-NULL. */
int
-sg_get_sense_filemark_eom_ili(const unsigned char * sensep, int sb_len,
+sg_get_sense_filemark_eom_ili(const unsigned char * sbp, int sb_len,
int * filemark_p, int * eom_p, int * ili_p)
{
const unsigned char * bp;
if (sb_len < 7)
return 0;
- switch (sensep[0] & 0x7f) {
+ switch (sbp[0] & 0x7f) {
case 0x70:
case 0x71:
- if (sensep[2] & 0xe0) {
+ if (sbp[2] & 0xe0) {
if (filemark_p)
- *filemark_p = !!(sensep[2] & 0x80);
+ *filemark_p = !!(sbp[2] & 0x80);
if (eom_p)
- *eom_p = !!(sensep[2] & 0x40);
+ *eom_p = !!(sbp[2] & 0x40);
if (ili_p)
- *ili_p = !!(sensep[2] & 0x20);
+ *ili_p = !!(sbp[2] & 0x20);
return 1;
} else
return 0;
case 0x72:
case 0x73:
/* Look for stream commands sense data descriptor */
- bp = sg_scsi_sense_desc_find(sensep, sb_len, 4);
+ bp = sg_scsi_sense_desc_find(sbp, sb_len, 4);
if (bp && (bp[1] >= 2)) {
if (bp[3] & 0xe0) {
if (filemark_p)
@@ -402,7 +399,7 @@ sg_get_sense_filemark_eom_ili(const unsigned char * sensep, int sb_len,
* Hint: if 1 is returned *progress_outp may be multiplied by 100 then
* divided by 65536 to get the percentage completion. */
int
-sg_get_sense_progress_fld(const unsigned char * sensep, int sb_len,
+sg_get_sense_progress_fld(const unsigned char * sbp, int sb_len,
int * progress_outp)
{
const unsigned char * bp;
@@ -410,30 +407,30 @@ sg_get_sense_progress_fld(const unsigned char * sensep, int sb_len,
if (sb_len < 7)
return 0;
- switch (sensep[0] & 0x7f) {
+ switch (sbp[0] & 0x7f) {
case 0x70:
case 0x71:
- sk = (sensep[2] & 0xf);
+ sk = (sbp[2] & 0xf);
if ((sb_len < 18) ||
((SPC_SK_NO_SENSE != sk) && (SPC_SK_NOT_READY != sk)))
return 0;
- if (sensep[15] & 0x80) { /* SKSV bit set */
+ if (sbp[15] & 0x80) { /* SKSV bit set */
if (progress_outp)
- *progress_outp = sg_get_unaligned_be16(sensep + 16);
+ *progress_outp = sg_get_unaligned_be16(sbp + 16);
return 1;
} else
return 0;
case 0x72:
case 0x73:
/* sense key specific progress (0x2) or progress descriptor (0xa) */
- sk = (sensep[1] & 0xf);
+ sk = (sbp[1] & 0xf);
sk_pr = (SPC_SK_NO_SENSE == sk) || (SPC_SK_NOT_READY == sk);
- if (sk_pr && ((bp = sg_scsi_sense_desc_find(sensep, sb_len, 2))) &&
+ if (sk_pr && ((bp = sg_scsi_sense_desc_find(sbp, sb_len, 2))) &&
(0x6 == bp[1]) && (0x80 & bp[4])) {
if (progress_outp)
*progress_outp = sg_get_unaligned_be16(bp + 5);
return 1;
- } else if (((bp = sg_scsi_sense_desc_find(sensep, sb_len, 0xa))) &&
+ } else if (((bp = sg_scsi_sense_desc_find(sbp, sb_len, 0xa))) &&
((0x6 == bp[1]))) {
if (progress_outp)
*progress_outp = sg_get_unaligned_be16(bp + 6);
@@ -449,9 +446,9 @@ char *
sg_get_pdt_str(int pdt, int buff_len, char * buff)
{
if ((pdt < 0) || (pdt > 31))
- my_snprintf(buff, buff_len, "bad pdt");
+ scnpr(buff, buff_len, "bad pdt");
else
- my_snprintf(buff, buff_len, "%s", sg_lib_pdt_strs[pdt]);
+ scnpr(buff, buff_len, "%s", sg_lib_pdt_strs[pdt]);
return buff;
}
@@ -467,12 +464,183 @@ char *
sg_get_trans_proto_str(int tpi, int buff_len, char * buff)
{
if ((tpi < 0) || (tpi > 15))
- my_snprintf(buff, buff_len, "bad tpi");
+ scnpr(buff, buff_len, "bad tpi");
else
- my_snprintf(buff, buff_len, "%s", sg_lib_transport_proto_strs[tpi]);
+ scnpr(buff, buff_len, "%s", sg_lib_transport_proto_strs[tpi]);
return buff;
}
+#define TRANSPORT_ID_MIN_LEN 24
+
+char *
+sg_decode_transportid_str(const char * lip, unsigned char * bp, int bplen,
+ bool only_one, int blen, char * b)
+{
+ int proto_id, num, k, n, normal_len, tpid_format;
+ uint64_t ull;
+ int bump;
+
+ if ((NULL == b) || (blen < 1))
+ return b;
+ else if (1 == blen) {
+ b[0] = '\0';
+ return b;
+ }
+ if (NULL == lip)
+ lip = "";
+ bump = TRANSPORT_ID_MIN_LEN;
+ for (k = 0, n = 0; bplen > 0; ++k, bp += bump, bplen -= bump) {
+ if ((k > 0) && only_one)
+ break;
+ if ((bplen < 24) || (0 != (bplen % 4)))
+ n += scnpr(b + n, blen - n, "%sTransport Id short or not "
+ "multiple of 4 [length=%d]:\n", lip, blen);
+ else
+ n += scnpr(b + n, blen - n, "%sTransport Id of initiator:\n",
+ lip);
+ tpid_format = ((bp[0] >> 6) & 0x3);
+ proto_id = (bp[0] & 0xf);
+ normal_len = (bplen > TRANSPORT_ID_MIN_LEN) ?
+ TRANSPORT_ID_MIN_LEN : bplen;
+ switch (proto_id) {
+ case TPROTO_FCP: /* Fibre channel */
+ n += scnpr(b + n, blen - n, "%s FCP-2 World Wide Name:\n", lip);
+ if (0 != tpid_format)
+ n += scnpr(b + n, blen - n, "%s [Unexpected TPID format: "
+ "%d]\n", lip, tpid_format);
+ n += dStrHexStr((const char *)bp +8, 8, lip, -1, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_SPI: /* Scsi Parallel Interface, obsolete */
+ n += scnpr(b + n, blen - n, "%s Parallel SCSI initiator SCSI "
+ "address: 0x%x\n", lip, sg_get_unaligned_be16(bp + 2));
+ if (0 != tpid_format)
+ n += scnpr(b + n, blen - n, "%s [Unexpected TPID format: "
+ "%d]\n", lip, tpid_format);
+ n += scnpr(b + n, blen - n, "%s relative port number (of "
+ "corresponding target): 0x%x\n", lip,
+ sg_get_unaligned_be16(bp + 6));
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_SSA:
+ n += scnpr(b + n, blen - n, "%s SSA (transport id not "
+ "defined):\n", lip);
+ n += scnpr(b + n, blen - n, "%s TPID format: %d\n", lip,
+ tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_1394: /* IEEE 1394 */
+ n += scnpr(b + n, blen - n, "%s IEEE 1394 EUI-64 name:\n", lip);
+ if (0 != tpid_format)
+ n += scnpr(b + n, blen - n, "%s [Unexpected TPID format: "
+ "%d]\n", lip, tpid_format);
+ n += dStrHexStr((const char *)&bp[8], 8, lip, -1, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_SRP: /* SCSI over RDMA */
+ n += scnpr(b + n, blen - n, "%s RDMA initiator port "
+ "identifier:\n", lip);
+ if (0 != tpid_format)
+ n += scnpr(b + n, blen - n, "%s [Unexpected TPID format: "
+ "%d]\n", lip, tpid_format);
+ n += dStrHexStr((const char *)&bp[8], 16, lip, -1, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_ISCSI:
+ n += scnpr(b + n, blen - n, "%s iSCSI ", lip);
+ num = sg_get_unaligned_be16(bp + 2);
+ if (0 == tpid_format)
+ n += scnpr(b + n, blen - n, "name: %.*s\n", num, &bp[4]);
+ else if (1 == tpid_format)
+ n += scnpr(b + n, blen - n, "world wide unique port id: "
+ "%.*s\n", num, &bp[4]);
+ else {
+ n += scnpr(b + n, blen - n, " [Unexpected TPID format: "
+ "%d]\n", tpid_format);
+ n += dStrHexStr((const char *)bp, num + 4, lip, 0,
+ blen - n, b + n);
+ }
+ bump = (((num + 4) < TRANSPORT_ID_MIN_LEN) ?
+ TRANSPORT_ID_MIN_LEN : num + 4);
+ break;
+ case TPROTO_SAS:
+ ull = sg_get_unaligned_be64(bp + 4);
+ n += scnpr(b + n, blen - n, "%s SAS address: 0x%" PRIx64 "\n",
+ lip, ull);
+ if (0 != tpid_format)
+ n += scnpr(b + n, blen - n, "%s [Unexpected TPID format: "
+ "%d]\n", lip, tpid_format);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_ADT: /* no TransportID defined by T10 yet */
+ n += scnpr(b + n, blen - n, "%s ADT:\n", lip);
+ n += scnpr(b + n, blen - n, "%s TPID format: %d\n", lip,
+ tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_ATA: /* no TransportID defined by T10 yet */
+ n += scnpr(b + n, blen - n, "%s ATAPI:\n", lip);
+ n += scnpr(b + n, blen - n, "%s TPID format: %d\n", lip,
+ tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_UAS: /* no TransportID defined by T10 yet */
+ n += scnpr(b + n, blen - n, "%s UAS:\n", lip);
+ n += scnpr(b + n, blen - n, "%s TPID format: %d\n", lip,
+ tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_SOP:
+ n += scnpr(b + n, blen - n, "%s SOP ", lip);
+ num = sg_get_unaligned_be16(bp + 2);
+ if (0 == tpid_format)
+ n += scnpr(b + n, blen - n, "Routing ID: 0x%x\n", num);
+ else {
+ n += scnpr(b + n, blen - n, " [Unexpected TPID format: "
+ "%d]\n", tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0,
+ blen - n, b + n);
+ }
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_PCIE: /* no TransportID defined by T10 yet */
+ n += scnpr(b + n, blen - n, "%s PCIE:\n", lip);
+ n += scnpr(b + n, blen - n, "%s TPID format: %d\n", lip,
+ tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ case TPROTO_NONE: /* no TransportID defined by T10 */
+ n += scnpr(b + n, blen - n, "%s No specified protocol\n", lip);
+ /* n += dStrHexStr((const char *)bp, ((bplen > 24) ? 24 : bplen),
+ * lip, 0, blen - n, b + n); */
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ default:
+ n += scnpr(b + n, blen - n, "%s unknown protocol id=0x%x "
+ "TPID format=%d\n", lip, proto_id, tpid_format);
+ n += dStrHexStr((const char *)bp, normal_len, lip, 0, blen - n,
+ b + n);
+ bump = TRANSPORT_ID_MIN_LEN;
+ break;
+ }
+ }
+ return b;
+}
+
+
static const char * desig_code_set_str_arr[] =
{
"Reserved [0x0]",
@@ -537,10 +705,9 @@ sg_get_desig_type_str(int val)
}
int
-sg_get_designation_descriptor_str(const char * leadin,
- const unsigned char * ddp, int dd_len,
- int print_assoc, int do_long, int blen,
- char * b)
+sg_get_designation_descriptor_str(const char * lip, const unsigned char * ddp,
+ int dd_len, int print_assoc, int do_long,
+ int blen, char * b)
{
int m, p_id, piv, c_set, assoc, desig_type, ci_off, c_id, d_id, naa;
int vsi, k, n, dlen;
@@ -549,21 +716,19 @@ sg_get_designation_descriptor_str(const char * leadin,
uint64_t id_ext;
char e[64];
const char * cp;
- const char * lip = "";
n = 0;
- if (leadin)
- lip = leadin;
+ if (NULL == lip)
+ lip = "";
if (dd_len < 4) {
- n += my_snprintf(b + n, blen - n, "%sdesignator desc too short: "
- "got length of %d want 4 or more\n", lip, dd_len);
+ n += scnpr(b + n, blen - n, "%sdesignator desc too short: got "
+ "length of %d want 4 or more\n", lip, dd_len);
return n;
}
dlen = ddp[3];
if (dlen > (dd_len - 4)) {
- n += my_snprintf(b + n, blen - n, "%sdesignator too long: says it "
- "is %d bytes, but given %d bytes\n", lip, dlen,
- dd_len - 4);
+ n += scnpr(b + n, blen - n, "%sdesignator too long: says it is %d "
+ "bytes, but given %d bytes\n", lip, dlen, dd_len - 4);
return n;
}
ip = ddp + 4;
@@ -573,19 +738,19 @@ sg_get_designation_descriptor_str(const char * leadin,
assoc = ((ddp[1] >> 4) & 0x3);
desig_type = (ddp[1] & 0xf);
if (print_assoc && ((cp = sg_get_desig_assoc_str(assoc))))
- n += my_snprintf(b + n, blen - n, "%s %s:\n", lip, cp);
- n += my_snprintf(b + n, blen - n, "%s designator type: ", lip);
+ n += scnpr(b + n, blen - n, "%s %s:\n", lip, cp);
+ n += scnpr(b + n, blen - n, "%s designator type: ", lip);
cp = sg_get_desig_type_str(desig_type);
if (cp)
- n += my_snprintf(b + n, blen - n, "%s", cp);
- n += my_snprintf(b + n, blen - n, ", code set: ");
+ n += scnpr(b + n, blen - n, "%s", cp);
+ n += scnpr(b + n, blen - n, ", code set: ");
cp = sg_get_desig_code_set_str(c_set);
if (cp)
- n += my_snprintf(b + n, blen - n, "%s", cp);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%s", cp);
+ n += scnpr(b + n, blen - n, "\n");
if (piv && ((1 == assoc) || (2 == assoc)))
- n += my_snprintf(b + n, blen - n, "%s transport: %s\n", lip,
- sg_get_trans_proto_str(p_id, sizeof(e), e));
+ n += scnpr(b + n, blen - n, "%s transport: %s\n", lip,
+ sg_get_trans_proto_str(p_id, sizeof(e), e));
/* printf(" associated with the %s\n", sdparm_assoc_arr[assoc]); */
switch (desig_type) {
case 0: /* vendor specific */
@@ -597,51 +762,48 @@ sg_get_designation_descriptor_str(const char * leadin,
k = 1;
}
if (k)
- n += my_snprintf(b + n, blen - n, "%s vendor specific: "
- "%.*s\n", lip, dlen, ip);
+ n += scnpr(b + n, blen - n, "%s vendor specific: %.*s\n",
+ lip, dlen, ip);
else {
- n += my_snprintf(b + n, blen - n, "%s vendor specific:\n",
- lip);
+ n += scnpr(b + n, blen - n, "%s vendor specific:\n", lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
}
break;
case 1: /* T10 vendor identification */
- n += my_snprintf(b + n, blen - n, "%s vendor id: %.8s\n", lip,
- ip);
+ n += scnpr(b + n, blen - n, "%s vendor id: %.8s\n", lip, ip);
if (dlen > 8) {
if ((2 == c_set) || (3 == c_set)) { /* ASCII or UTF-8 */
- n += my_snprintf(b + n, blen - n, "%s vendor specific: "
- "%.*s\n", lip, dlen - 8, ip + 8);
+ n += scnpr(b + n, blen - n, "%s vendor specific: "
+ "%.*s\n", lip, dlen - 8, ip + 8);
} else {
- n += my_snprintf(b + n, blen - n, "%s vendor specific: "
- "0x", lip);
+ n += scnpr(b + n, blen - n, "%s vendor specific: 0x",
+ lip);
for (m = 8; m < dlen; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "\n");
}
}
break;
case 2: /* EUI-64 based */
if (! do_long) {
if ((8 != dlen) && (12 != dlen) && (16 != dlen)) {
- n += my_snprintf(b + n, blen - n, "%s << expect 8, 12 "
- "and 16 byte EUI, got %d >>\n", lip, dlen);
+ n += scnpr(b + n, blen - n, "%s << expect 8, 12 and 16 "
+ "byte EUI, got %d >>\n", lip, dlen);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n,
b + n);
break;
}
- n += my_snprintf(b + n, blen - n, "%s 0x", lip);
+ n += scnpr(b + n, blen - n, "%s 0x", lip);
for (m = 0; m < dlen; ++m)
- n += my_snprintf(b + n, blen - n, "%02x", (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "\n");
break;
}
- n += my_snprintf(b + n, blen - n, "%s EUI-64 based %d byte "
- "identifier\n", lip, dlen);
+ n += scnpr(b + n, blen - n, "%s EUI-64 based %d byte "
+ "identifier\n", lip, dlen);
if (1 != c_set) {
- n += my_snprintf(b + n, blen - n, "%s << expected binary "
- "code_set (1) >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected binary code_set "
+ "(1) >>\n", lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
@@ -649,35 +811,35 @@ sg_get_designation_descriptor_str(const char * leadin,
if (16 == dlen) {
ci_off = 8;
id_ext = sg_get_unaligned_be64(ip);
- n += my_snprintf(b + n, blen - n, "%s Identifier extension: "
- "0x%" PRIx64 "\n", lip, id_ext);
+ n += scnpr(b + n, blen - n, "%s Identifier extension: 0x%"
+ PRIx64 "\n", lip, id_ext);
} else if ((8 != dlen) && (12 != dlen)) {
- n += my_snprintf(b + n, blen - n, "%s << can only decode 8, "
- "12 and 16 byte ids >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << can only decode 8, 12 "
+ "and 16 byte ids >>\n", lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
c_id = sg_get_unaligned_be24(ip + ci_off);
- n += my_snprintf(b + n, blen - n, "%s IEEE Company_id: 0x%x\n",
- lip, c_id);
+ n += scnpr(b + n, blen - n, "%s IEEE Company_id: 0x%x\n", lip,
+ c_id);
vsei = 0;
for (m = 0; m < 5; ++m) {
if (m > 0)
vsei <<= 8;
vsei |= ip[ci_off + 3 + m];
}
- n += my_snprintf(b + n, blen - n, "%s Vendor Specific Extension "
- "Identifier: 0x%" PRIx64 "\n", lip, vsei);
+ n += scnpr(b + n, blen - n, "%s Vendor Specific Extension "
+ "Identifier: 0x%" PRIx64 "\n", lip, vsei);
if (12 == dlen) {
d_id = sg_get_unaligned_be32(ip + 8);
- n += my_snprintf(b + n, blen - n, "%s Directory ID: 0x%x\n",
- lip, d_id);
+ n += scnpr(b + n, blen - n, "%s Directory ID: 0x%x\n", lip,
+ d_id);
}
break;
case 3: /* NAA <n> */
if (1 != c_set) {
- n += my_snprintf(b + n, blen - n, "%s << unexpected code "
- "set %d for NAA >>\n", lip, c_set);
+ n += scnpr(b + n, blen - n, "%s << unexpected code set %d "
+ "for NAA >>\n", lip, c_set);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
@@ -685,8 +847,8 @@ sg_get_designation_descriptor_str(const char * leadin,
switch (naa) {
case 2: /* NAA 2: IEEE Extended */
if (8 != dlen) {
- n += my_snprintf(b + n, blen - n, "%s << unexpected NAA "
- "2 identifier length: 0x%x >>\n", lip, dlen);
+ n += scnpr(b + n, blen - n, "%s << unexpected NAA 2 "
+ "identifier length: 0x%x >>\n", lip, dlen);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n,
b + n);
break;
@@ -695,43 +857,42 @@ sg_get_designation_descriptor_str(const char * leadin,
c_id = sg_get_unaligned_be24(ip + 2);
vsi = sg_get_unaligned_be24(ip + 5);
if (do_long) {
- n += my_snprintf(b + n, blen - n, "%s NAA 2, vendor "
- "specific identifier A: 0x%x\n", lip, d_id);
- n += my_snprintf(b + n, blen - n, "%s IEEE Company_id: "
- "0x%x\n", lip, c_id);
- n += my_snprintf(b + n, blen - n, "%s vendor specific "
- "identifier B: 0x%x\n", lip, vsi);
- n += my_snprintf(b + n, blen - n, "%s [0x", lip);
+ n += scnpr(b + n, blen - n, "%s NAA 2, vendor specific "
+ "identifier A: 0x%x\n", lip, d_id);
+ n += scnpr(b + n, blen - n, "%s IEEE Company_id: 0x%x\n",
+ lip, c_id);
+ n += scnpr(b + n, blen - n, "%s vendor specific "
+ "identifier B: 0x%x\n", lip, vsi);
+ n += scnpr(b + n, blen - n, "%s [0x", lip);
for (m = 0; m < 8; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "]\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "]\n");
}
- n += my_snprintf(b + n, blen - n, "%s 0x", lip);
+ n += scnpr(b + n, blen - n, "%s 0x", lip);
for (m = 0; m < 8; ++m)
- n += my_snprintf(b + n, blen - n, "%02x", (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "\n");
break;
case 3: /* NAA 3: Locally assigned */
if (8 != dlen) {
- n += my_snprintf(b + n, blen - n, "%s << unexpected NAA "
- "3 identifier length: 0x%x >>\n", lip, dlen);
+ n += scnpr(b + n, blen - n, "%s << unexpected NAA 3 "
+ "identifier length: 0x%x >>\n", lip, dlen);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n,
b + n);
break;
}
if (do_long)
- n += my_snprintf(b + n, blen - n, "%s NAA 3, Locally "
- "assigned:\n", lip);
- n += my_snprintf(b + n, blen - n, "%s 0x", lip);
+ n += scnpr(b + n, blen - n, "%s NAA 3, Locally "
+ "assigned:\n", lip);
+ n += scnpr(b + n, blen - n, "%s 0x", lip);
for (m = 0; m < 8; ++m)
- n += my_snprintf(b + n, blen - n, "%02x", (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "\n");
break;
case 5: /* NAA 5: IEEE Registered */
if (8 != dlen) {
- n += my_snprintf(b + n, blen - n, "%s << unexpected NAA "
- "5 identifier length: 0x%x >>\n", lip, dlen);
+ n += scnpr(b + n, blen - n, "%s << unexpected NAA 5 "
+ "identifier length: 0x%x >>\n", lip, dlen);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n,
b + n);
break;
@@ -744,27 +905,25 @@ sg_get_designation_descriptor_str(const char * leadin,
vsei |= ip[3 + m];
}
if (do_long) {
- n += my_snprintf(b + n, blen - n, "%s NAA 5, IEEE "
- "Company_id: 0x%x\n", lip, c_id);
- n += my_snprintf(b + n, blen - n, "%s Vendor Specific "
- "Identifier: 0x%" PRIx64 "\n", lip, vsei);
- n += my_snprintf(b + n, blen - n, "%s [0x", lip);
+ n += scnpr(b + n, blen - n, "%s NAA 5, IEEE "
+ "Company_id: 0x%x\n", lip, c_id);
+ n += scnpr(b + n, blen - n, "%s Vendor Specific "
+ "Identifier: 0x%" PRIx64 "\n", lip, vsei);
+ n += scnpr(b + n, blen - n, "%s [0x", lip);
for (m = 0; m < 8; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "]\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "]\n");
} else {
- n += my_snprintf(b + n, blen - n, "%s 0x", lip);
+ n += scnpr(b + n, blen - n, "%s 0x", lip);
for (m = 0; m < 8; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "\n");
}
break;
case 6: /* NAA 6: IEEE Registered extended */
if (16 != dlen) {
- n += my_snprintf(b + n, blen - n, "%s << unexpected NAA "
- "6 identifier length: 0x%x >>\n", lip, dlen);
+ n += scnpr(b + n, blen - n, "%s << unexpected NAA 6 "
+ "identifier length: 0x%x >>\n", lip, dlen);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n,
b + n);
break;
@@ -777,162 +936,158 @@ sg_get_designation_descriptor_str(const char * leadin,
vsei |= ip[3 + m];
}
if (do_long) {
- n += my_snprintf(b + n, blen - n, "%s NAA 6, IEEE "
- "Company_id: 0x%x\n", lip, c_id);
- n += my_snprintf(b + n, blen - n, "%s Vendor Specific "
- "Identifier: 0x%" PRIx64 "\n", lip, vsei);
+ n += scnpr(b + n, blen - n, "%s NAA 6, IEEE "
+ "Company_id: 0x%x\n", lip, c_id);
+ n += scnpr(b + n, blen - n, "%s Vendor Specific "
+ "Identifier: 0x%" PRIx64 "\n", lip, vsei);
vsei = sg_get_unaligned_be64(ip + 8);
- n += my_snprintf(b + n, blen - n, "%s Vendor Specific "
- "Identifier Extension: 0x%" PRIx64 "\n", lip,
+ n += scnpr(b + n, blen - n, "%s Vendor Specific "
+ "Identifier Extension: 0x%" PRIx64 "\n", lip,
vsei);
- n += my_snprintf(b + n, blen - n, "%s [0x", lip);
+ n += scnpr(b + n, blen - n, "%s [0x", lip);
for (m = 0; m < 16; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "]\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "]\n");
} else {
- n += my_snprintf(b + n, blen - n, "%s 0x", lip);
+ n += scnpr(b + n, blen - n, "%s 0x", lip);
for (m = 0; m < 16; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[m]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[m]);
+ n += scnpr(b + n, blen - n, "\n");
}
break;
default:
- n += my_snprintf(b + n, blen - n, "%s << unexpected NAA "
- "[0x%x] >>\n", lip, naa);
+ n += scnpr(b + n, blen - n, "%s << unexpected NAA [0x%x] "
+ ">>\n", lip, naa);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
break;
case 4: /* Relative target port */
if ((1 != c_set) || (1 != assoc) || (4 != dlen)) {
- n += my_snprintf(b + n, blen - n, "%s << expected binary "
- "code_set, target port association, length 4 "
- ">>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected binary "
+ "code_set, target port association, length 4 >>\n",
+ lip);
n += dStrHexStr((const char *)ip, dlen, "", 0, blen - n, b + n);
break;
}
d_id = sg_get_unaligned_be16(ip + 2);
- n += my_snprintf(b + n, blen - n, "%s Relative target port: "
- "0x%x\n", lip, d_id);
+ n += scnpr(b + n, blen - n, "%s Relative target port: 0x%x\n",
+ lip, d_id);
break;
case 5: /* (primary) Target port group */
if ((1 != c_set) || (1 != assoc) || (4 != dlen)) {
- n += my_snprintf(b + n, blen - n, "%s << expected binary "
- "code_set, target port association, length 4 "
- ">>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected binary "
+ "code_set, target port association, length 4 >>\n",
+ lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
d_id = sg_get_unaligned_be16(ip + 2);
- n += my_snprintf(b + n, blen - n, "%s Target port group: 0x%x\n",
- lip, d_id);
+ n += scnpr(b + n, blen - n, "%s Target port group: 0x%x\n", lip,
+ d_id);
break;
case 6: /* Logical unit group */
if ((1 != c_set) || (0 != assoc) || (4 != dlen)) {
- n += my_snprintf(b + n, blen - n, "%s << expected binary "
- "code_set, logical unit association, length "
- "4 >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected binary "
+ "code_set, logical unit association, length 4 >>\n",
+ lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
d_id = sg_get_unaligned_be16(ip + 2);
- n += my_snprintf(b + n, blen - n, "%s Logical unit group: "
- "0x%x\n", lip, d_id);
+ n += scnpr(b + n, blen - n, "%s Logical unit group: 0x%x\n", lip,
+ d_id);
break;
case 7: /* MD5 logical unit identifier */
if ((1 != c_set) || (0 != assoc)) {
- n += my_snprintf(b + n, blen - n, "%s << expected binary "
- "code_set, logical unit association >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected binary "
+ "code_set, logical unit association >>\n", lip);
n += dStrHexStr((const char *)ip, dlen, "", 0, blen - n, b + n);
break;
}
- n += my_snprintf(b + n, blen - n, "%s MD5 logical unit "
- "identifier:\n", lip);
+ n += scnpr(b + n, blen - n, "%s MD5 logical unit identifier:\n",
+ lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
case 8: /* SCSI name string */
if (3 != c_set) { /* accept ASCII as subset of UTF-8 */
if (2 == c_set) {
if (do_long)
- n += my_snprintf(b + n, blen - n, "%s << expected "
- "UTF-8, use ASCII >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected UTF-8, "
+ "use ASCII >>\n", lip);
} else {
- n += my_snprintf(b + n, blen - n, "%s << expected UTF-8 "
- "code_set >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected UTF-8 "
+ "code_set >>\n", lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n,
b + n);
break;
}
}
- n += my_snprintf(b + n, blen - n, "%s SCSI name string:\n", lip);
+ n += scnpr(b + n, blen - n, "%s SCSI name string:\n", lip);
/* does %s print out UTF-8 ok??
* Seems to depend on the locale. Looks ok here with my
* locale setting: en_AU.UTF-8
*/
- n += my_snprintf(b + n, blen - n, "%s %.*s\n", lip,
- dlen, (const char *)ip);
+ n += scnpr(b + n, blen - n, "%s %.*s\n", lip, dlen,
+ (const char *)ip);
break;
case 9: /* Protocol specific port identifier */
/* added in spc4r36, PIV must be set, proto_id indicates */
/* whether UAS (USB) or SOP (PCIe) or ... */
if (! piv)
- n += my_snprintf(b + n, blen - n, " %s >>>> Protocol "
- "specific port identifier expects protocol\n"
- "%s identifier to be valid and it is "
- "not\n", lip, lip);
+ n += scnpr(b + n, blen - n, " %s >>>> Protocol specific "
+ "port identifier expects protocol\n"
+ "%s identifier to be valid and it is not\n",
+ lip, lip);
if (TPROTO_UAS == p_id) {
- n += my_snprintf(b + n, blen - n, "%s USB device address: "
- "0x%x\n", lip, 0x7f & ip[0]);
- n += my_snprintf(b + n, blen - n, "%s USB interface number: "
- "0x%x\n", lip, ip[2]);
+ n += scnpr(b + n, blen - n, "%s USB device address: 0x%x\n",
+ lip, 0x7f & ip[0]);
+ n += scnpr(b + n, blen - n, "%s USB interface number: "
+ "0x%x\n", lip, ip[2]);
} else if (TPROTO_SOP == p_id) {
- n += my_snprintf(b + n, blen - n, "%s PCIe routing ID, bus "
- "number: 0x%x\n", lip, ip[0]);
- n += my_snprintf(b + n, blen - n, "%s function number: "
- "0x%x\n", lip, ip[1]);
- n += my_snprintf(b + n, blen - n, "%s [or device "
- "number: 0x%x, function number: 0x%x]\n", lip,
- (0x1f & (ip[1] >> 3)), 0x7 & ip[1]);
+ n += scnpr(b + n, blen - n, "%s PCIe routing ID, bus "
+ "number: 0x%x\n", lip, ip[0]);
+ n += scnpr(b + n, blen - n, "%s function number: 0x%x\n",
+ lip, ip[1]);
+ n += scnpr(b + n, blen - n, "%s [or device number: "
+ "0x%x, function number: 0x%x]\n", lip,
+ (0x1f & (ip[1] >> 3)), 0x7 & ip[1]);
} else
- n += my_snprintf(b + n, blen - n, "%s >>>> unexpected "
- "protocol indentifier: %s\n%s with "
- "Protocol specific port identifier\n", lip,
- sg_get_trans_proto_str(p_id, sizeof(e), e), lip);
+ n += scnpr(b + n, blen - n, "%s >>>> unexpected protocol "
+ "indentifier: %s\n%s with Protocol specific "
+ "port identifier\n", lip,
+ sg_get_trans_proto_str(p_id, sizeof(e), e), lip);
break;
case 0xa: /* UUID identifier */
if (1 != c_set) {
- n += my_snprintf(b + n, blen - n, "%s << expected binary "
- "code_set >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected binary "
+ "code_set >>\n", lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
if ((1 != ((ip[0] >> 4) & 0xf)) || (18 != dlen)) {
- n += my_snprintf(b + n, blen - n, "%s << expected locally "
- "assigned UUID, 16 bytes long >>\n", lip);
+ n += scnpr(b + n, blen - n, "%s << expected locally "
+ "assigned UUID, 16 bytes long >>\n", lip);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
- n += my_snprintf(b + n, blen - n, "%s Locally assigned UUID: ",
- lip);
+ n += scnpr(b + n, blen - n, "%s Locally assigned UUID: ", lip);
for (m = 0; m < 16; ++m) {
if ((4 == m) || (6 == m) || (8 == m) || (10 == m))
- n += my_snprintf(b + n, blen - n, "-");
- n += my_snprintf(b + n, blen - n, "%02x", (unsigned int)ip[2 + m]);
+ n += scnpr(b + n, blen - n, "-");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[2 + m]);
}
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "\n");
if (do_long) {
- n += my_snprintf(b + n, blen - n, "%s [0x", lip);
+ n += scnpr(b + n, blen - n, "%s [0x", lip);
for (m = 0; m < 16; ++m)
- n += my_snprintf(b + n, blen - n, "%02x",
- (unsigned int)ip[2 + m]);
- n += my_snprintf(b + n, blen - n, "]\n");
+ n += scnpr(b + n, blen - n, "%02x", (unsigned int)ip[2 + m]);
+ n += scnpr(b + n, blen - n, "]\n");
}
break;
default: /* reserved */
- n += my_snprintf(b + n, blen - n, "%s reserved "
- "designator=0x%x\n", lip, desig_type);
+ n += scnpr(b + n, blen - n, "%s reserved designator=0x%x\n", lip,
+ desig_type);
n += dStrHexStr((const char *)ip, dlen, lip, 0, blen - n, b + n);
break;
}
@@ -940,83 +1095,77 @@ sg_get_designation_descriptor_str(const char * leadin,
}
static int
-decode_sks(const char * leadin, const unsigned char * descp, int add_d_len,
+decode_sks(const char * lip, const unsigned char * descp, int add_d_len,
int sense_key, bool * processedp, int blen, char * b)
{
int progress, pr, rem, n;
- const char * lip = "";
n = 0;
- if (leadin)
- lip = leadin;
+ if (NULL == lip)
+ lip = "";
switch (sense_key) {
case SPC_SK_ILLEGAL_REQUEST:
if (add_d_len < 6) {
- n += my_snprintf(b + n, blen - n, "Field pointer: ");
+ n += scnpr(b + n, blen - n, "Field pointer: ");
goto too_short;
}
/* abbreviate to fit on one line */
- n += my_snprintf(b + n, blen - n, "Field pointer:\n");
- n += my_snprintf(b + n, blen - n, "%s Error in %s: byte %d",
- lip, (descp[4] & 0x40) ? "Command" :
+ n += scnpr(b + n, blen - n, "Field pointer:\n");
+ n += scnpr(b + n, blen - n, "%s Error in %s: byte %d", lip,
+ (descp[4] & 0x40) ? "Command" :
"Data parameters",
sg_get_unaligned_be16(descp + 5));
if (descp[4] & 0x08) {
- n += my_snprintf(b + n, blen - n, " bit %d\n",
- descp[4] & 0x07);
+ n += scnpr(b + n, blen - n, " bit %d\n", descp[4] & 0x07);
} else
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "\n");
break;
case SPC_SK_HARDWARE_ERROR:
case SPC_SK_MEDIUM_ERROR:
case SPC_SK_RECOVERED_ERROR:
- n += my_snprintf(b + n, blen - n, "Actual retry count: ");
+ n += scnpr(b + n, blen - n, "Actual retry count: ");
if (add_d_len < 6)
goto too_short;
- n += my_snprintf(b + n, blen - n,"%u\n",
- sg_get_unaligned_be16(descp + 5));
+ n += scnpr(b + n, blen - n,"%u\n", sg_get_unaligned_be16(descp + 5));
break;
case SPC_SK_NO_SENSE:
case SPC_SK_NOT_READY:
- n += my_snprintf(b + n, blen - n, "Progress indication: ");
+ n += scnpr(b + n, blen - n, "Progress indication: ");
if (add_d_len < 6)
goto too_short;
progress = sg_get_unaligned_be16(descp + 5);
pr = (progress * 100) / 65536;
rem = ((progress * 100) % 65536) / 656;
- n += my_snprintf(b + n, blen - n, "%d.%02d%%\n", pr, rem);
+ n += scnpr(b + n, blen - n, "%d.%02d%%\n", pr, rem);
break;
case SPC_SK_COPY_ABORTED:
- n += my_snprintf(b + n, blen - n, "Segment pointer:\n");
+ n += scnpr(b + n, blen - n, "Segment pointer:\n");
if (add_d_len < 6)
goto too_short;
- n += my_snprintf(b + n, blen - n, "%s Relative to start of "
- "%s, byte %d", lip,
- (descp[4] & 0x20) ? "segment descriptor" :
- "parameter list",
- sg_get_unaligned_be16(descp + 5));
+ n += scnpr(b + n, blen - n, "%s Relative to start of %s, byte "
+ "%d", lip, (descp[4] & 0x20) ? "segment descriptor" :
+ "parameter list",
+ sg_get_unaligned_be16(descp + 5));
if (descp[4] & 0x08)
- n += my_snprintf(b + n, blen - n, " bit %d\n",
- descp[4] & 0x07);
+ n += scnpr(b + n, blen - n, " bit %d\n", descp[4] & 0x07);
else
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "\n");
break;
case SPC_SK_UNIT_ATTENTION:
- n += my_snprintf(b + n, blen - n, "Unit attention condition "
- "queue:\n");
- n += my_snprintf(b + n, blen - n, "%s overflow flag is %d\n",
- lip, !!(descp[4] & 0x1));
+ n += scnpr(b + n, blen - n, "Unit attention condition queue:\n");
+ n += scnpr(b + n, blen - n, "%s overflow flag is %d\n", lip,
+ !!(descp[4] & 0x1));
break;
default:
- n += my_snprintf(b + n, blen - n, "Sense_key: 0x%x "
- "unexpected\n", sense_key);
+ n += scnpr(b + n, blen - n, "Sense_key: 0x%x unexpected\n",
+ sense_key);
*processedp = false;
break;
}
return n;
too_short:
- n += my_snprintf(b + n, blen - n, "%s\n", " >> descriptor too short");
+ n += scnpr(b + n, blen - n, "%s\n", " >> descriptor too short");
*processedp = false;
return n;
}
@@ -1033,25 +1182,25 @@ decode_tpgs_state(int st, char * b, int blen)
{
switch (st) {
case TPGS_STATE_OPTIMIZED:
- return my_snprintf(b, blen, "active/optimized");
+ return scnpr(b, blen, "active/optimized");
case TPGS_STATE_NONOPTIMIZED:
- return my_snprintf(b, blen, "active/non optimized");
+ return scnpr(b, blen, "active/non optimized");
case TPGS_STATE_STANDBY:
- return my_snprintf(b, blen, "standby");
+ return scnpr(b, blen, "standby");
case TPGS_STATE_UNAVAILABLE:
- return my_snprintf(b, blen, "unavailable");
+ return scnpr(b, blen, "unavailable");
case TPGS_STATE_OFFLINE:
- return my_snprintf(b, blen, "offline");
+ return scnpr(b, blen, "offline");
case TPGS_STATE_TRANSITIONING:
- return my_snprintf(b, blen, "transitioning between states");
+ return scnpr(b, blen, "transitioning between states");
default:
- return my_snprintf(b, blen, "unknown: 0x%x", st);
+ return scnpr(b, blen, "unknown: 0x%x", st);
}
}
static int
uds_referral_descriptor_str(char * b, int blen, const unsigned char * dp,
- int alen, const char * leadin)
+ int alen, const char * lip)
{
int n = 0;
int dlen = alen - 2;
@@ -1059,33 +1208,32 @@ uds_referral_descriptor_str(char * b, int blen, const unsigned char * dp,
const unsigned char * tp;
uint64_t ull;
char c[40];
- const char * lip = "";
- if (leadin)
- lip = leadin;
- n += my_snprintf(b + n, blen - n, "%s Not all referrals: %d\n", lip,
- !!(dp[2] & 0x1));
+ if (NULL == lip)
+ lip = "";
+ n += scnpr(b + n, blen - n, "%s Not all referrals: %d\n", lip,
+ !!(dp[2] & 0x1));
dp += 4;
for (k = 0, f = 1; (k + 4) < dlen; k += g, dp += g, ++f) {
tpgd = dp[3];
g = (tpgd * 4) + 20;
- n += my_snprintf(b + n, blen - n, "%s Descriptor %d\n", lip, f);
+ n += scnpr(b + n, blen - n, "%s Descriptor %d\n", lip, f);
if ((k + g) > dlen) {
- n += my_snprintf(b + n, blen - n, "%s truncated descriptor, "
- "stop\n", lip);
+ n += scnpr(b + n, blen - n, "%s truncated descriptor, "
+ "stop\n", lip);
return n;
}
ull = sg_get_unaligned_be64(dp + 4);
- n += my_snprintf(b + n, blen - n, "%s first uds LBA: 0x%" PRIx64
- "\n", lip, ull);
+ n += scnpr(b + n, blen - n, "%s first uds LBA: 0x%" PRIx64 "\n",
+ lip, ull);
ull = sg_get_unaligned_be64(dp + 12);
- n += my_snprintf(b + n, blen - n, "%s last uds LBA: 0x%" PRIx64
- "\n", lip, ull);
+ n += scnpr(b + n, blen - n, "%s last uds LBA: 0x%" PRIx64 "\n",
+ lip, ull);
for (j = 0; j < tpgd; ++j) {
tp = dp + 20 + (j * 4);
decode_tpgs_state(tp[0] & 0xf, c, sizeof(c));
- n += my_snprintf(b + n, blen - n, "%s tpg: %d state: "
- "%s\n", lip, sg_get_unaligned_be16(tp + 2), c);
+ n += scnpr(b + n, blen - n, "%s tpg: %d state: %s\n",
+ lip, sg_get_unaligned_be16(tp + 2), c);
}
}
return n;
@@ -1103,15 +1251,13 @@ static const char * dd_usage_reason_str_arr[] = {
/* Decode descriptor format sense descriptors (assumes sense buffer is
* in descriptor format) */
int
-sg_get_sense_descriptors_str(const char * leadin,
- const unsigned char * sense_buffer, int sb_len,
- int blen, char * b)
+sg_get_sense_descriptors_str(const char * lip, const unsigned char * sbp,
+ int sb_len, int blen, char * b)
{
int add_sb_len, add_d_len, desc_len, k, j, sense_key;
int n, progress, pr, rem;
bool processed;
const unsigned char * descp;
- const char * lip = "";
const char * dtsp = " >> descriptor too short";
const char * eccp = "Extended copy command";
const char * ddp = "destination device";
@@ -1120,174 +1266,168 @@ sg_get_sense_descriptors_str(const char * leadin,
if ((NULL == b) || (blen <= 0))
return 0;
b[0] = '\0';
- if (leadin) {
- lip = leadin;
- snprintf(z, sizeof(z), "%.60s ", lip);
- } else
- snprintf(z, sizeof(z), " ");
- if ((sb_len < 8) || (0 == (add_sb_len = sense_buffer[7])))
+ if (lip)
+ scnpr(z, sizeof(z), "%.60s ", lip);
+ else
+ scnpr(z, sizeof(z), " ");
+ if ((sb_len < 8) || (0 == (add_sb_len = sbp[7])))
return 0;
add_sb_len = (add_sb_len < (sb_len - 8)) ? add_sb_len : (sb_len - 8);
- sense_key = (sense_buffer[1] & 0xf);
+ sense_key = (sbp[1] & 0xf);
- for (descp = (sense_buffer + 8), k = 0, n = 0;
+ for (descp = (sbp + 8), k = 0, n = 0;
(k < add_sb_len) && (n < blen);
k += desc_len, descp += desc_len) {
add_d_len = (k < (add_sb_len - 1)) ? descp[1] : -1;
if ((k + add_d_len + 2) > add_sb_len)
add_d_len = add_sb_len - k - 2;
desc_len = add_d_len + 2;
- n += my_snprintf(b + n, blen - n, "%s Descriptor type: ", lip);
+ n += scnpr(b + n, blen - n, "%s Descriptor type: ", lip);
processed = true;
switch (descp[0]) {
case 0:
- n += my_snprintf(b + n, blen - n, "Information: ");
+ n += scnpr(b + n, blen - n, "Information: ");
if ((add_d_len >= 10) && (0x80 & descp[2])) {
- n += my_snprintf(b + n, blen - n, "0x");
+ n += scnpr(b + n, blen - n, "0x");
for (j = 0; j < 8; ++j)
- n += my_snprintf(b + n, blen - n, "%02x", descp[4 + j]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", descp[4 + j]);
+ n += scnpr(b + n, blen - n, "\n");
} else {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
}
break;
case 1:
- n += my_snprintf(b + n, blen - n, "Command specific: ");
+ n += scnpr(b + n, blen - n, "Command specific: ");
if (add_d_len >= 10) {
- n += my_snprintf(b + n, blen - n, "0x");
+ n += scnpr(b + n, blen - n, "0x");
for (j = 0; j < 8; ++j)
- n += my_snprintf(b + n, blen - n, "%02x", descp[4 + j]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", descp[4 + j]);
+ n += scnpr(b + n, blen - n, "\n");
} else {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
}
break;
case 2: /* Sense Key Specific */
- n += my_snprintf(b + n, blen - n, "Sense key specific: ");
+ n += scnpr(b + n, blen - n, "Sense key specific: ");
n += decode_sks(lip, descp, add_d_len, sense_key, &processed,
blen - n, b + n);
break;
case 3:
- n += my_snprintf(b + n, blen - n, "Field replaceable unit code: ");
+ n += scnpr(b + n, blen - n, "Field replaceable unit code: ");
if (add_d_len >= 2)
- n += my_snprintf(b + n, blen - n, "0x%x\n", descp[3]);
+ n += scnpr(b + n, blen - n, "0x%x\n", descp[3]);
else {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
}
break;
case 4:
- n += my_snprintf(b + n, blen - n, "Stream commands: ");
+ n += scnpr(b + n, blen - n, "Stream commands: ");
if (add_d_len >= 2) {
if (descp[3] & 0x80)
- n += my_snprintf(b + n, blen - n, "FILEMARK");
+ n += scnpr(b + n, blen - n, "FILEMARK");
if (descp[3] & 0x40)
- n += my_snprintf(b + n, blen - n, "End Of Medium (EOM)");
+ n += scnpr(b + n, blen - n, "End Of Medium (EOM)");
if (descp[3] & 0x20)
- n += my_snprintf(b + n, blen - n, "Incorrect Length "
- "Indicator (ILI)");
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "Incorrect Length Indicator "
+ "(ILI)");
+ n += scnpr(b + n, blen - n, "\n");
} else {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
}
break;
case 5:
- n += my_snprintf(b + n, blen - n, "Block commands: ");
+ n += scnpr(b + n, blen - n, "Block commands: ");
if (add_d_len >= 2)
- n += my_snprintf(b + n, blen - n, "Incorrect Length "
- "Indicator (ILI) %s\n",
- (descp[3] & 0x20) ? "set" : "clear");
+ n += scnpr(b + n, blen - n, "Incorrect Length Indicator "
+ "(ILI) %s\n", (descp[3] & 0x20) ? "set" : "clear");
else {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
}
break;
case 6:
- n += my_snprintf(b + n, blen - n, "OSD object identification\n");
+ n += scnpr(b + n, blen - n, "OSD object identification\n");
processed = false;
break;
case 7:
- n += my_snprintf(b + n, blen - n, "OSD response integrity check "
+ n += scnpr(b + n, blen - n, "OSD response integrity check "
"value\n");
processed = false;
break;
case 8:
- n += my_snprintf(b + n, blen - n, "OSD attribute "
- "identification\n");
+ n += scnpr(b + n, blen - n, "OSD attribute identification\n");
processed = false;
break;
case 9: /* this is defined in SAT (SAT-2) */
- n += my_snprintf(b + n, blen - n, "ATA Status Return: ");
+ n += scnpr(b + n, blen - n, "ATA Status Return: ");
if (add_d_len >= 12) {
int extend, count;
extend = descp[2] & 1;
count = descp[5] + (extend ? (descp[4] << 8) : 0);
- n += my_snprintf(b + n, blen - n, "extend=%d error=0x%x "
- "\n%s count=0x%x ", extend,
- descp[3], lip, count);
+ n += scnpr(b + n, blen - n, "extend=%d error=0x%x \n%s"
+ " count=0x%x ", extend, descp[3], lip,
+ count);
if (extend)
- n += my_snprintf(b + n, blen - n,
- "lba=0x%02x%02x%02x%02x%02x%02x ",
- descp[10], descp[8], descp[6],
- descp[11], descp[9], descp[7]);
+ n += scnpr(b + n, blen - n,
+ "lba=0x%02x%02x%02x%02x%02x%02x ",
+ descp[10], descp[8], descp[6], descp[11],
+ descp[9], descp[7]);
else
- n += my_snprintf(b + n, blen - n,
- "lba=0x%02x%02x%02x ",
- descp[11], descp[9], descp[7]);
- n += my_snprintf(b + n, blen - n, "device=0x%x status=0x%x\n",
- descp[12], descp[13]);
+ n += scnpr(b + n, blen - n, "lba=0x%02x%02x%02x ",
+ descp[11], descp[9], descp[7]);
+ n += scnpr(b + n, blen - n, "device=0x%x status=0x%x\n",
+ descp[12], descp[13]);
} else {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
}
break;
case 0xa:
/* Added in SPC-4 rev 17, became 'Another ...' in rev 34 */
- n += my_snprintf(b + n, blen - n, "Another progress "
- "indication: ");
+ n += scnpr(b + n, blen - n, "Another progress indication: ");
if (add_d_len < 6) {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
break;
}
progress = sg_get_unaligned_be16(descp + 6);
pr = (progress * 100) / 65536;
rem = ((progress * 100) % 65536) / 656;
- n += my_snprintf(b + n, blen - n, "%d.02%d%%\n", pr, rem);
- n += my_snprintf(b + n, blen - n, "%s [sense_key=0x%x "
- "asc,ascq=0x%x,0x%x]\n", lip, descp[2], descp[3],
- descp[4]);
+ n += scnpr(b + n, blen - n, "%d.02%d%%\n", pr, rem);
+ n += scnpr(b + n, blen - n, "%s [sense_key=0x%x "
+ "asc,ascq=0x%x,0x%x]\n", lip, descp[2], descp[3],
+ descp[4]);
break;
case 0xb: /* Added in SPC-4 rev 23, defined in SBC-3 rev 22 */
- n += my_snprintf(b + n, blen - n, "User data segment referral: ");
+ n += scnpr(b + n, blen - n, "User data segment referral: ");
if (add_d_len < 2) {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
break;
}
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "\n");
n += uds_referral_descriptor_str(b + n, blen - n, descp,
add_d_len, lip);
break;
case 0xc: /* Added in SPC-4 rev 28 */
- n += my_snprintf(b + n, blen - n, "Forwarded sense data\n");
+ n += scnpr(b + n, blen - n, "Forwarded sense data\n");
if (add_d_len < 2) {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
break;
}
- n += my_snprintf(b + n, blen - n, "%s FSDT: %s\n", lip,
- (descp[2] & 0x80) ? "set" : "clear");
+ n += scnpr(b + n, blen - n, "%s FSDT: %s\n", lip,
+ (descp[2] & 0x80) ? "set" : "clear");
j = descp[2] & 0xf;
- n += my_snprintf(b + n, blen - n, "%s Sense data source: ",
- lip);
+ n += scnpr(b + n, blen - n, "%s Sense data source: ", lip);
switch (j) {
case 0:
- n += my_snprintf(b + n, blen - n, "%s source device\n", eccp);
+ n += scnpr(b + n, blen - n, "%s source device\n", eccp);
break;
case 1:
case 2:
@@ -1296,99 +1436,93 @@ sg_get_sense_descriptors_str(const char * leadin,
case 5:
case 6:
case 7:
- n += my_snprintf(b + n, blen - n, "%s %s %d\n", eccp, ddp,
- j - 1);
+ n += scnpr(b + n, blen - n, "%s %s %d\n", eccp, ddp, j - 1);
break;
default:
- n += my_snprintf(b + n, blen - n, "unknown [%d]\n", j);
+ n += scnpr(b + n, blen - n, "unknown [%d]\n", j);
}
{
char c[480];
sg_get_scsi_status_str(descp[3], sizeof(c) - 1, c);
c[sizeof(c) - 1] = '\0';
- n += my_snprintf(b + n, blen - n, "%s Forwarded status: "
- "%s\n", lip, c);
+ n += scnpr(b + n, blen - n, "%s Forwarded status: %s\n",
+ lip, c);
if (add_d_len > 2) {
/* recursing; hope not to get carried away */
- n += my_snprintf(b + n, blen - n, "%s vvvvvvvvvvvvvvvv\n",
- lip);
+ n += scnpr(b + n, blen - n, "%s vvvvvvvvvvvvvvvv\n", lip);
sg_get_sense_str(lip, descp + 4, add_d_len - 2, 0,
sizeof(c), c);
- n += my_snprintf(b + n, blen - n, "%s", c);
- n += my_snprintf(b + n, blen - n, "%s ^^^^^^^^^^^^^^^^\n",
- lip);
+ n += scnpr(b + n, blen - n, "%s", c);
+ n += scnpr(b + n, blen - n, "%s ^^^^^^^^^^^^^^^^\n", lip);
}
}
break;
case 0xd: /* Added in SBC-3 rev 36d */
/* this descriptor combines descriptors 0, 1, 2 and 3 */
- n += my_snprintf(b + n, blen - n, "Direct-access block device\n");
+ n += scnpr(b + n, blen - n, "Direct-access block device\n");
if (add_d_len < 28) {
- n += my_snprintf(b + n, blen - n, "%s\n", dtsp);
+ n += scnpr(b + n, blen - n, "%s\n", dtsp);
processed = false;
break;
}
if (0x20 & descp[2])
- n += my_snprintf(b + n, blen - n, "%s ILI (incorrect "
- "length indication) set\n", lip);
+ n += scnpr(b + n, blen - n, "%s ILI (incorrect length "
+ "indication) set\n", lip);
if (0x80 & descp[4]) {
- n += my_snprintf(b + n, blen - n, "%s Sense key "
- "specific: ", lip);
+ n += scnpr(b + n, blen - n, "%s Sense key specific: ",
+ lip);
n += decode_sks(lip, descp, add_d_len, sense_key, &processed,
blen - n, b + n);
}
- n += my_snprintf(b + n, blen - n, "%s Field replaceable unit "
- "code: 0x%x\n", lip, descp[7]);
+ n += scnpr(b + n, blen - n, "%s Field replaceable unit code: "
+ "0x%x\n", lip, descp[7]);
if (0x80 & descp[2]) {
- n += my_snprintf(b + n, blen - n, "%s Information: 0x",
- lip);
+ n += scnpr(b + n, blen - n, "%s Information: 0x", lip);
for (j = 0; j < 8; ++j)
- n += my_snprintf(b + n, blen - n, "%02x", descp[8 + j]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", descp[8 + j]);
+ n += scnpr(b + n, blen - n, "\n");
}
- n += my_snprintf(b + n, blen - n, "%s Command specific: 0x",
- lip);
+ n += scnpr(b + n, blen - n, "%s Command specific: 0x", lip);
for (j = 0; j < 8; ++j)
- n += my_snprintf(b + n, blen - n, "%02x", descp[16 + j]);
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "%02x", descp[16 + j]);
+ n += scnpr(b + n, blen - n, "\n");
break;
case 0xe: /* Added in SPC-5 rev 6 (for bind/unbind) */
- n += my_snprintf(b + n, blen - n, "Device designation\n");
+ n += scnpr(b + n, blen - n, "Device designation\n");
j = (int)(sizeof(dd_usage_reason_str_arr) /
sizeof(dd_usage_reason_str_arr[0]));
if (descp[3] < j)
- n += my_snprintf(b + n, blen - n, "%s Usage reason: %s\n",
- lip, dd_usage_reason_str_arr[descp[3]]);
+ n += scnpr(b + n, blen - n, "%s Usage reason: %s\n", lip,
+ dd_usage_reason_str_arr[descp[3]]);
else
- n += my_snprintf(b + n, blen - n, "%s Usage reason: "
- "reserved[%d]\n", lip, descp[3]);
+ n += scnpr(b + n, blen - n, "%s Usage reason: "
+ "reserved[%d]\n", lip, descp[3]);
n += sg_get_designation_descriptor_str(z, descp + 4, descp[1] - 2,
1, 0, blen - n, b + n);
break;
default:
if (descp[0] >= 0x80)
- n += my_snprintf(b + n, blen - n, "Vendor specific [0x%x]\n",
- descp[0]);
+ n += scnpr(b + n, blen - n, "Vendor specific [0x%x]\n",
+ descp[0]);
else
- n += my_snprintf(b + n, blen - n, "Unknown [0x%x]\n",
- descp[0]);
+ n += scnpr(b + n, blen - n, "Unknown [0x%x]\n", descp[0]);
processed = false;
break;
}
if (! processed) {
if (add_d_len > 0) {
- n += my_snprintf(b + n, blen - n, "%s ", lip);
+ n += scnpr(b + n, blen - n, "%s ", lip);
for (j = 0; j < add_d_len; ++j) {
if ((j > 0) && (0 == (j % 24)))
- n += my_snprintf(b + n, blen - n, "\n%s ", lip);
- n += my_snprintf(b + n, blen - n, "%02x ", descp[j + 2]);
+ n += scnpr(b + n, blen - n, "\n%s ", lip);
+ n += scnpr(b + n, blen - n, "%02x ", descp[j + 2]);
}
- n += my_snprintf(b + n, blen - n, "\n");
+ n += scnpr(b + n, blen - n, "\n");
}
}
if (add_d_len < 0)
- n += my_snprintf(b + n, blen - n, "%s short descriptor\n", lip);
+ n += scnpr(b + n, blen - n, "%s short descriptor\n", lip);
}
return n;
}
@@ -1398,39 +1532,38 @@ sg_get_sense_descriptors_str(const char * leadin,
* That extra field information may be available in the ATA pass-through
* results log page parameter with the corresponding 'log_index'. */
static int
-sg_get_sense_sat_pt_fixed_str(const char * leadin, const unsigned char * sp,
+sg_get_sense_sat_pt_fixed_str(const char * lip, const unsigned char * sp,
int slen, int blen, char * b)
{
int n = 0;
bool extend, count_upper_nz, lba_upper_nz;
- const char * lip = "";
if ((blen < 1) || (slen < 12))
return n;
- if (leadin)
- lip = leadin;
+ if (NULL == lip)
+ lip = "";
if (SPC_SK_RECOVERED_ERROR != (0xf & sp[2]))
- n += my_snprintf(b + n, blen - n, "%s >> expected Sense key: "
- "Recovered Error ??\n", lip);
+ n += scnpr(b + n, blen - n, "%s >> expected Sense key: Recovered "
+ "Error ??\n", lip);
/* Fixed sense command-specific information field starts at sp + 8 */
extend = !!(0x80 & sp[8]);
count_upper_nz = !!(0x40 & sp[8]);
lba_upper_nz = !!(0x20 & sp[8]);
/* Fixed sense information field starts at sp + 3 */
- n += my_snprintf(b + n, blen - n, "%s error=0x%x, status=0x%x, "
- "device=0x%x, count(7:0)=0x%x%c\n", lip, sp[3],
- sp[4], sp[5], sp[6], (count_upper_nz ? '+' : ' '));
- n += my_snprintf(b + n, blen - n, "%s extend=%d, log_index=0x%x, "
- "lba_high,mid,low(7:0)=0x%x,0x%x,0x%x%c\n", lip,
- (int)extend, (0xf & sp[8]), sp[9], sp[10], sp[11],
- (lba_upper_nz ? '+' : ' '));
+ n += scnpr(b + n, blen - n, "%s error=0x%x, status=0x%x, device=0x%x, "
+ "count(7:0)=0x%x%c\n", lip, sp[3], sp[4], sp[5], sp[6],
+ (count_upper_nz ? '+' : ' '));
+ n += scnpr(b + n, blen - n, "%s extend=%d, log_index=0x%x, "
+ "lba_high,mid,low(7:0)=0x%x,0x%x,0x%x%c\n", lip, (int)extend,
+ (0xf & sp[8]), sp[9], sp[10], sp[11],
+ (lba_upper_nz ? '+' : ' '));
return n;
}
/* Fetch sense information */
int
-sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer,
- int sb_len, int raw_sinfo, int buff_len, char * buff)
+sg_get_sense_str(const char * lip, const unsigned char * sbp, int sb_len,
+ int raw_sinfo, int buff_len, char * buff)
{
int len, progress, n, r, pr, rem, blen;
unsigned int info;
@@ -1441,7 +1574,6 @@ sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer,
char error_buff[64];
char b[256];
struct sg_scsi_sense_hdr ssh;
- const char * lip = "";
if ((NULL == buff) || (buff_len <= 0))
return 0;
@@ -1451,182 +1583,176 @@ sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer,
}
blen = sizeof(b);
n = 0;
- if (leadin)
- lip = leadin;
- if ((NULL == sense_buffer) || (sb_len < 1)) {
- n += my_snprintf(buff, buff_len, "%s >>> sense buffer empty\n",
- lip);
+ if (NULL == lip)
+ lip = "";
+ if ((NULL == sbp) || (sb_len < 1)) {
+ n += scnpr(buff, buff_len, "%s >>> sense buffer empty\n", lip);
return n;
}
len = sb_len;
- if (sg_scsi_normalize_sense(sense_buffer, sb_len, &ssh)) {
+ if (sg_scsi_normalize_sense(sbp, sb_len, &ssh)) {
switch (ssh.response_code) {
case 0x70: /* fixed, current */
ebp = "Fixed format, current";
- len = (sb_len > 7) ? (sense_buffer[7] + 8) : sb_len;
+ len = (sb_len > 7) ? (sbp[7] + 8) : sb_len;
len = (len > sb_len) ? sb_len : len;
- sdat_ovfl = (len > 2) ? !!(sense_buffer[2] & 0x10) : false;
+ sdat_ovfl = (len > 2) ? !!(sbp[2] & 0x10) : false;
break;
case 0x71: /* fixed, deferred */
/* error related to a previous command */
ebp = "Fixed format, <<<deferred>>>";
- len = (sb_len > 7) ? (sense_buffer[7] + 8) : sb_len;
+ len = (sb_len > 7) ? (sbp[7] + 8) : sb_len;
len = (len > sb_len) ? sb_len : len;
- sdat_ovfl = (len > 2) ? !!(sense_buffer[2] & 0x10) : false;
+ sdat_ovfl = (len > 2) ? !!(sbp[2] & 0x10) : false;
break;
case 0x72: /* descriptor, current */
descriptor_format = true;
ebp = "Descriptor format, current";
- sdat_ovfl = (sb_len > 4) ? !!(sense_buffer[4] & 0x80) : false;
+ sdat_ovfl = (sb_len > 4) ? !!(sbp[4] & 0x80) : false;
break;
case 0x73: /* descriptor, deferred */
descriptor_format = true;
ebp = "Descriptor format, <<<deferred>>>";
- sdat_ovfl = (sb_len > 4) ? !!(sense_buffer[4] & 0x80) : false;
+ sdat_ovfl = (sb_len > 4) ? !!(sbp[4] & 0x80) : false;
break;
case 0x0:
ebp = "Response code: 0x0 (?)";
break;
default:
- my_snprintf(error_buff, sizeof(error_buff),
- "Unknown response code: 0x%x", ssh.response_code);
+ scnpr(error_buff, sizeof(error_buff), "Unknown response code: "
+ "0x%x", ssh.response_code);
ebp = error_buff;
break;
}
- n += my_snprintf(buff + n, buff_len - n, "%s%s; Sense key: %s\n",
- lip, ebp, sg_lib_sense_key_desc[ssh.sense_key]);
+ n += scnpr(buff + n, buff_len - n, "%s%s; Sense key: %s\n", lip, ebp,
+ sg_lib_sense_key_desc[ssh.sense_key]);
if (sdat_ovfl)
- n += my_snprintf(buff + n, buff_len - n, "%s<<<Sense data "
- "overflow>>>\n", lip);
+ n += scnpr(buff + n, buff_len - n, "%s<<<Sense data "
+ "overflow>>>\n", lip);
if (descriptor_format) {
- n += my_snprintf(buff + n, buff_len - n, "%s%s\n", lip,
- sg_get_asc_ascq_str(ssh.asc, ssh.ascq,
- sizeof(b), b));
- n += sg_get_sense_descriptors_str(lip, sense_buffer, len,
+ n += scnpr(buff + n, buff_len - n, "%s%s\n", lip,
+ sg_get_asc_ascq_str(ssh.asc, ssh.ascq, sizeof(b), b));
+ n += sg_get_sense_descriptors_str(lip, sbp, len,
buff_len - n, buff + n);
} else if ((len > 12) && (0 == ssh.asc) &&
(ASCQ_ATA_PT_INFO_AVAILABLE == ssh.ascq)) {
/* SAT ATA PASS-THROUGH fixed format */
- n += my_snprintf(buff + n, buff_len - n, "%s%s\n", lip,
- sg_get_asc_ascq_str(ssh.asc, ssh.ascq,
+ n += scnpr(buff + n, buff_len - n, "%s%s\n", lip,
+ sg_get_asc_ascq_str(ssh.asc, ssh.ascq,
sizeof(b), b));
- n += sg_get_sense_sat_pt_fixed_str(lip, sense_buffer, len,
+ n += sg_get_sense_sat_pt_fixed_str(lip, sbp, len,
buff_len - n, buff + n);
} else if (len > 2) { /* fixed format */
if (len > 12)
- n += my_snprintf(buff + n, buff_len - n, "%s%s\n", lip,
- sg_get_asc_ascq_str(ssh.asc, ssh.ascq,
+ n += scnpr(buff + n, buff_len - n, "%s%s\n", lip,
+ sg_get_asc_ascq_str(ssh.asc, ssh.ascq,
sizeof(b), b));
r = 0;
- valid = !!(sense_buffer[0] & 0x80);
+ valid = !!(sbp[0] & 0x80);
if (strlen(lip) > 0)
- r += my_snprintf(b + r, blen - r, "%s", lip);
+ r += scnpr(b + r, blen - r, "%s", lip);
if (len > 6) {
- info = sg_get_unaligned_be32(sense_buffer + 3);
+ info = sg_get_unaligned_be32(sbp + 3);
if (valid)
- r += my_snprintf(b + r, blen - r, " Info fld=0x%x [%u] ",
- info, info);
+ r += scnpr(b + r, blen - r, " Info fld=0x%x [%u] ",
+ info, info);
else if (info > 0)
- r += my_snprintf(b + r, blen - r, " Valid=0, Info "
- "fld=0x%x [%u] ", info, info);
+ r += scnpr(b + r, blen - r, " Valid=0, Info fld=0x%x "
+ "[%u] ", info, info);
} else
info = 0;
- if (sense_buffer[2] & 0xe0) {
- if (sense_buffer[2] & 0x80)
- r += my_snprintf(b + r, blen - r, " FMK");
+ if (sbp[2] & 0xe0) {
+ if (sbp[2] & 0x80)
+ r += scnpr(b + r, blen - r, " FMK");
/* current command has read a filemark */
- if (sense_buffer[2] & 0x40)
- r += my_snprintf(b + r, blen - r, " EOM");
+ if (sbp[2] & 0x40)
+ r += scnpr(b + r, blen - r, " EOM");
/* end-of-medium condition exists */
- if (sense_buffer[2] & 0x20)
- r += my_snprintf(b + r, blen - r, " ILI");
+ if (sbp[2] & 0x20)
+ r += scnpr(b + r, blen - r, " ILI");
/* incorrect block length requested */
- r += my_snprintf(b + r, blen - r, "\n");
+ r += scnpr(b + r, blen - r, "\n");
} else if (valid || (info > 0))
- r += my_snprintf(b + r, blen - r, "\n");
- if ((len >= 14) && sense_buffer[14])
- r += my_snprintf(b + r, blen - r, "%s Field replaceable unit "
- "code: %d\n", lip, sense_buffer[14]);
- if ((len >= 18) && (sense_buffer[15] & 0x80)) {
+ r += scnpr(b + r, blen - r, "\n");
+ if ((len >= 14) && sbp[14])
+ r += scnpr(b + r, blen - r, "%s Field replaceable unit "
+ "code: %d\n", lip, sbp[14]);
+ if ((len >= 18) && (sbp[15] & 0x80)) {
/* sense key specific decoding */
switch (ssh.sense_key) {
case SPC_SK_ILLEGAL_REQUEST:
- r += my_snprintf(b + r, blen - r, "%s Sense Key "
- "Specific: Error in %s: byte %d", lip,
- ((sense_buffer[15] & 0x40) ? "Command" :
- "Data parameters"),
- sg_get_unaligned_be16(sense_buffer + 16));
- if (sense_buffer[15] & 0x08)
- r += my_snprintf(b + r, blen - r, " bit %d\n",
- sense_buffer[15] & 0x07);
+ r += scnpr(b + r, blen - r, "%s Sense Key Specific: "
+ "Error in %s: byte %d", lip,
+ ((sbp[15] & 0x40) ? "Command" :
+ "Data parameters"),
+ sg_get_unaligned_be16(sbp + 16));
+ if (sbp[15] & 0x08)
+ r += scnpr(b + r, blen - r, " bit %d\n",
+ sbp[15] & 0x07);
else
- r += my_snprintf(b + r, blen - r, "\n");
+ r += scnpr(b + r, blen - r, "\n");
break;
case SPC_SK_NO_SENSE:
case SPC_SK_NOT_READY:
- progress = sg_get_unaligned_be16(sense_buffer + 16);
+ progress = sg_get_unaligned_be16(sbp + 16);
pr = (progress * 100) / 65536;
rem = ((progress * 100) % 65536) / 656;
- r += my_snprintf(b + r, blen - r, "%s Progress "
- "indication: %d.%02d%%\n", lip, pr, rem);
+ r += scnpr(b + r, blen - r, "%s Progress indication: "
+ "%d.%02d%%\n", lip, pr, rem);
break;
case SPC_SK_HARDWARE_ERROR:
case SPC_SK_MEDIUM_ERROR:
case SPC_SK_RECOVERED_ERROR:
- r += my_snprintf(b + r, blen - r, "%s Actual retry "
- "count: " "0x%02x%02x\n", lip,
- sense_buffer[16], sense_buffer[17]);
+ r += scnpr(b + r, blen - r, "%s Actual retry count: "
+ "0x%02x%02x\n", lip, sbp[16], sbp[17]);
break;
case SPC_SK_COPY_ABORTED:
- r += my_snprintf(b + r, blen - r, "%s Segment pointer: ",
- lip);
- r += my_snprintf(b + r, blen - r, "Relative to start of "
- "%s, byte %d",
- ((sense_buffer[15] & 0x20) ?
- "segment descriptor" : "parameter list"),
- sg_get_unaligned_be16(sense_buffer + 16));
- if (sense_buffer[15] & 0x08)
- r += my_snprintf(b + r, blen - r, " bit %d\n",
- sense_buffer[15] & 0x07);
+ r += scnpr(b + r, blen - r, "%s Segment pointer: ", lip);
+ r += scnpr(b + r, blen - r, "Relative to start of %s, "
+ "byte %d", ((sbp[15] & 0x20) ?
+ "segment descriptor" : "parameter list"),
+ sg_get_unaligned_be16(sbp + 16));
+ if (sbp[15] & 0x08)
+ r += scnpr(b + r, blen - r, " bit %d\n",
+ sbp[15] & 0x07);
else
- r += my_snprintf(b + r, blen - r, "\n");
+ r += scnpr(b + r, blen - r, "\n");
break;
case SPC_SK_UNIT_ATTENTION:
- r += my_snprintf(b + r, blen - r, "%s Unit attention "
- "condition queue: ", lip);
- r += my_snprintf(b + r, blen - r, "overflow flag is %d\n",
- !!(sense_buffer[15] & 0x1));
+ r += scnpr(b + r, blen - r, "%s Unit attention "
+ "condition queue: ", lip);
+ r += scnpr(b + r, blen - r, "overflow flag is %d\n",
+ !!(sbp[15] & 0x1));
break;
default:
- r += my_snprintf(b + r, blen - r, "%s Sense_key: 0x%x "
- "unexpected\n", lip, ssh.sense_key);
+ r += scnpr(b + r, blen - r, "%s Sense_key: 0x%x "
+ "unexpected\n", lip, ssh.sense_key);
break;
}
}
if (r > 0)
- n += my_snprintf(buff + n, buff_len - n, "%s", b);
+ n += scnpr(buff + n, buff_len - n, "%s", b);
} else
- n += my_snprintf(buff + n, buff_len - n, "%s fixed descriptor "
- "length too short, len=%d\n", lip, len);
+ n += scnpr(buff + n, buff_len - n, "%s fixed descriptor length "
+ "too short, len=%d\n", lip, len);
} else { /* non-extended SCSI-1 sense data ?? */
if (sb_len < 4) {
- n += my_snprintf(buff + n, buff_len - n, "%ssense buffer too "
- "short (4 byte minimum)\n", lip);
+ n += scnpr(buff + n, buff_len - n, "%ssense buffer too short (4 "
+ "byte minimum)\n", lip);
return n;
}
r = 0;
if (strlen(lip) > 0)
- r += my_snprintf(b + r, blen - r, "%s", lip);
- r += my_snprintf(b + r, blen - r, "Probably uninitialized data.\n%s "
- "Try to view as SCSI-1 non-extended sense:\n", lip);
- r += my_snprintf(b + r, blen - r, " AdValid=%d Error class=%d "
- "Error code=%d\n", !!(sense_buffer[0] & 0x80),
- ((sense_buffer[0] >> 4) & 0x7),
- (sense_buffer[0] & 0xf));
- if (sense_buffer[0] & 0x80)
- my_snprintf(b + r, blen - r, "%s lba=0x%x\n", lip,
- sg_get_unaligned_be24(sense_buffer + 1) & 0x1fffff);
- n += my_snprintf(buff + n, buff_len - n, "%s\n", b);
+ r += scnpr(b + r, blen - r, "%s", lip);
+ r += scnpr(b + r, blen - r, "Probably uninitialized data.\n%s Try "
+ "to view as SCSI-1 non-extended sense:\n", lip);
+ r += scnpr(b + r, blen - r, " AdValid=%d Error class=%d Error "
+ "code=%d\n", !!(sbp[0] & 0x80), ((sbp[0] >> 4) & 0x7),
+ (sbp[0] & 0xf));
+ if (sbp[0] & 0x80)
+ scnpr(b + r, blen - r, "%s lba=0x%x\n", lip,
+ sg_get_unaligned_be24(sbp + 1) & 0x1fffff);
+ n += scnpr(buff + n, buff_len - n, "%s\n", b);
len = sb_len;
if (len > 32)
len = 32; /* trim in case there is a lot of rubbish */
@@ -1634,12 +1760,12 @@ sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer,
if (raw_sinfo) {
char z[64];
- n += my_snprintf(buff + n, buff_len - n, "%s Raw sense data (in hex):"
- "\n", lip);
+ n += scnpr(buff + n, buff_len - n, "%s Raw sense data (in hex):\n",
+ lip);
if (n >= (buff_len - 1))
return n;
- snprintf(z, sizeof(z), "%.50s ", lip);
- n += dStrHexStr((const char *)sense_buffer, len, z, 0,
+ scnpr(z, sizeof(z), "%.50s ", lip);
+ n += dStrHexStr((const char *)sbp, len, z, 0,
buff_len - n, buff + n);
}
return n;
@@ -1647,60 +1773,59 @@ sg_get_sense_str(const char * leadin, const unsigned char * sense_buffer,
/* Print sense information */
void
-sg_print_sense(const char * leadin, const unsigned char * sense_buffer,
- int sb_len, int raw_sinfo)
+sg_print_sense(const char * leadin, const unsigned char * sbp, int sb_len,
+ int raw_sinfo)
{
char b[2048];
- sg_get_sense_str(leadin, sense_buffer, sb_len, raw_sinfo, sizeof(b), b);
+ sg_get_sense_str(leadin, sbp, sb_len, raw_sinfo, sizeof(b), b);
pr2ws("%s", b);
}
/* See description in sg_lib.h header file */
int
-sg_scsi_normalize_sense(const unsigned char * sensep, int sb_len,
+sg_scsi_normalize_sense(const unsigned char * sbp, int sb_len,
struct sg_scsi_sense_hdr * sshp)
{
if (sshp)
memset(sshp, 0, sizeof(struct sg_scsi_sense_hdr));
- if ((NULL == sensep) || (0 == sb_len) || (0x70 != (0x70 & sensep[0])))
+ if ((NULL == sbp) || (0 == sb_len) || (0x70 != (0x70 & sbp[0])))
return 0;
if (sshp) {
- sshp->response_code = (0x7f & sensep[0]);
+ sshp->response_code = (0x7f & sbp[0]);
if (sshp->response_code >= 0x72) { /* descriptor format */
if (sb_len > 1)
- sshp->sense_key = (0xf & sensep[1]);
+ sshp->sense_key = (0xf & sbp[1]);
if (sb_len > 2)
- sshp->asc = sensep[2];
+ sshp->asc = sbp[2];
if (sb_len > 3)
- sshp->ascq = sensep[3];
+ sshp->ascq = sbp[3];
if (sb_len > 7)
- sshp->additional_length = sensep[7];
+ sshp->additional_length = sbp[7];
} else { /* fixed format */
if (sb_len > 2)
- sshp->sense_key = (0xf & sensep[2]);
+ sshp->sense_key = (0xf & sbp[2]);
if (sb_len > 7) {
- sb_len = (sb_len < (sensep[7] + 8)) ? sb_len :
- (sensep[7] + 8);
+ sb_len = (sb_len < (sbp[7] + 8)) ? sb_len : (sbp[7] + 8);
if (sb_len > 12)
- sshp->asc = sensep[12];
+ sshp->asc = sbp[12];
if (sb_len > 13)
- sshp->ascq = sensep[13];
+ sshp->ascq = sbp[13];
}
}
}
return 1;
}
-/* Returns a SG_LIB_CAT_* value. If cannot decode sense_buffer or a less
- * common sense key then return SG_LIB_CAT_SENSE .*/
+/* Returns a SG_LIB_CAT_* value. If cannot decode sense buffer (sbp) or a
+ * less common sense key then return SG_LIB_CAT_SENSE .*/
int
-sg_err_category_sense(const unsigned char * sense_buffer, int sb_len)
+sg_err_category_sense(const unsigned char * sbp, int sb_len)
{
struct sg_scsi_sense_hdr ssh;
- if ((sense_buffer && (sb_len > 2)) &&
- (sg_scsi_normalize_sense(sense_buffer, sb_len, &ssh))) {
+ if ((sbp && (sb_len > 2)) &&
+ (sg_scsi_normalize_sense(sbp, sb_len, &ssh))) {
switch (ssh.sense_key) { /* 0 to 0x1f */
case SPC_SK_NO_SENSE:
return SG_LIB_CAT_NO_SENSE;
@@ -1774,7 +1899,7 @@ sg_get_command_name(const unsigned char * cmdp, int peri_type, int buff_len,
return;
}
if (NULL == cmdp) {
- my_snprintf(buff, buff_len, "%s", "<null> command pointer");
+ scnpr(buff, buff_len, "%s", "<null> command pointer");
return;
}
service_action = (SG_VARIABLE_LENGTH_CMD == cmdp[0]) ?
@@ -1839,14 +1964,14 @@ sg_get_opcode_sa_name(unsigned char cmd_byte0, int service_action,
vnp = get_value_name(osp->arr, service_action, peri_type);
if (vnp) {
if (osp->prefix)
- my_snprintf(buff, buff_len, "%s, %s", osp->prefix,
- vnp->name);
+ scnpr(buff, buff_len, "%s, %s", osp->prefix,
+ vnp->name);
else
- my_snprintf(buff, buff_len, "%s", vnp->name);
+ scnpr(buff, buff_len, "%s", vnp->name);
} else {
sg_get_opcode_name(cmd_byte0, peri_type, sizeof(b), b);
- my_snprintf(buff, buff_len, "%s service action=0x%x",
- b, service_action);
+ scnpr(buff, buff_len, "%s service action=0x%x", b,
+ service_action);
}
} else
sg_get_opcode_name(cmd_byte0, peri_type, buff_len, buff);
@@ -1870,7 +1995,7 @@ sg_get_opcode_name(unsigned char cmd_byte0, int peri_type, int buff_len,
return;
}
if (SG_VARIABLE_LENGTH_CMD == cmd_byte0) {
- my_snprintf(buff, buff_len, "%s", "Variable length");
+ scnpr(buff, buff_len, "%s", "Variable length");
return;
}
grp = (cmd_byte0 >> 5) & 0x7;
@@ -1882,19 +2007,19 @@ sg_get_opcode_name(unsigned char cmd_byte0, int peri_type, int buff_len,
case 5:
vnp = get_value_name(sg_lib_normal_opcodes, cmd_byte0, peri_type);
if (vnp)
- my_snprintf(buff, buff_len, "%s", vnp->name);
+ scnpr(buff, buff_len, "%s", vnp->name);
else
- my_snprintf(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0);
+ scnpr(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0);
break;
case 3:
- my_snprintf(buff, buff_len, "Reserved [0x%x]", (int)cmd_byte0);
+ scnpr(buff, buff_len, "Reserved [0x%x]", (int)cmd_byte0);
break;
case 6:
case 7:
- my_snprintf(buff, buff_len, "Vendor specific [0x%x]", (int)cmd_byte0);
+ scnpr(buff, buff_len, "Vendor specific [0x%x]", (int)cmd_byte0);
break;
default:
- my_snprintf(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0);
+ scnpr(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0);
break;
}
}
@@ -1957,143 +2082,143 @@ sg_get_category_sense_str(int sense_cat, int buff_len, char * buff,
return buff;
switch (sense_cat) {
case SG_LIB_CAT_CLEAN: /* 0 */
- snprintf(buff, buff_len, "No errors");
+ scnpr(buff, buff_len, "No errors");
break;
case SG_LIB_SYNTAX_ERROR: /* 1 */
- snprintf(buff, buff_len, "Syntax error");
+ scnpr(buff, buff_len, "Syntax error");
break;
case SG_LIB_CAT_NOT_READY: /* 2 */
- n = snprintf(buff, buff_len, "Not ready");
+ n = scnpr(buff, buff_len, "Not ready");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key");
+ scnpr(buff + n, buff_len - n, " sense key");
break;
case SG_LIB_CAT_MEDIUM_HARD: /* 3 */
- n = snprintf(buff, buff_len, "Medium or hardware error");
+ n = scnpr(buff, buff_len, "Medium or hardware error");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key (plus blank check)");
+ scnpr(buff + n, buff_len - n, " sense key (plus blank check)");
break;
case SG_LIB_CAT_ILLEGAL_REQ: /* 5 */
- n = snprintf(buff, buff_len, "Illegal request");
+ n = scnpr(buff, buff_len, "Illegal request");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key, apart from Invalid "
- "opcode");
+ scnpr(buff + n, buff_len - n, " sense key, apart from Invalid "
+ "opcode");
break;
case SG_LIB_CAT_UNIT_ATTENTION: /* 6 */
- n = snprintf(buff, buff_len, "Unit attention");
+ n = scnpr(buff, buff_len, "Unit attention");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key");
+ scnpr(buff + n, buff_len - n, " sense key");
break;
case SG_LIB_CAT_DATA_PROTECT: /* 7 */
- n = snprintf(buff, buff_len, "Data protect");
+ n = scnpr(buff, buff_len, "Data protect");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key, write protected "
+ scnpr(buff + n, buff_len - n, " sense key, write protected "
"media?");
break;
case SG_LIB_CAT_INVALID_OP: /* 9 */
- n = snprintf(buff, buff_len, "Illegal request, invalid opcode");
+ n = scnpr(buff, buff_len, "Illegal request, invalid opcode");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key");
+ scnpr(buff + n, buff_len - n, " sense key");
break;
case SG_LIB_CAT_COPY_ABORTED: /* 10 */
- n = snprintf(buff, buff_len, "Copy aborted");
+ n = scnpr(buff, buff_len, "Copy aborted");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key");
+ scnpr(buff + n, buff_len - n, " sense key");
break;
case SG_LIB_CAT_ABORTED_COMMAND: /* 11 */
- n = snprintf(buff, buff_len, "Aborted command");
+ n = scnpr(buff, buff_len, "Aborted command");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key, other than "
+ scnpr(buff + n, buff_len - n, " sense key, other than "
"protection related (asc=0x10)");
break;
case SG_LIB_CAT_MISCOMPARE: /* 14 */
- n = snprintf(buff, buff_len, "Miscompare");
+ n = scnpr(buff, buff_len, "Miscompare");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key");
+ scnpr(buff + n, buff_len - n, " sense key");
break;
case SG_LIB_FILE_ERROR: /* 15 */
- snprintf(buff, buff_len, "File error");
+ scnpr(buff, buff_len, "File error");
break;
case SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO: /* 17 */
- snprintf(buff, buff_len, "Illegal request with info");
+ scnpr(buff, buff_len, "Illegal request with info");
break;
case SG_LIB_CAT_MEDIUM_HARD_WITH_INFO: /* 18 */
- snprintf(buff, buff_len, "Medium or hardware error with info");
+ scnpr(buff, buff_len, "Medium or hardware error with info");
break;
case SG_LIB_CAT_NO_SENSE: /* 20 */
- n = snprintf(buff, buff_len, "No sense key");
+ n = scnpr(buff, buff_len, "No sense key");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " probably additional sense "
+ scnpr(buff + n, buff_len - n, " probably additional sense "
"information");
break;
case SG_LIB_CAT_RECOVERED: /* 21 */
- n = snprintf(buff, buff_len, "Recovered error");
+ n = scnpr(buff, buff_len, "Recovered error");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " sense key");
+ scnpr(buff + n, buff_len - n, " sense key");
break;
case SG_LIB_CAT_RES_CONFLICT: /* 24 */
- n = snprintf(buff, buff_len, "Reservation conflict");
+ n = scnpr(buff, buff_len, "Reservation conflict");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " SCSI status");
+ scnpr(buff + n, buff_len - n, " SCSI status");
break;
case SG_LIB_CAT_CONDITION_MET: /* 25 */
- n = snprintf(buff, buff_len, "Condition met");
+ n = scnpr(buff, buff_len, "Condition met");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " SCSI status");
+ scnpr(buff + n, buff_len - n, " SCSI status");
break;
case SG_LIB_CAT_BUSY: /* 26 */
- n = snprintf(buff, buff_len, "Busy");
+ n = scnpr(buff, buff_len, "Busy");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " SCSI status");
+ scnpr(buff + n, buff_len - n, " SCSI status");
break;
case SG_LIB_CAT_TS_FULL: /* 27 */
- n = snprintf(buff, buff_len, "Task set full");
+ n = scnpr(buff, buff_len, "Task set full");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " SCSI status");
+ scnpr(buff + n, buff_len - n, " SCSI status");
break;
case SG_LIB_CAT_ACA_ACTIVE: /* 28 */
- n = snprintf(buff, buff_len, "ACA active");
+ n = scnpr(buff, buff_len, "ACA active");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " SCSI status");
+ scnpr(buff + n, buff_len - n, " SCSI status");
break;
case SG_LIB_CAT_TASK_ABORTED: /* 29 */
- n = snprintf(buff, buff_len, "Task aborted");
+ n = scnpr(buff, buff_len, "Task aborted");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " SCSI status");
+ scnpr(buff + n, buff_len - n, " SCSI status");
break;
case SG_LIB_CAT_TIMEOUT: /* 33 */
- snprintf(buff, buff_len, "SCSI command timeout");
+ scnpr(buff, buff_len, "SCSI command timeout");
break;
case SG_LIB_CAT_PROTECTION: /* 40 */
- n = snprintf(buff, buff_len, "Aborted command, protection");
+ n = scnpr(buff, buff_len, "Aborted command, protection");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " information (PI) problem");
+ scnpr(buff + n, buff_len - n, " information (PI) problem");
break;
case SG_LIB_CAT_PROTECTION_WITH_INFO: /* 41 */
- n = snprintf(buff, buff_len, "Aborted command with info, protection");
+ n = scnpr(buff, buff_len, "Aborted command with info, protection");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " information (PI) problem");
+ scnpr(buff + n, buff_len - n, " information (PI) problem");
break;
case SG_LIB_CAT_MALFORMED: /* 97 */
- n = snprintf(buff, buff_len, "Malformed response");
+ n = scnpr(buff, buff_len, "Malformed response");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, " to SCSI command");
+ scnpr(buff + n, buff_len - n, " to SCSI command");
break;
case SG_LIB_CAT_SENSE: /* 98 */
- n = snprintf(buff, buff_len, "Some other sense data problem");
+ n = scnpr(buff, buff_len, "Some other sense data problem");
if (verbose && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, ", try '-v' option for more "
+ scnpr(buff + n, buff_len - n, ", try '-v' option for more "
"information");
break;
case SG_LIB_CAT_OTHER: /* 99 */
- n = snprintf(buff, buff_len, "Some other error/warning has occurred");
+ n = scnpr(buff, buff_len, "Some other error/warning has occurred");
if ((0 == verbose) && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, ", possible transport of driver "
+ scnpr(buff + n, buff_len - n, ", possible transport of driver "
"issue");
break;
default:
- n = snprintf(buff, buff_len, "Sense category: %d", sense_cat);
+ n = scnpr(buff, buff_len, "Sense category: %d", sense_cat);
if ((0 == verbose) && (n < (buff_len - 1)))
- snprintf(buff + n, buff_len - n, ", try '-v' option for more "
+ scnpr(buff + n, buff_len - n, ", try '-v' option for more "
"information");
break;
}
@@ -2119,8 +2244,7 @@ safe_strerror(int errnum)
errstr = strerror(errnum);
if (NULL == errstr) {
len = strlen(safe_errbuf);
- my_snprintf(safe_errbuf + len, sizeof(safe_errbuf) - len, "%i",
- errnum);
+ scnpr(safe_errbuf + len, sizeof(safe_errbuf) - len, "%i", errnum);
return safe_errbuf;
}
return errstr;
@@ -2177,8 +2301,7 @@ dStrHexFp(const char* str, int len, int no_ascii, FILE * fp)
c = *p++;
if (bpos == (bpstart + (8 * 3)))
bpos++;
- my_snprintf(&buff[bpos], blen - bpos, "%.2x",
- (int)(unsigned char)c);
+ scnpr(&buff[bpos], blen - bpos, "%.2x", (int)(unsigned char)c);
buff[bpos + 2] = ' ';
if ((k > 0) && (0 == ((k + 1) % 16))) {
trimTrailingSpaces(buff);
@@ -2196,7 +2319,7 @@ dStrHexFp(const char* str, int len, int no_ascii, FILE * fp)
return;
}
/* no_ascii>=0, start each line with address (offset) */
- k = my_snprintf(buff + 1, blen - 1, "%.2x", a);
+ k = scnpr(buff + 1, blen - 1, "%.2x", a);
buff[k + 1] = ' ';
for (i = 0; i < len; i++) {
@@ -2204,7 +2327,7 @@ dStrHexFp(const char* str, int len, int no_ascii, FILE * fp)
bpos += 3;
if (bpos == (bpstart + (9 * 3)))
bpos++;
- my_snprintf(&buff[bpos], blen - bpos, "%.2x", (int)(unsigned char)c);
+ scnpr(&buff[bpos], blen - bpos, "%.2x", (int)(unsigned char)c);
buff[bpos + 2] = ' ';
if (no_ascii)
buff[cpos++] = ' ';
@@ -2221,7 +2344,7 @@ dStrHexFp(const char* str, int len, int no_ascii, FILE * fp)
cpos = cpstart;
a += 16;
memset(buff, ' ', 80);
- k = my_snprintf(buff + 1, blen - 1, "%.2x", a);
+ k = scnpr(buff + 1, blen - 1, "%.2x", a);
buff[k + 1] = ' ';
}
}
@@ -2286,12 +2409,12 @@ dStrHexStr(const char* str, int len, const char * leadin, int format,
c = *p++;
if (bpos == (bpstart + (8 * 3)))
bpos++;
- my_snprintf(&buff[bpos], (int)sizeof(buff) - bpos, "%.2x",
- (int)(unsigned char)c);
+ scnpr(buff + bpos, (int)sizeof(buff) - bpos, "%.2x",
+ (int)(unsigned char)c);
buff[bpos + 2] = ' ';
if ((k > 0) && (0 == ((k + 1) % 16))) {
trimTrailingSpaces(buff);
- n += my_snprintf(b + n, b_len - n, "%s\n", buff);
+ n += scnpr(b + n, b_len - n, "%s\n", buff);
if (n >= (b_len - 1))
return n;
bpos = bpstart;
@@ -2303,7 +2426,7 @@ dStrHexStr(const char* str, int len, const char * leadin, int format,
}
if (bpos > bpstart) {
trimTrailingSpaces(buff);
- n += my_snprintf(b + n, b_len - n, "%s\n", buff);
+ n += scnpr(b + n, b_len - n, "%s\n", buff);
}
return n;
}
@@ -2369,7 +2492,7 @@ dWordHex(const unsigned short* words, int num, int no_ascii, int swapb)
if (swapb)
c = swapb_ushort(c);
bpos += 5;
- my_snprintf(&buff[bpos], blen - bpos, "%.4x", (unsigned int)c);
+ scnpr(buff + bpos, blen - bpos, "%.4x", (unsigned int)c);
buff[bpos + 4] = ' ';
if ((k > 0) && (0 == ((k + 1) % 8))) {
if (-2 == no_ascii)
@@ -2389,7 +2512,7 @@ dWordHex(const unsigned short* words, int num, int no_ascii, int swapb)
return;
}
/* no_ascii>=0, start each line with address (offset) */
- k = my_snprintf(buff + 1, blen - 1, "%.2x", a);
+ k = scnpr(buff + 1, blen - 1, "%.2x", a);
buff[k + 1] = ' ';
for (i = 0; i < num; i++) {
@@ -2397,7 +2520,7 @@ dWordHex(const unsigned short* words, int num, int no_ascii, int swapb)
if (swapb)
c = swapb_ushort(c);
bpos += 5;
- my_snprintf(&buff[bpos], blen - bpos, "%.4x", (unsigned int)c);
+ scnpr(buff + bpos, blen - bpos, "%.4x", (unsigned int)c);
buff[bpos + 4] = ' ';
if (no_ascii) {
buff[cpos++] = ' ';
@@ -2420,7 +2543,7 @@ dWordHex(const unsigned short* words, int num, int no_ascii, int swapb)
cpos = cpstart;
a += 8;
memset(buff, ' ', 80);
- k = my_snprintf(buff + 1, blen - 1, "%.2x", a);
+ k = scnpr(buff + 1, blen - 1, "%.2x", a);
buff[k + 1] = ' ';
}
}
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index fe5f59ad..5a02d14c 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -17,7 +17,7 @@
#endif
-const char * sg_lib_version_str = "2.20 20160423"; /* spc5r08, sbc4r10 */
+const char * sg_lib_version_str = "2.21 20160426"; /* spc5r09, sbc4r10 */
/* indexed by pdt; those that map to own index do not decay */
@@ -358,6 +358,7 @@ struct sg_lib_value_name_t sg_lib_serv_in16_arr[] = {
/* Service action out(16) [0x9f] service actions */
struct sg_lib_value_name_t sg_lib_serv_out16_arr[] = {
+ {0x0d, 0, "Set affiliation"},
{0x11, 0, "Write long(16)"},
{0x14, PDT_ZBC, "Reset write pointer"},
{0x1f, PDT_ADC, "Notify data transfer device(16)"},
@@ -691,6 +692,7 @@ struct sg_lib_asc_ascq_t sg_lib_asc_ascq[] =
{0x04,0x20,"Logical unit not ready, logical unit reset required"},
{0x04,0x21,"Logical unit not ready, hard reset required"},
{0x04,0x22,"Logical unit not ready, power cycle required"},
+ {0x04,0x23,"Logical unit not ready, affiliation required"},
{0x05,0x00,"Logical unit does not respond to selection"},
{0x06,0x00,"No reference position found"},
{0x07,0x00,"Multiple peripheral devices selected"},
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 4f7b7943..979484ac 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -43,7 +43,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.58 20160423"; /* SPC-5 rev 08 */
+static const char * version_str = "1.59 20160426"; /* SPC-5 rev 09 */
/* INQUIRY notes:
* It is recommended that the initial allocation length given to a
@@ -124,8 +124,6 @@ static char usn_buff[MX_ALLOC_LEN + 1];
static const char * find_version_descriptor_str(int value);
static void decode_dev_ids(const char * leadin, unsigned char * buff,
int len, int do_hex, int verbose);
-static void decode_transport_id(const char * leadin, unsigned char * bp,
- int len);
#if defined(SG_LIB_LINUX) && defined(SG_SCSI_STRINGS)
static int try_ata_identify(int ata_fd, int do_hex, int do_raw,
@@ -1425,8 +1423,12 @@ decode_scsi_ports_vpd(unsigned char * buff, int len, int do_hex, int verbose)
printf(" Initiator port transport id:\n");
dStrHex((const char *)(bp + 8), ip_tid_len,
(1 == do_hex) ? 1 : -1);
- } else
- decode_transport_id(" ", bp + 8, ip_tid_len);
+ } else {
+ char b[1024];
+
+ printf("%s", sg_decode_transportid_str(" ", bp + 8,
+ ip_tid_len, true, sizeof(b), b));
+ }
}
tpd_len = sg_get_unaligned_be16(bp + bump + 2);
if ((k + bump + tpd_len + 4) > len) {
@@ -2119,129 +2121,6 @@ export_dev_ids(unsigned char * buff, int len, int verbose)
"around offset=%d\n", off);
}
-/* Transport IDs are initiator port identifiers, typically other than the
- initiator port issuing a SCSI command. */
-static void
-decode_transport_id(const char * leadin, unsigned char * bp, int len)
-{
- int format_code, proto_id, num, k;
- uint64_t ull;
- int bump;
-
- for (k = 0, bump = 24; k < len; k += bump, bp += bump) {
- if ((len < 24) || (0 != (len % 4)))
- printf("%sTransport Id short or not multiple of 4 "
- "[length=%d]:\n", leadin, len);
- else
- printf("%sTransport Id of initiator:\n", leadin);
- format_code = ((bp[0] >> 6) & 0x3);
- proto_id = (bp[0] & 0xf);
- switch (proto_id) {
- case TPROTO_FCP:
- printf("%s FCP-2 World Wide Name:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 8, -1);
- bump = 24;
- break;
- case TPROTO_SPI:
- printf("%s Parallel SCSI initiator SCSI address: 0x%x\n",
- leadin, sg_get_unaligned_be16(bp + 2));
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- printf("%s relative port number (of corresponding target): "
- "0x%x\n", leadin, sg_get_unaligned_be16(bp + 6));
- bump = 24;
- break;
- case TPROTO_SSA: /* SSA */
- printf("%s SSA (transport id not defined):\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- bump = 24;
- break;
- case TPROTO_1394:
- printf("%s IEEE 1394 EUI-64 name:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 8, -1);
- bump = 24;
- break;
- case TPROTO_SRP:
- printf("%s RDMA initiator port identifier:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 16, -1);
- bump = 24;
- break;
- case TPROTO_ISCSI:
- printf("%s iSCSI ", leadin);
- num = sg_get_unaligned_be16(bp + 2);
- if (0 == format_code)
- printf("name: %.*s\n", num, &bp[4]);
- else if (1 == format_code)
- printf("world wide unique port id: %.*s\n", num, &bp[4]);
- else {
- printf(" [Unexpected format code: %d]\n", format_code);
- dStrHex((const char *)bp, num + 4, -1);
- }
- bump = (((num + 4) < 24) ? 24 : num + 4);
- break;
- case TPROTO_SAS:
- ull = sg_get_unaligned_be64(bp + 4);
- printf("%s SAS address: 0x%" PRIx64 "\n", leadin, ull);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- bump = 24;
- break;
- case TPROTO_ADT:
- printf("%s ADT:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- bump = 24;
- break;
- case TPROTO_ATA:
- printf("%s ATAPI:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- bump = 24;
- break;
- case TPROTO_UAS:
- printf("%s UAS:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- bump = 24;
- break;
- case TPROTO_SOP:
- printf("%s SOP ", leadin);
- num = sg_get_unaligned_be16(bp + 2);
- if (0 == format_code)
- printf("Routing ID: 0x%x\n", num);
- else {
- printf(" [Unexpected format code: %d]\n", format_code);
- dStrHex((const char *)bp, 24, -1);
- }
- bump = 24;
- break;
- case TPROTO_NONE:
- pr2serr("%s No specified protocol\n", leadin);
- /* dStrHexErr((const char *)bp, ((len > 24) ? 24 : len), 0); */
- bump = 24;
- break;
- default:
- pr2serr("%s unknown protocol id=0x%x "
- "format_code=%d\n", leadin, proto_id, format_code);
- dStrHexErr((const char *)bp, ((len > 24) ? 24 : len), 0);
- bump = 24;
- break;
- }
- }
-}
-
/* VPD_EXT_INQ Extended Inquiry */
static void
decode_x_inq_vpd(unsigned char * buff, int len, int do_hex)
diff --git a/src/sg_inq_data.c b/src/sg_inq_data.c
index 6e387d3f..18e2d53c 100644
--- a/src/sg_inq_data.c
+++ b/src/sg_inq_data.c
@@ -48,8 +48,8 @@ struct sg_version_descriptor {
const char * name;
};
-/* table from SPC-5 revision 08 [sorted numerically (from Annex E.9)] */
-/* Can also be obtained from : http://www.t10.org/lists/stds.txt 20160125 */
+/* table from SPC-5 revision 09 [sorted numerically (from Annex E.9)] */
+/* Can also be obtained from : http://www.t10.org/lists/stds.txt 20160402 */
#ifdef SG_SCSI_STRINGS
@@ -225,6 +225,7 @@ struct sg_version_descriptor sg_version_descriptor_arr[] = {
{0x527, "SSC-4 SSC-4 ANSI INCITS 516-2013"},
{0x560, "OSD-3 (no version claimed)"},
{0x580, "SES-3 (no version claimed)"},
+ {0x582, "SES-3 T10/BSR INCITS 518 revision 13"},
{0x5a0, "SSC-5 (no version claimed)"},
{0x5c0, "SPC-5 (no version claimed)"},
{0x5e0, "SFSC (no version claimed)"},
@@ -497,6 +498,7 @@ struct sg_version_descriptor sg_version_descriptor_arr[] = {
{0x1ee4, "SAT-3 T10/BSR INCITS 517 revision 7"},
{0x1ee8, "SAT-3 ANSI INCITS 517-2015"},
{0x1f00, "SAT-4 (no version claimed)"},
+ {0x1f02, "SAT-4 T10/BSR INCITS 491 revision 5"},
{0x20a0, "SPL (no version claimed)"},
{0x20a3, "SPL T10/2124-D revision 6a"},
{0x20a5, "SPL T10/2124-D revision 7"},
diff --git a/src/sg_persist.c b/src/sg_persist.c
index 73b01866..e76d8d21 100644
--- a/src/sg_persist.c
+++ b/src/sg_persist.c
@@ -28,7 +28,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "0.53 20160423";
+static const char * version_str = "0.54 20160426";
#define PRIN_RKEY_SA 0x0
@@ -236,120 +236,6 @@ usage(int help)
}
}
-/* If num_tids==0 then only one TransportID is assumed with len bytes in
- * it. If num_tids>0 then that many TransportIDs is assumed, each in an
- * element that is MX_TID_LEN bytes long (and the 'len' argument is
- * ignored). */
-static void
-decode_transport_id(const char * leadin, unsigned char * bp, int len,
- int num_tids)
-{
- int format_code, proto_id, num, k;
- int bump;
-
- if (num_tids > 0)
- len = num_tids * MX_TID_LEN;
- for (k = 0, bump = MX_TID_LEN; k < len; k += bump, bp += bump) {
- if ((len < 24) || (0 != (len % 4)))
- printf("%sTransport Id short or not multiple of 4 "
- "[length=%d]:\n", leadin, len);
- else
- printf("%sTransport Id of initiator:\n", leadin);
- format_code = ((bp[0] >> 6) & 0x3);
- proto_id = (bp[0] & 0xf);
- switch (proto_id) {
- case TPROTO_FCP: /* Fibre channel */
- printf("%s FCP-2 World Wide Name:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 8, -1);
- break;
- case TPROTO_SPI: /* Parallel SCSI */
- printf("%s Parallel SCSI initiator SCSI address: 0x%x\n",
- leadin, sg_get_unaligned_be16(bp + 2));
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- printf("%s relative port number (of corresponding target): "
- "0x%x\n", leadin, sg_get_unaligned_be16(bp + 6));
- break;
- case TPROTO_SSA:
- printf("%s SSA (transport id not defined):\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- break;
- case TPROTO_1394: /* IEEE 1394 */
- printf("%s IEEE 1394 EUI-64 name:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 8, -1);
- break;
- case TPROTO_SRP:
- printf("%s RDMA initiator port identifier:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 16, -1);
- break;
- case TPROTO_ISCSI:
- printf("%s iSCSI ", leadin);
- num = sg_get_unaligned_be16(bp + 2);
- if (0 == format_code)
- printf("name: %.*s\n", num, &bp[4]);
- else if (1 == format_code)
- printf("name and session id: %.*s\n", num, &bp[4]);
- else {
- printf(" [Unexpected format code: %d]\n", format_code);
- dStrHex((const char *)bp, num + 4, -1);
- }
- break;
- case TPROTO_SAS:
- printf("%s SAS address: 0x%016" PRIx64 "\n", leadin,
- sg_get_unaligned_be64(bp + 4));
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- break;
- case TPROTO_ADT:
- printf("%s ADT:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- break;
- case TPROTO_ATA:
- printf("%s ATAPI:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- break;
- case TPROTO_UAS:
- printf("%s UAS:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- break;
- case TPROTO_SOP:
- printf("%s SOP ", leadin);
- num = sg_get_unaligned_be16(bp + 2);
- if (0 == format_code)
- printf("Routing ID: 0x%x\n", num);
- else {
- printf(" [Unexpected format code: %d]\n", format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), -1);
- }
- break;
- case TPROTO_NONE:
- pr2serr("%s No specified protocol\n", leadin);
- /* dStrHexErr((const char *)bp, ((len > 24) ? 24 : len), -1); */
- break;
- default:
- pr2serr("%s unknown protocol id=0x%x format_code=%d\n",
- leadin, proto_id, format_code);
- dStrHexErr((const char *)bp, ((len > 24) ? 24 : len), -1);
- break;
- }
- }
-}
-
static int
prin_work(int sg_fd, const struct opts_t * op)
{
@@ -501,8 +387,12 @@ prin_work(int sg_fd, const struct opts_t * op)
printf(" type: %s\n", pr_type_strs[j]);
} else
printf(" not reservation holder\n");
- if (add_desc_len > 0)
- decode_transport_id(" ", &bp[24], add_desc_len, 0);
+ if (add_desc_len > 0) {
+ char b[1024];
+
+ printf("%s", sg_decode_transportid_str(" ", bp + 24,
+ add_desc_len, true, sizeof(b), b));
+ }
}
}
}
@@ -979,7 +869,7 @@ my_cont_b:
int
main(int argc, char * argv[])
{
- int sg_fd, c, res;
+ int sg_fd, c, k, res;
const char * device_name = NULL;
char buff[48];
int help =0;
@@ -1235,11 +1125,17 @@ main(int argc, char * argv[])
pr2serr("warning>>> --prout-type probably needs to be given\n");
}
if ((op->verbose > 2) && op->num_transportids) {
+ char b[1024];
+ unsigned char * bp;
+
pr2serr("number of tranport-ids decoded from command line (or "
"stdin): %d\n", op->num_transportids);
pr2serr(" Decode given transport-ids:\n");
- decode_transport_id(" ", op->transportid_arr,
- 0, op->num_transportids);
+ for (k = 0; k < op->num_transportids; ++k) {
+ bp = op->transportid_arr + (MX_TID_LEN * k);
+ printf("%s", sg_decode_transportid_str(" ", bp, MX_TID_LEN,
+ true, sizeof(b), b));
+ }
}
if (op->inquiry) {
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
index 9c856058..cf6f2999 100644
--- a/src/sg_vpd.c
+++ b/src/sg_vpd.c
@@ -37,7 +37,7 @@
*/
-static const char * version_str = "1.17 20160421"; /* spc5r08 + sbc4r10 */
+static const char * version_str = "1.18 20160426"; /* spc5r09 + sbc4r10 */
/* These structures are duplicates of those of the same name in
@@ -145,8 +145,6 @@ unsigned char rsp_buff[MX_ALLOC_LEN + 2];
static int decode_dev_ids(const char * print_if_found, unsigned char * buff,
int len, int m_assoc, int m_desig_type,
int m_code_set, const struct opts_t * op);
-static void decode_transport_id(const char * leadin, unsigned char * bp,
- int len);
static struct option long_options[] = {
{"all", no_argument, 0, 'a'},
@@ -949,8 +947,12 @@ decode_scsi_ports_vpd(unsigned char * buff, int len, const struct opts_t * op)
if (op->do_hex > 1) {
printf(" Initiator port transport id:\n");
dStrHex((const char *)(bp + 8), ip_tid_len, 1);
- } else
- decode_transport_id(" ", bp + 8, ip_tid_len);
+ } else {
+ char b[1024];
+
+ printf("%s", sg_decode_transportid_str(" ", bp + 8,
+ ip_tid_len, true, sizeof(b), b));
+ }
}
tpd_len = sg_get_unaligned_be16(bp + bump + 2);
if ((k + bump + tpd_len + 4) > len) {
@@ -1543,129 +1545,6 @@ decode_dev_ids(const char * print_if_found, unsigned char * buff, int len,
return 0;
}
-/* Transport IDs are initiator port identifiers, typically other than the
- initiator port issuing a SCSI command. */
-static void
-decode_transport_id(const char * leadin, unsigned char * bp, int len)
-{
- int format_code, proto_id, num, k;
- uint64_t ull;
- int bump;
-
- for (k = 0, bump= 24; k < len; k += bump, bp += bump) {
- if ((len < 24) || (0 != (len % 4)))
- printf("%sTransport Id short or not multiple of 4 "
- "[length=%d]:\n", leadin, len);
- else
- printf("%sTransport Id of initiator:\n", leadin);
- format_code = ((bp[0] >> 6) & 0x3);
- proto_id = (bp[0] & 0xf);
- switch (proto_id) {
- case TPROTO_FCP: /* Fibre channel */
- printf("%s FCP-2 World Wide Name:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 8, -1);
- bump = 24;
- break;
- case TPROTO_SPI: /* Scsi Parallel Interface */
- printf("%s Parallel SCSI initiator SCSI address: 0x%x\n",
- leadin, sg_get_unaligned_be16(bp + 2));
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- printf("%s relative port number (of corresponding target): "
- "0x%x\n", leadin, sg_get_unaligned_be16(bp + 6));
- bump = 24;
- break;
- case TPROTO_SSA:
- printf("%s SSA (transport id not defined):\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), 0);
- bump = 24;
- break;
- case TPROTO_1394: /* IEEE 1394 */
- printf("%s IEEE 1394 EUI-64 name:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 8, -1);
- bump = 24;
- break;
- case TPROTO_SRP:
- printf("%s RDMA initiator port identifier:\n", leadin);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- dStrHex((const char *)&bp[8], 16, -1);
- bump = 24;
- break;
- case TPROTO_ISCSI:
- printf("%s iSCSI ", leadin);
- num = sg_get_unaligned_be16(bp + 2);
- if (0 == format_code)
- printf("name: %.*s\n", num, &bp[4]);
- else if (1 == format_code)
- printf("world wide unique port id: %.*s\n", num, &bp[4]);
- else {
- pr2serr(" [Unexpected format code: %d]\n", format_code);
- dStrHexErr((const char *)bp, num + 4, 0);
- }
- bump = (((num + 4) < 24) ? 24 : num + 4);
- break;
- case TPROTO_SAS:
- ull = sg_get_unaligned_be64(bp + 4);
- printf("%s SAS address: 0x%" PRIx64 "\n", leadin, ull);
- if (0 != format_code)
- printf("%s [Unexpected format code: %d]\n", leadin,
- format_code);
- bump = 24;
- break;
- case TPROTO_ADT:
- printf("%s ADT:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), 0);
- bump = 24;
- break;
- case TPROTO_ATA: /* ATA/ATAPI */
- printf("%s ATAPI:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), 0);
- bump = 24;
- break;
- case TPROTO_UAS:
- printf("%s UAS:\n", leadin);
- printf("%s format code: %d\n", leadin, format_code);
- dStrHex((const char *)bp, ((len > 24) ? 24 : len), 0);
- bump = 24;
- break;
- case TPROTO_SOP:
- printf("%s SOP ", leadin);
- num = sg_get_unaligned_be16(bp + 2);
- if (0 == format_code)
- printf("Routing ID: 0x%x\n", num);
- else {
- pr2serr(" [Unexpected format code: %d]\n", format_code);
- dStrHexErr((const char *)bp, 24, 0);
- }
- bump = 24;
- break;
- case TPROTO_NONE:
- pr2serr("%s No specified protocol\n", leadin);
- /* dStrHexErr((const char *)bp, ((len > 24) ? 24 : len), 0); */
- bump = 24;
- break;
- default:
- pr2serr("%s unknown protocol id=0x%x format_code=%d\n", leadin,
- proto_id, format_code);
- dStrHexErr((const char *)bp, ((len > 24) ? 24 : len), 0);
- bump = 24;
- break;
- }
- }
-}
-
/* VPD_EXT_INQ Extended Inquiry VPD */
static void
decode_x_inq_vpd(unsigned char * b, int len, int do_hex, int do_long,