diff options
author | scottl <scottl@FreeBSD.org> | 2016-04-13 15:43:11 +0000 |
---|---|---|
committer | scottl <scottl@FreeBSD.org> | 2016-04-13 15:43:11 +0000 |
commit | a9631932520f7bf37a07665c623cdb0cc19c9469 (patch) | |
tree | b98d1ae544aaed40df75ddaf1053fa7fcc6eac50 /sys/cam | |
parent | 1e9dcae23e4d877badbc3d3af39e9c08480f628b (diff) | |
download | FreeBSD-src-a9631932520f7bf37a07665c623cdb0cc19c9469.zip FreeBSD-src-a9631932520f7bf37a07665c623cdb0cc19c9469.tar.gz |
Add scsi_cdb_sbuf() for handling CDB strings. Reimplement scsi_cdb_string()
in terms of it.
Reviewed by: imp, mav, ken
MFC after: 3 days
Sponsored by: Netflix
Differential Revision: D5934
Diffstat (limited to 'sys/cam')
-rw-r--r-- | sys/cam/scsi/scsi_all.c | 33 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_all.h | 1 |
2 files changed, 26 insertions, 8 deletions
diff --git a/sys/cam/scsi/scsi_all.c b/sys/cam/scsi/scsi_all.c index 023103b..0c40899 100644 --- a/sys/cam/scsi/scsi_all.c +++ b/sys/cam/scsi/scsi_all.c @@ -3464,14 +3464,32 @@ scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) { + struct sbuf sb; + int error; + + if (len == 0) + return (""); + + sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN); + + scsi_cdb_sbuf(cdb_ptr, &sb); + + /* ENOMEM just means that the fixed buffer is full, OK to ignore */ + error = sbuf_finish(&sb); + if (error != 0 && error != ENOMEM) + return (""); + + return(sbuf_data(&sb)); +} + +void +scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb) +{ u_int8_t cdb_len; int i; if (cdb_ptr == NULL) - return(""); - - /* Silence warnings */ - cdb_len = 0; + return; /* * This is taken from the SCSI-3 draft spec. @@ -3508,12 +3526,11 @@ scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) cdb_len = 12; break; } - *cdb_string = '\0'; + for (i = 0; i < cdb_len; i++) - snprintf(cdb_string + strlen(cdb_string), - len - strlen(cdb_string), "%02hhx ", cdb_ptr[i]); + sbuf_printf(sb, "%02hhx ", cdb_ptr[i]); - return(cdb_string); + return; } const char * diff --git a/sys/cam/scsi/scsi_all.h b/sys/cam/scsi/scsi_all.h index 997a58c..e5b492f 100644 --- a/sys/cam/scsi/scsi_all.h +++ b/sys/cam/scsi/scsi_all.h @@ -3646,6 +3646,7 @@ const char * scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data); char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len); +void scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb); void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); void scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data); |