void ctl_scsi_sense_print(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data) { struct sbuf sb; char str[512]; sbuf_new(&sb, str, sizeof(str), 0); ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND); sbuf_finish(&sb); printf("%s", sbuf_data(&sb)); }
char * ctl_scsi_sense_string(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data, char *str, int str_len) { struct sbuf sb; sbuf_new(&sb, str, str_len, 0); ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND); sbuf_finish(&sb); return(sbuf_data(&sb)); }
/* * ctl_scsi_sense_sbuf() returns 0 for success and -1 for failure. */ int ctl_scsi_sense_sbuf(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data, struct sbuf *sb, scsi_sense_string_flags flags) { char path_str[64]; if ((ctsio == NULL) || (sb == NULL)) return(-1); ctl_scsi_path_string((union ctl_io *)ctsio, path_str, sizeof(path_str)); if (flags & SSS_FLAG_PRINT_COMMAND) { sbuf_cat(sb, path_str); ctl_scsi_command_string(ctsio, inq_data, sb); sbuf_printf(sb, "\n"); } scsi_sense_only_sbuf(&ctsio->sense_data, ctsio->sense_len, sb, path_str, inq_data, ctsio->cdb, ctsio->cdb_len); return(0); } char * ctl_scsi_sense_string(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data, char *str, int str_len) { struct sbuf sb; sbuf_new(&sb, str, str_len, 0); ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND); sbuf_finish(&sb); return(sbuf_data(&sb)); } #ifdef _KERNEL void ctl_scsi_sense_print(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data) { struct sbuf sb; char str[512]; sbuf_new(&sb, str, sizeof(str), 0); ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND); sbuf_finish(&sb); printf("%s", sbuf_data(&sb)); } #else /* _KERNEL */ void ctl_scsi_sense_print(struct ctl_scsiio *ctsio, struct scsi_inquiry_data *inq_data, FILE *ofile) { struct sbuf sb; char str[512]; if ((ctsio == NULL) || (ofile == NULL)) return; sbuf_new(&sb, str, sizeof(str), 0); ctl_scsi_sense_sbuf(ctsio, inq_data, &sb, SSS_FLAG_PRINT_COMMAND); sbuf_finish(&sb); fprintf(ofile, "%s", sbuf_data(&sb)); }
void ctl_io_error_sbuf(union ctl_io *io, struct scsi_inquiry_data *inq_data, struct sbuf *sb) { struct ctl_status_desc *status_desc; char path_str[64]; unsigned int i; ctl_io_sbuf(io, sb); status_desc = NULL; for (i = 0; i < (sizeof(ctl_status_table)/sizeof(ctl_status_table[0])); i++) { if ((io->io_hdr.status & CTL_STATUS_MASK) == ctl_status_table[i].status) { status_desc = &ctl_status_table[i]; break; } } ctl_scsi_path_string(io, path_str, sizeof(path_str)); sbuf_cat(sb, path_str); if (status_desc == NULL) sbuf_printf(sb, "CTL Status: Unknown status %#x\n", io->io_hdr.status); else sbuf_printf(sb, "CTL Status: %s\n", status_desc->description); if ((io->io_hdr.io_type == CTL_IO_SCSI) && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SCSI_ERROR)) { sbuf_cat(sb, path_str); sbuf_printf(sb, "SCSI Status: %s\n", ctl_scsi_status_string(&io->scsiio)); if (io->scsiio.scsi_status == SCSI_STATUS_CHECK_COND) ctl_scsi_sense_sbuf(&io->scsiio, inq_data, sb, SSS_FLAG_NONE); } }