Skip to content

Commit

Permalink
Set SCSI level in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Feb 1, 2024
1 parent 1563c3a commit b3c09b2
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cpp/base/primary_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int PrimaryDevice::GetId() const

bool PrimaryDevice::SetScsiLevel(scsi_level l)
{
if (l < scsi_level::scsi_1_ccs || l > scsi_level::spc_6) {
if (l == scsi_level::none || l > scsi_level::spc_6) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/base/primary_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class PrimaryDevice : private ScsiPrimaryCommands, public Device

public:

PrimaryDevice(PbDeviceType type, int lun, int delay = Bus::SEND_NO_DELAY) : Device(type, lun), delay_after_bytes(
delay)
PrimaryDevice(PbDeviceType type, scsi_level l, int lun, int delay = Bus::SEND_NO_DELAY)
: Device(type, lun), level(l), delay_after_bytes(delay)
{
}
~PrimaryDevice() override = default;
Expand Down Expand Up @@ -137,7 +137,7 @@ class PrimaryDevice : private ScsiPrimaryCommands, public Device

DeviceLogger device_logger;

scsi_level level = scsi_level::scsi_2;
scsi_level level = scsi_level::none;

// Owned by the controller factory
AbstractController *controller = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/daynaport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using namespace s2p_util;

// The MacOS DaynaPort driver needs to have a delay after the size/flags field of the read response.
// It appears as if the real DaynaPort hardware indeed has this delay.
DaynaPort::DaynaPort(int lun) : PrimaryDevice(SCDP, lun, DAYNAPORT_READ_HEADER_SZ)
DaynaPort::DaynaPort(int lun) : PrimaryDevice(SCDP, scsi_level::scsi_2, lun, DAYNAPORT_READ_HEADER_SZ)
{
// These data are required by the DaynaPort drivers
SetVendor("Dayna");
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Disk : public StorageDevice, private ScsiBlockCommands

public:

Disk(PbDeviceType type, int lun, bool supports_mode_pages, const unordered_set<uint32_t> &s)
: StorageDevice(type, lun, supports_mode_pages), supported_sector_sizes(s)
Disk(PbDeviceType type, scsi_level level, int lun, bool supports_mode_pages, const unordered_set<uint32_t> &s)
: StorageDevice(type, level, lun, supports_mode_pages), supported_sector_sizes(s)
{
}
~Disk() override = default;
Expand Down
3 changes: 1 addition & 2 deletions cpp/devices/host_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ using namespace s2p_interface;
using namespace memory_util;
using namespace protobuf_util;

HostServices::HostServices(int lun) : ModePageDevice(SCHS, lun, false)
HostServices::HostServices(int lun) : ModePageDevice(SCHS, scsi_level::spc_3, lun, false)
{
SetScsiLevel(scsi_level::spc_3);
SetProduct("Host Services");
}

Expand Down
3 changes: 2 additions & 1 deletion cpp/devices/mode_page_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ModePageDevice : public PrimaryDevice
{
public:

ModePageDevice(PbDeviceType type, int lun, bool m) : PrimaryDevice(type, lun), supports_mode_select(m)
ModePageDevice(PbDeviceType type, scsi_level level, int lun, bool m)
: PrimaryDevice(type, level, lun), supports_mode_select(m)
{
}
~ModePageDevice() override = default;
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/optical_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

using namespace memory_util;

OpticalMemory::OpticalMemory(int lun) : Disk(SCMO, lun, true, { 512, 1024, 2048, 4096 })
OpticalMemory::OpticalMemory(int lun) : Disk(SCMO, scsi_level::scsi_2, lun, true, { 512, 1024, 2048, 4096 })
{
// 128 MB, 512 bytes per sector, 248826 sectors
geometries[512 * 248826] = { 512, 248826 };
Expand Down
3 changes: 1 addition & 2 deletions cpp/devices/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
using namespace filesystem;
using namespace memory_util;

Printer::Printer(int lun) : PrimaryDevice(SCLP, lun)
Printer::Printer(int lun) : PrimaryDevice(SCLP, scsi_level::scsi_2, lun)
{
SetScsiLevel(scsi_level::scsi_2);
SetProduct("SCSI PRINTER");
SupportsParams(true);
}
Expand Down
3 changes: 2 additions & 1 deletion cpp/devices/sasi_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "sasi_hd.h"

SasiHd::SasiHd(int lun, const unordered_set<uint32_t> &sector_sizes) : Disk(SAHD, lun, false, sector_sizes)
SasiHd::SasiHd(int lun, const unordered_set<uint32_t> &sector_sizes) : Disk(SAHD, scsi_level::none, lun, false,
sector_sizes)
{
SetProduct("SASI HD");
SetProtectable(true);
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/scsi_cd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

using namespace memory_util;

ScsiCd::ScsiCd(int lun, bool scsi1) : Disk(SCCD, lun, true, { 512, 2048 })
ScsiCd::ScsiCd(int lun, bool scsi1) : Disk(SCCD, scsi1 ? scsi_level::scsi_1_ccs : scsi_level::scsi_2, lun, true, { 512,
2048 })
{
SetScsiLevel(scsi1 ? scsi_level::scsi_1_ccs : scsi_level::scsi_2);
SetProduct("SCSI CD-ROM");
SetReadOnly(true);
SetRemovable(true);
Expand Down
4 changes: 1 addition & 3 deletions cpp/devices/scsi_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
using namespace memory_util;

ScsiHd::ScsiHd(int lun, bool removable, bool apple, bool scsi1, const unordered_set<uint32_t> &sector_sizes)
: Disk(removable ? SCRM : SCHD, lun, true, sector_sizes)
: Disk(removable ? SCRM : SCHD, scsi1 ? scsi_level::scsi_1_ccs : scsi_level::scsi_2, lun, true, sector_sizes)
{
SetScsiLevel(scsi1 ? scsi_level::scsi_1_ccs : scsi_level::scsi_2);

// Some Apple tools require a particular drive identification.
// Except for the vendor string .hda is the same as .hds.
if (apple) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

using namespace filesystem;

StorageDevice::StorageDevice(PbDeviceType type, int lun, bool supports_mode_pages)
: ModePageDevice(type, lun, supports_mode_pages)
StorageDevice::StorageDevice(PbDeviceType type, scsi_level level, int lun, bool supports_mode_pages)
: ModePageDevice(type, level, lun, supports_mode_pages)
{
SupportsFile(true);
SetStoppable(true);
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/storage_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StorageDevice : public ModePageDevice
{
public:

StorageDevice(PbDeviceType, int, bool);
StorageDevice(PbDeviceType, scsi_level, int, bool);
~StorageDevice() override = default;

void CleanUp() override;
Expand Down
1 change: 1 addition & 0 deletions cpp/shared/scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace scsi_defs
{
enum class scsi_level
{
none = 0,
scsi_1_ccs = 1,
scsi_2 = 2,
spc = 3,
Expand Down
8 changes: 4 additions & 4 deletions cpp/test/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class MockPrimaryDevice : public PrimaryDevice
MOCK_METHOD(vector<uint8_t>, InquiryInternal, (), (const, override));
MOCK_METHOD(void, FlushCache, (), (override));

explicit MockPrimaryDevice(int lun) : PrimaryDevice(UNDEFINED, lun)
explicit MockPrimaryDevice(int lun) : PrimaryDevice(UNDEFINED, scsi_level::scsi_2, lun)
{
}
~MockPrimaryDevice() override = default;
Expand All @@ -292,7 +292,7 @@ class MockModePageDevice : public ModePageDevice
MOCK_METHOD(int, ModeSense6, (span<const int>, vector<uint8_t>&), (const, override));
MOCK_METHOD(int, ModeSense10, (span<const int>, vector<uint8_t>&), (const, override));

MockModePageDevice() : ModePageDevice(UNDEFINED, 0, false)
MockModePageDevice() : ModePageDevice(UNDEFINED, scsi_level::scsi_2, 0, false)
{
}
~MockModePageDevice() override = default;
Expand Down Expand Up @@ -340,7 +340,7 @@ class MockStorageDevice : public StorageDevice
MOCK_METHOD(int, ModeSense10, (span<const int>, vector<uint8_t>&), (const, override));
MOCK_METHOD(void, SetUpModePages, ((map<int, vector<byte>>&), int, bool), (const, override));

MockStorageDevice() : StorageDevice(UNDEFINED, 0, false)
MockStorageDevice() : StorageDevice(UNDEFINED, scsi_level::scsi_2, 0, false)
{
}
~MockStorageDevice() override = default;
Expand Down Expand Up @@ -390,7 +390,7 @@ class MockDisk : public Disk
MOCK_METHOD(void, FlushCache, (), (override));
MOCK_METHOD(void, Open, (), (override));

MockDisk() : Disk(SCHD, false, false, { 512, 1024, 2048, 4096 })
MockDisk() : Disk(SCHD, scsi_level::scsi_2, 0, false, { 512, 1024, 2048, 4096 })
{
}
~MockDisk() override = default;
Expand Down

0 comments on commit b3c09b2

Please sign in to comment.