| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Write10Cdb |
|
| 1.0;1 |
| 1 | package org.jscsi.target.scsi.cdb; | |
| 2 | ||
| 3 | ||
| 4 | import java.nio.ByteBuffer; | |
| 5 | ||
| 6 | import org.jscsi.target.util.BitManip; | |
| 7 | import org.jscsi.target.util.ReadWrite; | |
| 8 | ||
| 9 | ||
| 10 | /** | |
| 11 | * This class represents Command Descriptor Blocks for the <code>WRITE (6)</code> SCSI command. | |
| 12 | * | |
| 13 | * @author Andreas Ergenzinger | |
| 14 | */ | |
| 15 | public class Write10Cdb extends WriteCdb { | |
| 16 | ||
| 17 | /** | |
| 18 | * The value of the WRPROTECT field determines which checks on the protection information resulting from the | |
| 19 | * attempted write operation to the medium the target shall perform before returning status for the command | |
| 20 | * associated with this command descriptor block. | |
| 21 | * <p> | |
| 22 | * Since the jSCSI Target simulates a logical unit formatted without any protection information (that can be | |
| 23 | * checked), the value of this field is inconsequential. | |
| 24 | */ | |
| 25 | private final int writeProtect; | |
| 26 | ||
| 27 | /** | |
| 28 | * This variable represents the value of the DPO bit. Since the jSCSI Target does not support advanced caching | |
| 29 | * strategies, the value of this variable is ignored. | |
| 30 | * <p> | |
| 31 | * A disable page out (DPO) bit set to zero specifies that the retention priority shall be determined by the | |
| 32 | * RETENTION PRIORITY fields in the Caching mode page (see 6.4.5). A DPO bit set to one specifies that the device | |
| 33 | * server shall assign the logical blocks accessed by this command the lowest retention priority for being fetched | |
| 34 | * into or retained by the cache. A DPO bit set to one overrides any retention priority specified in the Caching | |
| 35 | * mode page. All other aspects of the algorithm implementing the cache replacement strategy are not defined by this | |
| 36 | * standard. | |
| 37 | * <p> | |
| 38 | * NOTE 11 - The DPO bit is used to control replacement of logical blocks in the cache when the application client | |
| 39 | * has information on the future usage of the logical blocks. If the DPO bit is set to one, then the application | |
| 40 | * client is specifying that the logical blocks accessed by the command are not likely to be accessed again in the | |
| 41 | * near future and should not be put in the cache nor retained by the cache. If the DPO bit is set to zero, then the | |
| 42 | * application client is specifying that the logical blocks accessed by this command are likely to be accessed again | |
| 43 | * in the near future. | |
| 44 | */ | |
| 45 | private final boolean disablePageOut; | |
| 46 | ||
| 47 | /** | |
| 48 | * The FUA ({@link #forceUnitAccess}) and FUA_NV ( {@link #forceUnitAccessNonVolatileCache}) bits together determine | |
| 49 | * where exactly the transmitted data shall be written (cache, non-volatile cache, or medium) before sending the | |
| 50 | * response. | |
| 51 | * <p> | |
| 52 | * <table border="1"> | |
| 53 | * <tr> | |
| 54 | * <th>FUA</th> | |
| 55 | * <th>FUA_NV</th> | |
| 56 | * <th>Description</th> | |
| 57 | * </tr> | |
| 58 | * <tr> | |
| 59 | * <td>0</td> | |
| 60 | * <td>0</td> | |
| 61 | * <td>The device server may read the logical blocks from volatile cache, non-volatile cache, and/or the medium.</td> | |
| 62 | * </tr> | |
| 63 | * <tr> | |
| 64 | * <td>0</td> | |
| 65 | * <td>1</td> | |
| 66 | * <td>If the NV_SUP bit is set to one in the Extended INQUIRY Data VPD page (see SPC-4), then the device server | |
| 67 | * shall read the logical blocks from non-volatile cache or the medium. If a non-volatile cache is present and a | |
| 68 | * volatile cache contains a more recent version of a logical block, then the device server shall write the logical | |
| 69 | * block to:<br/> | |
| 70 | * a) non-volatile cache; and/or<br/> | |
| 71 | * b) the medium,<br/> | |
| 72 | * before reading it. If the NV_SUP bit is set to zero in the Extended INQUIRY Data VPD page (see SPC-4), then the | |
| 73 | * device server may write the logical blocks to volatile cache, non-volatile cache, and/or the medium.</td> | |
| 74 | * </tr> | |
| 75 | * <tr> | |
| 76 | * <td>1</td> | |
| 77 | * <td>0 or 1</td> | |
| 78 | * <td>The device server may read the logical blocks from volatile cache, non-volatile cache, and/or the medium.</td> | |
| 79 | * </tr> | |
| 80 | * </table> | |
| 81 | */ | |
| 82 | private final boolean forceUnitAccess; | |
| 83 | ||
| 84 | /** | |
| 85 | * The FUA ({@link #forceUnitAccess}) and FUA_NV ( {@link #forceUnitAccessNonVolatileCache}) bits together determine | |
| 86 | * where exactly the transmitted data shall be written (cache, non-volatile cache, or medium) before sending the | |
| 87 | * response. | |
| 88 | * | |
| 89 | * @see #forceUnitAccess | |
| 90 | */ | |
| 91 | private final boolean forceUnitAccessNonVolatileCache; | |
| 92 | ||
| 93 | /** | |
| 94 | * The GROUP NUMBER field can specify a particular grouping function, which is a function that collects information | |
| 95 | * about attributes associated with commands (i.e., information about commands with the same group value are | |
| 96 | * collected into the specified group). | |
| 97 | * <p> | |
| 98 | * The collection of this information is outside the scope of the SCSI standard (as of SBC3R25) and also not part of | |
| 99 | * the iSCSI specification, so the value of this field will be ignored. | |
| 100 | * <p> | |
| 101 | * Support for the grouping function is indicated in the GROUP_SUP bit in the Extended INQUIRY Data VPD page (see | |
| 102 | * SPC-4). | |
| 103 | * <p> | |
| 104 | * | |
| 105 | */ | |
| 106 | private final int groupNumber; | |
| 107 | ||
| 108 | public Write10Cdb (ByteBuffer buffer) { | |
| 109 | 0 | super(buffer);// OPERATION CODE + CONTROL |
| 110 | ||
| 111 | // RDPROTECT | |
| 112 | 0 | byte b = buffer.get(1); |
| 113 | 0 | writeProtect = (b >> 5) & 7; |
| 114 | ||
| 115 | // DPO | |
| 116 | 0 | disablePageOut = BitManip.getBit(b, 4); |
| 117 | ||
| 118 | // FUA | |
| 119 | 0 | forceUnitAccess = BitManip.getBit(b, 3); |
| 120 | ||
| 121 | // FUA_NV | |
| 122 | 0 | forceUnitAccessNonVolatileCache = BitManip.getBit(b, 1); |
| 123 | ||
| 124 | // GROUP NUMBER | |
| 125 | 0 | b = buffer.get(6); |
| 126 | 0 | groupNumber = b & 31; |
| 127 | 0 | } |
| 128 | ||
| 129 | @Override | |
| 130 | protected long deserializeLogicalBlockAddress (ByteBuffer buffer) { | |
| 131 | 0 | return ReadWrite.readUnsignedInt(buffer, 2); |
| 132 | } | |
| 133 | ||
| 134 | @Override | |
| 135 | protected int deserializeTransferLength (ByteBuffer buffer) { | |
| 136 | 0 | return ReadWrite.readTwoByteInt(buffer, 7); |
| 137 | } | |
| 138 | ||
| 139 | public int getWriteProtect () { | |
| 140 | 0 | return writeProtect; |
| 141 | } | |
| 142 | ||
| 143 | public boolean disablePageOut () { | |
| 144 | 0 | return disablePageOut; |
| 145 | } | |
| 146 | ||
| 147 | public boolean getForceUnitAccess () { | |
| 148 | 0 | return forceUnitAccess; |
| 149 | } | |
| 150 | ||
| 151 | public boolean getForceUnitAccessNonVolatile () { | |
| 152 | 0 | return forceUnitAccessNonVolatileCache; |
| 153 | } | |
| 154 | ||
| 155 | public int getGroupNumber () { | |
| 156 | 0 | return groupNumber; |
| 157 | } | |
| 158 | ||
| 159 | @Override | |
| 160 | protected int getLogicalBlockAddressFieldIndex () { | |
| 161 | 0 | return 2; |
| 162 | } | |
| 163 | ||
| 164 | @Override | |
| 165 | protected int getTransferLengthFieldIndex () { | |
| 166 | 0 | return 7; |
| 167 | } | |
| 168 | ||
| 169 | } |