View Javadoc

1   package org.jscsi.target.scsi.cdb;
2   
3   
4   import java.nio.ByteBuffer;
5   
6   
7   /**
8    * This is an abstract super-class for command descriptor blocks that that are used for requesting information about the
9    * capacity of the storage device.
10   * 
11   * @author Andreas Ergenzinger
12   */
13  public abstract class ReadCapacityCdb extends CommandDescriptorBlock {
14  
15      /**
16       * The LOGICAL BLOCK ADDRESS field specifies the LBA of the first logical block accessed by this command.
17       * <p>
18       * If the specified LBA exceeds the capacity of the medium, then the device server shall terminate the command with
19       * CHECK CONDITION status with the sense key set to ILLEGAL REQUEST and the additional sense code set to LOGICAL
20       * BLOCK ADDRESS OUT OF RANGE.
21       * 
22       * @see #partialMediumIndicator
23       */
24      protected final long logicalBlockAddress;
25  
26      /**
27       * A partial medium indicator (PMI) bit set to zero specifies that the device server return information on the last
28       * logical block on the direct-access block device.
29       * <p>
30       * A PMI bit set to one specifies that the device server return information on the last logical block after that
31       * specified in the LOGICAL BLOCK ADDRESS field before a substantial vendor specific delay in data transfer may be
32       * encountered.
33       * <p>
34       * The LOGICAL BLOCK ADDRESS field shall be set to zero if the PMI bit is set to zero. If the PMI bit is set to zero
35       * and the LOGICAL BLOCK ADDRESS field is not set to zero, then the device server shall terminate the command with
36       * CHECK CONDITION status with the sense key set to ILLEGAL REQUEST and the additional sense code set to INVALID
37       * FIELD IN CDB.
38       * 
39       * @see #logicalBlockAddress
40       */
41      protected final boolean partialMediumIndicator;
42  
43      public ReadCapacityCdb (final ByteBuffer buffer) {
44          super(buffer);
45          logicalBlockAddress = deserializeLogicalBlockAddress(buffer);
46          partialMediumIndicator = deserializePartialMediumIndicator(buffer);
47          // check constraint
48          if (!partialMediumIndicator && logicalBlockAddress > 0) addIllegalFieldPointer(2);
49      }
50  
51      protected abstract long deserializeLogicalBlockAddress (ByteBuffer buffer);
52  
53      protected abstract boolean deserializePartialMediumIndicator (ByteBuffer buffer);
54  
55      public final long getLogicalBlockAddress () {
56          return logicalBlockAddress;
57      }
58  
59      public final boolean getPartialMediumIndicator () {
60          return partialMediumIndicator;
61      }
62  }