| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FormatUnitCDB |
|
| 2.0;2 |
| 1 | package org.jscsi.target.scsi.cdb; | |
| 2 | ||
| 3 | ||
| 4 | import java.nio.ByteBuffer; | |
| 5 | ||
| 6 | import org.jscsi.target.util.BitManip; | |
| 7 | ||
| 8 | ||
| 9 | /** | |
| 10 | * This class represents Command Descriptor Blocks for the <code>FORMAT UNIT</code> SCSI command. | |
| 11 | * | |
| 12 | * @author Andreas Ergenzinger | |
| 13 | */ | |
| 14 | public final class FormatUnitCDB extends CommandDescriptorBlock { | |
| 15 | ||
| 16 | /** | |
| 17 | * The format protection information (FMTPINFO) field in combination with the PROTECTION FIELD USAGE field | |
| 18 | */ | |
| 19 | private byte formatProtectionInformation; | |
| 20 | ||
| 21 | /** | |
| 22 | * A LONGLIST bit set to zero specifies that the parameter list, if any, contains a short parameter list header as | |
| 23 | * defined in SBC-3. A LONGLIST bit set to one specifies that the parameter list, if any, contains a long parameter | |
| 24 | * list header. | |
| 25 | * <p> | |
| 26 | * If the FMTDATA bit is set to zero, then the LONGLIST bit shall be ignored. | |
| 27 | */ | |
| 28 | private boolean longList; | |
| 29 | ||
| 30 | /** | |
| 31 | * A format data (FMTDATA) bit set to zero specifies that no parameter list be transferred from the data-out buffer | |
| 32 | * (i.e. the PDU's data segment is empty). | |
| 33 | */ | |
| 34 | private boolean formatData; | |
| 35 | ||
| 36 | /** | |
| 37 | * A complete list (CMPLST) bit set to zero specifies that the defect list included in the FORMAT UNIT parameter | |
| 38 | * list shall be used in an addition to the existing list of defects. | |
| 39 | */ | |
| 40 | private boolean completeList; | |
| 41 | ||
| 42 | /** | |
| 43 | * If the FMTDATA bit is set to one, then the DEFECT LIST FORMAT field specifies the format of the address | |
| 44 | * descriptors in the defect list. | |
| 45 | */ | |
| 46 | private DefectListFormat defectListFormat; | |
| 47 | ||
| 48 | public FormatUnitCDB (ByteBuffer buffer) { | |
| 49 | 0 | super(buffer); |
| 50 | ||
| 51 | 0 | byte b = buffer.get(1); |
| 52 | ||
| 53 | // format protection information | |
| 54 | 0 | formatProtectionInformation = (byte) (b >>> 6); |
| 55 | ||
| 56 | // long list | |
| 57 | 0 | longList = BitManip.getBit(b, 5); |
| 58 | ||
| 59 | // format data | |
| 60 | 0 | formatData = BitManip.getBit(b, 4); |
| 61 | ||
| 62 | // complete list | |
| 63 | 0 | completeList = BitManip.getBit(b, 3); |
| 64 | ||
| 65 | // defect list format | |
| 66 | 0 | defectListFormat = DefectListFormat.valueOf(b & 7); |
| 67 | 0 | if (!formatData) { |
| 68 | 0 | if (defectListFormat != DefectListFormat.SHORT_BLOCK) addIllegalFieldPointer(1, 2);// illegal defect list |
| 69 | // format | |
| 70 | /* | |
| 71 | * If the FMTDATA bit is set to zero and the FMTPINFO field is not set to zero, then the device server shall | |
| 72 | * terminate the command with CHECK CONDITION status with the sense key set to ILLEGAL REQUEST and the | |
| 73 | * additional sense code set to INVALID FIELD IN CDB. | |
| 74 | */ | |
| 75 | 0 | if (formatProtectionInformation != 0) addIllegalFieldPointer(1, 7); |
| 76 | 0 | } else if (formatData) addIllegalFieldPointer(1, 4);// no support for format data |
| 77 | 0 | } |
| 78 | ||
| 79 | public final boolean getCompleteList () { | |
| 80 | 0 | return completeList; |
| 81 | } | |
| 82 | ||
| 83 | public final int getFormatProtectionInformation () { | |
| 84 | 0 | return formatProtectionInformation; |
| 85 | } | |
| 86 | ||
| 87 | public final boolean getLongList () { | |
| 88 | 0 | return longList; |
| 89 | } | |
| 90 | } |