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