More LUN handling cleanups

This commit is contained in:
Uwe Seimet 2021-08-23 10:18:11 +02:00
parent aefcf462cb
commit e17513b3a4
2 changed files with 10 additions and 14 deletions

View File

@ -246,13 +246,12 @@ void SCSIDEV::Execute()
LOGDEBUG("++++ CMD ++++ %s Executing command $%02X", __PRETTY_FUNCTION__, (unsigned int)ctrl.cmd[0]);
int lun;
if ((SCSIDEV::scsi_command)ctrl.cmd[0] == eCmdInquiry) {
// Use LUN0 for INQUIRY because LUN0 is assumed to be always available
lun = 0;
}
else {
// Use LUN0 for INQUIRY and REQUEST SENSE because LUN0 is assumed to be always available.
// INQUIRY and REQUEST SENSE have a special LUN handling of their own, required by the SCSI standard.
int lun = 0;
if ((SCSIDEV::scsi_command)ctrl.cmd[0] != eCmdInquiry && (SCSIDEV::scsi_command)ctrl.cmd[0] != eCmdRequestSense) {
lun = (ctrl.cmd[1] >> 5) & 0x07;
if (!ctrl.unit[lun]) {
LOGINFO("Invalid LUN %d for ID %d", lun, GetSCSIID());
@ -353,9 +352,7 @@ void SCSIDEV::Error(ERROR_CODES::sense_key sense_key, ERROR_CODES::asc asc)
ctrl.unit[lun]->SetStatusCode((sense_key << 16) | (asc << 8));
}
// Set status (CHECK CONDITION only for valid LUNs for non-REQUEST SENSE)
ctrl.status = (ctrl.cmd[0] == eCmdRequestSense && asc == ERROR_CODES::asc::INVALID_LUN) ? 0x00 : 0x02;
ctrl.status = 0x02;
ctrl.message = 0x00;
LOGTRACE("%s Error (to status phase)", __PRETTY_FUNCTION__);

View File

@ -383,20 +383,20 @@ void Disk::RequestSense(SASIDEV *controller)
{
DWORD lun = (ctrl->cmd[1] >> 5) & 0x07;
// Note: According to the SCSI specs the LUN handling for REQUEST SENSE is special.
// Non-existing LUNs do *not* result in CHECK CONDITION.
// Only the Sense Key and ASC are set in order to signal the non-existing LUN.
// Note: According to the SCSI specs the LUN handling for REQUEST SENSE non-existing LUNs do *not* result
// in CHECK CONDITION. Only the Sense Key and ASC are set in order to signal the non-existing LUN.
if (!ctrl->unit[lun]) {
// LUN 0 can be assumed to be present (required to call RequestSense() below)
lun = 0;
controller->Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_LUN);
ctrl->status = 0x00;
}
ctrl->length = ctrl->unit[lun]->RequestSense(ctrl->cmd, ctrl->buffer);
ASSERT(ctrl->length > 0);
LOGDEBUG("%s Sense Key $%02X, ASC $%02X",__PRETTY_FUNCTION__, ctrl->buffer[2], ctrl->buffer[12]);
LOGTRACE("%s Status $%02X, Sense Key $%02X, ASC $%02X",__PRETTY_FUNCTION__, ctrl->status, ctrl->buffer[2], ctrl->buffer[12]);
// Read phase
controller->DataIn();
@ -1361,7 +1361,6 @@ int Disk::RequestSense(const DWORD *cdb, BYTE *buf)
// Size determination (according to allocation length)
int size = (int)cdb[4];
LOGTRACE("%s size of data = %d", __PRETTY_FUNCTION__, size);
ASSERT((size >= 0) && (size < 0x100));
// For SCSI-1, transfer 4 bytes when the size is 0