BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
SCSICommandParser parser = (SCSICommandParser) bhs.getParser();
final int initiatorTaskTag = bhs.getInitiatorTaskTag();
// get the Read(6) or Read(10) CDB
ReadCdb cdb;
final ScsiOperationCode scsiOpCode = ScsiOperationCode.valueOf(parser.getCDB().get(0));
if (scsiOpCode == ScsiOperationCode.READ_10)// most likely option first
cdb = new Read10Cdb(parser.getCDB());
else if (scsiOpCode == ScsiOperationCode.READ_6)
cdb = new Read6Cdb(parser.getCDB());
else {
// anything else wouldn't be good (programmer error)
// close connection
throw new InternetSCSIException("wrong SCSI Operation Code " + scsiOpCode + " in ReadStage");
}
// check if requested blocks are out of bounds
checkOverAndUnderflow(cdb);
// check illegal field pointers
if (cdb.getIllegalFieldPointers() != null) {
// the command must fail
LOGGER.debug("illegal field in Read CDB");
// create and send error PDU and leave stage
final ProtocolDataUnit responsePdu = createFixedFormatErrorPdu(cdb.getIllegalFieldPointers(),// senseKeySpecificData
initiatorTaskTag, parser.getExpectedDataTransferLength());
connection.sendPdu(responsePdu);
return;
}
final int totalTransferLength = VIRTUAL_BLOCK_SIZE * cdb.getTransferLength();
final long storageOffset = VIRTUAL_BLOCK_SIZE * cdb.getLogicalBlockAddress();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("cdb.getLogicalBlockAddress() = " + cdb.getLogicalBlockAddress());
LOGGER.debug("blockSize = " + VIRTUAL_BLOCK_SIZE);
LOGGER.debug("totalTransferLength = " + totalTransferLength);
LOGGER.debug("expectedDataSegmentLength = " + parser.getExpectedDataTransferLength());
}