Coverage Report - org.jscsi.target.scsi.inquiry.SupportedVpdPages
 
Classes in this File Line Coverage Branch Coverage Complexity
SupportedVpdPages
0%
0/18
0%
0/8
2
 
 1  
 package org.jscsi.target.scsi.inquiry;
 2  
 
 3  
 
 4  
 import java.nio.ByteBuffer;
 5  
 
 6  
 import org.jscsi.target.scsi.IResponseData;
 7  
 import org.jscsi.target.scsi.inquiry.PageCode.VitalProductDataPageName;
 8  
 
 9  
 
 10  
 /**
 11  
  * This Vital Product Data page contains a list of the VPD page codes supported by the logical unit.
 12  
  * <p>
 13  
  * This class uses the singleton pattern since the list of supported Vital Product Data page requests will never change.
 14  
  * 
 15  
  * @author Andreas Ergenzinger
 16  
  */
 17  
 public final class SupportedVpdPages implements IResponseData {
 18  
 
 19  
     /**
 20  
      * The total length of all fields that are not part of the Supported VPD page list.
 21  
      */
 22  
     private static final int HEADER_SIZE = 4;
 23  
 
 24  
     /**
 25  
      * The singleton.
 26  
      */
 27  
     private static SupportedVpdPages instance;
 28  
 
 29  
     /*
 30  
      * determine which pages to support must be in ascending order see PAGECode.VitalProductDataPageName
 31  
      */
 32  0
     public static final byte[] SUPPORTED_VPD_PAGES = new byte[] { (byte) 0x00,// SUPPORTED_VPD_PAGES,
 33  
             // mandatory
 34  
     (byte) 0x83,// DECIVE_IDENTIFICATION, mandatory
 35  
     };
 36  
 
 37  
     /**
 38  
      * Returns the singleton.
 39  
      * 
 40  
      * @return the singleton
 41  
      */
 42  
     public static SupportedVpdPages getInstance () {
 43  0
         if (instance == null) instance = new SupportedVpdPages();
 44  0
         return instance;
 45  
     }
 46  
 
 47  0
     private SupportedVpdPages () {
 48  
         // private due to singleton pattern
 49  0
     }
 50  
 
 51  
     public void serialize (ByteBuffer byteBuffer, int index) {
 52  
 
 53  
         // *** byte 0 ***
 54  
         /*
 55  
          * Peripheral Qualifier (bits 7 - 5): 000b A peripheral device having the specified peripheral device type is
 56  
          * connected to this logical unit. If the device server is unable to determine whether or not a peripheral
 57  
          * device is connected, it also shall use this peripheral qualifier. This peripheral qualifier does not mean
 58  
          * that the peripheral device connected to the logical unit is ready for access. Peripheral Device Type (bits 4
 59  
          * - 0): 00000b direct access block device
 60  
          */
 61  0
         byteBuffer.position(index);
 62  0
         byteBuffer.put((byte) 0);
 63  
 
 64  
         // *** byte 1 ***
 65  
         /*
 66  
          * Page Code: 0x00 supported VPD pages
 67  
          */
 68  0
         byteBuffer.put((byte) 0);
 69  
 
 70  
         // *** byte 2 ***
 71  
         // RESERVED
 72  0
         byteBuffer.put((byte) 0);
 73  
 
 74  
         // *** byte 3 ***
 75  
         /*
 76  
          * Page Length: n - 3 = 5 - 3 = 2 (for now)
 77  
          */
 78  0
         byteBuffer.put((byte) SUPPORTED_VPD_PAGES.length);
 79  
 
 80  
         // *** bytes 4 and 5 - Supported VPD Pages ***
 81  0
         for (int i = 0; i < SUPPORTED_VPD_PAGES.length; ++i)
 82  0
             byteBuffer.put(SUPPORTED_VPD_PAGES[i]);
 83  0
     }
 84  
 
 85  
     public int size () {
 86  0
         return HEADER_SIZE + SUPPORTED_VPD_PAGES.length;
 87  
     }
 88  
 
 89  
     /**
 90  
      * Returns <code>true</code> for those and only for those VPD Page Codes which are supported by the jSCSI Target.
 91  
      * 
 92  
      * @param vitalProductDataPageName VPD Page Name whose support is inquired
 93  
      * @return <code>true</code> for those and only for those VPD Page Codes which are supported by the jSCSI Target
 94  
      */
 95  
     public static boolean vpdPageCodeSupported (final VitalProductDataPageName vitalProductDataPageName) {
 96  0
         for (int i = 0; i < SUPPORTED_VPD_PAGES.length; ++i) {
 97  0
             PageCode pageCode = new PageCode(SUPPORTED_VPD_PAGES[i]);
 98  0
             if (pageCode.getVitalProductDataPageName() == vitalProductDataPageName) return true;
 99  
         }
 100  0
         return false;
 101  
     }
 102  
 }