From 594e5b052a825f6887ee1025544e7b7c49ff8096 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Tue, 9 Apr 2024 09:31:33 +0900 Subject: [PATCH] Revert "Honor sector size change via ModeSelect6 in scsicd (#1406)" This reverts commit b7f65d33e237c4aaf9272c2af7447612a8494ff0. --- cpp/devices/disk.cpp | 10 ++-------- cpp/devices/disk.h | 2 +- cpp/devices/disk_cache.h | 1 - cpp/devices/mode_page_device.cpp | 2 +- cpp/devices/mode_page_device.h | 2 +- cpp/devices/scsicd.cpp | 23 ----------------------- cpp/devices/scsicd.h | 1 - cpp/devices/scsihd.cpp | 2 +- cpp/devices/scsihd.h | 2 +- cpp/devices/scsimo.cpp | 2 +- cpp/devices/scsimo.h | 2 +- cpp/test/mocks.h | 1 - cpp/test/scsicd_test.cpp | 23 ----------------------- 13 files changed, 9 insertions(+), 64 deletions(-) diff --git a/cpp/devices/disk.cpp b/cpp/devices/disk.cpp index b771b881..7ae8f275 100644 --- a/cpp/devices/disk.cpp +++ b/cpp/devices/disk.cpp @@ -696,17 +696,11 @@ uint32_t Disk::GetSectorSizeInBytes() const void Disk::SetSectorSizeInBytes(uint32_t size_in_bytes) { if (!GetSupportedSectorSizes().contains(size_in_bytes)) { - throw io_exception("Invalid sector size of " + to_string(size_in_bytes) + " byte(s)"); + throw io_exception("Invalid sector size of " + to_string(size_in_bytes) + " byte(s)"); } - uint64_t current_blocks = GetBlockCount(); - uint32_t current_size_shift_count = size_shift_count; - uint64_t current_size = current_blocks << current_size_shift_count; size_shift_count = CalculateShiftCount(size_in_bytes); assert(size_shift_count); - if ((current_blocks > 0) && (current_size_shift_count > 0)) { - SetBlockCount(current_size >> size_shift_count); - } } uint32_t Disk::GetConfiguredSectorSize() const @@ -720,7 +714,7 @@ bool Disk::SetConfiguredSectorSize(uint32_t configured_size) return false; } - configured_sector_size = configured_size; + configured_sector_size = configured_size; return true; } diff --git a/cpp/devices/disk.h b/cpp/devices/disk.h index a69a4662..6bb54d66 100644 --- a/cpp/devices/disk.h +++ b/cpp/devices/disk.h @@ -112,7 +112,7 @@ protected: void SetUpCache(off_t, bool = false); void ResizeCache(const string&, bool); - bool GetRawMode() const { return (cache?cache->GetRawMode():false); } + void SetUpModePages(map>&, int, bool) const override; void AddErrorPage(map>&, bool) const; virtual void AddFormatPage(map>&, bool) const; diff --git a/cpp/devices/disk_cache.h b/cpp/devices/disk_cache.h index d25eb2f0..ec486edd 100644 --- a/cpp/devices/disk_cache.h +++ b/cpp/devices/disk_cache.h @@ -51,7 +51,6 @@ public: ~DiskCache() = default; void SetRawMode(bool b) { cd_raw = b; } // CD-ROM raw mode setting - bool GetRawMode() const { return cd_raw; } bool Save(); // Save and release all bool ReadSector(span, uint32_t); // Sector Read diff --git a/cpp/devices/mode_page_device.cpp b/cpp/devices/mode_page_device.cpp index bb64cc37..7335d5a3 100644 --- a/cpp/devices/mode_page_device.cpp +++ b/cpp/devices/mode_page_device.cpp @@ -114,7 +114,7 @@ void ModePageDevice::ModeSense10() const EnterDataInPhase(); } -void ModePageDevice::ModeSelect(scsi_command, cdb_t, span, int) +void ModePageDevice::ModeSelect(scsi_command, cdb_t, span, int) const { // There is no default implementation of MODE SELECT throw scsi_exception(sense_key::illegal_request, asc::invalid_command_operation_code); diff --git a/cpp/devices/mode_page_device.h b/cpp/devices/mode_page_device.h index 4b657ebe..4a487fb2 100644 --- a/cpp/devices/mode_page_device.h +++ b/cpp/devices/mode_page_device.h @@ -23,7 +23,7 @@ public: bool Init(const param_map&) override; - virtual void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int); + virtual void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int) const; protected: diff --git a/cpp/devices/scsicd.cpp b/cpp/devices/scsicd.cpp index 71ffccc4..eec4b1a2 100644 --- a/cpp/devices/scsicd.cpp +++ b/cpp/devices/scsicd.cpp @@ -165,29 +165,6 @@ vector SCSICD::InquiryInternal() const return HandleInquiry(device_type::cd_rom, scsi_level, true); } -void SCSICD::ModeSelect(scsi_command cmd, cdb_t cdb, span buf, int length) -{ - int sector_size = 1 << GetSectorSizeShiftCount(); - int wanted_sector_size; - // skip Block Descriptor - int offset = 4; - // evaluate Mode Parameter Block Descriptor, sector size - wanted_sector_size = scsi_command_util::GetInt16(buf, offset + 6); - if (wanted_sector_size != sector_size) { - LogDebug("Changing sector size from " + to_string(sector_size) + " to " + to_string(wanted_sector_size)); - SetSectorSizeInBytes(wanted_sector_size); - ClearTrack(); - CreateDataTrack(); - FlushCache(); - ResizeCache(GetFilename(), GetRawMode()); - } - - if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, sector_size); - !result.empty()) { - LogWarn(result); - } -} - void SCSICD::SetUpModePages(map>& pages, int page, bool changeable) const { Disk::SetUpModePages(pages, page, changeable); diff --git a/cpp/devices/scsicd.h b/cpp/devices/scsicd.h index cb1158dd..c2aaf4e3 100644 --- a/cpp/devices/scsicd.h +++ b/cpp/devices/scsicd.h @@ -34,7 +34,6 @@ public: vector InquiryInternal() const override; int Read(span, uint64_t) override; - void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int) override; protected: diff --git a/cpp/devices/scsihd.cpp b/cpp/devices/scsihd.cpp index 51384c6a..09c6645a 100644 --- a/cpp/devices/scsihd.cpp +++ b/cpp/devices/scsihd.cpp @@ -82,7 +82,7 @@ vector SCSIHD::InquiryInternal() const return HandleInquiry(device_type::direct_access, scsi_level, IsRemovable()); } -void SCSIHD::ModeSelect(scsi_command cmd, cdb_t cdb, span buf, int length) +void SCSIHD::ModeSelect(scsi_command cmd, cdb_t cdb, span buf, int length) const { if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, 1 << GetSectorSizeShiftCount()); !result.empty()) { diff --git a/cpp/devices/scsihd.h b/cpp/devices/scsihd.h index 95ded11a..28a6119d 100644 --- a/cpp/devices/scsihd.h +++ b/cpp/devices/scsihd.h @@ -37,7 +37,7 @@ public: // Commands vector InquiryInternal() const override; - void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int) override; + void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int) const override; void AddFormatPage(map>&, bool) const override; void AddVendorPage(map>&, int, bool) const override; diff --git a/cpp/devices/scsimo.cpp b/cpp/devices/scsimo.cpp index ab2af6c4..57311be8 100644 --- a/cpp/devices/scsimo.cpp +++ b/cpp/devices/scsimo.cpp @@ -88,7 +88,7 @@ void SCSIMO::AddOptionPage(map>& pages, bool) const // Do not report update blocks } -void SCSIMO::ModeSelect(scsi_command cmd, cdb_t cdb, span buf, int length) +void SCSIMO::ModeSelect(scsi_command cmd, cdb_t cdb, span buf, int length) const { if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, 1 << GetSectorSizeShiftCount()); !result.empty()) { diff --git a/cpp/devices/scsimo.h b/cpp/devices/scsimo.h index b41c193c..1ef651b8 100644 --- a/cpp/devices/scsimo.h +++ b/cpp/devices/scsimo.h @@ -32,7 +32,7 @@ public: void Open() override; vector InquiryInternal() const override; - void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int) override; + void ModeSelect(scsi_defs::scsi_command, cdb_t, span, int) const override; protected: diff --git a/cpp/test/mocks.h b/cpp/test/mocks.h index 919afd8d..3fefdb40 100644 --- a/cpp/test/mocks.h +++ b/cpp/test/mocks.h @@ -387,7 +387,6 @@ class MockSCSICD : public SCSICD //NOSONAR Ignore inheritance hierarchy depth in FRIEND_TEST(ScsiCdTest, GetSectorSizes); FRIEND_TEST(ScsiCdTest, SetUpModePages); FRIEND_TEST(ScsiCdTest, ReadToc); - FRIEND_TEST(ScsiCdTest, ModeSelect); using SCSICD::SCSICD; }; diff --git a/cpp/test/scsicd_test.cpp b/cpp/test/scsicd_test.cpp index 4ebe3ce2..b4c9154f 100644 --- a/cpp/test/scsicd_test.cpp +++ b/cpp/test/scsicd_test.cpp @@ -133,26 +133,3 @@ TEST(ScsiCdTest, ReadToc) // Further testing requires filesystem access } - -TEST(ScsiCdTest, ModeSelect) -{ - MockSCSICD cd(0); - vector cmd(6); - vector buf(255); - - cd.SetSectorSizeInBytes(2048); - - // PF - cmd[1] = 0x10; - // Length - buf[3] = 0x08; - // 2048 bytes per sector - buf[10] = 0x08; - // Page 3 (Device Format Page) - buf[12] = 0x01; - EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 2048 is supported"; - - // 512 bytes per sector - buf[10] = 0x02; - EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 512 is supported"; -}