| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SegmentPointerSenseKeySpecificData |
|
| 1.0;1 |
| 1 | package org.jscsi.target.scsi.sense.senseDataDescriptor.senseKeySpecific; | |
| 2 | ||
| 3 | ||
| 4 | import java.nio.ByteBuffer; | |
| 5 | ||
| 6 | import org.jscsi.target.scsi.sense.SenseData; | |
| 7 | import org.jscsi.target.scsi.sense.SenseKey; | |
| 8 | import org.jscsi.target.scsi.sense.senseDataDescriptor.CommandSpecificSenseDataDescriptor; | |
| 9 | import org.jscsi.target.util.BitManip; | |
| 10 | import org.jscsi.target.util.ReadWrite; | |
| 11 | ||
| 12 | ||
| 13 | /** | |
| 14 | * Segment pointer sense-key-specific data is to be used, when the sense key of the enclosing {@link SenseData} has the | |
| 15 | * value {@link SenseKey#COPY_ABORTED}. | |
| 16 | * | |
| 17 | * @author Andreas Ergenzinger | |
| 18 | */ | |
| 19 | public class SegmentPointerSenseKeySpecificData extends SenseKeySpecificData { | |
| 20 | ||
| 21 | /** | |
| 22 | * The segment descriptor (SD) bit indicates whether the field pointer is relative to the start of the parameter | |
| 23 | * list or to the start of a segment descriptor. An SD bit set to zero indicates that the field pointer is relative | |
| 24 | * to the start of the parameter list. An SD bit set to one indicates that the field pointer is relative to the | |
| 25 | * start of the segment descriptor indicated by the third and fourth bytes of the | |
| 26 | * {@link CommandSpecificSenseDataDescriptor#commandSpecificInformation} field. | |
| 27 | */ | |
| 28 | private final boolean segmentDescriptor; | |
| 29 | ||
| 30 | /** | |
| 31 | * A bit pointer valid (BPV) bit set to zero indicates that the value in the {@link #bitPointer} field is not valid. | |
| 32 | * A BPV bit set to one indicates that the {@link #bitPointer} field specifies which bit of the byte designated by | |
| 33 | * the {@link #fieldPointer} field is in error. When a multiple-bit field is in error, the {@link #bitPointerValid} | |
| 34 | * field shall point to the most-significant (i.e., left-most) bit of the field. | |
| 35 | */ | |
| 36 | private final boolean bitPointerValid; | |
| 37 | ||
| 38 | /** | |
| 39 | * The FIELD POINTER field indicates which byte of the parameter list or segment descriptor was in error. | |
| 40 | * | |
| 41 | * @see #bitPointerValid | |
| 42 | */ | |
| 43 | private final short fieldPointer; | |
| 44 | ||
| 45 | /** | |
| 46 | * Points to the leftmost bit of the field in error. | |
| 47 | * | |
| 48 | * @see #bitPointerValid | |
| 49 | */ | |
| 50 | private final int bitPointer; | |
| 51 | ||
| 52 | /** | |
| 53 | * The constructor. | |
| 54 | * <p> | |
| 55 | * All parameters are used to initialize the member variables with the same name. | |
| 56 | * | |
| 57 | * @param senseKeySpecificDataValid | |
| 58 | * @param segmentDescriptor | |
| 59 | * @param bitPointerValid | |
| 60 | * @param bitPointer | |
| 61 | * @param fieldPointer | |
| 62 | */ | |
| 63 | public SegmentPointerSenseKeySpecificData (final boolean senseKeySpecificDataValid, final boolean segmentDescriptor, final boolean bitPointerValid, final int bitPointer, final int fieldPointer) { | |
| 64 | 0 | super(senseKeySpecificDataValid); |
| 65 | 0 | this.segmentDescriptor = segmentDescriptor; |
| 66 | 0 | this.bitPointerValid = bitPointerValid; |
| 67 | 0 | this.bitPointer = bitPointer; |
| 68 | 0 | this.fieldPointer = (short) fieldPointer; |
| 69 | 0 | } |
| 70 | ||
| 71 | @Override | |
| 72 | protected void serializeSpecificFields (final ByteBuffer byteBuffer, final int index) { | |
| 73 | ||
| 74 | 0 | byte b = byteBuffer.get(index);// SKSV bit has already been set and has |
| 75 | // to be preserved | |
| 76 | ||
| 77 | // segment descriptor | |
| 78 | 0 | b = BitManip.getByteWithBitSet(b, 5, segmentDescriptor); |
| 79 | ||
| 80 | // bit pointer valid | |
| 81 | 0 | b = BitManip.getByteWithBitSet(b, 3, bitPointerValid); |
| 82 | ||
| 83 | // bit pointer | |
| 84 | 0 | b &= (bitPointer & 7); |
| 85 | ||
| 86 | // store first byte | |
| 87 | 0 | byteBuffer.put(index, b); |
| 88 | ||
| 89 | // field pointer | |
| 90 | 0 | ReadWrite.writeTwoByteInt(byteBuffer, fieldPointer, byteBuffer.position()); |
| 91 | 0 | } |
| 92 | ||
| 93 | } |