View Javadoc

1   package org.jscsi.target.scsi.cdb;
2   
3   
4   import java.nio.ByteBuffer;
5   
6   import org.jscsi.target.util.ReadWrite;
7   
8   
9   /**
10   * This class represents Command Descriptor Blocks for the <code>WRITE (6)</code> SCSI command.
11   * <p>
12   * The WRITE (6) command requests that the device server transfer the specified logical block(s) from the data-out
13   * buffer and write them.
14   * <p>
15   * Each logical block transferred includes user data but does not include protection information. Each logical block
16   * written includes user data and, if the medium is formatted with protection information enabled, protection
17   * information.
18   * <p>
19   * A TRANSFER LENGTH field set to zero specifies that 256 logical blocks shall be written. Any other value specifies the
20   * number of logical blocks that shall be written.
21   * 
22   * @author Andreas Ergenzinger
23   */
24  public class Write6Cdb extends WriteCdb {
25  
26      public Write6Cdb (ByteBuffer buffer) {
27          super(buffer);
28      }
29  
30      @Override
31      protected long deserializeLogicalBlockAddress (ByteBuffer buffer) {
32          // the first three bits of byte 1 are reserved, i.e. must be 0,
33          // check that
34          final byte b = buffer.get(1);
35          if (((b >> 5) & 7) != 0) addIllegalFieldPointer(1);
36  
37          // read the field's value
38          return ((b & 31) << 16) | ReadWrite.readTwoByteInt(buffer, 2);
39      }
40  
41      @Override
42      protected int deserializeTransferLength (ByteBuffer buffer) {
43          /*
44           * A TRANSFER LENGTH field set to zero specifies that 256 logical blocks shall be written. Any other value
45           * specifies the number of logical blocks that shall be written.
46           */
47          final int value = ReadWrite.readOneByteInt(buffer, 4);
48          if (value == 0) return 256;
49          return value;
50      }
51  
52      @Override
53      protected int getLogicalBlockAddressFieldIndex () {
54          return 1;
55      }
56  
57      @Override
58      protected int getTransferLengthFieldIndex () {
59          return 4;
60      }
61  
62  }