Use enums for device type and scsi level (#718)

* Use enums for device type and scsi level

* Renaming

* Use new enum instead of magic values

* Comment update

* Fixed REQUEST SENSE regression
This commit is contained in:
Uwe Seimet 2022-03-02 18:31:42 +01:00 committed by GitHub
parent 0297fe856a
commit 305a7fb99d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 30 additions and 25 deletions

View File

@ -59,8 +59,7 @@ void HostServices::TestUnitReady(SCSIDEV *controller)
vector<BYTE> HostServices::Inquiry() const
{
// Processor device, SPC-5, not removable
return PrimaryDevice::Inquiry(3, 7, false);
return PrimaryDevice::Inquiry(device_type::PROCESSOR, scsi_level::SPC_5, false);
}
void HostServices::StartStopUnit(SCSIDEV *controller)

View File

@ -111,7 +111,6 @@ void PrimaryDevice::RequestSense(SASIDEV *controller)
controller->Error(sense_key::ILLEGAL_REQUEST, asc::INVALID_LUN);
ctrl->status = 0x00;
return;
}
size_t allocation_length = ctrl->cmd[4];
@ -161,21 +160,20 @@ bool PrimaryDevice::CheckReady()
return true;
}
vector<BYTE> PrimaryDevice::Inquiry(int type, int scsi_level, bool is_removable) const
vector<BYTE> PrimaryDevice::Inquiry(device_type type, scsi_level level, bool is_removable) const
{
vector<BYTE> buf = vector<BYTE>(0x1F + 5);
// Basic data
// buf[0] ... SCSI Device type
// buf[0] ... SCSI device type
// buf[1] ... Bit 7: Removable/not removable
// buf[2] ... SCSI-2 compliant command system
// buf[3] ... SCSI-2 compliant Inquiry response
// buf[2] ... SCSI compliance level of command system
// buf[3] ... SCSI compliance level of Inquiry response
// buf[4] ... Inquiry additional data
buf[0] = type;
buf[1] = is_removable ? 0x80 : 0x00;
buf[2] = scsi_level;
// Response data format is SCSI-2 for devices supporting SCSI-2 or newer, otherwise it is SCSI-1-CCS
buf[3] = scsi_level >= 2 ? 2 : 1;
buf[2] = level;
buf[3] = level >= scsi_level::SCSI_2 ? scsi_level::SCSI_2 : scsi_level::SCSI_1_CCS;
buf[4] = 0x1F;
// Padded vendor, product, revision

View File

@ -41,7 +41,7 @@ public:
protected:
vector<BYTE> Inquiry(int, int, bool) const;
vector<BYTE> Inquiry(scsi_defs::device_type, scsi_level, bool) const;
SASIDEV::ctrl_t *ctrl;

View File

@ -114,8 +114,7 @@ void SCSIDaynaPort::Open(const Filepath& path)
vector<BYTE> SCSIDaynaPort::Inquiry() const
{
// Processor device, SCSI-2, not removable
return PrimaryDevice::Inquiry(3, 2, false);
return PrimaryDevice::Inquiry(device_type::PROCESSOR, scsi_level::SCSI_2, false);
}
//---------------------------------------------------------------------------

View File

@ -101,8 +101,7 @@ bool SCSIBR::Dispatch(SCSIDEV *controller)
vector<BYTE> SCSIBR::Inquiry() const
{
// Communications device, SCSI-2, not removable
vector<BYTE> b = PrimaryDevice::Inquiry(9, 2, false);
vector<BYTE> b = PrimaryDevice::Inquiry(device_type::COMMUNICATIONS, scsi_level::SCSI_2, false);
// The bridge returns 6 more additional bytes than the other devices
vector<BYTE> buf = vector<BYTE>(0x1F + 8 + 5);

View File

@ -105,8 +105,7 @@ void SCSIPrinter::TestUnitReady(SCSIDEV *controller)
vector<BYTE> SCSIPrinter::Inquiry() const
{
// Printer device, SCSI-2, not removable
return PrimaryDevice::Inquiry(2, 2, false);
return PrimaryDevice::Inquiry(device_type::PRINTER, scsi_level::SCSI_2, false);
}
void SCSIPrinter::ReserveUnit(SCSIDEV *controller)

View File

@ -399,8 +399,7 @@ void SCSICD::ReadToc(SASIDEV *controller)
vector<BYTE> SCSICD::Inquiry() const
{
// CD-ROM device, SCSI-2, removable
return PrimaryDevice::Inquiry(5, 2, true);
return PrimaryDevice::Inquiry(device_type::CD_ROM, scsi_level::SCSI_2, true);
//
// The following code worked with the modified Apple CD-ROM drivers. Need to

View File

@ -100,8 +100,7 @@ void SCSIHD::Open(const Filepath& path)
vector<BYTE> SCSIHD::Inquiry() const
{
// Direct access device, SCSI-2
return PrimaryDevice::Inquiry(0, 2, IsRemovable());
return PrimaryDevice::Inquiry(device_type::DIRECT_ACCESS, scsi_level::SCSI_2, IsRemovable());
}
bool SCSIHD::ModeSelect(const DWORD *cdb, const BYTE *buf, int length)

View File

@ -137,8 +137,7 @@ void SCSIHD_NEC::Open(const Filepath& path)
vector<BYTE> SCSIHD_NEC::Inquiry() const
{
// Direct access device, SCSI-1-CCS, not removable
return PrimaryDevice::Inquiry(0, 1, false);
return PrimaryDevice::Inquiry(device_type::DIRECT_ACCESS, scsi_level::SCSI_1_CCS, false);
}
void SCSIHD_NEC::AddErrorPage(map<int, vector<BYTE>>& pages, bool) const

View File

@ -65,8 +65,7 @@ void SCSIMO::Open(const Filepath& path)
vector<BYTE> SCSIMO::Inquiry() const
{
// Optical memory device, SCSI-2, removable
return PrimaryDevice::Inquiry(7, 2, true);
return PrimaryDevice::Inquiry(device_type::OPTICAL_MEMORY, scsi_level::SCSI_2, true);
}
void SCSIMO::SetDeviceParameters(BYTE *buf)

View File

@ -124,6 +124,21 @@ private:
//
//===========================================================================
namespace scsi_defs {
enum scsi_level : int {
SCSI_1_CCS = 1,
SCSI_2 = 2,
SPC_5 = 7
};
enum device_type : int {
DIRECT_ACCESS = 0,
PRINTER = 2,
PROCESSOR = 3,
CD_ROM = 5,
OPTICAL_MEMORY = 7,
COMMUNICATIONS = 9
};
enum scsi_command : int {
eCmdTestUnitReady = 0x00,
eCmdRezero = 0x01,