View Javadoc

1   package org.jscsi.target.scsi.lun;
2   
3   
4   import java.nio.ByteBuffer;
5   
6   import org.jscsi.target.scsi.IResponseData;
7   import org.jscsi.target.util.ReadWrite;
8   
9   
10  /**
11   * Instances of this class are sent to the initiator in response to <code>REPORT LUNS</code> SCSI commands. They contain
12   * a zero or more logical unit numbers (LUNs) that identify some or all of the target's logical units, depending on the
13   * <code>REPORT
14   * LUNS</code> parameters.
15   * 
16   * @author Andreas Ergenzinger
17   */
18  public final class ReportLunsParameterData implements IResponseData {
19  
20      /**
21       * The length of the mandatory header fields in bytes.
22       */
23      private static final int HEADER_LENGTH = 8;
24  
25      /**
26       * The length in bytes of the list of logical unit numbers.
27       */
28      private int lunListLength = 0;
29  
30      /**
31       * LUNs identifying all reported logical units.
32       */
33      private LogicalUnitNumber[] luns;
34  
35      /**
36       * The constructor.
37       * 
38       * @param luns the LUNs to report
39       */
40      public ReportLunsParameterData (LogicalUnitNumber... luns) {
41          this.luns = luns;
42          if (luns != null) lunListLength = LogicalUnitNumber.SIZE * luns.length;
43      }
44  
45      public void serialize (ByteBuffer byteBuffer, int index) {
46  
47          // LUN list length
48          ReadWrite.writeInt(lunListLength, byteBuffer, index);
49  
50          // LUN list
51          int lunIndex = index + HEADER_LENGTH;
52          for (int i = 0; i < luns.length; ++i) {
53              luns[i].serialize(byteBuffer, lunIndex);
54              lunIndex += luns[i].size();
55          }
56      }
57  
58      public int size () {
59          return HEADER_LENGTH + lunListLength;
60      }
61  }