| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ModePageCode |
|
| 1.0;1 |
| 1 | package org.jscsi.target.scsi.modeSense; | |
| 2 | ||
| 3 | ||
| 4 | import java.util.HashMap; | |
| 5 | import java.util.Map; | |
| 6 | ||
| 7 | ||
| 8 | /** | |
| 9 | * Mode Pages for direct-access block devices, as defined in SBC-3. | |
| 10 | * <p> | |
| 11 | * Instances of this enumeration are used to identify a requested or a returned {@link ModePage}. | |
| 12 | * | |
| 13 | * @author Andreas Ergenzinger | |
| 14 | */ | |
| 15 | 0 | public enum ModePageCode { |
| 16 | 0 | APPLICATION_TAG_MODE_PAGE(0x0a, 0x02), BACKGROUND_CONTROL_MODE_PAGE(0x1c, 0x01), CACHING_MODE_PAGE(0x08, 0x00), CONTROL_EXTENSION_MODE_PAGE(0x0a, 0x01), CONTROL_MODE_PAGE(0x0a, 0x00), DISCONNECT_RECONNECT_MODE_PAGE(0x02, 0x00), ENCLOSURE_SERVICES_MANAGEMENT_MODE_PAGE(0x14, 0x00), // do |
| 17 | // not | |
| 18 | // support, | |
| 19 | // since | |
| 20 | // ENCSERV | |
| 21 | // bit | |
| 22 | // in | |
| 23 | // Inquiry | |
| 24 | // data | |
| 25 | // is | |
| 26 | // 0 | |
| 27 | 0 | INFORMATIONAL_EXCEPTIONS_CONTROL_MODE_PAGE(0x1c, 0x00), LOGICAL_BLOCK_PROVISIONING_MODE_PAGE(0x1c, 0x02), POWER_CONDITION_MODE_PAGE(0x1a, 0x00), PROTOCOL_SPECIFIC_LUN_MODE_PAGE(0x18, 0x00), PROTOCOL_SPECIFIC_PORT_MODE_PAGE(0x19, 0x00), READ_WRITE_ERROR_RECOVERY_MODE_PAGE(0x01, 0x00), RETURN_ALL_MODE_PAGES_AND_SUBPAGES(0x3f, 0xff), RETURN_ALL_MODE_PAGES_ONLY(0x3f, 0x00), VERIFY_ERROR_RECOVERY_MODE_PAGE(0x07, 0x00), XOR_CONTROL_MODE_PAGE(0x10, 0x00), |
| 28 | // for returning subpages of the above mode pages (subpageCode = 0xff) | |
| 29 | 0 | APPLICATION_TAG_MODE_PAGE_SUBPAGES(0x0a, 0xff), BACKGROUND_CONTROL_MODE_PAGE_SUBPAGES(0x1c, 0xff), CACHING_MODE_PAGE_SUBPAGES(0x08, 0xff), CONTROL_EXTENSION_MODE_PAGE_SUBPAGES(0x0a, 0xff), CONTROL_MODE_PAGE_SUBPAGES(0x0a, 0xff), DISCONNECT_RECONNECT_MODE_PAGE_SUBPAGES(0x02, 0xff), ENCLOSURE_SERVICES_MANAGEMENT_MODE_PAGE_SUBPAGES(0x14, 0xff), // do |
| 30 | // not | |
| 31 | // support, | |
| 32 | // since | |
| 33 | // ENCSERV | |
| 34 | // bit | |
| 35 | // in | |
| 36 | // Inquiry | |
| 37 | // data | |
| 38 | // is | |
| 39 | // 0 | |
| 40 | 0 | INFORMATIONAL_EXCEPTIONS_CONTROL_MODE_PAGE_SUBPAGES(0x1c, 0xff), LOGICAL_BLOCK_PROVISIONING_MODE_PAGE_SUBPAGES(0x1c, 0xff), POWER_CONDITION_MODE_PAGE_SUBPAGES(0x1a, 0xff), PROTOCOL_SPECIFIC_LUN_MODE_PAGE_SUBPAGES(0x18, 0xff), PROTOCOL_SPECIFIC_PORT_MODE_PAGE_SUBPAGES(0x19, 0xff), READ_WRITE_ERROR_RECOVERY_MODE_PAGE_SUBPAGES(0x01, 0xff), VERIFY_ERROR_RECOVERY_MODE_PAGE_SUBPAGES(0x07, 0xff), XOR_CONTROL_MODE_PAGE_SUBPAGES(0x10, 0xff); |
| 41 | ||
| 42 | /** | |
| 43 | * Allows the retrieval of {@link ModePageCode} instances based on merged PAGE CODE and SUBPAGE CODE field values. | |
| 44 | * | |
| 45 | * @see #joinCodes(int, int) | |
| 46 | */ | |
| 47 | 0 | private static Map<Integer , ModePageCode> map = new HashMap<Integer , ModePageCode>(); |
| 48 | static {// initialize map | |
| 49 | 0 | final ModePageCode[] modePages = values(); |
| 50 | 0 | for (ModePageCode mp : modePages) |
| 51 | 0 | map.put(joinCodes(mp.pageCode, mp.subpageCode),// key |
| 52 | mp);// value | |
| 53 | 0 | } |
| 54 | ||
| 55 | /** | |
| 56 | * Returns the {@link ModePageCode} instance identified by the passed parameters. | |
| 57 | * | |
| 58 | * @param pageCode determines the general category of a {@link ModePage} | |
| 59 | * @param subpageCode determines the sub-category of a {@link ModePage} | |
| 60 | * @return the corresponding {@link ModePageCode} instance of <code> | |
| 61 | * null</code> if there is no corresponding object | |
| 62 | */ | |
| 63 | public static ModePageCode getModePage (final int pageCode, final int subpageCode) { | |
| 64 | 0 | return map.get(joinCodes(pageCode, subpageCode)); |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Determines the general category of the MODE PAGE. | |
| 69 | */ | |
| 70 | private final int pageCode; | |
| 71 | ||
| 72 | /** | |
| 73 | * Determines the sub-category of the MODE PAGE, if applicable. | |
| 74 | */ | |
| 75 | private final int subpageCode; | |
| 76 | ||
| 77 | /** | |
| 78 | * The constructor. | |
| 79 | * | |
| 80 | * @param pageCode determines the general category of a {@link ModePage} | |
| 81 | * @param subpageCode determines the sub-category of a {@link ModePage} | |
| 82 | */ | |
| 83 | 0 | private ModePageCode (final int pageCode, final int subpageCode) { |
| 84 | 0 | this.pageCode = pageCode; |
| 85 | 0 | this.subpageCode = subpageCode; |
| 86 | 0 | } |
| 87 | ||
| 88 | /** | |
| 89 | * Merges the the passed PAGE CODE and SUBPAGE CODE field values to a single value | |
| 90 | * | |
| 91 | * @param pageCode the value of a PAGE CODE field | |
| 92 | * @param subpageCode the value of a SUBPAGE CODE field | |
| 93 | * @return a merged value containing the relevant bits from both parameters | |
| 94 | */ | |
| 95 | private static int joinCodes (final int pageCode, final int subpageCode) { | |
| 96 | 0 | return (pageCode << 8) | subpageCode; |
| 97 | } | |
| 98 | } |