From f0c36fba77fd09ab3f335374b17b94059ea91d7a Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Sat, 10 Sep 2022 07:59:41 +0200 Subject: [PATCH] SonarCloud coverage setup, fixed numerous SonarCloud issues (#840) * SonarCloud coverage setup, fixed numerous SonarCloud issues * Code cleanup --- .github/workflows/run_tests.yml | 72 +++------ src/raspberrypi/Makefile | 10 +- .../controllers/abstract_controller.h | 2 + .../controllers/controller_manager.cpp | 2 +- .../controllers/controller_manager.h | 2 + .../controllers/scsi_controller.cpp | 91 +++++------ src/raspberrypi/controllers/scsi_controller.h | 44 ++--- src/raspberrypi/devices/cfilesystem.cpp | 79 ++++----- src/raspberrypi/devices/cfilesystem.h | 15 ++ src/raspberrypi/devices/ctapdriver.cpp | 33 ++-- src/raspberrypi/devices/ctapdriver.h | 4 +- src/raspberrypi/devices/device.cpp | 5 - src/raspberrypi/devices/device.h | 34 ++-- src/raspberrypi/devices/device_factory.cpp | 10 +- src/raspberrypi/devices/device_factory.h | 2 + src/raspberrypi/devices/disk.cpp | 91 ++++++----- src/raspberrypi/devices/disk.h | 2 + src/raspberrypi/devices/disk_track_cache.h | 4 + src/raspberrypi/devices/dispatcher.h | 7 +- src/raspberrypi/devices/file_support.cpp | 3 +- src/raspberrypi/devices/file_support.h | 4 +- src/raspberrypi/devices/host_services.cpp | 22 +-- src/raspberrypi/devices/host_services.h | 2 + src/raspberrypi/devices/mode_page_device.cpp | 18 +-- src/raspberrypi/devices/mode_page_device.h | 2 + src/raspberrypi/devices/primary_device.cpp | 32 ++-- src/raspberrypi/devices/primary_device.h | 2 + src/raspberrypi/devices/scsi_command_util.cpp | 17 +- src/raspberrypi/devices/scsi_command_util.h | 1 - src/raspberrypi/devices/scsi_daynaport.cpp | 17 +- src/raspberrypi/devices/scsi_daynaport.h | 2 + src/raspberrypi/devices/scsi_host_bridge.cpp | 115 ++++++-------- src/raspberrypi/devices/scsi_host_bridge.h | 2 + src/raspberrypi/devices/scsi_printer.cpp | 25 ++- src/raspberrypi/devices/scsi_printer.h | 2 + src/raspberrypi/devices/scsicd.cpp | 2 +- src/raspberrypi/devices/scsicd.h | 11 +- src/raspberrypi/devices/scsihd.cpp | 2 +- src/raspberrypi/devices/scsihd.h | 5 +- src/raspberrypi/devices/scsihd_nec.cpp | 6 +- src/raspberrypi/devices/scsihd_nec.h | 2 + src/raspberrypi/devices/scsimo.cpp | 8 +- src/raspberrypi/devices/scsimo.h | 4 +- src/raspberrypi/fileio.h | 3 + src/raspberrypi/filepath.cpp | 2 +- src/raspberrypi/filepath.h | 4 + src/raspberrypi/gpiobus.h | 150 +++++++++--------- src/raspberrypi/rascsi_response.cpp | 14 +- .../test/controller_manager_test.cpp | 2 +- src/raspberrypi/test/device_test.cpp | 4 +- src/raspberrypi/test/file_support_test.cpp | 2 +- src/raspberrypi/test/testing.h | 21 ++- 52 files changed, 499 insertions(+), 518 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 41cb71f0..e525146c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -3,68 +3,33 @@ name: Run automated unit tests on: [push, pull_request] jobs: - functional_test: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - - name: Install libraries - run: sudo apt-get install libspdlog-dev libpcap-dev libevdev2 libev-dev protobuf-compiler libgtest-dev libgmock-dev - - - name: Run tests - run: make -C src/raspberrypi -j6 test - - - name: Save Log - run: src/raspberrypi/bin/fullspec/rascsi_test | tee test_log.txt - - - name: upload artifacts - uses: actions/upload-artifact@v2 - with: - name: test log - path: test_log.txt - - code_coverage_test: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - - name: Install libraries - run: sudo apt-get install libspdlog-dev libpcap-dev libevdev2 libev-dev protobuf-compiler libgtest-dev libgmock-dev lcov - - - name: Gerenate coverage - run: make -C src/raspberrypi -j6 coverage - - - name: tar coverage data - run: tar -czvf coverage.tar.gz ./coverage - working-directory: ./src/raspberrypi - - - name: upload artifacts - uses: actions/upload-artifact@v2 - with: - name: Coverage data - path: ./src/raspberrypi/coverage.tar.gz - - - SonarCloud_Analysis: + Tests_and_SonarCloud_Analysis: runs-on: ubuntu-22.04 env: + MAKEFLAGS: -j2 # Number of available processors + SOURCES: src/raspberrypi SONAR_SCANNER_VERSION: 4.7.0.2747 SONAR_SERVER_URL: "https://sonarcloud.io" BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed steps: - uses: actions/checkout@v2 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Install cross compile toolchain - run: sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf binutils-arm-linux-gnueabihf libspdlog-dev libpcap-dev protobuf-compiler - + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Install dependencies - run: sudo apt-get install libspdlog-dev libpcap-dev protobuf-compiler libprotobuf-dev libprotobuf-c-dev libev-dev libevdev2 libgmock-dev + run: sudo apt-get install libspdlog-dev libpcap-dev libevdev2 libev-dev protobuf-compiler libgtest-dev libgmock-dev - - name: Set up JDK 11 + - name: Run unit tests and save log + run: $SOURCES/bin/fullspec/rascsi_test | tee test_log.txt + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: test log + path: test_log.txt + + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Download and set up sonar-scanner env: SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip @@ -82,11 +47,14 @@ jobs: echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH - name: Run build-wrapper run: | - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -C src/raspberrypi -j6 all + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -C $SOURCES coverage + + - name: Run gcov + run: (cd $SOURCES ; gcov --preserve-paths $(find -name '*.gcno')) - name: Run sonar-scanner env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | - sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.projectKey=akuker_RASCSI --define sonar.organization=rascsi + cd $SOURCES | sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.projectKey=akuker_RASCSI --define sonar.organization=rascsi --define sonar.cfamily.gcov.reportsPath=. --define sonar.cfamily.cache.enabled=false --define sonar.coverage.exclusions="tests/*" --define sonar.python.version=3 diff --git a/src/raspberrypi/Makefile b/src/raspberrypi/Makefile index 3a66263f..5f125b75 100644 --- a/src/raspberrypi/Makefile +++ b/src/raspberrypi/Makefile @@ -169,11 +169,12 @@ $(SRC_PROTOBUF): $(SRC_PROTOC) ## the text versions of the manpages ## docs : Re-generate the text versions of the man pages ## test : Build and run unit tests -## coverage : Build and run unit tests and create coverage HTML files. +## coverage : Build and run unit tests and create coverage SonarQube files. +## lcov : Build and run unit tests and create coverage HTML files. ## Note that you have to run 'make clean' before switching -## between coverage and no-coverage builds. +## between coverage and non-coverage builds. .DEFAULT_GOAL := all -.PHONY: all ALL docs test coverage +.PHONY: all ALL docs test coverage lcov all: $(BIN_ALL) docs test: $(BINDIR)/$(RASCSI_TEST) @@ -181,6 +182,9 @@ test: $(BINDIR)/$(RASCSI_TEST) coverage: CXXFLAGS += --coverage coverage: test + +lcov: CXXFLAGS += --coverage +lcov: test lcov -q -c -d . --include '*/raspberrypi/*' -o $(COVERAGE_FILE) --exclude '*/test/*' --exclude '*/interfaces/*' --exclude '*/rascsi_interface.pb*' genhtml -q -o $(COVERAGE_DIR) --legend $(COVERAGE_FILE) diff --git a/src/raspberrypi/controllers/abstract_controller.h b/src/raspberrypi/controllers/abstract_controller.h index 32f5240a..98fa255e 100644 --- a/src/raspberrypi/controllers/abstract_controller.h +++ b/src/raspberrypi/controllers/abstract_controller.h @@ -59,6 +59,8 @@ public: AbstractController(BUS *bus, int target_id) : bus(bus), target_id(target_id) {} ~AbstractController() override = default; + AbstractController(AbstractController&) = delete; + AbstractController& operator=(const AbstractController&) = delete; virtual BUS::phase_t Process(int) = 0; diff --git a/src/raspberrypi/controllers/controller_manager.cpp b/src/raspberrypi/controllers/controller_manager.cpp index dd9b60f4..96a028b7 100644 --- a/src/raspberrypi/controllers/controller_manager.cpp +++ b/src/raspberrypi/controllers/controller_manager.cpp @@ -32,7 +32,7 @@ bool ControllerManager::CreateScsiController(BUS *bus, PrimaryDevice *device) { AbstractController *controller = FindController(device->GetId()); if (controller == nullptr) { - controller = new ScsiController(bus, device->GetId()); + controller = make_unique(bus, device->GetId()).release(); controllers[device->GetId()] = controller; } diff --git a/src/raspberrypi/controllers/controller_manager.h b/src/raspberrypi/controllers/controller_manager.h index ddcafc4e..a1c9d527 100644 --- a/src/raspberrypi/controllers/controller_manager.h +++ b/src/raspberrypi/controllers/controller_manager.h @@ -21,6 +21,8 @@ class ControllerManager { ControllerManager() = default; ~ControllerManager(); + ControllerManager(ControllerManager&) = delete; + ControllerManager& operator=(const ControllerManager&) = delete; public: // Maximum number of controller devices diff --git a/src/raspberrypi/controllers/scsi_controller.cpp b/src/raspberrypi/controllers/scsi_controller.cpp index e22a9f0d..fd23783a 100644 --- a/src/raspberrypi/controllers/scsi_controller.cpp +++ b/src/raspberrypi/controllers/scsi_controller.cpp @@ -56,12 +56,12 @@ void ScsiController::Reset() bytes_to_transfer = 0; // Reset all LUNs - for (auto& lun : ctrl.luns) { - lun.second->Reset(); + for (auto& [lun, device] : ctrl.luns) { + device->Reset(); } } -BUS::phase_t ScsiController::Process(int initiator_id) +BUS::phase_t ScsiController::Process(int id) { // Get bus information bus->Acquire(); @@ -79,14 +79,14 @@ BUS::phase_t ScsiController::Process(int initiator_id) return ctrl.phase; } - if (initiator_id != UNKNOWN_INITIATOR_ID) { - LOGTRACE("%s Initiator ID is %d", __PRETTY_FUNCTION__, initiator_id) + if (id != UNKNOWN_INITIATOR_ID) { + LOGTRACE("%s Initiator ID is %d", __PRETTY_FUNCTION__, id) } else { LOGTRACE("%s Initiator ID is unknown", __PRETTY_FUNCTION__) } - this->initiator_id = initiator_id; + initiator_id = id; try { // Phase processing @@ -128,7 +128,7 @@ BUS::phase_t ScsiController::Process(int initiator_id) break; } } - catch(const scsi_error_exception& e) { + catch(const scsi_error_exception&) { // Any exception should have been handled during the phase processing assert(false); @@ -207,8 +207,7 @@ void ScsiController::Selection() { if (ctrl.phase != BUS::selection) { // A different device controller was selected - int id = 1 << GetTargetId(); - if ((bus->GetDAT() & id) == 0) { + if (int id = 1 << GetTargetId(); (bus->GetDAT() & id) == 0) { return; } @@ -545,11 +544,10 @@ void ScsiController::Send() // TODO The delay has to be taken from ctrl.unit[lun], but as there are currently no Daynaport drivers for // LUNs other than 0 this work-around works. - int len = bus->SendHandShake(&ctrl.buffer[ctrl.offset], ctrl.length, + if (int len = bus->SendHandShake(&ctrl.buffer[ctrl.offset], ctrl.length, HasDeviceForLun(0) ? GetDeviceForLun(0)->GetSendDelay() : 0); - - // If you cannot send all, move to status phase - if (len != (int)ctrl.length) { + len != (int)ctrl.length) { + // If you cannot send all, move to status phase Error(sense_key::ABORTED_COMMAND); return; } @@ -822,7 +820,7 @@ bool ScsiController::XferMsg(int msg) // Save message out data if (scsi.atnmsg) { - scsi.msb[scsi.msc] = msg; + scsi.msb[scsi.msc] = (BYTE)msg; scsi.msc++; scsi.msc %= 256; } @@ -1012,8 +1010,8 @@ bool ScsiController::XferOut(bool cont) is_byte_transfer = false; - PrimaryDevice *device = GetDeviceForLun(GetEffectiveLun()); - if (device != nullptr && ctrl.cmd[0] == scsi_command::eCmdWrite6) { + if (auto device = GetDeviceForLun(GetEffectiveLun()); + device != nullptr && ctrl.cmd[0] == scsi_command::eCmdWrite6) { return device->WriteByteSequence(ctrl.buffer, bytes_to_transfer); } @@ -1026,24 +1024,24 @@ void ScsiController::FlushUnit() { assert(ctrl.phase == BUS::dataout); - Disk *disk = dynamic_cast(GetDeviceForLun(GetEffectiveLun())); + auto disk = dynamic_cast(GetDeviceForLun(GetEffectiveLun())); if (disk == nullptr) { return; } // WRITE system only switch ((ScsiController::rw_command)ctrl.cmd[0]) { - case ScsiController::eCmdWrite6: - case ScsiController::eCmdWrite10: - case ScsiController::eCmdWrite16: - case ScsiController::eCmdWriteLong10: - case ScsiController::eCmdWriteLong16: - case ScsiController::eCmdVerify10: - case ScsiController::eCmdVerify16: + case ScsiController::eRwCmdWrite6: + case ScsiController::eRwCmdWrite10: + case ScsiController::eRwCmdWrite16: + case ScsiController::eRwCmdWriteLong10: + case ScsiController::eRwCmdWriteLong16: + case ScsiController::eRwCmdVerify10: + case ScsiController::eRwCmdVerify16: break; - case ScsiController::eCmdModeSelect6: - case ScsiController::eCmdModeSelect10: + case ScsiController::eRwCmdModeSelect6: + case ScsiController::eRwCmdModeSelect10: // TODO What is this special handling of ModeSelect good for? // Without it we would not need this method at all. // ModeSelect is already handled in XferOutBlockOriented(). Why would it have to be handled once more? @@ -1057,12 +1055,12 @@ void ScsiController::FlushUnit() } break; - case ScsiController::eCmdSetMcastAddr: + case ScsiController::eRwCmdSetMcastAddr: // TODO: Eventually, we should store off the multicast address configuration data here... break; default: - LOGWARN("Received an unexpected flush command $%02X\n",(WORD)ctrl.cmd[0]); + LOGWARN("Received an unexpected flush command $%02X\n",(WORD)ctrl.cmd[0]) break; } } @@ -1088,14 +1086,14 @@ bool ScsiController::XferIn(BYTE *buf) // Limited to read commands switch (ctrl.cmd[0]) { - case eCmdRead6: - case eCmdRead10: - case eCmdRead16: + case eRwCmdRead6: + case eRwCmdRead10: + case eRwCmdRead16: // Read from disk try { ctrl.length = ((Disk *)GetDeviceForLun(lun))->Read(ctrl.cmd, buf, ctrl.next); } - catch(const scsi_error_exception& e) { + catch(const scsi_error_exception&) { // If there is an error, go to the status phase return false; } @@ -1126,15 +1124,15 @@ bool ScsiController::XferIn(BYTE *buf) //--------------------------------------------------------------------------- bool ScsiController::XferOutBlockOriented(bool cont) { - Disk *disk = dynamic_cast(GetDeviceForLun(GetEffectiveLun())); + auto disk = dynamic_cast(GetDeviceForLun(GetEffectiveLun())); if (disk == nullptr) { return false; } // Limited to write commands switch (ctrl.cmd[0]) { - case eCmdModeSelect6: - case eCmdModeSelect10: + case eRwCmdModeSelect6: + case eRwCmdModeSelect10: try { disk->ModeSelect(ctrl.cmd, ctrl.buffer, ctrl.offset); } @@ -1144,17 +1142,16 @@ bool ScsiController::XferOutBlockOriented(bool cont) } break; - case eCmdWrite6: - case eCmdWrite10: - case eCmdWrite16: + case eRwCmdWrite6: + case eRwCmdWrite10: + case eRwCmdWrite16: // TODO Verify has to verify, not to write - case eCmdVerify10: - case eCmdVerify16: + case eRwCmdVerify10: + case eRwCmdVerify16: { // Special case Write function for brige // TODO This class must not know about SCSIBR - SCSIBR *bridge = dynamic_cast(disk); - if (bridge) { + if (auto bridge = dynamic_cast(disk); bridge) { if (!bridge->WriteBytes(ctrl.cmd, ctrl.buffer, ctrl.length)) { // Write failed return false; @@ -1166,8 +1163,7 @@ bool ScsiController::XferOutBlockOriented(bool cont) // Special case Write function for DaynaPort // TODO This class must not know about DaynaPort - SCSIDaynaPort *daynaport = dynamic_cast(disk); - if (daynaport) { + if (auto daynaport = dynamic_cast(disk); daynaport) { daynaport->WriteBytes(ctrl.cmd, ctrl.buffer, 0); ctrl.offset = 0; @@ -1195,7 +1191,7 @@ bool ScsiController::XferOutBlockOriented(bool cont) try { ctrl.length = disk->WriteCheck(ctrl.next - 1); } - catch(const scsi_error_exception& e) { + catch(const scsi_error_exception&) { // Cannot write return false; } @@ -1204,7 +1200,7 @@ bool ScsiController::XferOutBlockOriented(bool cont) break; } - case eCmdSetMcastAddr: + case eRwCmdSetMcastAddr: LOGTRACE("%s Done with DaynaPort Set Multicast Address", __PRETTY_FUNCTION__) break; @@ -1223,8 +1219,7 @@ int ScsiController::GetEffectiveLun() const void ScsiController::Sleep() { - uint32_t time = SysTimer::GetTimerLow() - execstart; - if (time < MIN_EXEC_TIME) { + if (uint32_t time = SysTimer::GetTimerLow() - execstart; time < MIN_EXEC_TIME) { SysTimer::SleepUsec(MIN_EXEC_TIME - time); } execstart = 0; diff --git a/src/raspberrypi/controllers/scsi_controller.h b/src/raspberrypi/controllers/scsi_controller.h index 53605c71..2659ae94 100644 --- a/src/raspberrypi/controllers/scsi_controller.h +++ b/src/raspberrypi/controllers/scsi_controller.h @@ -31,34 +31,34 @@ class ScsiController : public AbstractController static const int MAX_SYNC_PERIOD = 50; // REQ/ACK offset(limited to 16) - static const int MAX_SYNC_OFFSET = 16; + static const BYTE MAX_SYNC_OFFSET = 16; static const int UNKNOWN_INITIATOR_ID = -1; const int DEFAULT_BUFFER_SIZE = 0x1000; enum rw_command : int { - eCmdRead6 = 0x08, - eCmdWrite6 = 0x0A, - eCmdSetMcastAddr = 0x0D, // DaynaPort specific command - eCmdModeSelect6 = 0x15, - eCmdRead10 = 0x28, - eCmdWrite10 = 0x2A, - eCmdVerify10 = 0x2E, - eCmdVerify = 0x2F, - eCmdModeSelect10 = 0x55, - eCmdRead16 = 0x88, - eCmdWrite16 = 0x8A, - eCmdVerify16 = 0x8F, - eCmdWriteLong10 = 0x3F, - eCmdWriteLong16 = 0x9F + eRwCmdRead6 = 0x08, + eRwCmdWrite6 = 0x0A, + eRwCmdSetMcastAddr = 0x0D, // DaynaPort specific command + eRwCmdModeSelect6 = 0x15, + eRwCmdRead10 = 0x28, + eRwCmdWrite10 = 0x2A, + eRwCmdVerify10 = 0x2E, + eRwCmdVerify = 0x2F, + eRwCmdModeSelect10 = 0x55, + eRwCmdRead16 = 0x88, + eRwCmdWrite16 = 0x8A, + eRwCmdVerify16 = 0x8F, + eRwCmdWriteLong10 = 0x3F, + eRwCmdWriteLong16 = 0x9F }; using scsi_t = struct _scsi_t { // Synchronous transfer bool syncenable; // Synchronous transfer possible - int syncperiod = MAX_SYNC_PERIOD; // Synchronous transfer period - int syncoffset; // Synchronous transfer offset + BYTE syncperiod = MAX_SYNC_PERIOD; // Synchronous transfer period + BYTE syncoffset; // Synchronous transfer offset int syncack; // Number of synchronous transfer ACKs // ATN message @@ -71,6 +71,8 @@ public: ScsiController(BUS *, int); ~ScsiController() override; + ScsiController(ScsiController&) = delete; + ScsiController& operator=(const ScsiController&) = delete; void Reset() override; @@ -78,13 +80,13 @@ public: int GetEffectiveLun() const override; - int GetMaxLuns() const override { return LUN_MAX; }; + int GetMaxLuns() const override { return LUN_MAX; } void Error(scsi_defs::sense_key sense_key, scsi_defs::asc asc = scsi_defs::asc::NO_ADDITIONAL_SENSE_INFORMATION, scsi_defs::status status = scsi_defs::status::CHECK_CONDITION) override; int GetInitiatorId() const override { return initiator_id; } - void SetByteTransfer(bool is_byte_transfer) override { this->is_byte_transfer = is_byte_transfer; } + void SetByteTransfer(bool b) override { is_byte_transfer = b; } void Status() override; void DataIn() override; @@ -105,7 +107,7 @@ private: uint32_t bytes_to_transfer = 0; // Phases - void SetPhase(BUS::phase_t phase) override { ctrl.phase = phase; } + void SetPhase(BUS::phase_t p) override { ctrl.phase = p; } void BusFree() override; void Selection() override; void Command() override; @@ -124,7 +126,7 @@ private: void FlushUnit(); void Receive(); - void ScheduleShutdown(rascsi_shutdown_mode shutdown_mode) override { this->shutdown_mode = shutdown_mode; } + void ScheduleShutdown(rascsi_shutdown_mode mode) override { shutdown_mode = mode; } void Sleep(); diff --git a/src/raspberrypi/devices/cfilesystem.cpp b/src/raspberrypi/devices/cfilesystem.cpp index 832f7a46..884696c8 100644 --- a/src/raspberrypi/devices/cfilesystem.cpp +++ b/src/raspberrypi/devices/cfilesystem.cpp @@ -43,8 +43,7 @@ static void convert(char const *src, char const *dest, return; } - size_t ret = iconv(cd, &inbuf, &in, &outbuf, &out); - if (ret == (size_t)-1) { + if (size_t ret = iconv(cd, &inbuf, &in, &outbuf, &out); ret == (size_t)-1) { return; } @@ -853,7 +852,7 @@ void CHostFilename::ConvertHuman(int nCount) } nMax--; pNumber--; - BYTE c = (BYTE)((nOption >> 24) & 0x7F); + auto c = (BYTE)((nOption >> 24) & 0x7F); if (c == 0) c = XM6_HOST_FILENAME_MARK; *pNumber = c; @@ -867,9 +866,9 @@ void CHostFilename::ConvertHuman(int nCount) { strcpy(szHost, m_szHost); - const BYTE* pRead = (const BYTE*)szHost; + auto pRead = (const BYTE*)szHost; BYTE* pWrite = szHuman; - const BYTE* pPeriod = SeparateExt(pRead); + const auto pPeriod = SeparateExt(pRead); for (bool bFirst = true;; bFirst = false) { BYTE c = *pRead++; @@ -935,14 +934,14 @@ void CHostFilename::ConvertHuman(int nCount) // Delete spaces at the end while (pExt < pLast - 1 && *(pLast - 1) == ' ') { pLast--; - BYTE* p = (BYTE*)pLast; + auto p = (BYTE*)pLast; *p = '\0'; } // Delete if the file name disappeared after conversion if (pExt + 1 >= pLast) { pLast = pExt; - BYTE* p = (BYTE*)pLast; + auto p = (BYTE*)pLast; *p = '\0'; // Just in case } } else { @@ -978,7 +977,7 @@ void CHostFilename::ConvertHuman(int nCount) pStop = pFirst; // Evaluate base name - pCut = (BYTE*)strchr((const char*)pCut, '.'); // The 2nd byte of Shift-JIS is always 0x40 or higher, so this is ok + pCut = (const BYTE*)strchr((const char*)pCut, '.'); // The 2nd byte of Shift-JIS is always 0x40 or higher, so this is ok if (pCut == nullptr) pCut = pLast; if ((size_t)(pCut - pFirst) > nMax) @@ -993,8 +992,8 @@ void CHostFilename::ConvertHuman(int nCount) } // Shorten base name - size_t nExt = pExt - pSecond; // Length of extension segment - if ((size_t)(pCut - pFirst) + nExt > nMax) + // Length of extension segment + if (size_t nExt = pExt - pSecond; (size_t)(pCut - pFirst) + nExt > nMax) pCut = pFirst + nMax - nExt; // If in the middle of a 2 byte char, shorten even further for (p = pFirst; p < pCut; p++) { @@ -1053,7 +1052,7 @@ void CHostFilename::CopyHuman(const BYTE* szHuman) strcpy((char*)m_szHuman, (const char*)szHuman); m_bCorrect = TRUE; m_pszHumanLast = m_szHuman + strlen((const char*)m_szHuman); - m_pszHumanExt = (BYTE*)SeparateExt(m_szHuman); + m_pszHumanExt = SeparateExt(m_szHuman); } //--------------------------------------------------------------------------- @@ -1099,7 +1098,7 @@ void CHostFilename::SetEntryName() //--------------------------------------------------------------------------- BOOL CHostFilename::isReduce() const { - return strcmp((char *)m_szHost, (const char*)m_szHuman) != 0; + return strcmp((char *)m_szHost, (char*)m_szHuman) != 0; } //--------------------------------------------------------------------------- @@ -1129,16 +1128,15 @@ const BYTE* CHostFilename::SeparateExt(const BYTE* szHuman) // static const BYTE* pLast = pFirst + nLength; // Confirm the position of the Human68k extension - const BYTE* pExt = (BYTE*)strrchr((const char*)pFirst, '.'); // The 2nd byte of Shift-JIS is always 0x40 or higher, so this is ok + auto pExt = (const BYTE*)strrchr((const char*)pFirst, '.'); // The 2nd byte of Shift-JIS is always 0x40 or higher, so this is ok if (pExt == nullptr) pExt = pLast; // Special handling of the pattern where the file name is 20~22 chars, and the 19th char is '.' or ends with '.' if (20 <= nLength && nLength <= 22 && pFirst[18] == '.' && pFirst[nLength - 1] == '.') pExt = pFirst + 18; // Calculate the number of chars in the extension (-1:None 0:Only period 1~3:Human68k extension 4 or above:extension name) - size_t nExt = pLast - pExt - 1; // Consider it an extension only when '.' is anywhere except the beginning of the string, and between 1~3 chars long - if (pExt == pFirst || nExt < 1 || nExt > 3) + if (size_t nExt = pLast - pExt - 1; pExt == pFirst || nExt < 1 || nExt > 3) pExt = pLast; return pExt; @@ -1183,7 +1181,7 @@ CHostPath::ring_t* CHostPath::Alloc(size_t nLength) // static ASSERT(nLength < FILEPATH_MAX); size_t n = offsetof(ring_t, f) + CHostFilename::Offset() + (nLength + 1) * sizeof(TCHAR); - ring_t* p = (ring_t*)malloc(n); + auto p = (ring_t*)malloc(n); ASSERT(p); p->r.Init(); // This is nothing to worry about! @@ -1380,15 +1378,14 @@ const CHostFilename* CHostPath::FindFilename(const BYTE* szHuman, DWORD nHumanAt // Find something that matches perfectly with either of the stored file names const ring_t* p = (ring_t*)m_cRing.Next(); - for (; p != (ring_t*)&m_cRing; p = (ring_t*)p->r.Next()) { + for (; p != (const ring_t*)&m_cRing; p = (ring_t*)p->r.Next()) { if (p->f.CheckAttribute(nHumanAttribute) == 0) continue; // Calulate number of chars const BYTE* pBufFirst = p->f.GetHuman(); const BYTE* pBufLast = p->f.GetHumanLast(); - size_t nBufLength = pBufLast - pBufFirst; // Check number of chars - if (nLength != nBufLength) + if (size_t nBufLength = pBufLast - pBufFirst; nLength != nBufLength) continue; // File name check if (Compare(pFirst, pLast, pBufFirst, pBufLast) == 0) @@ -1418,7 +1415,7 @@ const CHostFilename* CHostPath::FindFilenameWildcard(const BYTE* szHuman, DWORD const BYTE* pExt = CHostFilename::SeparateExt(pFirst); // Move to the start position - const ring_t* p = (ring_t*)m_cRing.Next(); + auto p = (const ring_t*)m_cRing.Next(); if (pFind->count > 0) { if (pFind->id == m_nId) { // If the same directory entry, continue right away from the previous position @@ -1426,12 +1423,12 @@ const CHostFilename* CHostPath::FindFilenameWildcard(const BYTE* szHuman, DWORD } else { // Find the start position in the directory entry contents DWORD n = 0; - for (;; p = (ring_t*)p->r.Next()) { - if (p == (ring_t*)&m_cRing) { + for (;; p = (const ring_t*)p->r.Next()) { + if (p == (const ring_t*)&m_cRing) { // Extrapolate from the count when the same entry isn't found (just in case) - p = (ring_t*)m_cRing.Next(); + p = (const ring_t*)m_cRing.Next(); n = 0; - for (; p != (ring_t*)&m_cRing; p = (ring_t*)p->r.Next()) { + for (; p != (const ring_t*)&m_cRing; p = (const ring_t*)p->r.Next()) { if (n >= pFind->count) break; n++; @@ -1449,7 +1446,7 @@ const CHostFilename* CHostPath::FindFilenameWildcard(const BYTE* szHuman, DWORD } // Find files - for (; p != (ring_t*)&m_cRing; p = (ring_t*)p->r.Next()) { + for (; p != (const ring_t*)&m_cRing; p = (const ring_t*)p->r.Next()) { pFind->count++; if (p->f.CheckAttribute(nHumanAttribute) == 0) @@ -1469,10 +1466,10 @@ const CHostFilename* CHostPath::FindFilenameWildcard(const BYTE* szHuman, DWORD if (strcmp((const char*)pExt, ".???") == 0 || Compare(pExt, pLast, pBufExt, pBufLast) == 0) { // Store the contents of the next candidate's directory entry - const ring_t* pNext = (ring_t*)p->r.Next(); + const auto pNext = (const ring_t*)p->r.Next(); pFind->id = m_nId; pFind->pos = pNext; - if (pNext != (ring_t*)&m_cRing) + if (pNext != (const ring_t*)&m_cRing) memcpy(&pFind->entry, pNext->f.GetEntry(), sizeof(pFind->entry)); else memset(&pFind->entry, 0, sizeof(pFind->entry)); @@ -1623,13 +1620,12 @@ void CHostPath::Refresh() nHumanAttribute |= Human68k::AT_READONLY; pFilename->SetEntryAttribute(nHumanAttribute); - DWORD nHumanSize = (DWORD)sb.st_size; + auto nHumanSize = (DWORD)sb.st_size; pFilename->SetEntrySize(nHumanSize); WORD nHumanDate = 0; WORD nHumanTime = 0; - const tm* pt = localtime(&sb.st_mtime); - if (pt) { + if (const tm* pt = localtime(&sb.st_mtime); pt) { nHumanDate = (WORD)(((pt->tm_year - 80) << 9) | ((pt->tm_mon + 1) << 5) | pt->tm_mday); nHumanTime = (WORD)((pt->tm_hour << 11) | (pt->tm_min << 5) | (pt->tm_sec >> 1)); } @@ -2216,8 +2212,7 @@ void CHostFilesManager::Init() // Allocate memory for (DWORD i = 0; i < XM6_HOST_FILES_MAX; i++) { - ring_t* p = new ring_t; - ASSERT(p); + auto p = new ring_t(); p->r.Insert(&m_cRing); } } @@ -2277,7 +2272,7 @@ void CHostFilesManager::Free(CHostFiles* pFiles) pFiles->SetKey(0); // Move to the end of the ring - ring_t* p = (ring_t*)((size_t)pFiles - offsetof(ring_t, f)); + auto p = (ring_t*)((size_t)pFiles - offsetof(ring_t, f)); p->r.InsertTail(&m_cRing); } @@ -2373,8 +2368,7 @@ BOOL CHostFcb::Open() ASSERT(strlen(m_szFilename) > 0); // Fail if directory - struct stat st; //NOSONAR Cannot be declared in a separate statement because struct keyword is required - if (stat(S2U(m_szFilename), &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR)) { + if (struct stat st; stat(S2U(m_szFilename), &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR)) { return FALSE || m_bFlag; } @@ -2570,7 +2564,7 @@ void CHostFcbManager::Init() // Memory allocation for (DWORD i = 0; i < XM6_HOST_FCB_MAX; i++) { - ring_t* p = new ring_t; + auto p = new ring_t; ASSERT(p); p->r.Insert(&m_cRing); } @@ -2640,7 +2634,7 @@ void CHostFcbManager::Free(CHostFcb* pFcb) pFcb->Close(); // Move to the end of the ring - ring_t* p = (ring_t*)((size_t)pFcb - offsetof(ring_t, f)); + auto p = (ring_t*)((size_t)pFcb - offsetof(ring_t, f)); p->r.InsertTail(&m_cRing); } @@ -2740,7 +2734,7 @@ void CFileSys::Init() continue; // Create 1 unit file system - CHostDrv* p = new CHostDrv; // std::nothrow + auto p = new CHostDrv; if (p) { m_cEntry.SetDrv(nUnit, p); p->Init(m_szBase[n], m_nFlag[n]); @@ -3728,7 +3722,7 @@ int CFileSys::DiskRead(DWORD nUnit, BYTE* pBuffer, DWORD nSector, DWORD nSize) const CHostFiles* pHostFiles = m_cFiles.Search(nSector); if (pHostFiles) { // Generate pseudo-directory entry - Human68k::dirent_t* dir = (Human68k::dirent_t*)pBuffer; + auto dir = (Human68k::dirent_t*)pBuffer; memcpy(pBuffer, pHostFiles->GetEntry(), sizeof(*dir)); memset(pBuffer + sizeof(*dir), 0xE5, 0x200 - sizeof(*dir)); @@ -3900,10 +3894,8 @@ int CFileSys::CheckMedia(DWORD nUnit) const return FS_INVALIDFUNC; // Avoid triggering a fatal error in mint when resuming with an invalid drive // Media change check - BOOL bResult = m_cEntry.CheckMedia(nUnit); - // Throw error when media is not inserted - if (bResult == FALSE) { + if (BOOL bResult = m_cEntry.CheckMedia(nUnit); bResult == FALSE) { return FS_INVALIDFUNC; } @@ -4046,8 +4038,7 @@ BOOL CFileSys::FilesVolume(DWORD nUnit, Human68k::files_t* pFiles) // Get volume label TCHAR szVolume[32]; - BOOL bResult = m_cEntry.GetVolumeCache(nUnit, szVolume); - if (bResult == FALSE) { + if (BOOL bResult = m_cEntry.GetVolumeCache(nUnit, szVolume); bResult == FALSE) { // Carry out an extra media check here because it may be skipped when doing a manual eject if (m_cEntry.isEnable(nUnit) == FALSE) return FALSE; diff --git a/src/raspberrypi/devices/cfilesystem.h b/src/raspberrypi/devices/cfilesystem.h index 01a5ab5d..5d488c7d 100644 --- a/src/raspberrypi/devices/cfilesystem.h +++ b/src/raspberrypi/devices/cfilesystem.h @@ -357,6 +357,9 @@ class CRing { public: CRing() { Init(); } ~CRing() { Remove(); } + CRing(CRing&) = delete; + CRing& operator=(const CRing&) = delete; + void Init() { next = prev = this; } CRing* Next() const { return next; } ///< Get the next element @@ -525,6 +528,9 @@ public: CHostPath(); ~CHostPath(); + CHostPath(CHostPath&) = delete; + CHostPath& operator=(const CHostPath&) = delete; + void Clean(); ///< Initialialize for reuse void SetHuman(const BYTE* szHuman); ///< Directly specify the name on the Human68k side @@ -662,6 +668,9 @@ class CHostFcb { public: CHostFcb() { SetKey(0); Init(); } ~CHostFcb() { Close(); } + CHostFcb(CHostFcb&) = delete; + CHostFcb& operator=(const CHostFcb&) = delete; + void Init(); void SetKey(DWORD nKey) { m_nKey = nKey; } ///< Set search key @@ -733,6 +742,9 @@ class CHostDrv public: CHostDrv(); ~CHostDrv(); + CHostDrv(CHostDrv&) = delete; + CHostDrv& operator=(const CHostDrv&) = delete; + void Init(const TCHAR* szBase, DWORD nFlag); ///< Initialization (device startup and load) BOOL isWriteProtect() const { return m_bWriteProtect; } @@ -789,6 +801,9 @@ class CHostEntry { public: CHostEntry(); ~CHostEntry(); + CHostEntry(CHostEntry&) = delete; + CHostEntry& operator=(const CHostEntry&) = delete; + void Init(); ///< Initialization (when the driver is installed) void Clean(); ///< Release (when starting up or resetting) diff --git a/src/raspberrypi/devices/ctapdriver.cpp b/src/raspberrypi/devices/ctapdriver.cpp index 6733a550..e666b87c 100644 --- a/src/raspberrypi/devices/ctapdriver.cpp +++ b/src/raspberrypi/devices/ctapdriver.cpp @@ -96,20 +96,20 @@ bool CTapDriver::Init(const unordered_map& const_params) "Provide the interface list and the IP address/netmask with the 'interface' and 'inet' parameters") // TODO Remove the deprecated syntax in a future version - const string& interfaces = params["interfaces"]; - size_t separatorPos = interfaces.find(':'); + const string& ifaces = params["interfaces"]; + size_t separatorPos = ifaces.find(':'); if (separatorPos != string::npos) { - params["interface"] = interfaces.substr(0, separatorPos); - params["inet"] = interfaces.substr(separatorPos + 1); + params["interface"] = ifaces.substr(0, separatorPos); + params["inet"] = ifaces.substr(separatorPos + 1); } } stringstream s(params["interface"]); string interface; while (getline(s, interface, ',')) { - this->interfaces.push_back(interface); + interfaces.push_back(interface); } - this->inet = params["inet"]; + inet = params["inet"]; LOGTRACE("Opening Tap device") // TAP device initilization @@ -165,15 +165,15 @@ bool CTapDriver::Init(const unordered_map& const_params) LOGTRACE("Checking which interface is available for creating the bridge") string bridge_interface; - for (const string& interface : interfaces) { - if (is_interface_up(interface)) { - LOGTRACE("%s", string("Interface " + interface + " is up").c_str()) + for (const string& iface : interfaces) { + if (is_interface_up(iface)) { + LOGTRACE("%s", string("Interface " + iface + " is up").c_str()) - bridge_interface = interface; + bridge_interface = iface; break; } else { - LOGTRACE("%s", string("Interface " + interface + " is not available or is not up").c_str()) + LOGTRACE("%s", string("Interface " + iface + " is not available or is not up").c_str()) } } @@ -208,8 +208,7 @@ bool CTapDriver::Init(const unordered_map& const_params) else { string address = inet; string netmask = "255.255.255.0"; - size_t separatorPos = inet.find('/'); - if (separatorPos != string::npos) { + if (size_t separatorPos = inet.find('/'); separatorPos != string::npos) { address = inet.substr(0, separatorPos); int m; @@ -223,7 +222,7 @@ bool CTapDriver::Init(const unordered_map& const_params) } // long long is required for compatibility with 32 bit platforms - long long mask = pow(2, 32) - (1 << (32 - m)); + auto mask = (long long)(pow(2, 32) - (1 << (32 - m))); char buf[16]; sprintf(buf, "%lld.%lld.%lld.%lld", (mask >> 24) & 0xff, (mask >> 16) & 0xff, (mask >> 8) & 0xff, mask & 0xff); @@ -464,9 +463,9 @@ int CTapDriver::Rx(BYTE *buf) } // Receive - DWORD dwReceived = read(m_hTAP, buf, ETH_FRAME_LEN); + auto dwReceived = (DWORD)read(m_hTAP, buf, ETH_FRAME_LEN); if (dwReceived == (DWORD)-1) { - LOGWARN("%s Error occured while receiving an packet", __PRETTY_FUNCTION__) + LOGWARN("%s Error occured while receiving a packet", __PRETTY_FUNCTION__) return 0; } @@ -524,5 +523,5 @@ int CTapDriver::Tx(const BYTE *buf, int len) } // Start sending - return write(m_hTAP, buf, len); + return (int)write(m_hTAP, buf, len); } diff --git a/src/raspberrypi/devices/ctapdriver.h b/src/raspberrypi/devices/ctapdriver.h index 6a1b2bba..da9536c2 100644 --- a/src/raspberrypi/devices/ctapdriver.h +++ b/src/raspberrypi/devices/ctapdriver.h @@ -37,8 +37,10 @@ private: friend class SCSIDaynaPort; friend class SCSIBR; - CTapDriver() : interfaces({}), inet({}) {} + CTapDriver() = default; ~CTapDriver() = default; + CTapDriver(CTapDriver&) = delete; + CTapDriver& operator=(const CTapDriver&) = delete; bool Init(const unordered_map&); diff --git a/src/raspberrypi/devices/device.cpp b/src/raspberrypi/devices/device.cpp index d3cea56a..3f665db9 100644 --- a/src/raspberrypi/devices/device.cpp +++ b/src/raspberrypi/devices/device.cpp @@ -27,11 +27,6 @@ Device::Device(const string& t) : type(t) revision = rev; } -Device::~Device() -{ - devices.erase(this); -} - void Device::Reset() { locked = false; diff --git a/src/raspberrypi/devices/device.h b/src/raspberrypi/devices/device.h index 6679b5ea..1829bfe6 100644 --- a/src/raspberrypi/devices/device.h +++ b/src/raspberrypi/devices/device.h @@ -76,11 +76,11 @@ class Device protected: - void SetReady(bool ready) { this->ready = ready; } + void SetReady(bool b) { ready = b; } bool IsReset() const { return reset; } - void SetReset(bool reset) { this->reset = reset; } + void SetReset(bool b) { reset = b; } bool IsAttn() const { return attn; } - void SetAttn(bool attn) { this->attn = attn; } + void SetAttn(bool b) { attn = b; } int GetStatusCode() const { return status_code; } @@ -93,7 +93,9 @@ protected: public: - virtual ~Device(); + virtual ~Device() = default; + Device(Device&) = delete; + Device& operator=(const Device&) = delete; // Override for device specific initializations, to be called after all device properties have been set virtual bool Init(const unordered_map&) { return true; }; @@ -106,30 +108,30 @@ public: void Reset(); bool IsProtectable() const { return protectable; } - void SetProtectable(bool protectable) { this->protectable = protectable; } + void SetProtectable(bool b) { protectable = b; } bool IsProtected() const { return write_protected; } void SetProtected(bool); bool IsReadOnly() const { return read_only; } - void SetReadOnly(bool read_only) { this->read_only = read_only; } + void SetReadOnly(bool b) { read_only = b; } bool IsStoppable() const { return stoppable; } - void SetStoppable(bool stoppable) { this->stoppable = stoppable; } + void SetStoppable(bool b) { stoppable = b; } bool IsStopped() const { return stopped; } - void SetStopped(bool stopped) { this->stopped = stopped; } + void SetStopped(bool b) { stopped = b; } bool IsRemovable() const { return removable; } - void SetRemovable(bool removable) { this->removable = removable; } + void SetRemovable(bool b) { removable = b; } bool IsRemoved() const { return removed; } - void SetRemoved(bool removed) { this->removed = removed; } + void SetRemoved(bool b) { removed = b; } bool IsLockable() const { return lockable; } - void SetLockable(bool lockable) { this->lockable = lockable; } + void SetLockable(bool b) { lockable = b; } bool IsLocked() const { return locked; } - void SetLocked(bool locked) { this->locked = locked; } + void SetLocked(bool b) { locked = b; } int32_t GetId() const { return id; } - void SetId(int32_t id) { this->id = id; } + void SetId(int32_t i) { id = i; } int32_t GetLun() const { return lun; } - void SetLun(int32_t lun) { this->lun = lun; } + void SetLun(int32_t l) { lun = l; } string GetVendor() const { return vendor; } void SetVendor(const string&); @@ -141,9 +143,9 @@ public: bool SupportsParams() const { return supports_params; } virtual bool SupportsFile() const { return !supports_params; } - void SupportsParams(bool supports_paams) { this->supports_params = supports_paams; } + void SupportsParams(bool b) { supports_params = b; } unordered_map GetParams() const { return params; } - void SetDefaultParams(const unordered_map& default_params) { this->default_params = default_params; } + void SetDefaultParams(const unordered_map& p) { default_params = p; } void SetStatusCode(int); diff --git a/src/raspberrypi/devices/device_factory.cpp b/src/raspberrypi/devices/device_factory.cpp index f8ba24cf..b56bb1a7 100644 --- a/src/raspberrypi/devices/device_factory.cpp +++ b/src/raspberrypi/devices/device_factory.cpp @@ -24,7 +24,7 @@ using namespace rascsi_interface; multimap DeviceFactory::devices; -DeviceFactory::DeviceFactory() : sector_sizes({}), geometries({}), default_params({}), extension_mapping({}) +DeviceFactory::DeviceFactory() { sector_sizes[SCHD] = { 512, 1024, 2048, 4096 }; sector_sizes[SCRM] = { 512, 1024, 2048, 4096 }; @@ -125,8 +125,7 @@ list DeviceFactory::GetAllDevices() const string DeviceFactory::GetExtension(const string& filename) const { string ext; - size_t separator = filename.rfind('.'); - if (separator != string::npos) { + if (size_t separator = filename.rfind('.'); separator != string::npos) { ext = filename.substr(separator + 1); } std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c){ return std::tolower(c); }); @@ -136,8 +135,7 @@ string DeviceFactory::GetExtension(const string& filename) const PbDeviceType DeviceFactory::GetTypeForFile(const string& filename) const { - const auto& it = extension_mapping.find(GetExtension(filename)); - if (it != extension_mapping.end()) { + if (const auto& it = extension_mapping.find(GetExtension(filename)); it != extension_mapping.end()) { return it->second; } else if (filename == "bridge") { @@ -289,7 +287,7 @@ list DeviceFactory::GetNetworkInterfaces() const strcpy(ifr.ifr_name, tmp->ifa_name); // Only list interfaces that are up if (!ioctl(fd, SIOCGIFFLAGS, &ifr) && ifr.ifr_flags & IFF_UP) { - network_interfaces.push_back(tmp->ifa_name); + network_interfaces.emplace_back(tmp->ifa_name); } close(fd); diff --git a/src/raspberrypi/devices/device_factory.h b/src/raspberrypi/devices/device_factory.h index 658b13e8..9edd7104 100644 --- a/src/raspberrypi/devices/device_factory.h +++ b/src/raspberrypi/devices/device_factory.h @@ -31,6 +31,8 @@ class DeviceFactory DeviceFactory(); ~DeviceFactory(); + DeviceFactory(DeviceFactory&) = delete; + DeviceFactory& operator=(const DeviceFactory&) = delete; public: diff --git a/src/raspberrypi/devices/disk.cpp b/src/raspberrypi/devices/disk.cpp index d422f9c6..2909db21 100644 --- a/src/raspberrypi/devices/disk.cpp +++ b/src/raspberrypi/devices/disk.cpp @@ -23,7 +23,7 @@ using namespace scsi_defs; -Disk::Disk(const string& id) : ModePageDevice(id), ScsiBlockCommands(), dispatcher({}) +Disk::Disk(const string& id) : ModePageDevice(id), ScsiBlockCommands() { dispatcher.AddCommand(eCmdRezero, "Rezero", &Disk::Rezero); dispatcher.AddCommand(eCmdFormat, "FormatUnit", &Disk::FormatUnit); @@ -98,8 +98,7 @@ void Disk::Open(const Filepath& path) disk.dcache = new DiskCache(path, disk.size, disk.blocks, disk.image_offset); // Can read/write open - Fileio fio; - if (fio.Open(path, Fileio::ReadWrite)) { + if (Fileio fio; fio.Open(path, Fileio::ReadWrite)) { // Write permission fio.Close(); } else { @@ -341,7 +340,7 @@ bool Disk::Eject(bool force) int Disk::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length) { // Get length, clear buffer - int length = (int)cdb[4]; + auto length = (int)cdb[4]; if (length > max_length) { length = max_length; } @@ -360,16 +359,16 @@ int Disk::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length) // Short LBA mode parameter block descriptor (number of blocks and block length) uint64_t disk_blocks = GetBlockCount(); - buf[4] = disk_blocks >> 24; - buf[5] = disk_blocks >> 16; - buf[6] = disk_blocks >> 8; - buf[7] = disk_blocks; + buf[4] = (BYTE)(disk_blocks >> 24); + buf[5] = (BYTE)(disk_blocks >> 16); + buf[6] = (BYTE)(disk_blocks >> 8); + buf[7] = (BYTE)disk_blocks; // Block descriptor (block length) uint32_t disk_size = GetSectorSizeInBytes(); - buf[9] = disk_size >> 16; - buf[10] = disk_size >> 8; - buf[11] = disk_size; + buf[9] = (BYTE)(disk_size >> 16); + buf[10] = (BYTE)(disk_size >> 8); + buf[11] = (BYTE)disk_size; } size = 12; @@ -386,7 +385,7 @@ int Disk::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length) } // Final setting of mode data length - buf[0] = size; + buf[0] = (BYTE)size; return size; } @@ -417,14 +416,14 @@ int Disk::ModeSense10(const DWORD *cdb, BYTE *buf, int max_length) // Short LBA mode parameter block descriptor (number of blocks and block length) - buf[8] = disk_blocks >> 24; - buf[9] = disk_blocks >> 16; - buf[10] = disk_blocks >> 8; - buf[11] = disk_blocks; + buf[8] = (BYTE)(disk_blocks >> 24); + buf[9] = (BYTE)(disk_blocks >> 16); + buf[10] = (BYTE)(disk_blocks >> 8); + buf[11] = (BYTE)disk_blocks; - buf[13] = disk_size >> 16; - buf[14] = disk_size >> 8; - buf[15] = disk_size; + buf[13] = (BYTE)(disk_size >> 16); + buf[14] = (BYTE)(disk_size >> 8); + buf[15] = (BYTE)disk_size; size = 16; } @@ -437,19 +436,19 @@ int Disk::ModeSense10(const DWORD *cdb, BYTE *buf, int max_length) // Long LBA mode parameter block descriptor (number of blocks and block length) - buf[8] = disk_blocks >> 56; - buf[9] = disk_blocks >> 48; - buf[10] = disk_blocks >> 40; - buf[11] = disk_blocks >> 32; - buf[12] = disk_blocks >> 24; - buf[13] = disk_blocks >> 16; - buf[14] = disk_blocks >> 8; - buf[15] = disk_blocks; + buf[8] = (BYTE)(disk_blocks >> 56); + buf[9] = (BYTE)(disk_blocks >> 48); + buf[10] = (BYTE)(disk_blocks >> 40); + buf[11] = (BYTE)(disk_blocks >> 32); + buf[12] = (BYTE)(disk_blocks >> 24); + buf[13] = (BYTE)(disk_blocks >> 16); + buf[14] = (BYTE)(disk_blocks >> 8); + buf[15] = (BYTE)disk_blocks; - buf[20] = disk_size >> 24; - buf[21] = disk_size >> 16; - buf[22] = disk_size >> 8; - buf[23] = disk_size; + buf[20] = (BYTE)(disk_size >> 24); + buf[21] = (BYTE)(disk_size >> 16); + buf[22] = (BYTE)(disk_size >> 8); + buf[23] = (BYTE)disk_size; size = 24; } @@ -467,8 +466,8 @@ int Disk::ModeSense10(const DWORD *cdb, BYTE *buf, int max_length) } // Final setting of mode data length - buf[0] = size >> 8; - buf[1] = size; + buf[0] = (BYTE)(size >> 8); + buf[1] = (BYTE)size; return size; } @@ -989,14 +988,14 @@ uint32_t Disk::GetSectorSizeInBytes() const return disk.size ? 1 << disk.size : 0; } -void Disk::SetSectorSizeInBytes(uint32_t size) +void Disk::SetSectorSizeInBytes(uint32_t size_in_bytes) { - unordered_set sector_sizes = DeviceFactory::instance().GetSectorSizes(GetType()); - if (!sector_sizes.empty() && sector_sizes.find(size) == sector_sizes.end()) { - throw io_exception("Invalid block size of " + to_string(size) + " bytes"); + if (unordered_set sizes = DeviceFactory::instance().GetSectorSizes(GetType()); + !sizes.empty() && sizes.find(size_in_bytes) == sizes.end()) { + throw io_exception("Invalid block size of " + to_string(size_in_bytes) + " bytes"); } - switch (size) { + switch (size_in_bytes) { case 512: disk.size = 9; break; @@ -1024,9 +1023,9 @@ uint32_t Disk::GetSectorSizeShiftCount() const return disk.size; } -void Disk::SetSectorSizeShiftCount(uint32_t size) +void Disk::SetSectorSizeShiftCount(uint32_t shift_count) { - disk.size = size; + disk.size = shift_count; } bool Disk::IsSectorSizeConfigurable() const @@ -1034,9 +1033,9 @@ bool Disk::IsSectorSizeConfigurable() const return !sector_sizes.empty(); } -void Disk::SetSectorSizes(const unordered_set& sector_sizes) +void Disk::SetSectorSizes(const unordered_set& sizes) { - this->sector_sizes = sector_sizes; + sector_sizes = sizes; } uint32_t Disk::GetConfiguredSectorSize() const @@ -1044,16 +1043,16 @@ uint32_t Disk::GetConfiguredSectorSize() const return configured_sector_size; } -bool Disk::SetConfiguredSectorSize(uint32_t configured_sector_size) +bool Disk::SetConfiguredSectorSize(uint32_t size) { const DeviceFactory& device_factory = DeviceFactory::instance(); - unordered_set sector_sizes = device_factory.GetSectorSizes(GetType()); - if (sector_sizes.find(configured_sector_size) == sector_sizes.end()) { + if (unordered_set sizes = device_factory.GetSectorSizes(GetType()); + sizes.find(size) == sizes.end()) { return false; } - this->configured_sector_size = configured_sector_size; + configured_sector_size = size; return true; } diff --git a/src/raspberrypi/devices/disk.h b/src/raspberrypi/devices/disk.h index 3e987bbe..94db5a5b 100644 --- a/src/raspberrypi/devices/disk.h +++ b/src/raspberrypi/devices/disk.h @@ -56,6 +56,8 @@ public: explicit Disk(const string&); ~Disk() override; + Disk(Disk&) = delete; + Disk& operator=(const Disk&) = delete; bool Dispatch() override; diff --git a/src/raspberrypi/devices/disk_track_cache.h b/src/raspberrypi/devices/disk_track_cache.h index fc952cca..0216d10b 100644 --- a/src/raspberrypi/devices/disk_track_cache.h +++ b/src/raspberrypi/devices/disk_track_cache.h @@ -42,6 +42,8 @@ private: public: DiskTrack(); ~DiskTrack(); + DiskTrack(DiskTrack&) = delete; + DiskTrack& operator=(const DiskTrack&) = delete; private: friend class DiskCache; @@ -68,6 +70,8 @@ public: DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0); ~DiskCache(); + DiskCache(DiskCache&) = delete; + DiskCache& operator=(const DiskCache&) = delete; void SetRawMode(BOOL raw); // CD-ROM raw mode setting diff --git a/src/raspberrypi/devices/dispatcher.h b/src/raspberrypi/devices/dispatcher.h index 1e566344..889ad884 100644 --- a/src/raspberrypi/devices/dispatcher.h +++ b/src/raspberrypi/devices/dispatcher.h @@ -23,13 +23,15 @@ class Dispatcher { public: - Dispatcher() : commands({}) {} + Dispatcher() = default; ~Dispatcher() { for (auto const& [name, command] : commands) { delete command; } } + Dispatcher(Dispatcher&) = delete; + Dispatcher& operator=(const Dispatcher&) = delete; using operation = void (T::*)(); using command_t = struct _command_t { @@ -47,8 +49,7 @@ public: bool Dispatch(T *instance, DWORD cmd) { - const auto& it = commands.find(static_cast(cmd)); - if (it != commands.end()) { + if (const auto& it = commands.find(static_cast(cmd)); it != commands.end()) { LOGDEBUG("%s Executing %s ($%02X)", __PRETTY_FUNCTION__, it->second->name, (uint32_t)cmd) (instance->*it->second->execute)(); diff --git a/src/raspberrypi/devices/file_support.cpp b/src/raspberrypi/devices/file_support.cpp index 8cb68501..cd0e4bd6 100644 --- a/src/raspberrypi/devices/file_support.cpp +++ b/src/raspberrypi/devices/file_support.cpp @@ -25,8 +25,7 @@ void FileSupport::UnreserveFile() bool FileSupport::GetIdsForReservedFile(const Filepath& path, int& id, int& lun) { - const auto& it = reserved_files.find(path.GetPath()); - if (it != reserved_files.end()) { + if (const auto& it = reserved_files.find(path.GetPath()); it != reserved_files.end()) { id = it->second.first; lun = it->second.second; diff --git a/src/raspberrypi/devices/file_support.h b/src/raspberrypi/devices/file_support.h index 1ef3cb7b..61bd347b 100644 --- a/src/raspberrypi/devices/file_support.h +++ b/src/raspberrypi/devices/file_support.h @@ -32,8 +32,10 @@ class FileSupport public: - FileSupport() : diskpath({}) {} + FileSupport() = default; virtual ~FileSupport() = default; + FileSupport(FileSupport&) = delete; + FileSupport& operator=(const FileSupport&) = delete; void GetPath(Filepath& path) const { path = diskpath; } void SetPath(const Filepath& path) { diskpath = path; } diff --git a/src/raspberrypi/devices/host_services.cpp b/src/raspberrypi/devices/host_services.cpp index ae6609cb..7e633517 100644 --- a/src/raspberrypi/devices/host_services.cpp +++ b/src/raspberrypi/devices/host_services.cpp @@ -102,7 +102,7 @@ int HostServices::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length) throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB); } - int length = (int)cdb[4]; + auto length = (int)cdb[4]; if (length > max_length) { length = max_length; } @@ -121,7 +121,7 @@ int HostServices::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length) size = length; } - buf[0] = size; + buf[0] = (BYTE)size; return size; } @@ -152,8 +152,8 @@ int HostServices::ModeSense10(const DWORD *cdb, BYTE *buf, int max_length) size = length; } - buf[0] = size >> 8; - buf[1] = size; + buf[0] = (BYTE)(size >> 8); + buf[1] = (BYTE)size; return size; } @@ -174,15 +174,15 @@ void HostServices::AddRealtimeClockPage(map>& pages, bool chan buf[2] = 0x01; buf[3] = 0x00; - std::time_t t = std::time(NULL); + std::time_t t = std::time(nullptr); std::tm tm = *std::localtime(&t); - buf[4] = tm.tm_year; - buf[5] = tm.tm_mon; - buf[6] = tm.tm_mday; - buf[7] = tm.tm_hour; - buf[8] = tm.tm_min; + buf[4] = (BYTE)tm.tm_year; + buf[5] = (BYTE)tm.tm_mon; + buf[6] = (BYTE)tm.tm_mday; + buf[7] = (BYTE)tm.tm_hour; + buf[8] = (BYTE)tm.tm_min; // Ignore leap second for simplicity - buf[9] = tm.tm_sec < 60 ? tm.tm_sec : 59; + buf[9] = (BYTE)(tm.tm_sec < 60 ? tm.tm_sec : 59); pages[32] = buf; } diff --git a/src/raspberrypi/devices/host_services.h b/src/raspberrypi/devices/host_services.h index 20bb2b3d..500529f4 100644 --- a/src/raspberrypi/devices/host_services.h +++ b/src/raspberrypi/devices/host_services.h @@ -23,6 +23,8 @@ public: HostServices(); ~HostServices() override = default; + HostServices(HostServices&) = delete; + HostServices& operator=(const HostServices&) = delete; bool Dispatch() override; diff --git a/src/raspberrypi/devices/mode_page_device.cpp b/src/raspberrypi/devices/mode_page_device.cpp index 22399631..434cc5a6 100644 --- a/src/raspberrypi/devices/mode_page_device.cpp +++ b/src/raspberrypi/devices/mode_page_device.cpp @@ -16,7 +16,7 @@ using namespace std; using namespace scsi_defs; -ModePageDevice::ModePageDevice(const string& id) : PrimaryDevice(id), dispatcher({}) +ModePageDevice::ModePageDevice(const string& id) : PrimaryDevice(id) { dispatcher.AddCommand(eCmdModeSense6, "ModeSense6", &ModePageDevice::ModeSense6); dispatcher.AddCommand(eCmdModeSense10, "ModeSense10", &ModePageDevice::ModeSense10); @@ -56,20 +56,20 @@ int ModePageDevice::AddModePages(const DWORD *cdb, BYTE *buf, int max_length) co vector result; vector page0; - for (auto const& page : pages) { + for (auto const& [index, data] : pages) { // The specification mandates that page 0 must be returned after all others - if (page.first) { + if (index) { size_t offset = result.size(); // Page data - result.insert(result.end(), page.second.begin(), page.second.end()); + result.insert(result.end(), data.begin(), data.end()); // Page code, PS bit may already have been set - result[offset] |= page.first; + result[offset] |= index; // Page payload size - result[offset + 1] = page.second.size() - 2; + result[offset + 1] = (BYTE)(data.size() - 2); } else { - page0 = page.second; + page0 = data; } } @@ -80,14 +80,14 @@ int ModePageDevice::AddModePages(const DWORD *cdb, BYTE *buf, int max_length) co // Page data result.insert(result.end(), page0.begin(), page0.end()); // Page payload size - result[offset + 1] = page0.size() - 2; + result[offset + 1] = (BYTE)(page0.size() - 2); } // Do not return more than the requested number of bytes size_t size = (size_t)max_length < result.size() ? max_length : result.size(); memcpy(buf, result.data(), size); - return size; + return (int)size; } void ModePageDevice::ModeSense6() diff --git a/src/raspberrypi/devices/mode_page_device.h b/src/raspberrypi/devices/mode_page_device.h index 6e550865..14a80e35 100644 --- a/src/raspberrypi/devices/mode_page_device.h +++ b/src/raspberrypi/devices/mode_page_device.h @@ -22,6 +22,8 @@ public: explicit ModePageDevice(const string&); ~ModePageDevice()override = default; + ModePageDevice(ModePageDevice&) = delete; + ModePageDevice& operator=(const ModePageDevice&) = delete; bool Dispatch() override; diff --git a/src/raspberrypi/devices/primary_device.cpp b/src/raspberrypi/devices/primary_device.cpp index f30e7367..1168405c 100644 --- a/src/raspberrypi/devices/primary_device.cpp +++ b/src/raspberrypi/devices/primary_device.cpp @@ -15,7 +15,7 @@ using namespace std; using namespace scsi_defs; -PrimaryDevice::PrimaryDevice(const string& id) : ScsiPrimaryCommands(), Device(id), dispatcher({}) +PrimaryDevice::PrimaryDevice(const string& id) : ScsiPrimaryCommands(), Device(id) { // Mandatory SCSI primary commands dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &PrimaryDevice::TestUnitReady); @@ -31,9 +31,9 @@ bool PrimaryDevice::Dispatch() return dispatcher.Dispatch(this, ctrl->cmd[0]); } -void PrimaryDevice::SetController(AbstractController *controller) +void PrimaryDevice::SetController(AbstractController *c) { - this->controller = controller; + controller = c; ctrl = controller->GetCtrl(); } @@ -59,12 +59,10 @@ void PrimaryDevice::Inquiry() } memcpy(ctrl->buffer, buf.data(), allocation_length); - ctrl->length = allocation_length; - - int lun = controller->GetEffectiveLun(); + ctrl->length = (uint32_t)allocation_length; // Report if the device does not support the requested LUN - if (!controller->HasDeviceForLun(lun)) { + if (int lun = controller->GetEffectiveLun(); !controller->HasDeviceForLun(lun)) { LOGTRACE("Reporting LUN %d for device ID %d as not supported", lun, GetId()) // Signal that the requested LUN does not exist @@ -91,12 +89,12 @@ void PrimaryDevice::ReportLuns() for (int lun = 0; lun < controller->GetMaxLuns(); lun++) { if (controller->HasDeviceForLun(lun)) { size += 8; - buf[size + 7] = lun; + buf[size + 7] = (BYTE)lun; } } - buf[2] = size >> 8; - buf[3] = size; + buf[2] = (BYTE)(size >> 8); + buf[3] = (BYTE)size; size += 8; @@ -131,7 +129,7 @@ void PrimaryDevice::RequestSense() } memcpy(ctrl->buffer, buf.data(), allocation_length); - ctrl->length = allocation_length; + ctrl->length = (uint32_t)allocation_length; EnterDataInPhase(); } @@ -172,10 +170,10 @@ vector PrimaryDevice::HandleInquiry(device_type type, scsi_level level, bo // 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[0] = (BYTE)type; buf[1] = is_removable ? 0x80 : 0x00; - buf[2] = level; - buf[3] = level >= scsi_level::SCSI_2 ? scsi_level::SCSI_2 : scsi_level::SCSI_1_CCS; + buf[2] = (BYTE)level; + buf[3] = (BYTE)(level >= scsi_level::SCSI_2 ? scsi_level::SCSI_2 : scsi_level::SCSI_1_CCS); buf[4] = 0x1F; // Padded vendor, product, revision @@ -198,10 +196,10 @@ vector PrimaryDevice::HandleRequestSense() // Current error buf[0] = 0x70; - buf[2] = GetStatusCode() >> 16; + buf[2] = (BYTE)(GetStatusCode() >> 16); buf[7] = 10; - buf[12] = GetStatusCode() >> 8; - buf[13] = GetStatusCode(); + buf[12] = (BYTE)(GetStatusCode() >> 8); + buf[13] = (BYTE)GetStatusCode(); LOGTRACE("%s Status $%02X, Sense Key $%02X, ASC $%02X",__PRETTY_FUNCTION__, ctrl->status, ctrl->buffer[2], ctrl->buffer[12]) diff --git a/src/raspberrypi/devices/primary_device.h b/src/raspberrypi/devices/primary_device.h index 93566247..47c96ea5 100644 --- a/src/raspberrypi/devices/primary_device.h +++ b/src/raspberrypi/devices/primary_device.h @@ -25,6 +25,8 @@ public: explicit PrimaryDevice(const string&); ~PrimaryDevice() override = default; + PrimaryDevice(PrimaryDevice&) = delete; + PrimaryDevice& operator=(const PrimaryDevice&) = delete; bool Dispatch() override; diff --git a/src/raspberrypi/devices/scsi_command_util.cpp b/src/raspberrypi/devices/scsi_command_util.cpp index c3e0f6df..a06bf314 100644 --- a/src/raspberrypi/devices/scsi_command_util.cpp +++ b/src/raspberrypi/devices/scsi_command_util.cpp @@ -27,7 +27,7 @@ void scsi_command_util::ModeSelect(const DWORD *cdb, const BYTE *buf, int length if (buf[9] != (BYTE)(sector_size >> 16) || buf[10] != (BYTE)(sector_size >> 8) || buf[11] != (BYTE)sector_size) { // See below for details - LOGWARN("In order to change the sector size use the -b option when launching rascsi"); + LOGWARN("In order to change the sector size use the -b option when launching rascsi") throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST); } @@ -46,14 +46,14 @@ void scsi_command_util::ModeSelect(const DWORD *cdb, const BYTE *buf, int length if (buf[0xc] != (BYTE)(sector_size >> 8) || buf[0xd] != (BYTE)sector_size) { // With rascsi it is not possible to permanently (by formatting) change the sector size, // because the size is an externally configurable setting only - LOGWARN("In order to change the sector size use the -b option when launching rascsi"); + LOGWARN("In order to change the sector size use the -b option when launching rascsi") throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST); } has_valid_page_code = true; } else { - LOGWARN("Unknown MODE SELECT page code: $%02X", page); + LOGWARN("Unknown MODE SELECT page code: $%02X", page) } // Advance to the next page @@ -77,17 +77,12 @@ void scsi_command_util::EnrichFormatPage(map>& pages, bool cha if (changeable) { // The sector size is simulated to be changeable, see the MODE SELECT implementation for details vector& format_page = pages[3]; - format_page[12] = sector_size >> 8; - format_page[13] = sector_size; + format_page[12] = (BYTE)(sector_size >> 8); + format_page[13] = (BYTE)sector_size; } } -//--------------------------------------------------------------------------- -// -// Add Vendor special page to make drive Apple compatible -// -//--------------------------------------------------------------------------- -void scsi_command_util::AddAppleVendorModePage(map>& pages, int page, bool changeable) +void scsi_command_util::AddAppleVendorModePage(map>& pages, int, bool changeable) { // Page code 48 (30h) - Apple Vendor Mode Page // Needed for SCCD for stock Apple driver support diff --git a/src/raspberrypi/devices/scsi_command_util.h b/src/raspberrypi/devices/scsi_command_util.h index 166767f0..d6d248f3 100644 --- a/src/raspberrypi/devices/scsi_command_util.h +++ b/src/raspberrypi/devices/scsi_command_util.h @@ -21,6 +21,5 @@ namespace scsi_command_util { void ModeSelect(const DWORD *, const BYTE *, int, int); void EnrichFormatPage(map>&, bool, int); - void AddAppleVendorModePage(map>&, int, bool); } diff --git a/src/raspberrypi/devices/scsi_daynaport.cpp b/src/raspberrypi/devices/scsi_daynaport.cpp index 3a7b160a..75ae66f1 100644 --- a/src/raspberrypi/devices/scsi_daynaport.cpp +++ b/src/raspberrypi/devices/scsi_daynaport.cpp @@ -36,7 +36,7 @@ const BYTE SCSIDaynaPort::m_bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff const BYTE SCSIDaynaPort::m_apple_talk_addr[6] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff }; // TODO Disk should not be the superclass -SCSIDaynaPort::SCSIDaynaPort() : Disk("SCDP"), dispatcher({}) +SCSIDaynaPort::SCSIDaynaPort() : Disk("SCDP") { dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &SCSIDaynaPort::TestUnitReady); dispatcher.AddCommand(eCmdRead6, "Read6", &SCSIDaynaPort::Read6); @@ -86,7 +86,7 @@ bool SCSIDaynaPort::Init(const unordered_map& params) LOGDEBUG("Tap interface created") } - this->Reset(); + Reset(); SetReady(true); SetReset(false); @@ -161,7 +161,7 @@ vector SCSIDaynaPort::InquiryInternal() const int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t) { int rx_packet_size = 0; - scsi_resp_read_t *response = (scsi_resp_read_t*)buf; + auto response = (scsi_resp_read_t*)buf; int requested_length = cdb[4]; LOGTRACE("%s Read maximum length %d, (%04X)", __PRETTY_FUNCTION__, requested_length, requested_length) @@ -175,6 +175,7 @@ int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t) // Some of the packets we receive will not be for us. So, we'll keep pulling messages // until the buffer is empty, or we've read X times. (X is just a made up number) + // TODO send_message_to_host is effctively always true bool send_message_to_host; int read_count = 0; while (read_count < MAX_READ_RETRIES) { @@ -259,8 +260,8 @@ int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t) // breaks because of this, the work-around has to be re-evaluated. size = 64; } - buf[0] = size >> 8; - buf[1] = size; + buf[0] = (BYTE)(size >> 8); + buf[1] = (BYTE)size; buf[2] = 0; buf[3] = 0; @@ -315,7 +316,7 @@ int SCSIDaynaPort::WriteCheck(uint64_t) //--------------------------------------------------------------------------- bool SCSIDaynaPort::WriteBytes(const DWORD *cdb, BYTE *buf, uint64_t) { - BYTE data_format = cdb[5]; + auto data_format = (BYTE)cdb[5]; WORD data_length = (WORD)cdb[4] + ((WORD)cdb[3] << 8); if (data_format == 0x00){ @@ -355,7 +356,7 @@ bool SCSIDaynaPort::WriteBytes(const DWORD *cdb, BYTE *buf, uint64_t) //--------------------------------------------------------------------------- int SCSIDaynaPort::RetrieveStats(const DWORD *cdb, BYTE *buffer) const { - int allocation_length = cdb[4] + (((DWORD)cdb[3]) << 8); + int allocation_length = cdb[4] + (cdb[3] << 8); // memset(buffer,0,18); // memcpy(&buffer[0],m_mac_addr,sizeof(m_mac_addr)); @@ -548,7 +549,7 @@ void SCSIDaynaPort::SetInterfaceMode() void SCSIDaynaPort::SetMcastAddr() { - ctrl->length = (DWORD)ctrl->cmd[4]; + ctrl->length = ctrl->cmd[4]; if (ctrl->length == 0) { LOGWARN("%s Not supported SetMcastAddr Command %02X", __PRETTY_FUNCTION__, (WORD)ctrl->cmd[2]) diff --git a/src/raspberrypi/devices/scsi_daynaport.h b/src/raspberrypi/devices/scsi_daynaport.h index 9ade303c..55bda15e 100644 --- a/src/raspberrypi/devices/scsi_daynaport.h +++ b/src/raspberrypi/devices/scsi_daynaport.h @@ -44,6 +44,8 @@ class SCSIDaynaPort: public Disk public: SCSIDaynaPort(); ~SCSIDaynaPort() final; + SCSIDaynaPort(SCSIDaynaPort&) = delete; + SCSIDaynaPort& operator=(const SCSIDaynaPort&) = delete; bool Init(const unordered_map&) override; void Open(const Filepath& path) override; diff --git a/src/raspberrypi/devices/scsi_host_bridge.cpp b/src/raspberrypi/devices/scsi_host_bridge.cpp index 48d0d185..eb5bec94 100644 --- a/src/raspberrypi/devices/scsi_host_bridge.cpp +++ b/src/raspberrypi/devices/scsi_host_bridge.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace scsi_defs; -SCSIBR::SCSIBR() : Disk("SCBR"), dispatcher({}), fs(new CFileSys()) +SCSIBR::SCSIBR() : Disk("SCBR"), fs(new CFileSys()) { // Create host file system fs->Reset(); @@ -56,7 +56,7 @@ bool SCSIBR::Init(const unordered_map& params) tap = new CTapDriver(); m_bTapEnable = tap->Init(GetParams()); if (!m_bTapEnable){ - LOGERROR("Unable to open the TAP interface"); + LOGERROR("Unable to open the TAP interface") return false; } @@ -92,7 +92,7 @@ vector SCSIBR::InquiryInternal() const vector b = HandleInquiry(device_type::COMMUNICATIONS, scsi_level::SCSI_2, false); // The bridge returns 6 more additional bytes than the other devices - vector buf = vector(0x1F + 8 + 5); + auto buf = vector(0x1F + 8 + 5); memcpy(buf.data(), b.data(), b.size()); buf[4] = 0x1F + 8; @@ -413,12 +413,11 @@ void SCSIBR::FS_InitDevice(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_CheckDir(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; - i += sizeof(Human68k::namests_t); + const auto pNamests = (Human68k::namests_t*)&buf[i]; fsresult = fs->CheckDir(nUnit, pNamests); } @@ -430,12 +429,11 @@ void SCSIBR::FS_CheckDir(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_MakeDir(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; - i += sizeof(Human68k::namests_t); + const auto pNamests = (Human68k::namests_t*)&buf[i]; fsresult = fs->MakeDir(nUnit, pNamests); } @@ -447,12 +445,11 @@ void SCSIBR::FS_MakeDir(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_RemoveDir(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; - i += sizeof(Human68k::namests_t); + const auto pNamests = (Human68k::namests_t*)&buf[i]; fsresult = fs->RemoveDir(nUnit, pNamests); } @@ -464,15 +461,14 @@ void SCSIBR::FS_RemoveDir(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Rename(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; + const auto pNamests = (Human68k::namests_t*)&buf[i]; i += sizeof(Human68k::namests_t); const Human68k::namests_t *pNamestsNew = (Human68k::namests_t*)&buf[i]; - i += sizeof(Human68k::namests_t); fsresult = fs->Rename(nUnit, pNamests, pNamestsNew); } @@ -484,12 +480,11 @@ void SCSIBR::FS_Rename(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Delete(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; - i += sizeof(Human68k::namests_t); + const auto *pNamests = (Human68k::namests_t*)&buf[i]; fsresult = fs->Delete(nUnit, pNamests); } @@ -501,16 +496,15 @@ void SCSIBR::FS_Delete(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Attribute(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; + const auto pNamests = (Human68k::namests_t*)&buf[i]; i += sizeof(Human68k::namests_t); dp = (DWORD*)&buf[i]; DWORD nHumanAttribute = ntohl(*dp); - i += sizeof(DWORD); fsresult = fs->Attribute(nUnit, pNamests, nHumanAttribute); } @@ -522,7 +516,7 @@ void SCSIBR::FS_Attribute(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Files(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -530,11 +524,10 @@ void SCSIBR::FS_Files(BYTE *buf) DWORD nKey = ntohl(*dp); i += sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; + const auto pNamests = (Human68k::namests_t*)&buf[i]; i += sizeof(Human68k::namests_t); - Human68k::files_t *files = (Human68k::files_t*)&buf[i]; - i += sizeof(Human68k::files_t); + auto files = (Human68k::files_t*)&buf[i]; files->sector = ntohl(files->sector); files->offset = ntohs(files->offset); @@ -564,7 +557,7 @@ void SCSIBR::FS_Files(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_NFiles(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -572,8 +565,7 @@ void SCSIBR::FS_NFiles(BYTE *buf) DWORD nKey = ntohl(*dp); i += sizeof(DWORD); - Human68k::files_t *files = (Human68k::files_t*)&buf[i]; - i += sizeof(Human68k::files_t); + auto files = (Human68k::files_t*)&buf[i]; files->sector = ntohl(files->sector); files->offset = ntohs(files->offset); @@ -603,7 +595,7 @@ void SCSIBR::FS_NFiles(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Create(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -611,19 +603,18 @@ void SCSIBR::FS_Create(BYTE *buf) DWORD nKey = ntohl(*dp); i += sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; + const auto pNamests = (Human68k::namests_t*)&buf[i]; i += sizeof(Human68k::namests_t); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; + auto pFcb = (Human68k::fcb_t*)&buf[i]; i += sizeof(Human68k::fcb_t); dp = (DWORD*)&buf[i]; DWORD nAttribute = ntohl(*dp); i += sizeof(DWORD); - BOOL *bp = (BOOL*)&buf[i]; + auto bp = (BOOL*)&buf[i]; DWORD bForce = ntohl(*bp); - i += sizeof(BOOL); pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -653,7 +644,7 @@ void SCSIBR::FS_Create(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Open(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -661,11 +652,10 @@ void SCSIBR::FS_Open(BYTE *buf) DWORD nKey = ntohl(*dp); i += sizeof(DWORD); - const Human68k::namests_t *pNamests = (Human68k::namests_t*)&buf[i]; + const auto pNamests = (Human68k::namests_t*)&buf[i]; i += sizeof(Human68k::namests_t); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; - i += sizeof(Human68k::fcb_t); + auto pFcb = (Human68k::fcb_t*)&buf[i]; pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -695,7 +685,7 @@ void SCSIBR::FS_Open(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Close(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -703,8 +693,7 @@ void SCSIBR::FS_Close(BYTE *buf) DWORD nKey = ntohl(*dp); i += sizeof(DWORD); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; - i += sizeof(Human68k::fcb_t); + auto pFcb = (Human68k::fcb_t*)&buf[i]; pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -734,16 +723,15 @@ void SCSIBR::FS_Close(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Read(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nKey = ntohl(*dp); int i = sizeof(DWORD); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; + auto pFcb = (Human68k::fcb_t*)&buf[i]; i += sizeof(Human68k::fcb_t); dp = (DWORD*)&buf[i]; DWORD nSize = ntohl(*dp); - i += sizeof(DWORD); pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -775,16 +763,15 @@ void SCSIBR::FS_Read(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Write(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nKey = ntohl(*dp); int i = sizeof(DWORD); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; + auto pFcb = (Human68k::fcb_t*)&buf[i]; i += sizeof(Human68k::fcb_t); dp = (DWORD*)&buf[i]; DWORD nSize = ntohl(*dp); - i += sizeof(DWORD); pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -814,11 +801,11 @@ void SCSIBR::FS_Write(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Seek(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nKey = ntohl(*dp); int i = sizeof(DWORD); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; + auto pFcb = (Human68k::fcb_t*)&buf[i]; i += sizeof(Human68k::fcb_t); dp = (DWORD*)&buf[i]; @@ -827,7 +814,6 @@ void SCSIBR::FS_Seek(BYTE *buf) auto ip = (const int*)&buf[i]; int nOffset = ntohl(*ip); - i += sizeof(int); pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -857,7 +843,7 @@ void SCSIBR::FS_Seek(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_TimeStamp(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -865,12 +851,11 @@ void SCSIBR::FS_TimeStamp(BYTE *buf) DWORD nKey = ntohl(*dp); i += sizeof(DWORD); - Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; + auto pFcb = (Human68k::fcb_t*)&buf[i]; i += sizeof(Human68k::fcb_t); dp = (DWORD*)&buf[i]; DWORD nHumanTime = ntohl(*dp); - i += sizeof(DWORD); pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->mode = ntohs(pFcb->mode); @@ -900,7 +885,7 @@ void SCSIBR::FS_TimeStamp(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_GetCapacity(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); Human68k::capacity_t cap; @@ -922,11 +907,11 @@ void SCSIBR::FS_GetCapacity(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_CtrlDrive(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); - Human68k::ctrldrive_t *pCtrlDrive = (Human68k::ctrldrive_t*)&buf[i]; + auto pCtrlDrive = (Human68k::ctrldrive_t*)&buf[i]; fsresult = fs->CtrlDrive(nUnit, pCtrlDrive); @@ -941,7 +926,7 @@ void SCSIBR::FS_CtrlDrive(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_GetDPB(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); Human68k::dpb_t dpb; @@ -965,7 +950,7 @@ void SCSIBR::FS_GetDPB(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_DiskRead(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -975,7 +960,6 @@ void SCSIBR::FS_DiskRead(BYTE *buf) dp = (DWORD*)&buf[i]; DWORD nSize = ntohl(*dp); - i += sizeof(DWORD); fsresult = fs->DiskRead(nUnit, fsout, nSector, nSize); fsoutlen = 0x200; @@ -988,7 +972,7 @@ void SCSIBR::FS_DiskRead(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_DiskWrite(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); fsresult = fs->DiskWrite(nUnit); @@ -1001,7 +985,7 @@ void SCSIBR::FS_DiskWrite(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Ioctrl(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); int i = sizeof(DWORD); @@ -1009,8 +993,7 @@ void SCSIBR::FS_Ioctrl(BYTE *buf) DWORD nFunction = ntohl(*dp); i += sizeof(DWORD); - Human68k::ioctrl_t *pIoctrl = (Human68k::ioctrl_t*)&buf[i]; - i += sizeof(Human68k::ioctrl_t); + auto pIoctrl = (Human68k::ioctrl_t*)&buf[i]; switch (nFunction) { case 2: @@ -1048,7 +1031,7 @@ void SCSIBR::FS_Ioctrl(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Flush(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); fsresult = fs->Flush(nUnit); @@ -1061,7 +1044,7 @@ void SCSIBR::FS_Flush(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_CheckMedia(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); fsresult = fs->CheckMedia(nUnit); @@ -1074,7 +1057,7 @@ void SCSIBR::FS_CheckMedia(BYTE *buf) //--------------------------------------------------------------------------- void SCSIBR::FS_Lock(BYTE *buf) { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; DWORD nUnit = ntohl(*dp); fsresult = fs->Lock(nUnit); @@ -1087,7 +1070,7 @@ void SCSIBR::FS_Lock(BYTE *buf) //--------------------------------------------------------------------------- int SCSIBR::ReadFsResult(BYTE *buf) const { - DWORD *dp = (DWORD*)buf; + auto dp = (DWORD*)buf; *dp = htonl(fsresult); return sizeof(DWORD); } diff --git a/src/raspberrypi/devices/scsi_host_bridge.h b/src/raspberrypi/devices/scsi_host_bridge.h index 9b853812..0b6f67d2 100644 --- a/src/raspberrypi/devices/scsi_host_bridge.h +++ b/src/raspberrypi/devices/scsi_host_bridge.h @@ -36,6 +36,8 @@ public: SCSIBR(); ~SCSIBR() final; + SCSIBR(SCSIBR&) = delete; + SCSIBR& operator=(const SCSIBR&) = delete; bool Init(const unordered_map&) override; bool Dispatch() override; diff --git a/src/raspberrypi/devices/scsi_printer.cpp b/src/raspberrypi/devices/scsi_printer.cpp index dbe3099c..60d1d9d9 100644 --- a/src/raspberrypi/devices/scsi_printer.cpp +++ b/src/raspberrypi/devices/scsi_printer.cpp @@ -48,7 +48,7 @@ using namespace std; using namespace scsi_defs; using namespace ras_util; -SCSIPrinter::SCSIPrinter() : PrimaryDevice("SCLP"), ScsiPrinterCommands(), dispatcher({}) +SCSIPrinter::SCSIPrinter() : PrimaryDevice("SCLP"), ScsiPrinterCommands() { dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &SCSIPrinter::TestUnitReady); dispatcher.AddCommand(eCmdReserve6, "ReserveUnit", &SCSIPrinter::ReserveUnit); @@ -148,12 +148,12 @@ void SCSIPrinter::Print() length <<= 8; length |= ctrl->cmd[4]; - LOGTRACE("Receiving %d bytes to be printed", length); + LOGTRACE("Receiving %d bytes to be printed", length) // TODO This device suffers from the statically allocated buffer size, // see https://github.com/akuker/RASCSI/issues/669 if (length > (uint32_t)ctrl->bufsize) { - LOGERROR("Transfer buffer overflow"); + LOGERROR("Transfer buffer overflow") throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB); } @@ -187,12 +187,12 @@ void SCSIPrinter::SynchronizeBuffer() cmd.replace(file_position, 2, filename); cmd = "sudo -u lp " + cmd; - LOGTRACE("%s", string("Printing file with size of " + to_string(st.st_size) +" byte(s)").c_str()); + LOGTRACE("%s", string("Printing file with size of " + to_string(st.st_size) +" byte(s)").c_str()) - LOGDEBUG("Executing '%s'", cmd.c_str()); + LOGDEBUG("Executing '%s'", cmd.c_str()) if (system(cmd.c_str())) { - LOGERROR("Printing failed, the printing system might not be configured"); + LOGERROR("Printing failed, the printing system might not be configured") unlink(filename); @@ -206,9 +206,8 @@ void SCSIPrinter::SynchronizeBuffer() void SCSIPrinter::SendDiagnostic() { - CheckReservation(); - - EnterStatusPhase(); + // Both command implemntations are identical + TestUnitReady(); } void SCSIPrinter::StopPrint() @@ -226,16 +225,16 @@ bool SCSIPrinter::WriteByteSequence(BYTE *buf, uint32_t length) strcpy(filename, TMP_FILE_PATTERN); fd = mkstemp(filename); if (fd == -1) { - LOGERROR("Can't create printer output file: %s", strerror(errno)); + LOGERROR("Can't create printer output file: %s", strerror(errno)) return false; } - LOGTRACE("Created printer output file '%s'", filename); + LOGTRACE("Created printer output file '%s'", filename) } - LOGTRACE("Appending %d byte(s) to printer output file", length); + LOGTRACE("Appending %d byte(s) to printer output file", length) - uint32_t num_written = write(fd, buf, length); + uint32_t num_written = (uint32_t)write(fd, buf, length); return num_written == length; } diff --git a/src/raspberrypi/devices/scsi_printer.h b/src/raspberrypi/devices/scsi_printer.h index d43664a7..48234a64 100644 --- a/src/raspberrypi/devices/scsi_printer.h +++ b/src/raspberrypi/devices/scsi_printer.h @@ -28,6 +28,8 @@ public: SCSIPrinter(); ~SCSIPrinter() final; + SCSIPrinter(SCSIPrinter&) = delete; + SCSIPrinter& operator=(const SCSIPrinter&) = delete; bool Dispatch() override; diff --git a/src/raspberrypi/devices/scsicd.cpp b/src/raspberrypi/devices/scsicd.cpp index 9ba5ef6e..755917da 100644 --- a/src/raspberrypi/devices/scsicd.cpp +++ b/src/raspberrypi/devices/scsicd.cpp @@ -94,7 +94,7 @@ DWORD CDTrack::GetBlocks() const ASSERT(first_lba < last_lba); // Calculate from start LBA and end LBA - return (DWORD)(last_lba - first_lba + 1); + return last_lba - first_lba + 1; } int CDTrack::GetTrackNo() const diff --git a/src/raspberrypi/devices/scsicd.h b/src/raspberrypi/devices/scsicd.h index bdbf4cf9..8d0bea77 100644 --- a/src/raspberrypi/devices/scsicd.h +++ b/src/raspberrypi/devices/scsicd.h @@ -34,6 +34,7 @@ private: CDTrack() = default; virtual ~CDTrack() final = default; + CDTrack(CDTrack&) = delete; public: @@ -65,14 +66,15 @@ private: //=========================================================================== class SCSICD : public Disk, public ScsiMmcCommands, public FileSupport { + // Maximum number of tracks + static const int TRACK_MAX = 96; public: - enum { - TrackMax = 96 // Maximum number of tracks - }; explicit SCSICD(const unordered_set&); ~SCSICD() override; + SCSICD(SCSICD&) = delete; + SCSICD& operator=(const SCSICD&) = delete; bool Dispatch() override; @@ -89,6 +91,7 @@ protected: void AddVendorPage(map>&, int, bool) const override; private: + using super = Disk; Dispatcher dispatcher; @@ -111,7 +114,7 @@ private: // Track management void ClearTrack(); // Clear the track int SearchTrack(DWORD lba) const; // Track search - CDTrack* track[TrackMax] = {}; // Track opbject references + CDTrack* track[TRACK_MAX] = {}; // Track opbject references int tracks = 0; // Effective number of track objects int dataindex = -1; // Current data track int audioindex = -1; // Current audio track diff --git a/src/raspberrypi/devices/scsihd.cpp b/src/raspberrypi/devices/scsihd.cpp index 3173701b..dadf4d8d 100644 --- a/src/raspberrypi/devices/scsihd.cpp +++ b/src/raspberrypi/devices/scsihd.cpp @@ -25,7 +25,7 @@ static const char *DEFAULT_PRODUCT = "SCSI HD"; SCSIHD::SCSIHD(const unordered_set& sector_sizes, bool removable, scsi_defs::scsi_level level) : Disk(removable ? "SCRM" : "SCHD") { - this->scsi_level = level; + scsi_level = level; SetSectorSizes(sector_sizes); } diff --git a/src/raspberrypi/devices/scsihd.h b/src/raspberrypi/devices/scsihd.h index 271701f4..0e62a465 100644 --- a/src/raspberrypi/devices/scsihd.h +++ b/src/raspberrypi/devices/scsihd.h @@ -21,10 +21,13 @@ class SCSIHD : public Disk, public FileSupport { + public: SCSIHD(const unordered_set&, bool, scsi_defs::scsi_level = scsi_level::SCSI_2); - virtual ~SCSIHD() {} + ~SCSIHD() override = default; + SCSIHD(SCSIHD&) = delete; + SCSIHD& operator=(const SCSIHD&) = delete; void FinalizeSetup(const Filepath&, off_t); diff --git a/src/raspberrypi/devices/scsihd_nec.cpp b/src/raspberrypi/devices/scsihd_nec.cpp index 4449281b..b3be7b39 100644 --- a/src/raspberrypi/devices/scsihd_nec.cpp +++ b/src/raspberrypi/devices/scsihd_nec.cpp @@ -75,7 +75,7 @@ void SCSIHD_NEC::Open(const Filepath& path) if (const char *ext = path.GetFileExt(); !strcasecmp(ext, ".hdn")) { // Assuming sector size 512, number of sectors 25, number of heads 8 as default settings disk.image_offset = 0; - image_size = size; + image_size = (int)size; sector_size = 512; sectors = 25; heads = 8; @@ -100,7 +100,7 @@ void SCSIHD_NEC::Open(const Filepath& path) heads = getWordLE(&root_sector[0x118]); sectors = getWordLE(&root_sector[0x11a]); sector_size = getWordLE(&root_sector[0x11c]); - image_size = (off_t)cylinders * heads * sectors * sector_size; + image_size = (int)((off_t)cylinders * heads * sectors * sector_size); } else { throw io_exception("Invalid NEC image file format"); @@ -124,7 +124,7 @@ void SCSIHD_NEC::Open(const Filepath& path) if (size <= 0 || size > 16) { throw io_exception("Invalid NEC disk size"); } - SetSectorSizeShiftCount(size); + SetSectorSizeShiftCount((uint32_t)size); // Number of blocks SetBlockCount(image_size >> disk.size); diff --git a/src/raspberrypi/devices/scsihd_nec.h b/src/raspberrypi/devices/scsihd_nec.h index 4bba4809..166d27d3 100644 --- a/src/raspberrypi/devices/scsihd_nec.h +++ b/src/raspberrypi/devices/scsihd_nec.h @@ -30,6 +30,8 @@ public: explicit SCSIHD_NEC() : SCSIHD(sector_sizes, false) {} ~SCSIHD_NEC() override = default; + SCSIHD_NEC(SCSIHD_NEC&) = delete; + SCSIHD_NEC& operator=(const SCSIHD_NEC&) = delete; void Open(const Filepath& path) override; diff --git a/src/raspberrypi/devices/scsimo.cpp b/src/raspberrypi/devices/scsimo.cpp index 3245d01e..653e81eb 100644 --- a/src/raspberrypi/devices/scsimo.cpp +++ b/src/raspberrypi/devices/scsimo.cpp @@ -20,7 +20,7 @@ #include "scsimo.h" SCSIMO::SCSIMO(const unordered_set& sector_sizes, const unordered_map& geometries) - : Disk("SCMO"), geometries({}) + : Disk("SCMO") { SetSectorSizes(sector_sizes); SetGeometries(geometries); @@ -49,9 +49,6 @@ void SCSIMO::Open(const Filepath& path) SetBlockCount(size >> GetSectorSizeShiftCount()); } - // Effective size must be a multiple of the sector size - size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes(); - SetReadOnly(false); SetProtectable(true); SetProtected(false); @@ -219,8 +216,7 @@ void SCSIMO::AddVendorPage(map>& pages, int page, bool changea } bool SCSIMO::SetGeometryForCapacity(uint64_t capacity) { - const auto& geometry = geometries.find(capacity); - if (geometry != geometries.end()) { + if (const auto& geometry = geometries.find(capacity); geometry != geometries.end()) { SetSectorSizeInBytes(geometry->second.first); SetBlockCount(geometry->second.second); diff --git a/src/raspberrypi/devices/scsimo.h b/src/raspberrypi/devices/scsimo.h index 4c715d97..14f2beeb 100644 --- a/src/raspberrypi/devices/scsimo.h +++ b/src/raspberrypi/devices/scsimo.h @@ -26,6 +26,8 @@ public: SCSIMO(const unordered_set&, const unordered_map&); ~SCSIMO() override = default; + SCSIMO(SCSIMO&) = delete; + SCSIMO& operator=(const SCSIMO&) = delete; void Open(const Filepath& path) override; @@ -43,7 +45,7 @@ private: void AddOptionPage(map>&, bool) const; - void SetGeometries(const unordered_map& geometries) { this->geometries = geometries; } + void SetGeometries(const unordered_map& g) { geometries = g; } bool SetGeometryForCapacity(uint64_t); // The mapping of supported capacities to block sizes and block counts, empty if there is no capacity restriction diff --git a/src/raspberrypi/fileio.h b/src/raspberrypi/fileio.h index 5d9b0302..4023f510 100644 --- a/src/raspberrypi/fileio.h +++ b/src/raspberrypi/fileio.h @@ -44,6 +44,9 @@ public: Fileio() = default; virtual ~Fileio(); + Fileio(Fileio&) = delete; + Fileio& operator=(const Fileio&) = delete; + BOOL Load(const Filepath& path, void *buffer, int size); // Load ROM, RAM BOOL Save(const Filepath& path, const void *buffer, int size); // Save RAM diff --git a/src/raspberrypi/filepath.cpp b/src/raspberrypi/filepath.cpp index 8d24fadc..65a06532 100644 --- a/src/raspberrypi/filepath.cpp +++ b/src/raspberrypi/filepath.cpp @@ -46,7 +46,7 @@ void Filepath::SetPath(const char *path) ASSERT(strlen(path) < _MAX_PATH); // Copy pathname - strcpy(m_szPath, (char *)path); + strcpy(m_szPath, path); // Split Split(); diff --git a/src/raspberrypi/filepath.h b/src/raspberrypi/filepath.h index 0f9a07ae..fc84183e 100644 --- a/src/raspberrypi/filepath.h +++ b/src/raspberrypi/filepath.h @@ -29,9 +29,12 @@ class Fileio; //=========================================================================== class Filepath { + public: + Filepath(); virtual ~Filepath() = default; + Filepath(Filepath&) = delete; Filepath& operator=(const Filepath& path); void Clear(); @@ -40,6 +43,7 @@ public: const char *GetFileExt() const; // Get short name (LPCTSTR) private: + void Split(); // Split the path TCHAR m_szPath[_MAX_PATH]; // File path TCHAR m_szDir[_MAX_DIR]; // Directory diff --git a/src/raspberrypi/gpiobus.h b/src/raspberrypi/gpiobus.h index 4691e653..7d049c13 100644 --- a/src/raspberrypi/gpiobus.h +++ b/src/raspberrypi/gpiobus.h @@ -106,14 +106,14 @@ #define CONNECT_DESC "STANDARD" // Startup message // Select signal control mode -#define SIGNAL_CONTROL_MODE 0 // SCSI logical specification +const static int SIGNAL_CONTROL_MODE = 0; // SCSI logical specification // Control signal pin assignment (-1 means no control) -#define PIN_ACT 4 // ACTIVE -#define PIN_ENB 5 // ENABLE -#define PIN_IND -1 // INITIATOR CTRL DIRECTION -#define PIN_TAD -1 // TARGET CTRL DIRECTION -#define PIN_DTD -1 // DATA DIRECTION +const static int PIN_ACT = 4; // ACTIVE +const static int PIN_ENB = 5; // ENABLE +const static int PIN_IND = -1; // INITIATOR CTRL DIRECTION +const static int PIN_TAD = -1; // TARGET CTRL DIRECTION +const static int PIN_DTD = -1; // DATA DIRECTION // Control signal output logic #define ACT_ON TRUE // ACTIVE SIGNAL ON @@ -123,24 +123,24 @@ #define DTD_IN TRUE // DATA SIGNAL INPUT // SCSI signal pin assignment -#define PIN_DT0 10 // Data 0 -#define PIN_DT1 11 // Data 1 -#define PIN_DT2 12 // Data 2 -#define PIN_DT3 13 // Data 3 -#define PIN_DT4 14 // Data 4 -#define PIN_DT5 15 // Data 5 -#define PIN_DT6 16 // Data 6 -#define PIN_DT7 17 // Data 7 -#define PIN_DP 18 // Data parity -#define PIN_ATN 19 // ATN -#define PIN_RST 20 // RST -#define PIN_ACK 21 // ACK -#define PIN_REQ 22 // REQ -#define PIN_MSG 23 // MSG -#define PIN_CD 24 // CD -#define PIN_IO 25 // IO -#define PIN_BSY 26 // BSY -#define PIN_SEL 27 // SEL +const static int PIN_DT0 = 10; // Data 0 +const static int PIN_DT1 = 11; // Data 1 +const static int PIN_DT2 = 12; // Data 2 +const static int PIN_DT3 = 13; // Data 3 +const static int PIN_DT4 = 14; // Data 4 +const static int PIN_DT5 = 15; // Data 5 +const static int PIN_DT6 = 16; // Data 6 +const static int PIN_DT7 = 17; // Data 7 +const static int PIN_DP = 18; // Data parity +const static int PIN_ATN = 19; // ATN +const static int PIN_RST = 20; // RST +const static int PIN_ACK = 21; // ACK +const static int PIN_REQ = 22; // REQ +const static int PIN_MSG = 23; // MSG +const static int PIN_CD = 24; // CD +const static int PIN_IO = 25; // IO +const static int PIN_BSY = 26; // BSY +const static int PIN_SEL = 27; // SEL #endif #ifdef CONNECT_TYPE_FULLSPEC @@ -175,14 +175,14 @@ const static int PIN_DT4 = 14; // Data 4 const static int PIN_DT5 = 15; // Data 5 const static int PIN_DT6 = 16; // Data 6 const static int PIN_DT7 = 17; // Data 7 -const static int PIN_DP = 18; // Data parity +const static int PIN_DP = 18; // Data parity const static int PIN_ATN = 19; // ATN const static int PIN_RST = 20; // RST const static int PIN_ACK = 21; // ACK const static int PIN_REQ = 22; // REQ const static int PIN_MSG = 23; // MSG -const static int PIN_CD = 24; // CD -const static int PIN_IO = 25; // IO +const static int PIN_CD = 24; // CD +const static int PIN_IO = 25; // IO const static int PIN_BSY = 26; // BSY const static int PIN_SEL = 27; // SEL #endif @@ -195,7 +195,7 @@ const static int PIN_SEL = 27; // SEL #define CONNECT_DESC "AIBOM PRODUCTS version" // Startup message // Select signal control mode -#define SIGNAL_CONTROL_MODE 2 // SCSI positive logic specification +const static int SIGNAL_CONTROL_MODE = 2; // SCSI positive logic specification // Control signal output logic #define ACT_ON TRUE // ACTIVE SIGNAL ON @@ -205,31 +205,31 @@ const static int PIN_SEL = 27; // SEL #define DTD_IN FALSE // DATA SIGNAL INPUT // Control signal pin assignment (-1 means no control) -#define PIN_ACT 4 // ACTIVE -#define PIN_ENB 17 // ENABLE -#define PIN_IND 27 // INITIATOR CTRL DIRECTION -#define PIN_TAD -1 // TARGET CTRL DIRECTION -#define PIN_DTD 18 // DATA DIRECTION +const static int PIN_ACT = 4; // ACTIVE +const static int PIN_ENB = 17; // ENABLE +const static int PIN_IND = 27; // INITIATOR CTRL DIRECTION +const static int PIN_TAD = -1; // TARGET CTRL DIRECTION +const static int PIN_DTD = 18; // DATA DIRECTION // SCSI signal pin assignment -#define PIN_DT0 6 // Data 0 -#define PIN_DT1 12 // Data 1 -#define PIN_DT2 13 // Data 2 -#define PIN_DT3 16 // Data 3 -#define PIN_DT4 19 // Data 4 -#define PIN_DT5 20 // Data 5 -#define PIN_DT6 26 // Data 6 -#define PIN_DT7 21 // Data 7 -#define PIN_DP 5 // Data parity -#define PIN_ATN 22 // ATN -#define PIN_RST 25 // RST -#define PIN_ACK 10 // ACK -#define PIN_REQ 7 // REQ -#define PIN_MSG 9 // MSG -#define PIN_CD 11 // CD -#define PIN_IO 23 // IO -#define PIN_BSY 24 // BSY -#define PIN_SEL 8 // SEL +const static int PIN_DT0 = 6; // Data 0 +const static int PIN_DT1 = 12; // Data 1 +const static int PIN_DT2 = 13; // Data 2 +const static int PIN_DT3 = 16; // Data 3 +const static int PIN_DT4 = 19; // Data 4 +const static int PIN_DT5 = 20; // Data 5 +const static int PIN_DT6 = 26; // Data 6 +const static int PIN_DT7 = 21; // Data 7 +const static int PIN_DP = 5; // Data parity +const static int PIN_ATN = 22; // ATN +const static int PIN_RST = 25; // RST +const static int PIN_ACK = 10; // ACK +const static int PIN_REQ = 7; // REQ +const static int PIN_MSG = 9; // MSG +const static int PIN_CD = 11; // CD +const static int PIN_IO = 23; // IO +const static int PIN_BSY = 24; // BSY +const static int PIN_SEL = 8; // SEL #endif // TODO Is this type stil relevant? @@ -241,7 +241,7 @@ const static int PIN_SEL = 27; // SEL #define CONNECT_DESC "GAMERnium.com version"// Startup message // Select signal control mode -#define SIGNAL_CONTROL_MODE 0 // SCSI logical specification +const static int SIGNAL_CONTROL_MODE = 0; // SCSI logical specification // Control signal output logic #define ACT_ON TRUE // ACTIVE SIGNAL ON @@ -251,31 +251,31 @@ const static int PIN_SEL = 27; // SEL #define DTD_IN TRUE // DATA SIGNAL INPUT // Control signal pin assignment (-1 means no control) -#define PIN_ACT 14 // ACTIVE -#define PIN_ENB 6 // ENABLE -#define PIN_IND 7 // INITIATOR CTRL DIRECTION -#define PIN_TAD 8 // TARGET CTRL DIRECTION -#define PIN_DTD 5 // DATA DIRECTION +const static int PIN_ACT = 14; // ACTIVE +const static int PIN_ENB = 6; // ENABLE +const static int PIN_IND = 7; // INITIATOR CTRL DIRECTION +const static int PIN_TAD = 8; // TARGET CTRL DIRECTION +const static int PIN_DTD = 5; // DATA DIRECTION // SCSI signal pin assignment -#define PIN_DT0 21 // Data 0 -#define PIN_DT1 26 // Data 1 -#define PIN_DT2 20 // Data 2 -#define PIN_DT3 19 // Data 3 -#define PIN_DT4 16 // Data 4 -#define PIN_DT5 13 // Data 5 -#define PIN_DT6 12 // Data 6 -#define PIN_DT7 11 // Data 7 -#define PIN_DP 25 // Data parity -#define PIN_ATN 10 // ATN -#define PIN_RST 22 // RST -#define PIN_ACK 24 // ACK -#define PIN_REQ 15 // REQ -#define PIN_MSG 17 // MSG -#define PIN_CD 18 // CD -#define PIN_IO 4 // IO -#define PIN_BSY 27 // BSY -#define PIN_SEL 23 // SEL +const static int PIN_DT0 = 21; // Data 0 +const static int PIN_DT1 = 26; // Data 1 +const static int PIN_DT2 = 20; // Data 2 +const static int PIN_DT3 = 19; // Data 3 +const static int PIN_DT4 = 16; // Data 4 +const static int PIN_DT5 = 13; // Data 5 +const static int PIN_DT6 = 12; // Data 6 +const static int PIN_DT7 = 11; // Data 7 +const static int PIN_DP = 25; // Data parity +const static int PIN_ATN = 10; // ATN +const static int PIN_RST = 22; // RST +const static int PIN_ACK = 24; // ACK +const static int PIN_REQ = 15; // REQ +const static int PIN_MSG = 17; // MSG +const static int PIN_CD = 18; // CD +const static int PIN_IO = 4; // IO +const static int PIN_BSY = 27; // BSY +const static int PIN_SEL = 23; // SEL #endif #define ALL_SCSI_PINS \ diff --git a/src/raspberrypi/rascsi_response.cpp b/src/raspberrypi/rascsi_response.cpp index 14560e02..b0b6523e 100644 --- a/src/raspberrypi/rascsi_response.cpp +++ b/src/raspberrypi/rascsi_response.cpp @@ -156,8 +156,7 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, stri string filename = folder + "/" + dir->d_name; - struct stat st; - if (dir->d_type == DT_REG && !stat(filename.c_str(), &st)) { + if (struct stat st; dir->d_type == DT_REG && !stat(filename.c_str(), &st)) { if (!st.st_size) { LOGWARN("File '%s' in image folder '%s' has a size of 0 bytes", dir->d_name, folder.c_str()) continue; @@ -174,8 +173,7 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, stri } if (file_pattern_lower.empty() || name_lower.find(file_pattern_lower) != string::npos) { - auto image_file = make_unique(); - if (GetImageFile(image_file.get(), filename)) { + if (auto image_file = make_unique(); GetImageFile(image_file.get(), filename)) { GetImageFile(image_files_info.add_image_files(), filename.substr(default_image_folder.length() + 1)); } } @@ -258,8 +256,8 @@ void RascsiResponse::GetDevicesInfo(PbResult& result, const PbCommand& command) auto devices_info = make_unique().release(); result.set_allocated_devices_info(devices_info); - for (const auto& id_set : id_sets) { - GetDevice(device_factory->GetDeviceByIdAndLun(id_set.first, id_set.second), devices_info->add_devices()); + for (const auto& [id, lun] : id_sets) { + GetDevice(device_factory->GetDeviceByIdAndLun(id, lun), devices_info->add_devices()); } result.set_status(true); @@ -341,8 +339,8 @@ PbMappingInfo *RascsiResponse::GetMappingInfo(PbResult& result) { auto mapping_info = make_unique().release(); - for (const auto& mapping : device_factory->GetExtensionMapping()) { - (*mapping_info->mutable_mapping())[mapping.first] = mapping.second; + for (const auto& [name, type] : device_factory->GetExtensionMapping()) { + (*mapping_info->mutable_mapping())[name] = type; } result.set_status(true); diff --git a/src/raspberrypi/test/controller_manager_test.cpp b/src/raspberrypi/test/controller_manager_test.cpp index d2aa1014..b5e7736d 100644 --- a/src/raspberrypi/test/controller_manager_test.cpp +++ b/src/raspberrypi/test/controller_manager_test.cpp @@ -15,7 +15,7 @@ TEST(ControllerManagerTest, ControllerManager) const int ID = 4; const int LUN = 6; - PrimaryDevice *device = static_cast(device_factory.CreateDevice(UNDEFINED, "services", ID)); + auto device = static_cast(device_factory.CreateDevice(UNDEFINED, "services", ID)); device->SetId(ID); device->SetLun(LUN); diff --git a/src/raspberrypi/test/device_test.cpp b/src/raspberrypi/test/device_test.cpp index 40f4e019..aa5f86ff 100644 --- a/src/raspberrypi/test/device_test.cpp +++ b/src/raspberrypi/test/device_test.cpp @@ -16,9 +16,9 @@ class TestDevice : public Device public: TestDevice() : Device("test") {} - ~TestDevice() = default; + ~TestDevice() final = default; - bool Dispatch() { return false; } + bool Dispatch() final { return false; } }; TEST(DeviceTest, ProductData) diff --git a/src/raspberrypi/test/file_support_test.cpp b/src/raspberrypi/test/file_support_test.cpp index ea80b12c..6ea6b71e 100644 --- a/src/raspberrypi/test/file_support_test.cpp +++ b/src/raspberrypi/test/file_support_test.cpp @@ -12,7 +12,7 @@ class TestFileSupport : public FileSupport { - void Open(const Filepath&) { + void Open(const Filepath&) final { // Do nothing when running unit tests } }; diff --git a/src/raspberrypi/test/testing.h b/src/raspberrypi/test/testing.h index 2e349401..fff9fe74 100644 --- a/src/raspberrypi/test/testing.h +++ b/src/raspberrypi/test/testing.h @@ -61,7 +61,7 @@ public: MOCK_METHOD(void, SetSignal, (int, bool), (override)); MockBus() = default; - ~MockBus() = default; + ~MockBus() final = default; }; class MockAbstractController : public AbstractController @@ -98,7 +98,7 @@ public: MOCK_METHOD(void, Reset, (), (override)); explicit MockAbstractController(int target_id) : AbstractController(nullptr, target_id) {} - ~MockAbstractController() = default; + ~MockAbstractController() final = default; }; class MockScsiController : public ScsiController @@ -136,8 +136,7 @@ public: FRIEND_TEST(PrimaryDeviceTest, ReportLuns); FRIEND_TEST(PrimaryDeviceTest, UnknownCommand); - MockScsiController(BUS *bus, int target_id) : ScsiController(bus, target_id) {} - ~MockScsiController() = default; + using ScsiController::ScsiController; }; class MockPrimaryDevice : public PrimaryDevice @@ -147,7 +146,7 @@ public: MOCK_METHOD(vector, InquiryInternal, (), (const)); MockPrimaryDevice() : PrimaryDevice("test") {} - ~MockPrimaryDevice() = default; + ~MockPrimaryDevice() final = default; // Make protected methods visible for testing @@ -164,7 +163,7 @@ class MockModePageDevice : public ModePageDevice public: MockModePageDevice() : ModePageDevice("test") {} - ~MockModePageDevice() = default; + ~MockModePageDevice() final = default; MOCK_METHOD(vector, InquiryInternal, (), (const)); MOCK_METHOD(int, ModeSense6, (const DWORD *, BYTE *, int), ()); @@ -191,7 +190,7 @@ class MockSCSIHD : public SCSIHD FRIEND_TEST(ModePagesTest, SCSIHD_AddModePages); explicit MockSCSIHD(const unordered_set& sector_sizes) : SCSIHD(sector_sizes, false) {} - ~MockSCSIHD() = default; + ~MockSCSIHD() final = default; }; class MockSCSIHD_NEC : public SCSIHD_NEC @@ -199,7 +198,7 @@ class MockSCSIHD_NEC : public SCSIHD_NEC FRIEND_TEST(ModePagesTest, SCSIHD_NEC_AddModePages); MockSCSIHD_NEC() = default; - ~MockSCSIHD_NEC() = default; + ~MockSCSIHD_NEC() final = default; }; class MockSCSICD : public SCSICD @@ -207,7 +206,7 @@ class MockSCSICD : public SCSICD FRIEND_TEST(ModePagesTest, SCSICD_AddModePages); explicit MockSCSICD(const unordered_set& sector_sizes) : SCSICD(sector_sizes) {} - ~MockSCSICD() = default; + ~MockSCSICD() final = default; }; class MockSCSIMO : public SCSIMO @@ -216,7 +215,7 @@ class MockSCSIMO : public SCSIMO MockSCSIMO(const unordered_set& sector_sizes, const unordered_map& geometries) : SCSIMO(sector_sizes, geometries) {} - ~MockSCSIMO() = default; + ~MockSCSIMO() final = default; }; class MockHostServices : public HostServices @@ -224,5 +223,5 @@ class MockHostServices : public HostServices FRIEND_TEST(ModePagesTest, HostServices_AddModePages); MockHostServices() = default; - ~MockHostServices() = default; + ~MockHostServices() final = default; };