| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DeviceIdentificationVpdPage |
|
| 1.5;1.5 |
| 1 | package org.jscsi.target.scsi.inquiry; | |
| 2 | ||
| 3 | ||
| 4 | import java.nio.ByteBuffer; | |
| 5 | ||
| 6 | import org.jscsi.target.TargetServer; | |
| 7 | import org.jscsi.target.scsi.IResponseData; | |
| 8 | import org.jscsi.target.util.ReadWrite; | |
| 9 | ||
| 10 | ||
| 11 | /** | |
| 12 | * The Device Identification VPD page provides the means to retrieve identification descriptors applying to the logical | |
| 13 | * unit. Logical units may have more than one identification descriptor (e.g., if several types or associations of | |
| 14 | * identifier are supported). | |
| 15 | * <p> | |
| 16 | * Device identifiers consist of one or more of the following: | |
| 17 | * <ul> | |
| 18 | * <li>Logical unit names</li> | |
| 19 | * <li>SCSI target port identifiers</li> | |
| 20 | * <li>SCSI target port names</li> | |
| 21 | * <li>SCSI target device names</li> | |
| 22 | * <li>Relative target port identifiers</li> | |
| 23 | * <li>SCSI target port group number or</li> | |
| 24 | * <li>Logical unit group number.</li> | |
| 25 | * </ul> | |
| 26 | * Identification descriptors shall be assigned to the peripheral device (e.g., a disk drive) and not to the currently | |
| 27 | * mounted media, in the case of removable media devices. Operating systems are expected to use the identification | |
| 28 | * descriptors during system configuration activities to determine whether alternate paths exist for the same peripheral | |
| 29 | * device. | |
| 30 | * <p> | |
| 31 | * This class uses the singleton pattern since the content of the DEVICE IDENTIFICATION VPD PAGE will never change. | |
| 32 | * | |
| 33 | * @author Andreas Ergenzinger | |
| 34 | */ | |
| 35 | public class DeviceIdentificationVpdPage implements IResponseData { | |
| 36 | ||
| 37 | /** | |
| 38 | * The total length of all mandatory fields in bytes. | |
| 39 | */ | |
| 40 | private static final int HEADER_LENGTH = 4; | |
| 41 | ||
| 42 | /** | |
| 43 | * The position of the PAGE LENGTH field's most significant byte. | |
| 44 | */ | |
| 45 | private static final int PAGE_LENGTH_FIELD_INDEX = 2; | |
| 46 | ||
| 47 | /** | |
| 48 | * The joint content of the PERIPHERAL QUALIFIER and the PERIPHERAL DEVICE TYPE fields with a total length of one | |
| 49 | * byte. | |
| 50 | * <p> | |
| 51 | * These values have the following meaning: | |
| 52 | * <p> | |
| 53 | * A peripheral device having the specified peripheral device type is connected to this logical unit. If the device | |
| 54 | * server is unable to determine whether or not a peripheral device is connected, it also shall use this peripheral | |
| 55 | * qualifier. This peripheral qualifier does not mean that the peripheral device connected to the logical unit is | |
| 56 | * ready for access. | |
| 57 | * <p> | |
| 58 | * The Logical Unit is a direct access block device (e.g., magnetic disk). | |
| 59 | */ | |
| 60 | 0 | private final byte peripheralQualifierAndPeripheralDeviceType = 0; |
| 61 | ||
| 62 | /** | |
| 63 | * Identifies this PAGE as a DEVICE IDENTIFICATION VPD PAGE. | |
| 64 | */ | |
| 65 | 0 | private final byte pageCode = (byte) 0x83; |
| 66 | ||
| 67 | 0 | private IdentificationDescriptor[] identificationDescriptors = new IdentificationDescriptor[0]; |
| 68 | ||
| 69 | 0 | public DeviceIdentificationVpdPage (TargetServer target) { |
| 70 | ||
| 71 | /* | |
| 72 | * For each logical unit that is not a well known logical unit, the Device Identification VPD page shall include | |
| 73 | * at least one identification descriptor in which a logical unit name (see SAM-3) is indicated. | |
| 74 | */ | |
| 75 | 0 | final ProtocolIdentifier protocolIdentifier = ProtocolIdentifier.INTERNET_SCSI; |
| 76 | 0 | final CodeSet codeSet = CodeSet.UTF8_CODES; |
| 77 | 0 | final boolean protocolIdentifierValid = true; |
| 78 | 0 | final Association association = Association.SCSI_TARGET_DEVICE; |
| 79 | 0 | final IdentifierType identifierType = IdentifierType.SCSI_NAME_STRING; |
| 80 | ||
| 81 | 0 | String[] targetNames = target.getTargetNames(); |
| 82 | 0 | identificationDescriptors = new IdentificationDescriptor[targetNames.length]; |
| 83 | 0 | for (int curTargetNum = 0; curTargetNum < targetNames.length; curTargetNum++) { |
| 84 | 0 | final IdentificationDescriptor identDescriptor = new IdentificationDescriptor(protocolIdentifier, codeSet, protocolIdentifierValid, association, identifierType, new ScsiNameStringIdentifier(targetNames[curTargetNum])); |
| 85 | ||
| 86 | 0 | identificationDescriptors[curTargetNum] = identDescriptor; |
| 87 | } | |
| 88 | ||
| 89 | 0 | } |
| 90 | ||
| 91 | /** | |
| 92 | * Returns the combined length of all contained IDENTIFICATION DESCRIPTORs. | |
| 93 | * | |
| 94 | * @return the combined length of all contained IDENTIFICATION DESCRIPTORs | |
| 95 | */ | |
| 96 | private short getPageLength () { | |
| 97 | 0 | short pageLength = 0; |
| 98 | 0 | for (int i = 0; i < identificationDescriptors.length; ++i) { |
| 99 | 0 | pageLength += (identificationDescriptors[i].size()); |
| 100 | } | |
| 101 | 0 | return pageLength; |
| 102 | } | |
| 103 | ||
| 104 | public void serialize (ByteBuffer byteBuffer, int index) { | |
| 105 | // serialize header | |
| 106 | 0 | byteBuffer.position(index); |
| 107 | 0 | byteBuffer.put(peripheralQualifierAndPeripheralDeviceType); |
| 108 | 0 | byteBuffer.put(pageCode); |
| 109 | ||
| 110 | 0 | ReadWrite.writeTwoByteInt(byteBuffer,// buffer |
| 111 | getPageLength(), index + PAGE_LENGTH_FIELD_INDEX);// index | |
| 112 | 0 | } |
| 113 | ||
| 114 | public int size () { | |
| 115 | 0 | return getPageLength() + HEADER_LENGTH; |
| 116 | } | |
| 117 | } |