1 package org.jscsi.target.scsi.sense; 2 3 /** 4 * The SENSE KEY field indicates generic information describing an error or exception condition. The field's length is 4 5 * bits. 6 * 7 * @author Andreas Ergenzinger 8 */ 9 public enum SenseKey { 10 /** 11 * Indicates that there is no specific sense key information to be reported. This may occur for a successful command 12 * or for a command that receives CHECK CONDITION status because one of the FILEMARK, EOM, or ILI bits is set to 13 * one. 14 */ 15 NO_SENSE(0x00), 16 /** 17 * Indicates that the command completed successfully, with some recovery action performed by the device server. 18 * Details may be determined by examining the additional sense bytes and the INFORMATION field. When multiple 19 * recovered errors occur during one command, the choice of which error to report (e.g., first, last, most severe) 20 * is vendor specific. 21 */ 22 RECOVERED_ERROR(0x1), 23 /** 24 * Indicates that the logical unit is not accessible. Operator intervention may be required to correct this 25 * condition. 26 */ 27 NOT_READY(0x2), 28 /** 29 * Indicates that the command terminated with a non-recovered error condition that may have been caused by a flaw in 30 * the medium or an error in the recorded data. This sense key may also be returned if the device server is unable 31 * to distinguish between a flaw in the medium and a specific hardware failure (i.e., sense key 4h 32 * {@link #HARDWARE_ERROR}). 33 */ 34 MEDIUM_ERROR(0x3), 35 /** 36 * Indicates that the device server detected a non-recoverable hardware failure (e.g., controller failure, device 37 * failure, or parity error) while performing the command or during a self test. 38 */ 39 HARDWARE_ERROR(0x4), 40 /** 41 * Indicates that: 42 * 43 * a) The command was addressed to an incorrect logical unit number (see SAM-3); b) The command had an invalid task 44 * attribute (see SAM-3); c) The command was addressed to a logical unit whose current configuration prohibits 45 * processing the command; d) There was an illegal parameter in the CDB; or e) There was an illegal parameter in the 46 * additional parameters supplied as data for some commands (e.g., PERSISTENT RESERVE OUT). 47 * 48 * If the device server detects an invalid parameter in the CDB, it shall terminate the command without altering the 49 * medium. If the device server detects an invalid parameter in the additional parameters supplied as data, the 50 * device server may have already altered the medium. 51 */ 52 ILLEGAL_REQUEST(0x5), 53 /** 54 * Indicates that a unit attention condition has been established (e.g., the removable medium may have been changed, 55 * a logical unit reset occurred). See SAM-3. 56 */ 57 UNIT_ATTENTION(0x6), 58 /** 59 * Indicates that a command that reads or writes the medium was attempted on a block that is protected. The read or 60 * write operation is not performed. 61 */ 62 DATA_PROTECT(0x7), 63 /** 64 * Indicates that a write-once device or a sequential-access device encountered blank medium or format-defined 65 * end-of-data indication while reading or that a write-once device encountered a non-blank medium while writing. 66 */ 67 BLANK_CHECK(0x8), 68 /** 69 * This sense key is available for reporting vendor specific conditions. 70 */ 71 VENDOR_SPECIFIC(0x9), 72 /** 73 * Indicates an EXTENDED COPY command was aborted due to an error condition on the source device, the destination 74 * device, or both (see "errors detected during processing of segment descriptors"). 75 */ 76 COPY_ABORTED(0xa), 77 /** 78 * Indicates that the device server aborted the command. The application client may be able to recover by trying the 79 * command again. 80 */ 81 ABORTED_COMMAND(0xb), 82 /* 83 * 0x0c is obsolete. 84 */ 85 /** 86 * Indicates that a buffered SCSI device has reached the end-of-partition and data may remain in the buffer that has 87 * not been written to the medium. One or more RECOVER BUFFERED DATA command(s) may be issued to read the unwritten 88 * data from the buffer. (See SSC-2.) 89 */ 90 VOLUME_OVERFLOW(0xd), 91 /** 92 * Indicates that the source data did not match the data read from the medium. 93 */ 94 MISCOMPARE(0xe); 95 /* 96 * 0xf is reserved. 97 */ 98 99 /** 100 * Look-up array that maps sense key values to instances of this enumeration. 101 */ 102 private static SenseKey[] mapping = new SenseKey[16]; 103 104 static {// initialize mapping 105 final SenseKey[] keys = values(); 106 for (int i = 0; i < keys.length; ++i) 107 mapping[keys[i].value] = keys[i]; 108 // some will remain initialized to null 109 } 110 111 /** 112 * Returns the {@link SenseKey} instance representing the passed <i>value</i>. 113 * 114 * @param value a sense key value 115 * @return the {@link SenseKey} instance representing the passed <i>value</i> 116 */ 117 public static SenseKey valueOf (final int value) { 118 final int index = 15 & value;// keep only the last four bits 119 if (0 < index || index >= mapping.length) return null; 120 return mapping[index]; 121 } 122 123 /** 124 * The serialized value of the {@link SenseKey} instance. 125 */ 126 private final int value; 127 128 /** 129 * The constructor. 130 * 131 * @param value the serialized value of the object. 132 */ 133 private SenseKey (int value) { 134 this.value = value; 135 } 136 137 /** 138 * The serialized value of the instance. 139 * 140 * @return serialized value of the instance 141 */ 142 public int getValue () { 143 return value; 144 } 145 }