| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ReadCapacity10ParameterData |
|
| 1.0;1 |
| 1 | package org.jscsi.target.scsi.readCapacity; | |
| 2 | ||
| 3 | ||
| 4 | import java.nio.ByteBuffer; | |
| 5 | ||
| 6 | import org.jscsi.target.util.ReadWrite; | |
| 7 | ||
| 8 | ||
| 9 | /** | |
| 10 | * <code>READ CAPACITY (10)</code> parameter data is sent in response to a successful <code> READ CAPACITY (10)</code> | |
| 11 | * SCSI command. | |
| 12 | * | |
| 13 | * @author Andreas Ergenzinger | |
| 14 | */ | |
| 15 | public final class ReadCapacity10ParameterData extends ReadCapacityParameterData { | |
| 16 | ||
| 17 | /** | |
| 18 | * Specifies the limit to the {@link ReadCapacityParameterData#returnedLogicalBlockAddress} field for READ CAPACITY | |
| 19 | * (10) parameter data. | |
| 20 | * <p> | |
| 21 | * If the value of the RETURNED LOGICAL BLOCK ADDRESS field does not fit completely into the available four bytes, | |
| 22 | * then this value will be inserted instead. | |
| 23 | */ | |
| 24 | private static final long MAX_RETURNED_LOGICAL_BLOCK_ADDRESS = 0xffffffffL; | |
| 25 | ||
| 26 | /** | |
| 27 | * The length in bytes of serialized READ CAPACITY (16) parameter data. | |
| 28 | */ | |
| 29 | private static final int SIZE = 8; | |
| 30 | ||
| 31 | public ReadCapacity10ParameterData (final long returnedLogicalBlockAddress, final int logicalBlockLengthInBytes) { | |
| 32 | 0 | super(returnedLogicalBlockAddress, logicalBlockLengthInBytes); |
| 33 | 0 | } |
| 34 | ||
| 35 | public void serialize (ByteBuffer byteBuffer, int index) { | |
| 36 | // returned logical block address | |
| 37 | // trim to size, and prevent overflow (initiator has to use READ | |
| 38 | // CAPACITY (16)) | |
| 39 | 0 | final int rlba = (int) Math.min(returnedLogicalBlockAddress, MAX_RETURNED_LOGICAL_BLOCK_ADDRESS); |
| 40 | 0 | ReadWrite.writeInt(rlba, byteBuffer, index); |
| 41 | ||
| 42 | // logical block length in bytes | |
| 43 | 0 | ReadWrite.writeInt(logicalBlockLengthInBytes, byteBuffer, index + 4); |
| 44 | 0 | } |
| 45 | ||
| 46 | public int size () { | |
| 47 | 0 | return SIZE; |
| 48 | } | |
| 49 | ||
| 50 | } |