📄 scsi_all.c
字号:
return; else { /* * XXX KDM this is stupid, but casting the * structure doesn't work... */ bcopy(&csio->sense_data, sense, sizeof(struct scsi_sense_data *)); } } else { /* * If the physical sense flag is set, but the sense pointer * is not also set, we assume that the user is an idiot and * return. (Well, okay, it could be that somehow, the * entire csio is physical, but we would have probably core * dumped on one of the bogus pointer deferences above * already.) */ if (csio->ccb_h.flags & CAM_SENSE_PHYS) return; else sense = &csio->sense_data; } xpt_print_path(csio->ccb_h.path); error_code = sense->error_code & SSD_ERRCODE; sense_key = sense->flags & SSD_KEY; switch (error_code) { case SSD_DEFERRED_ERROR: printf("Deferred Error: "); /* FALLTHROUGH */ case SSD_CURRENT_ERROR: printf("%s", scsi_sense_key_text[sense_key]); info = scsi_4btoul(sense->info); if (sense->error_code & SSD_ERRCODE_VALID) { switch (sense_key) { case SSD_KEY_NOT_READY: case SSD_KEY_ILLEGAL_REQUEST: case SSD_KEY_UNIT_ATTENTION: case SSD_KEY_DATA_PROTECT: break; case SSD_KEY_BLANK_CHECK: printf(" req sz: %d (decimal)", info); break; default: if (info) { if (sense->flags & SSD_ILI) { printf(" ILI (length mismatch):" " %d", info); } else { printf(" info:%x", info); } } } } else if (info) printf(" info?:%x", info); if (sense->extra_len >= 4) { if (bcmp(sense->cmd_spec_info, "\0\0\0\0", 4)) { printf(" csi:%x,%x,%x,%x", sense->cmd_spec_info[0], sense->cmd_spec_info[1], sense->cmd_spec_info[2], sense->cmd_spec_info[3]); } } asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0; ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0; if (asc || ascq) { const char *desc = scsi_sense_desc(asc, ascq, &cgd.inq_data); printf(" asc:%x,%x\n", asc, ascq); xpt_print_path(csio->ccb_h.path); printf("%s", desc); } if (sense->extra_len >= 7 && sense->fru) { printf(" field replaceable unit: %x", sense->fru); } if ((sense->extra_len >= 10) && (sense->sense_key_spec[0] & SSD_SCS_VALID) != 0) { printf(" sks:%x,%x", sense->sense_key_spec[0], scsi_2btoul(&sense->sense_key_spec[1])); } break; default: printf("error code %d", sense->error_code & SSD_ERRCODE); if (sense->error_code & SSD_ERRCODE_VALID) { printf(" at block no. %d (decimal)", info = scsi_4btoul(sense->info)); } } printf("\n");}#else /* !KERNEL */char *scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio, char *str, int str_len){ struct scsi_sense_data *sense; u_int32_t info; int error_code; int sense_key; int asc, ascq; u_int8_t command_print; char path_str[64]; char tmpstr[2048]; int tmpstrlen = 2048; int cur_len = 0, tmplen = 0, retlen; if ((device == NULL) || (csio == NULL) || (str == NULL)) return(NULL); if (str_len <= 0) return(NULL); /* * If the CDB is a physical address, we can't deal with it.. */ if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0) command_print = 0; else command_print = 1; cam_path_string(device, path_str, 64); str[0] = '\0'; sense = NULL; if (command_print != 0) { char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1]; retlen = snprintf(tmpstr, tmpstrlen, "%s", path_str); if ((tmplen = str_len - cur_len - 1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) { retlen = snprintf(tmpstr, tmpstrlen, "%s. CDB: %s\n", scsi_op_desc(csio->cdb_io.cdb_ptr[0], &device->inq_data), scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str, sizeof(cdb_str))); } else { retlen = snprintf(tmpstr, tmpstrlen, "%s. CDB: %s\n", scsi_op_desc(csio->cdb_io.cdb_bytes[0], &device->inq_data), scsi_cdb_string( csio->cdb_io.cdb_bytes, cdb_str, sizeof(cdb_str))); } if ((tmplen = str_len - cur_len - 1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; } /* * If the sense data is a physical pointer, forget it. */ if (csio->ccb_h.flags & CAM_SENSE_PTR) { if (csio->ccb_h.flags & CAM_SENSE_PHYS) return(NULL); else { /* * XXX KDM this is stupid, but casting the * structure doesn't work... */ bcopy(&csio->sense_data, sense, sizeof(struct scsi_sense_data *)); } } else { /* * If the physical sense flag is set, but the sense pointer * is not also set, we assume that the user is an idiot and * return. (Well, okay, it could be that somehow, the * entire csio is physical, but we would have probably core * dumped on one of the bogus pointer deferences above * already.) */ if (csio->ccb_h.flags & CAM_SENSE_PHYS) return(NULL); else sense = &csio->sense_data; } retlen = snprintf(tmpstr, tmpstrlen, "%s", path_str); if ((tmplen = str_len - cur_len - 1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; error_code = sense->error_code & SSD_ERRCODE; sense_key = sense->flags & SSD_KEY; switch (error_code) { case SSD_DEFERRED_ERROR: retlen = snprintf(tmpstr, tmpstrlen, "Deferred Error: "); if ((tmplen = str_len - cur_len - 1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; /* FALLTHROUGH */ case SSD_CURRENT_ERROR: retlen = snprintf(tmpstr, tmpstrlen, "%s", scsi_sense_key_text[sense_key]); if ((tmplen = str_len - cur_len - 1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; info = scsi_4btoul(sense->info); if (sense->error_code & SSD_ERRCODE_VALID) { switch (sense_key) { case SSD_KEY_NOT_READY: case SSD_KEY_ILLEGAL_REQUEST: case SSD_KEY_UNIT_ATTENTION: case SSD_KEY_DATA_PROTECT: break; case SSD_KEY_BLANK_CHECK: retlen = snprintf(tmpstr, tmpstrlen, " req sz: %d (decimal)", info); if ((tmplen = str_len - cur_len - 1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; break; default: if (info) { if (sense->flags & SSD_ILI) { retlen = snprintf (tmpstr, tmpstrlen, " ILI (length " "mismatch): %d", info); } else { retlen = snprintf(tmpstr, tmpstrlen, " info:%x", info); } if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; } } } else if (info) { retlen = snprintf(tmpstr, tmpstrlen," info?:%x", info); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; } if (sense->extra_len >= 4) { if (bcmp(sense->cmd_spec_info, "\0\0\0\0", 4)) { retlen = snprintf(tmpstr, tmpstrlen, " csi:%x,%x,%x,%x", sense->cmd_spec_info[0], sense->cmd_spec_info[1], sense->cmd_spec_info[2], sense->cmd_spec_info[3]); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; } } asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0; ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0; if (asc || ascq) { const char *desc = scsi_sense_desc(asc, ascq, &device->inq_data); retlen = snprintf(tmpstr, tmpstrlen, " asc:%x,%x\n%s%s", asc, ascq, path_str, desc); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; } if (sense->extra_len >= 7 && sense->fru) { retlen = snprintf(tmpstr, tmpstrlen, " field replaceable unit: %x", sense->fru); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); str[str_len - 1] = '\0'; cur_len += retlen; } if ((sense->extra_len >= 10) && (sense->sense_key_spec[0] & SSD_SCS_VALID) != 0) { retlen = snprintf(tmpstr, tmpstrlen, " sks:%x,%x", sense->sense_key_spec[0], scsi_2btoul(&sense->sense_key_spec[1])); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); str[str_len - 1] = '\0'; cur_len += retlen; } break; default: retlen = snprintf(tmpstr, tmpstrlen, "error code %d", sense->error_code & SSD_ERRCODE); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; if (sense->error_code & SSD_ERRCODE_VALID) { retlen = snprintf(tmpstr, tmpstrlen, " at block no. %d (decimal)", info = scsi_4btoul(sense->info)); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0'; } } retlen = snprintf(tmpstr, tmpstrlen, "\n"); if ((tmplen = str_len - cur_len -1) < 0) goto sst_bailout; strncat(str, tmpstr, tmplen); cur_len += retlen; str[str_len - 1] = '\0';sst_bailout: return(str);}voidscsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, FILE *ofile){ char str[2048]; if ((device == NULL) || (csio == NULL) || (ofile == NULL)) return; fprintf(ofile, "%s", scsi_sense_string(device, csio, str, 2048));}#endif /* KERNEL/!KERNEL */#ifdef KERNELintscsi_interpret_sense(union ccb *ccb, u_int32_t sense_flags, u_int32_t *relsim_flags, u_int3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -