| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SenseData |
|
| 4.0;4 |
| 1 | package org.jscsi.target.scsi.sense; | |
| 2 | ||
| 3 | ||
| 4 | import org.jscsi.target.scsi.ISerializable; | |
| 5 | ||
| 6 | ||
| 7 | /** | |
| 8 | * Sense data shall be returned in the same I_T_L_Q nexus transaction as a CHECK CONDITION status and as parameter data | |
| 9 | * in response to the REQUEST SENSE command. | |
| 10 | * <p> | |
| 11 | * Sense data returned in the same I_T_L_Q nexus transaction as a CHECK CONDITION status shall be either fixed or | |
| 12 | * descriptor format sense data format based on the value of the D_SENSE bit in the Control mode page. | |
| 13 | * <p> | |
| 14 | * The REQUEST SENSE command may be used to request either the fixed format sense data or the descriptor format sense | |
| 15 | * data. | |
| 16 | * | |
| 17 | * @author Andreas Ergenzinger | |
| 18 | */ | |
| 19 | public abstract class SenseData implements ISerializable { | |
| 20 | ||
| 21 | /** | |
| 22 | * The first byte of all sense data contains the RESPONSE CODE field that indicates the error type and format of the | |
| 23 | * sense data. | |
| 24 | * | |
| 25 | * @see #errorType | |
| 26 | * @see #senseDataFormat | |
| 27 | */ | |
| 28 | protected final int responseCode; | |
| 29 | ||
| 30 | /** | |
| 31 | * The error type of the sense data as determined by the {@link #responseCode} variable. | |
| 32 | */ | |
| 33 | protected final ErrorType errorType; | |
| 34 | ||
| 35 | /** | |
| 36 | * The format of the sense data as determined by the {@link #responseCode} variable. | |
| 37 | */ | |
| 38 | protected final SenseDataFormat senseDataFormat; | |
| 39 | ||
| 40 | /** | |
| 41 | * The {@link #senseKey} and {@link #additionalSenseCodeAndQualifier} fields provide a hierarchy of information. The | |
| 42 | * hierarchy provides a top-down approach for an application client to determine information relating to the error | |
| 43 | * and exception conditions. | |
| 44 | */ | |
| 45 | protected final SenseKey senseKey; | |
| 46 | ||
| 47 | /** | |
| 48 | * The {@link #senseKey} and {@link #additionalSenseCodeAndQualifier} fields provide a hierarchy of information. The | |
| 49 | * hierarchy provides a top-down approach for an application client to determine information relating to the error | |
| 50 | * and exception conditions. | |
| 51 | */ | |
| 52 | protected final AdditionalSenseCodeAndQualifier additionalSenseCodeAndQualifier; | |
| 53 | ||
| 54 | /** | |
| 55 | * The sense data constructor. | |
| 56 | * | |
| 57 | * @param errorType the error type of the sense data | |
| 58 | * @param senseDataFormat the format of the sense data | |
| 59 | * @param senseKey describes the general category of the error requiring the sending of sense data | |
| 60 | * @param additionalSenseCodeAndQualifier a more specific description of the error | |
| 61 | */ | |
| 62 | 0 | public SenseData (final ErrorType errorType, final SenseDataFormat senseDataFormat, final SenseKey senseKey, final AdditionalSenseCodeAndQualifier additionalSenseCodeAndQualifier) { |
| 63 | 0 | this.errorType = errorType; |
| 64 | 0 | this.senseDataFormat = senseDataFormat; |
| 65 | 0 | responseCode = getReponseCodeFor(errorType, senseDataFormat); |
| 66 | 0 | this.senseKey = senseKey; |
| 67 | 0 | this.additionalSenseCodeAndQualifier = additionalSenseCodeAndQualifier; |
| 68 | 0 | } |
| 69 | ||
| 70 | /** | |
| 71 | * Returns the proper response code for the given error type and sense data format. | |
| 72 | * | |
| 73 | * @param errorType a sense data error type | |
| 74 | * @param senseDataFormat a sense data format | |
| 75 | * @return the proper response code | |
| 76 | */ | |
| 77 | public static final int getReponseCodeFor (final ErrorType errorType, final SenseDataFormat senseDataFormat) { | |
| 78 | 0 | if (senseDataFormat == SenseDataFormat.FIXED) { |
| 79 | 0 | if (errorType == ErrorType.CURRENT) |
| 80 | 0 | return 0x70; |
| 81 | else | |
| 82 | // errorType == DEFERRED | |
| 83 | 0 | return 0x71; |
| 84 | } else {// senseDataFormat == DESCRIPTOR | |
| 85 | 0 | if (errorType == ErrorType.CURRENT) |
| 86 | 0 | return 0x72; |
| 87 | else | |
| 88 | // errorType == DEFERRED | |
| 89 | 0 | return 0x73; |
| 90 | } | |
| 91 | /* | |
| 92 | * Response codes 0x74 to 0x7E are reserved. Response code 0x7f is vendor specific. | |
| 93 | */ | |
| 94 | } | |
| 95 | } |