mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-23 12:31:10 +00:00
Updated LUN handling
This commit is contained in:
parent
abcfcf73a2
commit
edc3bab07a
src/raspberrypi
@ -245,30 +245,39 @@ void SCSIDEV::Execute()
|
||||
ctrl.status = 0;
|
||||
}
|
||||
|
||||
LOGDEBUG("++++ CMD ++++ %s Executing command $%02X", __PRETTY_FUNCTION__, (unsigned int)ctrl.cmd[0]);
|
||||
|
||||
int lun;
|
||||
try {
|
||||
// TODO Verify LUN handling
|
||||
if ((SCSIDEV::scsi_command)ctrl.cmd[0] == eCmdInquiry) {
|
||||
// Use LUN0 for INQUIRY because LUN0 is assumed to be always available
|
||||
ctrl.device = ctrl.unit[0];
|
||||
lun = 0;
|
||||
}
|
||||
else {
|
||||
ctrl.device = ctrl.unit[GetLun()];
|
||||
lun = GetLun();
|
||||
}
|
||||
}
|
||||
catch (const lun_exception& e) {
|
||||
LOGINFO("%s Invalid LUN %d for ID %d", __PRETTY_FUNCTION__, e.getlun(), GetSCSIID());
|
||||
LOGINFO("Invalid LUN %d for ID %d", e.getlun(), GetSCSIID());
|
||||
|
||||
Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_LUN);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGDEBUG("++++ CMD ++++ %s Dispatching command $%02X", __PRETTY_FUNCTION__, (unsigned int)ctrl.cmd[0]);
|
||||
ctrl.device = ctrl.unit[lun];
|
||||
|
||||
if (!ctrl.device->Dispatch(this)) {
|
||||
LOGWARN("%s ID %d received unsupported command: $%02X", __PRETTY_FUNCTION__, GetSCSIID(), (BYTE)ctrl.cmd[0]);
|
||||
LOGWARN("ID %d LUN %d received unsupported command: $%02X", GetSCSIID(), lun, (BYTE)ctrl.cmd[0]);
|
||||
|
||||
Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_COMMAND_OPERATION_CODE);
|
||||
}
|
||||
|
||||
if ((SCSIDEV::scsi_command)ctrl.cmd[0] == eCmdInquiry) {
|
||||
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
|
||||
if (((ctrl.cmd[1] >> 5) & 0x07) != ctrl.device->GetLun()) {
|
||||
ctrl.buffer[0] = 0x7f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@ -337,14 +346,11 @@ void SCSIDEV::Error(ERROR_CODES::sense_key sense_key, ERROR_CODES::asc asc)
|
||||
return;
|
||||
}
|
||||
|
||||
// Logical Unit
|
||||
DWORD lun = (ctrl.cmd[1] >> 5) & 0x07;
|
||||
if (!ctrl.unit[lun] || asc == ERROR_CODES::INVALID_LUN) {
|
||||
lun = 0;
|
||||
}
|
||||
|
||||
LOGDEBUG("%s Sense Key and ASC: $%02X, $%02X", __PRETTY_FUNCTION__, sense_key, asc);
|
||||
|
||||
if (sense_key || asc) {
|
||||
// Set Sense Key and ASC for a subsequent REQUEST SENSE
|
||||
ctrl.unit[lun]->SetStatusCode((sense_key << 16) | (asc << 8));
|
||||
|
@ -111,7 +111,9 @@ const string Device::GetPaddedName() const
|
||||
|
||||
void Device::SetStatusCode(int status_code)
|
||||
{
|
||||
LOGDEBUG("Setting status: Sense Key: $%02X, ASC: $%02X, ASCQ: $%02X", status_code >> 16, (status_code >> 8 &0xff), status_code & 0xff);
|
||||
if (status_code) {
|
||||
LOGDEBUG("Error status: Sense Key $%02X, ASC $%02X, ASCQ $%02X", status_code >> 16, (status_code >> 8 &0xff), status_code & 0xff);
|
||||
}
|
||||
|
||||
this->status_code = status_code;
|
||||
}
|
||||
|
@ -179,11 +179,6 @@ int SCSIDaynaPort::Inquiry(const DWORD *cdb, BYTE *buffer)
|
||||
memcpy(&buffer[8], GetPaddedName().c_str(), 28);
|
||||
}
|
||||
|
||||
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
|
||||
if ((cdb[1] >> 5) & 0x07) {
|
||||
buffer[0] |= 0x7f;
|
||||
}
|
||||
|
||||
LOGTRACE("response size is %d", (int)allocation_length);
|
||||
|
||||
return allocation_length;
|
||||
|
@ -140,12 +140,6 @@ int SCSIBR::Inquiry(const DWORD *cdb, BYTE *buf)
|
||||
// buf[4] ... Inquiry additional data
|
||||
memset(buf, 0, 8);
|
||||
buf[0] = 0x09;
|
||||
|
||||
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
|
||||
if (((cdb[1] >> 5) & 0x07) != GetLun()) {
|
||||
buf[0] = 0x7f;
|
||||
}
|
||||
|
||||
buf[2] = 0x02;
|
||||
buf[3] = 0x02;
|
||||
buf[4] = 36 - 5 + 8; // required + 8 byte extension
|
||||
|
@ -583,12 +583,6 @@ int SCSICD::Inquiry(const DWORD *cdb, BYTE *buf)
|
||||
// buf[4] ... Inquiry additional data
|
||||
memset(buf, 0, 8);
|
||||
buf[0] = 0x05;
|
||||
|
||||
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
|
||||
if (((cdb[1] >> 5) & 0x07) != GetLun()) {
|
||||
buf[0] = 0x7f;
|
||||
}
|
||||
|
||||
buf[1] = 0x80;
|
||||
buf[2] = 0x02;
|
||||
buf[3] = 0x02;
|
||||
|
@ -126,12 +126,6 @@ int SCSIHD::Inquiry(const DWORD *cdb, BYTE *buf)
|
||||
// buf[3] ... SCSI-2 compliant Inquiry response
|
||||
// buf[4] ... Inquiry additional data
|
||||
memset(buf, 0, 8);
|
||||
|
||||
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
|
||||
if (((cdb[1] >> 5) & 0x07) != GetLun()) {
|
||||
buf[0] = 0x7f;
|
||||
}
|
||||
|
||||
buf[1] = IsRemovable() ? 0x80 : 0x00;
|
||||
buf[2] = 0x02;
|
||||
buf[3] = 0x02;
|
||||
|
@ -125,12 +125,6 @@ int SCSIMO::Inquiry(const DWORD *cdb, BYTE *buf)
|
||||
// buf[4] ... Inquiry additional data
|
||||
memset(buf, 0, 8);
|
||||
buf[0] = 0x07;
|
||||
|
||||
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
|
||||
if (((cdb[1] >> 5) & 0x07) != GetLun()) {
|
||||
buf[0] = 0x7f;
|
||||
}
|
||||
|
||||
buf[1] = 0x80;
|
||||
buf[2] = 0x02;
|
||||
buf[3] = 0x02;
|
||||
|
Loading…
x
Reference in New Issue
Block a user