SonarCloud coverage setup, fixed numerous SonarCloud issues (#840)

* SonarCloud coverage setup, fixed numerous SonarCloud issues

* Code cleanup
This commit is contained in:
Uwe Seimet 2022-09-10 07:59:41 +02:00 committed by GitHub
parent 882e567f2c
commit f0c36fba77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 499 additions and 518 deletions

View File

@ -3,68 +3,33 @@ name: Run automated unit tests
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
functional_test: Tests_and_SonarCloud_Analysis:
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:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
env: env:
MAKEFLAGS: -j2 # Number of available processors
SOURCES: src/raspberrypi
SONAR_SCANNER_VERSION: 4.7.0.2747 SONAR_SCANNER_VERSION: 4.7.0.2747
SONAR_SERVER_URL: "https://sonarcloud.io" SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 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
- name: Install dependencies - 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 uses: actions/setup-java@v1
with: with:
java-version: 11 java-version: 17
- name: Download and set up sonar-scanner - name: Download and set up sonar-scanner
env: env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip 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 echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
- name: Run build-wrapper - name: Run build-wrapper
run: | 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 - name: Run sonar-scanner
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: | 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

View File

@ -169,11 +169,12 @@ $(SRC_PROTOBUF): $(SRC_PROTOC)
## the text versions of the manpages ## the text versions of the manpages
## docs : Re-generate the text versions of the man pages ## docs : Re-generate the text versions of the man pages
## test : Build and run unit tests ## 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 ## 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 .DEFAULT_GOAL := all
.PHONY: all ALL docs test coverage .PHONY: all ALL docs test coverage lcov
all: $(BIN_ALL) docs all: $(BIN_ALL) docs
test: $(BINDIR)/$(RASCSI_TEST) test: $(BINDIR)/$(RASCSI_TEST)
@ -181,6 +182,9 @@ test: $(BINDIR)/$(RASCSI_TEST)
coverage: CXXFLAGS += --coverage coverage: CXXFLAGS += --coverage
coverage: test coverage: test
lcov: CXXFLAGS += --coverage
lcov: test
lcov -q -c -d . --include '*/raspberrypi/*' -o $(COVERAGE_FILE) --exclude '*/test/*' --exclude '*/interfaces/*' --exclude '*/rascsi_interface.pb*' 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) genhtml -q -o $(COVERAGE_DIR) --legend $(COVERAGE_FILE)

View File

@ -59,6 +59,8 @@ public:
AbstractController(BUS *bus, int target_id) : bus(bus), target_id(target_id) {} AbstractController(BUS *bus, int target_id) : bus(bus), target_id(target_id) {}
~AbstractController() override = default; ~AbstractController() override = default;
AbstractController(AbstractController&) = delete;
AbstractController& operator=(const AbstractController&) = delete;
virtual BUS::phase_t Process(int) = 0; virtual BUS::phase_t Process(int) = 0;

View File

@ -32,7 +32,7 @@ bool ControllerManager::CreateScsiController(BUS *bus, PrimaryDevice *device)
{ {
AbstractController *controller = FindController(device->GetId()); AbstractController *controller = FindController(device->GetId());
if (controller == nullptr) { if (controller == nullptr) {
controller = new ScsiController(bus, device->GetId()); controller = make_unique<ScsiController>(bus, device->GetId()).release();
controllers[device->GetId()] = controller; controllers[device->GetId()] = controller;
} }

View File

@ -21,6 +21,8 @@ class ControllerManager
{ {
ControllerManager() = default; ControllerManager() = default;
~ControllerManager(); ~ControllerManager();
ControllerManager(ControllerManager&) = delete;
ControllerManager& operator=(const ControllerManager&) = delete;
public: public:
// Maximum number of controller devices // Maximum number of controller devices

View File

@ -56,12 +56,12 @@ void ScsiController::Reset()
bytes_to_transfer = 0; bytes_to_transfer = 0;
// Reset all LUNs // Reset all LUNs
for (auto& lun : ctrl.luns) { for (auto& [lun, device] : ctrl.luns) {
lun.second->Reset(); device->Reset();
} }
} }
BUS::phase_t ScsiController::Process(int initiator_id) BUS::phase_t ScsiController::Process(int id)
{ {
// Get bus information // Get bus information
bus->Acquire(); bus->Acquire();
@ -79,14 +79,14 @@ BUS::phase_t ScsiController::Process(int initiator_id)
return ctrl.phase; return ctrl.phase;
} }
if (initiator_id != UNKNOWN_INITIATOR_ID) { if (id != UNKNOWN_INITIATOR_ID) {
LOGTRACE("%s Initiator ID is %d", __PRETTY_FUNCTION__, initiator_id) LOGTRACE("%s Initiator ID is %d", __PRETTY_FUNCTION__, id)
} }
else { else {
LOGTRACE("%s Initiator ID is unknown", __PRETTY_FUNCTION__) LOGTRACE("%s Initiator ID is unknown", __PRETTY_FUNCTION__)
} }
this->initiator_id = initiator_id; initiator_id = id;
try { try {
// Phase processing // Phase processing
@ -128,7 +128,7 @@ BUS::phase_t ScsiController::Process(int initiator_id)
break; break;
} }
} }
catch(const scsi_error_exception& e) { catch(const scsi_error_exception&) {
// Any exception should have been handled during the phase processing // Any exception should have been handled during the phase processing
assert(false); assert(false);
@ -207,8 +207,7 @@ void ScsiController::Selection()
{ {
if (ctrl.phase != BUS::selection) { if (ctrl.phase != BUS::selection) {
// A different device controller was selected // A different device controller was selected
int id = 1 << GetTargetId(); if (int id = 1 << GetTargetId(); (bus->GetDAT() & id) == 0) {
if ((bus->GetDAT() & id) == 0) {
return; 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 // 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. // 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); HasDeviceForLun(0) ? GetDeviceForLun(0)->GetSendDelay() : 0);
len != (int)ctrl.length) {
// If you cannot send all, move to status phase // If you cannot send all, move to status phase
if (len != (int)ctrl.length) {
Error(sense_key::ABORTED_COMMAND); Error(sense_key::ABORTED_COMMAND);
return; return;
} }
@ -822,7 +820,7 @@ bool ScsiController::XferMsg(int msg)
// Save message out data // Save message out data
if (scsi.atnmsg) { if (scsi.atnmsg) {
scsi.msb[scsi.msc] = msg; scsi.msb[scsi.msc] = (BYTE)msg;
scsi.msc++; scsi.msc++;
scsi.msc %= 256; scsi.msc %= 256;
} }
@ -1012,8 +1010,8 @@ bool ScsiController::XferOut(bool cont)
is_byte_transfer = false; is_byte_transfer = false;
PrimaryDevice *device = GetDeviceForLun(GetEffectiveLun()); if (auto device = GetDeviceForLun(GetEffectiveLun());
if (device != nullptr && ctrl.cmd[0] == scsi_command::eCmdWrite6) { device != nullptr && ctrl.cmd[0] == scsi_command::eCmdWrite6) {
return device->WriteByteSequence(ctrl.buffer, bytes_to_transfer); return device->WriteByteSequence(ctrl.buffer, bytes_to_transfer);
} }
@ -1026,24 +1024,24 @@ void ScsiController::FlushUnit()
{ {
assert(ctrl.phase == BUS::dataout); assert(ctrl.phase == BUS::dataout);
Disk *disk = dynamic_cast<Disk *>(GetDeviceForLun(GetEffectiveLun())); auto disk = dynamic_cast<Disk *>(GetDeviceForLun(GetEffectiveLun()));
if (disk == nullptr) { if (disk == nullptr) {
return; return;
} }
// WRITE system only // WRITE system only
switch ((ScsiController::rw_command)ctrl.cmd[0]) { switch ((ScsiController::rw_command)ctrl.cmd[0]) {
case ScsiController::eCmdWrite6: case ScsiController::eRwCmdWrite6:
case ScsiController::eCmdWrite10: case ScsiController::eRwCmdWrite10:
case ScsiController::eCmdWrite16: case ScsiController::eRwCmdWrite16:
case ScsiController::eCmdWriteLong10: case ScsiController::eRwCmdWriteLong10:
case ScsiController::eCmdWriteLong16: case ScsiController::eRwCmdWriteLong16:
case ScsiController::eCmdVerify10: case ScsiController::eRwCmdVerify10:
case ScsiController::eCmdVerify16: case ScsiController::eRwCmdVerify16:
break; break;
case ScsiController::eCmdModeSelect6: case ScsiController::eRwCmdModeSelect6:
case ScsiController::eCmdModeSelect10: case ScsiController::eRwCmdModeSelect10:
// TODO What is this special handling of ModeSelect good for? // TODO What is this special handling of ModeSelect good for?
// Without it we would not need this method at all. // 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? // ModeSelect is already handled in XferOutBlockOriented(). Why would it have to be handled once more?
@ -1057,12 +1055,12 @@ void ScsiController::FlushUnit()
} }
break; break;
case ScsiController::eCmdSetMcastAddr: case ScsiController::eRwCmdSetMcastAddr:
// TODO: Eventually, we should store off the multicast address configuration data here... // TODO: Eventually, we should store off the multicast address configuration data here...
break; break;
default: 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; break;
} }
} }
@ -1088,14 +1086,14 @@ bool ScsiController::XferIn(BYTE *buf)
// Limited to read commands // Limited to read commands
switch (ctrl.cmd[0]) { switch (ctrl.cmd[0]) {
case eCmdRead6: case eRwCmdRead6:
case eCmdRead10: case eRwCmdRead10:
case eCmdRead16: case eRwCmdRead16:
// Read from disk // Read from disk
try { try {
ctrl.length = ((Disk *)GetDeviceForLun(lun))->Read(ctrl.cmd, buf, ctrl.next); 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 // If there is an error, go to the status phase
return false; return false;
} }
@ -1126,15 +1124,15 @@ bool ScsiController::XferIn(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool ScsiController::XferOutBlockOriented(bool cont) bool ScsiController::XferOutBlockOriented(bool cont)
{ {
Disk *disk = dynamic_cast<Disk *>(GetDeviceForLun(GetEffectiveLun())); auto disk = dynamic_cast<Disk *>(GetDeviceForLun(GetEffectiveLun()));
if (disk == nullptr) { if (disk == nullptr) {
return false; return false;
} }
// Limited to write commands // Limited to write commands
switch (ctrl.cmd[0]) { switch (ctrl.cmd[0]) {
case eCmdModeSelect6: case eRwCmdModeSelect6:
case eCmdModeSelect10: case eRwCmdModeSelect10:
try { try {
disk->ModeSelect(ctrl.cmd, ctrl.buffer, ctrl.offset); disk->ModeSelect(ctrl.cmd, ctrl.buffer, ctrl.offset);
} }
@ -1144,17 +1142,16 @@ bool ScsiController::XferOutBlockOriented(bool cont)
} }
break; break;
case eCmdWrite6: case eRwCmdWrite6:
case eCmdWrite10: case eRwCmdWrite10:
case eCmdWrite16: case eRwCmdWrite16:
// TODO Verify has to verify, not to write // TODO Verify has to verify, not to write
case eCmdVerify10: case eRwCmdVerify10:
case eCmdVerify16: case eRwCmdVerify16:
{ {
// Special case Write function for brige // Special case Write function for brige
// TODO This class must not know about SCSIBR // TODO This class must not know about SCSIBR
SCSIBR *bridge = dynamic_cast<SCSIBR *>(disk); if (auto bridge = dynamic_cast<SCSIBR *>(disk); bridge) {
if (bridge) {
if (!bridge->WriteBytes(ctrl.cmd, ctrl.buffer, ctrl.length)) { if (!bridge->WriteBytes(ctrl.cmd, ctrl.buffer, ctrl.length)) {
// Write failed // Write failed
return false; return false;
@ -1166,8 +1163,7 @@ bool ScsiController::XferOutBlockOriented(bool cont)
// Special case Write function for DaynaPort // Special case Write function for DaynaPort
// TODO This class must not know about DaynaPort // TODO This class must not know about DaynaPort
SCSIDaynaPort *daynaport = dynamic_cast<SCSIDaynaPort *>(disk); if (auto daynaport = dynamic_cast<SCSIDaynaPort *>(disk); daynaport) {
if (daynaport) {
daynaport->WriteBytes(ctrl.cmd, ctrl.buffer, 0); daynaport->WriteBytes(ctrl.cmd, ctrl.buffer, 0);
ctrl.offset = 0; ctrl.offset = 0;
@ -1195,7 +1191,7 @@ bool ScsiController::XferOutBlockOriented(bool cont)
try { try {
ctrl.length = disk->WriteCheck(ctrl.next - 1); ctrl.length = disk->WriteCheck(ctrl.next - 1);
} }
catch(const scsi_error_exception& e) { catch(const scsi_error_exception&) {
// Cannot write // Cannot write
return false; return false;
} }
@ -1204,7 +1200,7 @@ bool ScsiController::XferOutBlockOriented(bool cont)
break; break;
} }
case eCmdSetMcastAddr: case eRwCmdSetMcastAddr:
LOGTRACE("%s Done with DaynaPort Set Multicast Address", __PRETTY_FUNCTION__) LOGTRACE("%s Done with DaynaPort Set Multicast Address", __PRETTY_FUNCTION__)
break; break;
@ -1223,8 +1219,7 @@ int ScsiController::GetEffectiveLun() const
void ScsiController::Sleep() void ScsiController::Sleep()
{ {
uint32_t time = SysTimer::GetTimerLow() - execstart; if (uint32_t time = SysTimer::GetTimerLow() - execstart; time < MIN_EXEC_TIME) {
if (time < MIN_EXEC_TIME) {
SysTimer::SleepUsec(MIN_EXEC_TIME - time); SysTimer::SleepUsec(MIN_EXEC_TIME - time);
} }
execstart = 0; execstart = 0;

View File

@ -31,34 +31,34 @@ class ScsiController : public AbstractController
static const int MAX_SYNC_PERIOD = 50; static const int MAX_SYNC_PERIOD = 50;
// REQ/ACK offset(limited to 16) // 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; static const int UNKNOWN_INITIATOR_ID = -1;
const int DEFAULT_BUFFER_SIZE = 0x1000; const int DEFAULT_BUFFER_SIZE = 0x1000;
enum rw_command : int { enum rw_command : int {
eCmdRead6 = 0x08, eRwCmdRead6 = 0x08,
eCmdWrite6 = 0x0A, eRwCmdWrite6 = 0x0A,
eCmdSetMcastAddr = 0x0D, // DaynaPort specific command eRwCmdSetMcastAddr = 0x0D, // DaynaPort specific command
eCmdModeSelect6 = 0x15, eRwCmdModeSelect6 = 0x15,
eCmdRead10 = 0x28, eRwCmdRead10 = 0x28,
eCmdWrite10 = 0x2A, eRwCmdWrite10 = 0x2A,
eCmdVerify10 = 0x2E, eRwCmdVerify10 = 0x2E,
eCmdVerify = 0x2F, eRwCmdVerify = 0x2F,
eCmdModeSelect10 = 0x55, eRwCmdModeSelect10 = 0x55,
eCmdRead16 = 0x88, eRwCmdRead16 = 0x88,
eCmdWrite16 = 0x8A, eRwCmdWrite16 = 0x8A,
eCmdVerify16 = 0x8F, eRwCmdVerify16 = 0x8F,
eCmdWriteLong10 = 0x3F, eRwCmdWriteLong10 = 0x3F,
eCmdWriteLong16 = 0x9F eRwCmdWriteLong16 = 0x9F
}; };
using scsi_t = struct _scsi_t { using scsi_t = struct _scsi_t {
// Synchronous transfer // Synchronous transfer
bool syncenable; // Synchronous transfer possible bool syncenable; // Synchronous transfer possible
int syncperiod = MAX_SYNC_PERIOD; // Synchronous transfer period BYTE syncperiod = MAX_SYNC_PERIOD; // Synchronous transfer period
int syncoffset; // Synchronous transfer offset BYTE syncoffset; // Synchronous transfer offset
int syncack; // Number of synchronous transfer ACKs int syncack; // Number of synchronous transfer ACKs
// ATN message // ATN message
@ -71,6 +71,8 @@ public:
ScsiController(BUS *, int); ScsiController(BUS *, int);
~ScsiController() override; ~ScsiController() override;
ScsiController(ScsiController&) = delete;
ScsiController& operator=(const ScsiController&) = delete;
void Reset() override; void Reset() override;
@ -78,13 +80,13 @@ public:
int GetEffectiveLun() const override; 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, 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; scsi_defs::status status = scsi_defs::status::CHECK_CONDITION) override;
int GetInitiatorId() const override { return initiator_id; } 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 Status() override;
void DataIn() override; void DataIn() override;
@ -105,7 +107,7 @@ private:
uint32_t bytes_to_transfer = 0; uint32_t bytes_to_transfer = 0;
// Phases // 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 BusFree() override;
void Selection() override; void Selection() override;
void Command() override; void Command() override;
@ -124,7 +126,7 @@ private:
void FlushUnit(); void FlushUnit();
void Receive(); 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(); void Sleep();

View File

@ -43,8 +43,7 @@ static void convert(char const *src, char const *dest,
return; return;
} }
size_t ret = iconv(cd, &inbuf, &in, &outbuf, &out); if (size_t ret = iconv(cd, &inbuf, &in, &outbuf, &out); ret == (size_t)-1) {
if (ret == (size_t)-1) {
return; return;
} }
@ -853,7 +852,7 @@ void CHostFilename::ConvertHuman(int nCount)
} }
nMax--; nMax--;
pNumber--; pNumber--;
BYTE c = (BYTE)((nOption >> 24) & 0x7F); auto c = (BYTE)((nOption >> 24) & 0x7F);
if (c == 0) if (c == 0)
c = XM6_HOST_FILENAME_MARK; c = XM6_HOST_FILENAME_MARK;
*pNumber = c; *pNumber = c;
@ -867,9 +866,9 @@ void CHostFilename::ConvertHuman(int nCount)
{ {
strcpy(szHost, m_szHost); strcpy(szHost, m_szHost);
const BYTE* pRead = (const BYTE*)szHost; auto pRead = (const BYTE*)szHost;
BYTE* pWrite = szHuman; BYTE* pWrite = szHuman;
const BYTE* pPeriod = SeparateExt(pRead); const auto pPeriod = SeparateExt(pRead);
for (bool bFirst = true;; bFirst = false) { for (bool bFirst = true;; bFirst = false) {
BYTE c = *pRead++; BYTE c = *pRead++;
@ -935,14 +934,14 @@ void CHostFilename::ConvertHuman(int nCount)
// Delete spaces at the end // Delete spaces at the end
while (pExt < pLast - 1 && *(pLast - 1) == ' ') { while (pExt < pLast - 1 && *(pLast - 1) == ' ') {
pLast--; pLast--;
BYTE* p = (BYTE*)pLast; auto p = (BYTE*)pLast;
*p = '\0'; *p = '\0';
} }
// Delete if the file name disappeared after conversion // Delete if the file name disappeared after conversion
if (pExt + 1 >= pLast) { if (pExt + 1 >= pLast) {
pLast = pExt; pLast = pExt;
BYTE* p = (BYTE*)pLast; auto p = (BYTE*)pLast;
*p = '\0'; // Just in case *p = '\0'; // Just in case
} }
} else { } else {
@ -978,7 +977,7 @@ void CHostFilename::ConvertHuman(int nCount)
pStop = pFirst; pStop = pFirst;
// Evaluate base name // 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) if (pCut == nullptr)
pCut = pLast; pCut = pLast;
if ((size_t)(pCut - pFirst) > nMax) if ((size_t)(pCut - pFirst) > nMax)
@ -993,8 +992,8 @@ void CHostFilename::ConvertHuman(int nCount)
} }
// Shorten base name // Shorten base name
size_t nExt = pExt - pSecond; // Length of extension segment // Length of extension segment
if ((size_t)(pCut - pFirst) + nExt > nMax) if (size_t nExt = pExt - pSecond; (size_t)(pCut - pFirst) + nExt > nMax)
pCut = pFirst + nMax - nExt; pCut = pFirst + nMax - nExt;
// If in the middle of a 2 byte char, shorten even further // If in the middle of a 2 byte char, shorten even further
for (p = pFirst; p < pCut; p++) { for (p = pFirst; p < pCut; p++) {
@ -1053,7 +1052,7 @@ void CHostFilename::CopyHuman(const BYTE* szHuman)
strcpy((char*)m_szHuman, (const char*)szHuman); strcpy((char*)m_szHuman, (const char*)szHuman);
m_bCorrect = TRUE; m_bCorrect = TRUE;
m_pszHumanLast = m_szHuman + strlen((const char*)m_szHuman); 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 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; const BYTE* pLast = pFirst + nLength;
// Confirm the position of the Human68k extension // 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) if (pExt == nullptr)
pExt = pLast; pExt = pLast;
// Special handling of the pattern where the file name is 20~22 chars, and the 19th char is '.' or ends with '.' // 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] == '.') if (20 <= nLength && nLength <= 22 && pFirst[18] == '.' && pFirst[nLength - 1] == '.')
pExt = pFirst + 18; 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) // 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 // 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; pExt = pLast;
return pExt; return pExt;
@ -1183,7 +1181,7 @@ CHostPath::ring_t* CHostPath::Alloc(size_t nLength) // static
ASSERT(nLength < FILEPATH_MAX); ASSERT(nLength < FILEPATH_MAX);
size_t n = offsetof(ring_t, f) + CHostFilename::Offset() + (nLength + 1) * sizeof(TCHAR); 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); ASSERT(p);
p->r.Init(); // This is nothing to worry about! 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 // Find something that matches perfectly with either of the stored file names
const ring_t* p = (ring_t*)m_cRing.Next(); 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) if (p->f.CheckAttribute(nHumanAttribute) == 0)
continue; continue;
// Calulate number of chars // Calulate number of chars
const BYTE* pBufFirst = p->f.GetHuman(); const BYTE* pBufFirst = p->f.GetHuman();
const BYTE* pBufLast = p->f.GetHumanLast(); const BYTE* pBufLast = p->f.GetHumanLast();
size_t nBufLength = pBufLast - pBufFirst;
// Check number of chars // Check number of chars
if (nLength != nBufLength) if (size_t nBufLength = pBufLast - pBufFirst; nLength != nBufLength)
continue; continue;
// File name check // File name check
if (Compare(pFirst, pLast, pBufFirst, pBufLast) == 0) 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); const BYTE* pExt = CHostFilename::SeparateExt(pFirst);
// Move to the start position // 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->count > 0) {
if (pFind->id == m_nId) { if (pFind->id == m_nId) {
// If the same directory entry, continue right away from the previous position // 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 { } else {
// Find the start position in the directory entry contents // Find the start position in the directory entry contents
DWORD n = 0; DWORD n = 0;
for (;; p = (ring_t*)p->r.Next()) { for (;; p = (const ring_t*)p->r.Next()) {
if (p == (ring_t*)&m_cRing) { if (p == (const ring_t*)&m_cRing) {
// Extrapolate from the count when the same entry isn't found (just in case) // 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; 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) if (n >= pFind->count)
break; break;
n++; n++;
@ -1449,7 +1446,7 @@ const CHostFilename* CHostPath::FindFilenameWildcard(const BYTE* szHuman, DWORD
} }
// Find files // 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++; pFind->count++;
if (p->f.CheckAttribute(nHumanAttribute) == 0) if (p->f.CheckAttribute(nHumanAttribute) == 0)
@ -1469,10 +1466,10 @@ const CHostFilename* CHostPath::FindFilenameWildcard(const BYTE* szHuman, DWORD
if (strcmp((const char*)pExt, ".???") == 0 || if (strcmp((const char*)pExt, ".???") == 0 ||
Compare(pExt, pLast, pBufExt, pBufLast) == 0) { Compare(pExt, pLast, pBufExt, pBufLast) == 0) {
// Store the contents of the next candidate's directory entry // 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->id = m_nId;
pFind->pos = pNext; 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)); memcpy(&pFind->entry, pNext->f.GetEntry(), sizeof(pFind->entry));
else else
memset(&pFind->entry, 0, sizeof(pFind->entry)); memset(&pFind->entry, 0, sizeof(pFind->entry));
@ -1623,13 +1620,12 @@ void CHostPath::Refresh()
nHumanAttribute |= Human68k::AT_READONLY; nHumanAttribute |= Human68k::AT_READONLY;
pFilename->SetEntryAttribute(nHumanAttribute); pFilename->SetEntryAttribute(nHumanAttribute);
DWORD nHumanSize = (DWORD)sb.st_size; auto nHumanSize = (DWORD)sb.st_size;
pFilename->SetEntrySize(nHumanSize); pFilename->SetEntrySize(nHumanSize);
WORD nHumanDate = 0; WORD nHumanDate = 0;
WORD nHumanTime = 0; WORD nHumanTime = 0;
const tm* pt = localtime(&sb.st_mtime); if (const tm* pt = localtime(&sb.st_mtime); pt) {
if (pt) {
nHumanDate = (WORD)(((pt->tm_year - 80) << 9) | ((pt->tm_mon + 1) << 5) | pt->tm_mday); 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)); nHumanTime = (WORD)((pt->tm_hour << 11) | (pt->tm_min << 5) | (pt->tm_sec >> 1));
} }
@ -2216,8 +2212,7 @@ void CHostFilesManager::Init()
// Allocate memory // Allocate memory
for (DWORD i = 0; i < XM6_HOST_FILES_MAX; i++) { for (DWORD i = 0; i < XM6_HOST_FILES_MAX; i++) {
ring_t* p = new ring_t; auto p = new ring_t();
ASSERT(p);
p->r.Insert(&m_cRing); p->r.Insert(&m_cRing);
} }
} }
@ -2277,7 +2272,7 @@ void CHostFilesManager::Free(CHostFiles* pFiles)
pFiles->SetKey(0); pFiles->SetKey(0);
// Move to the end of the ring // 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); p->r.InsertTail(&m_cRing);
} }
@ -2373,8 +2368,7 @@ BOOL CHostFcb::Open()
ASSERT(strlen(m_szFilename) > 0); ASSERT(strlen(m_szFilename) > 0);
// Fail if directory // Fail if directory
struct stat st; //NOSONAR Cannot be declared in a separate statement because struct keyword is required if (struct stat st; stat(S2U(m_szFilename), &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR)) {
if (stat(S2U(m_szFilename), &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR)) {
return FALSE || m_bFlag; return FALSE || m_bFlag;
} }
@ -2570,7 +2564,7 @@ void CHostFcbManager::Init()
// Memory allocation // Memory allocation
for (DWORD i = 0; i < XM6_HOST_FCB_MAX; i++) { for (DWORD i = 0; i < XM6_HOST_FCB_MAX; i++) {
ring_t* p = new ring_t; auto p = new ring_t;
ASSERT(p); ASSERT(p);
p->r.Insert(&m_cRing); p->r.Insert(&m_cRing);
} }
@ -2640,7 +2634,7 @@ void CHostFcbManager::Free(CHostFcb* pFcb)
pFcb->Close(); pFcb->Close();
// Move to the end of the ring // 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); p->r.InsertTail(&m_cRing);
} }
@ -2740,7 +2734,7 @@ void CFileSys::Init()
continue; continue;
// Create 1 unit file system // Create 1 unit file system
CHostDrv* p = new CHostDrv; // std::nothrow auto p = new CHostDrv;
if (p) { if (p) {
m_cEntry.SetDrv(nUnit, p); m_cEntry.SetDrv(nUnit, p);
p->Init(m_szBase[n], m_nFlag[n]); 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); const CHostFiles* pHostFiles = m_cFiles.Search(nSector);
if (pHostFiles) { if (pHostFiles) {
// Generate pseudo-directory entry // Generate pseudo-directory entry
Human68k::dirent_t* dir = (Human68k::dirent_t*)pBuffer; auto dir = (Human68k::dirent_t*)pBuffer;
memcpy(pBuffer, pHostFiles->GetEntry(), sizeof(*dir)); memcpy(pBuffer, pHostFiles->GetEntry(), sizeof(*dir));
memset(pBuffer + sizeof(*dir), 0xE5, 0x200 - 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 return FS_INVALIDFUNC; // Avoid triggering a fatal error in mint when resuming with an invalid drive
// Media change check // Media change check
BOOL bResult = m_cEntry.CheckMedia(nUnit);
// Throw error when media is not inserted // Throw error when media is not inserted
if (bResult == FALSE) { if (BOOL bResult = m_cEntry.CheckMedia(nUnit); bResult == FALSE) {
return FS_INVALIDFUNC; return FS_INVALIDFUNC;
} }
@ -4046,8 +4038,7 @@ BOOL CFileSys::FilesVolume(DWORD nUnit, Human68k::files_t* pFiles)
// Get volume label // Get volume label
TCHAR szVolume[32]; TCHAR szVolume[32];
BOOL bResult = m_cEntry.GetVolumeCache(nUnit, szVolume); if (BOOL bResult = m_cEntry.GetVolumeCache(nUnit, szVolume); bResult == FALSE) {
if (bResult == FALSE) {
// Carry out an extra media check here because it may be skipped when doing a manual eject // Carry out an extra media check here because it may be skipped when doing a manual eject
if (m_cEntry.isEnable(nUnit) == FALSE) if (m_cEntry.isEnable(nUnit) == FALSE)
return FALSE; return FALSE;

View File

@ -357,6 +357,9 @@ class CRing {
public: public:
CRing() { Init(); } CRing() { Init(); }
~CRing() { Remove(); } ~CRing() { Remove(); }
CRing(CRing&) = delete;
CRing& operator=(const CRing&) = delete;
void Init() { next = prev = this; } void Init() { next = prev = this; }
CRing* Next() const { return next; } ///< Get the next element CRing* Next() const { return next; } ///< Get the next element
@ -525,6 +528,9 @@ public:
CHostPath(); CHostPath();
~CHostPath(); ~CHostPath();
CHostPath(CHostPath&) = delete;
CHostPath& operator=(const CHostPath&) = delete;
void Clean(); ///< Initialialize for reuse void Clean(); ///< Initialialize for reuse
void SetHuman(const BYTE* szHuman); ///< Directly specify the name on the Human68k side void SetHuman(const BYTE* szHuman); ///< Directly specify the name on the Human68k side
@ -662,6 +668,9 @@ class CHostFcb {
public: public:
CHostFcb() { SetKey(0); Init(); } CHostFcb() { SetKey(0); Init(); }
~CHostFcb() { Close(); } ~CHostFcb() { Close(); }
CHostFcb(CHostFcb&) = delete;
CHostFcb& operator=(const CHostFcb&) = delete;
void Init(); void Init();
void SetKey(DWORD nKey) { m_nKey = nKey; } ///< Set search key void SetKey(DWORD nKey) { m_nKey = nKey; } ///< Set search key
@ -733,6 +742,9 @@ class CHostDrv
public: public:
CHostDrv(); CHostDrv();
~CHostDrv(); ~CHostDrv();
CHostDrv(CHostDrv&) = delete;
CHostDrv& operator=(const CHostDrv&) = delete;
void Init(const TCHAR* szBase, DWORD nFlag); ///< Initialization (device startup and load) void Init(const TCHAR* szBase, DWORD nFlag); ///< Initialization (device startup and load)
BOOL isWriteProtect() const { return m_bWriteProtect; } BOOL isWriteProtect() const { return m_bWriteProtect; }
@ -789,6 +801,9 @@ class CHostEntry {
public: public:
CHostEntry(); CHostEntry();
~CHostEntry(); ~CHostEntry();
CHostEntry(CHostEntry&) = delete;
CHostEntry& operator=(const CHostEntry&) = delete;
void Init(); ///< Initialization (when the driver is installed) void Init(); ///< Initialization (when the driver is installed)
void Clean(); ///< Release (when starting up or resetting) void Clean(); ///< Release (when starting up or resetting)

View File

@ -96,20 +96,20 @@ bool CTapDriver::Init(const unordered_map<string, string>& const_params)
"Provide the interface list and the IP address/netmask with the 'interface' and 'inet' parameters") "Provide the interface list and the IP address/netmask with the 'interface' and 'inet' parameters")
// TODO Remove the deprecated syntax in a future version // TODO Remove the deprecated syntax in a future version
const string& interfaces = params["interfaces"]; const string& ifaces = params["interfaces"];
size_t separatorPos = interfaces.find(':'); size_t separatorPos = ifaces.find(':');
if (separatorPos != string::npos) { if (separatorPos != string::npos) {
params["interface"] = interfaces.substr(0, separatorPos); params["interface"] = ifaces.substr(0, separatorPos);
params["inet"] = interfaces.substr(separatorPos + 1); params["inet"] = ifaces.substr(separatorPos + 1);
} }
} }
stringstream s(params["interface"]); stringstream s(params["interface"]);
string interface; string interface;
while (getline(s, 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") LOGTRACE("Opening Tap device")
// TAP device initilization // TAP device initilization
@ -165,15 +165,15 @@ bool CTapDriver::Init(const unordered_map<string, string>& const_params)
LOGTRACE("Checking which interface is available for creating the bridge") LOGTRACE("Checking which interface is available for creating the bridge")
string bridge_interface; string bridge_interface;
for (const string& interface : interfaces) { for (const string& iface : interfaces) {
if (is_interface_up(interface)) { if (is_interface_up(iface)) {
LOGTRACE("%s", string("Interface " + interface + " is up").c_str()) LOGTRACE("%s", string("Interface " + iface + " is up").c_str())
bridge_interface = interface; bridge_interface = iface;
break; break;
} }
else { 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<string, string>& const_params)
else { else {
string address = inet; string address = inet;
string netmask = "255.255.255.0"; string netmask = "255.255.255.0";
size_t separatorPos = inet.find('/'); if (size_t separatorPos = inet.find('/'); separatorPos != string::npos) {
if (separatorPos != string::npos) {
address = inet.substr(0, separatorPos); address = inet.substr(0, separatorPos);
int m; int m;
@ -223,7 +222,7 @@ bool CTapDriver::Init(const unordered_map<string, string>& const_params)
} }
// long long is required for compatibility with 32 bit platforms // 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]; char buf[16];
sprintf(buf, "%lld.%lld.%lld.%lld", (mask >> 24) & 0xff, (mask >> 16) & 0xff, (mask >> 8) & 0xff, sprintf(buf, "%lld.%lld.%lld.%lld", (mask >> 24) & 0xff, (mask >> 16) & 0xff, (mask >> 8) & 0xff,
mask & 0xff); mask & 0xff);
@ -464,9 +463,9 @@ int CTapDriver::Rx(BYTE *buf)
} }
// Receive // Receive
DWORD dwReceived = read(m_hTAP, buf, ETH_FRAME_LEN); auto dwReceived = (DWORD)read(m_hTAP, buf, ETH_FRAME_LEN);
if (dwReceived == (DWORD)-1) { 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; return 0;
} }
@ -524,5 +523,5 @@ int CTapDriver::Tx(const BYTE *buf, int len)
} }
// Start sending // Start sending
return write(m_hTAP, buf, len); return (int)write(m_hTAP, buf, len);
} }

View File

@ -37,8 +37,10 @@ private:
friend class SCSIDaynaPort; friend class SCSIDaynaPort;
friend class SCSIBR; friend class SCSIBR;
CTapDriver() : interfaces({}), inet({}) {} CTapDriver() = default;
~CTapDriver() = default; ~CTapDriver() = default;
CTapDriver(CTapDriver&) = delete;
CTapDriver& operator=(const CTapDriver&) = delete;
bool Init(const unordered_map<string, string>&); bool Init(const unordered_map<string, string>&);

View File

@ -27,11 +27,6 @@ Device::Device(const string& t) : type(t)
revision = rev; revision = rev;
} }
Device::~Device()
{
devices.erase(this);
}
void Device::Reset() void Device::Reset()
{ {
locked = false; locked = false;

View File

@ -76,11 +76,11 @@ class Device
protected: protected:
void SetReady(bool ready) { this->ready = ready; } void SetReady(bool b) { ready = b; }
bool IsReset() const { return reset; } bool IsReset() const { return reset; }
void SetReset(bool reset) { this->reset = reset; } void SetReset(bool b) { reset = b; }
bool IsAttn() const { return attn; } bool IsAttn() const { return attn; }
void SetAttn(bool attn) { this->attn = attn; } void SetAttn(bool b) { attn = b; }
int GetStatusCode() const { return status_code; } int GetStatusCode() const { return status_code; }
@ -93,7 +93,9 @@ protected:
public: 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 // Override for device specific initializations, to be called after all device properties have been set
virtual bool Init(const unordered_map<string, string>&) { return true; }; virtual bool Init(const unordered_map<string, string>&) { return true; };
@ -106,30 +108,30 @@ public:
void Reset(); void Reset();
bool IsProtectable() const { return protectable; } bool IsProtectable() const { return protectable; }
void SetProtectable(bool protectable) { this->protectable = protectable; } void SetProtectable(bool b) { protectable = b; }
bool IsProtected() const { return write_protected; } bool IsProtected() const { return write_protected; }
void SetProtected(bool); void SetProtected(bool);
bool IsReadOnly() const { return read_only; } 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; } bool IsStoppable() const { return stoppable; }
void SetStoppable(bool stoppable) { this->stoppable = stoppable; } void SetStoppable(bool b) { stoppable = b; }
bool IsStopped() const { return stopped; } bool IsStopped() const { return stopped; }
void SetStopped(bool stopped) { this->stopped = stopped; } void SetStopped(bool b) { stopped = b; }
bool IsRemovable() const { return removable; } bool IsRemovable() const { return removable; }
void SetRemovable(bool removable) { this->removable = removable; } void SetRemovable(bool b) { removable = b; }
bool IsRemoved() const { return removed; } bool IsRemoved() const { return removed; }
void SetRemoved(bool removed) { this->removed = removed; } void SetRemoved(bool b) { removed = b; }
bool IsLockable() const { return lockable; } bool IsLockable() const { return lockable; }
void SetLockable(bool lockable) { this->lockable = lockable; } void SetLockable(bool b) { lockable = b; }
bool IsLocked() const { return locked; } bool IsLocked() const { return locked; }
void SetLocked(bool locked) { this->locked = locked; } void SetLocked(bool b) { locked = b; }
int32_t GetId() const { return id; } 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; } 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; } string GetVendor() const { return vendor; }
void SetVendor(const string&); void SetVendor(const string&);
@ -141,9 +143,9 @@ public:
bool SupportsParams() const { return supports_params; } bool SupportsParams() const { return supports_params; }
virtual bool SupportsFile() 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<string, string> GetParams() const { return params; } unordered_map<string, string> GetParams() const { return params; }
void SetDefaultParams(const unordered_map<string, string>& default_params) { this->default_params = default_params; } void SetDefaultParams(const unordered_map<string, string>& p) { default_params = p; }
void SetStatusCode(int); void SetStatusCode(int);

View File

@ -24,7 +24,7 @@ using namespace rascsi_interface;
multimap<int, Device *> DeviceFactory::devices; multimap<int, Device *> DeviceFactory::devices;
DeviceFactory::DeviceFactory() : sector_sizes({}), geometries({}), default_params({}), extension_mapping({}) DeviceFactory::DeviceFactory()
{ {
sector_sizes[SCHD] = { 512, 1024, 2048, 4096 }; sector_sizes[SCHD] = { 512, 1024, 2048, 4096 };
sector_sizes[SCRM] = { 512, 1024, 2048, 4096 }; sector_sizes[SCRM] = { 512, 1024, 2048, 4096 };
@ -125,8 +125,7 @@ list<Device *> DeviceFactory::GetAllDevices() const
string DeviceFactory::GetExtension(const string& filename) const string DeviceFactory::GetExtension(const string& filename) const
{ {
string ext; string ext;
size_t separator = filename.rfind('.'); if (size_t separator = filename.rfind('.'); separator != string::npos) {
if (separator != string::npos) {
ext = filename.substr(separator + 1); ext = filename.substr(separator + 1);
} }
std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c){ return std::tolower(c); }); 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 PbDeviceType DeviceFactory::GetTypeForFile(const string& filename) const
{ {
const auto& it = extension_mapping.find(GetExtension(filename)); if (const auto& it = extension_mapping.find(GetExtension(filename)); it != extension_mapping.end()) {
if (it != extension_mapping.end()) {
return it->second; return it->second;
} }
else if (filename == "bridge") { else if (filename == "bridge") {
@ -289,7 +287,7 @@ list<string> DeviceFactory::GetNetworkInterfaces() const
strcpy(ifr.ifr_name, tmp->ifa_name); strcpy(ifr.ifr_name, tmp->ifa_name);
// Only list interfaces that are up // Only list interfaces that are up
if (!ioctl(fd, SIOCGIFFLAGS, &ifr) && ifr.ifr_flags & IFF_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); close(fd);

View File

@ -31,6 +31,8 @@ class DeviceFactory
DeviceFactory(); DeviceFactory();
~DeviceFactory(); ~DeviceFactory();
DeviceFactory(DeviceFactory&) = delete;
DeviceFactory& operator=(const DeviceFactory&) = delete;
public: public:

View File

@ -23,7 +23,7 @@
using namespace scsi_defs; 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(eCmdRezero, "Rezero", &Disk::Rezero);
dispatcher.AddCommand(eCmdFormat, "FormatUnit", &Disk::FormatUnit); 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); disk.dcache = new DiskCache(path, disk.size, disk.blocks, disk.image_offset);
// Can read/write open // Can read/write open
Fileio fio; if (Fileio fio; fio.Open(path, Fileio::ReadWrite)) {
if (fio.Open(path, Fileio::ReadWrite)) {
// Write permission // Write permission
fio.Close(); fio.Close();
} else { } else {
@ -341,7 +340,7 @@ bool Disk::Eject(bool force)
int Disk::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length) int Disk::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length)
{ {
// Get length, clear buffer // Get length, clear buffer
int length = (int)cdb[4]; auto length = (int)cdb[4];
if (length > max_length) { if (length > max_length) {
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) // Short LBA mode parameter block descriptor (number of blocks and block length)
uint64_t disk_blocks = GetBlockCount(); uint64_t disk_blocks = GetBlockCount();
buf[4] = disk_blocks >> 24; buf[4] = (BYTE)(disk_blocks >> 24);
buf[5] = disk_blocks >> 16; buf[5] = (BYTE)(disk_blocks >> 16);
buf[6] = disk_blocks >> 8; buf[6] = (BYTE)(disk_blocks >> 8);
buf[7] = disk_blocks; buf[7] = (BYTE)disk_blocks;
// Block descriptor (block length) // Block descriptor (block length)
uint32_t disk_size = GetSectorSizeInBytes(); uint32_t disk_size = GetSectorSizeInBytes();
buf[9] = disk_size >> 16; buf[9] = (BYTE)(disk_size >> 16);
buf[10] = disk_size >> 8; buf[10] = (BYTE)(disk_size >> 8);
buf[11] = disk_size; buf[11] = (BYTE)disk_size;
} }
size = 12; size = 12;
@ -386,7 +385,7 @@ int Disk::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length)
} }
// Final setting of mode data length // Final setting of mode data length
buf[0] = size; buf[0] = (BYTE)size;
return 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) // Short LBA mode parameter block descriptor (number of blocks and block length)
buf[8] = disk_blocks >> 24; buf[8] = (BYTE)(disk_blocks >> 24);
buf[9] = disk_blocks >> 16; buf[9] = (BYTE)(disk_blocks >> 16);
buf[10] = disk_blocks >> 8; buf[10] = (BYTE)(disk_blocks >> 8);
buf[11] = disk_blocks; buf[11] = (BYTE)disk_blocks;
buf[13] = disk_size >> 16; buf[13] = (BYTE)(disk_size >> 16);
buf[14] = disk_size >> 8; buf[14] = (BYTE)(disk_size >> 8);
buf[15] = disk_size; buf[15] = (BYTE)disk_size;
size = 16; 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) // Long LBA mode parameter block descriptor (number of blocks and block length)
buf[8] = disk_blocks >> 56; buf[8] = (BYTE)(disk_blocks >> 56);
buf[9] = disk_blocks >> 48; buf[9] = (BYTE)(disk_blocks >> 48);
buf[10] = disk_blocks >> 40; buf[10] = (BYTE)(disk_blocks >> 40);
buf[11] = disk_blocks >> 32; buf[11] = (BYTE)(disk_blocks >> 32);
buf[12] = disk_blocks >> 24; buf[12] = (BYTE)(disk_blocks >> 24);
buf[13] = disk_blocks >> 16; buf[13] = (BYTE)(disk_blocks >> 16);
buf[14] = disk_blocks >> 8; buf[14] = (BYTE)(disk_blocks >> 8);
buf[15] = disk_blocks; buf[15] = (BYTE)disk_blocks;
buf[20] = disk_size >> 24; buf[20] = (BYTE)(disk_size >> 24);
buf[21] = disk_size >> 16; buf[21] = (BYTE)(disk_size >> 16);
buf[22] = disk_size >> 8; buf[22] = (BYTE)(disk_size >> 8);
buf[23] = disk_size; buf[23] = (BYTE)disk_size;
size = 24; size = 24;
} }
@ -467,8 +466,8 @@ int Disk::ModeSense10(const DWORD *cdb, BYTE *buf, int max_length)
} }
// Final setting of mode data length // Final setting of mode data length
buf[0] = size >> 8; buf[0] = (BYTE)(size >> 8);
buf[1] = size; buf[1] = (BYTE)size;
return size; return size;
} }
@ -989,14 +988,14 @@ uint32_t Disk::GetSectorSizeInBytes() const
return disk.size ? 1 << disk.size : 0; return disk.size ? 1 << disk.size : 0;
} }
void Disk::SetSectorSizeInBytes(uint32_t size) void Disk::SetSectorSizeInBytes(uint32_t size_in_bytes)
{ {
unordered_set<uint32_t> sector_sizes = DeviceFactory::instance().GetSectorSizes(GetType()); if (unordered_set<uint32_t> sizes = DeviceFactory::instance().GetSectorSizes(GetType());
if (!sector_sizes.empty() && sector_sizes.find(size) == sector_sizes.end()) { !sizes.empty() && sizes.find(size_in_bytes) == sizes.end()) {
throw io_exception("Invalid block size of " + to_string(size) + " bytes"); throw io_exception("Invalid block size of " + to_string(size_in_bytes) + " bytes");
} }
switch (size) { switch (size_in_bytes) {
case 512: case 512:
disk.size = 9; disk.size = 9;
break; break;
@ -1024,9 +1023,9 @@ uint32_t Disk::GetSectorSizeShiftCount() const
return disk.size; 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 bool Disk::IsSectorSizeConfigurable() const
@ -1034,9 +1033,9 @@ bool Disk::IsSectorSizeConfigurable() const
return !sector_sizes.empty(); return !sector_sizes.empty();
} }
void Disk::SetSectorSizes(const unordered_set<uint32_t>& sector_sizes) void Disk::SetSectorSizes(const unordered_set<uint32_t>& sizes)
{ {
this->sector_sizes = sector_sizes; sector_sizes = sizes;
} }
uint32_t Disk::GetConfiguredSectorSize() const uint32_t Disk::GetConfiguredSectorSize() const
@ -1044,16 +1043,16 @@ uint32_t Disk::GetConfiguredSectorSize() const
return configured_sector_size; return configured_sector_size;
} }
bool Disk::SetConfiguredSectorSize(uint32_t configured_sector_size) bool Disk::SetConfiguredSectorSize(uint32_t size)
{ {
const DeviceFactory& device_factory = DeviceFactory::instance(); const DeviceFactory& device_factory = DeviceFactory::instance();
unordered_set<uint32_t> sector_sizes = device_factory.GetSectorSizes(GetType()); if (unordered_set<uint32_t> sizes = device_factory.GetSectorSizes(GetType());
if (sector_sizes.find(configured_sector_size) == sector_sizes.end()) { sizes.find(size) == sizes.end()) {
return false; return false;
} }
this->configured_sector_size = configured_sector_size; configured_sector_size = size;
return true; return true;
} }

View File

@ -56,6 +56,8 @@ public:
explicit Disk(const string&); explicit Disk(const string&);
~Disk() override; ~Disk() override;
Disk(Disk&) = delete;
Disk& operator=(const Disk&) = delete;
bool Dispatch() override; bool Dispatch() override;

View File

@ -42,6 +42,8 @@ private:
public: public:
DiskTrack(); DiskTrack();
~DiskTrack(); ~DiskTrack();
DiskTrack(DiskTrack&) = delete;
DiskTrack& operator=(const DiskTrack&) = delete;
private: private:
friend class DiskCache; friend class DiskCache;
@ -68,6 +70,8 @@ public:
DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0); DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
~DiskCache(); ~DiskCache();
DiskCache(DiskCache&) = delete;
DiskCache& operator=(const DiskCache&) = delete;
void SetRawMode(BOOL raw); // CD-ROM raw mode setting void SetRawMode(BOOL raw); // CD-ROM raw mode setting

View File

@ -23,13 +23,15 @@ class Dispatcher
{ {
public: public:
Dispatcher() : commands({}) {} Dispatcher() = default;
~Dispatcher() ~Dispatcher()
{ {
for (auto const& [name, command] : commands) { for (auto const& [name, command] : commands) {
delete command; delete command;
} }
} }
Dispatcher(Dispatcher&) = delete;
Dispatcher& operator=(const Dispatcher&) = delete;
using operation = void (T::*)(); using operation = void (T::*)();
using command_t = struct _command_t { using command_t = struct _command_t {
@ -47,8 +49,7 @@ public:
bool Dispatch(T *instance, DWORD cmd) bool Dispatch(T *instance, DWORD cmd)
{ {
const auto& it = commands.find(static_cast<scsi_command>(cmd)); if (const auto& it = commands.find(static_cast<scsi_command>(cmd)); it != commands.end()) {
if (it != commands.end()) {
LOGDEBUG("%s Executing %s ($%02X)", __PRETTY_FUNCTION__, it->second->name, (uint32_t)cmd) LOGDEBUG("%s Executing %s ($%02X)", __PRETTY_FUNCTION__, it->second->name, (uint32_t)cmd)
(instance->*it->second->execute)(); (instance->*it->second->execute)();

View File

@ -25,8 +25,7 @@ void FileSupport::UnreserveFile()
bool FileSupport::GetIdsForReservedFile(const Filepath& path, int& id, int& lun) bool FileSupport::GetIdsForReservedFile(const Filepath& path, int& id, int& lun)
{ {
const auto& it = reserved_files.find(path.GetPath()); if (const auto& it = reserved_files.find(path.GetPath()); it != reserved_files.end()) {
if (it != reserved_files.end()) {
id = it->second.first; id = it->second.first;
lun = it->second.second; lun = it->second.second;

View File

@ -32,8 +32,10 @@ class FileSupport
public: public:
FileSupport() : diskpath({}) {} FileSupport() = default;
virtual ~FileSupport() = default; virtual ~FileSupport() = default;
FileSupport(FileSupport&) = delete;
FileSupport& operator=(const FileSupport&) = delete;
void GetPath(Filepath& path) const { path = diskpath; } void GetPath(Filepath& path) const { path = diskpath; }
void SetPath(const Filepath& path) { diskpath = path; } void SetPath(const Filepath& path) { diskpath = path; }

View File

@ -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); 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) { if (length > max_length) {
length = max_length; length = max_length;
} }
@ -121,7 +121,7 @@ int HostServices::ModeSense6(const DWORD *cdb, BYTE *buf, int max_length)
size = length; size = length;
} }
buf[0] = size; buf[0] = (BYTE)size;
return size; return size;
} }
@ -152,8 +152,8 @@ int HostServices::ModeSense10(const DWORD *cdb, BYTE *buf, int max_length)
size = length; size = length;
} }
buf[0] = size >> 8; buf[0] = (BYTE)(size >> 8);
buf[1] = size; buf[1] = (BYTE)size;
return size; return size;
} }
@ -174,15 +174,15 @@ void HostServices::AddRealtimeClockPage(map<int, vector<BYTE>>& pages, bool chan
buf[2] = 0x01; buf[2] = 0x01;
buf[3] = 0x00; buf[3] = 0x00;
std::time_t t = std::time(NULL); std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t); std::tm tm = *std::localtime(&t);
buf[4] = tm.tm_year; buf[4] = (BYTE)tm.tm_year;
buf[5] = tm.tm_mon; buf[5] = (BYTE)tm.tm_mon;
buf[6] = tm.tm_mday; buf[6] = (BYTE)tm.tm_mday;
buf[7] = tm.tm_hour; buf[7] = (BYTE)tm.tm_hour;
buf[8] = tm.tm_min; buf[8] = (BYTE)tm.tm_min;
// Ignore leap second for simplicity // 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; pages[32] = buf;
} }

View File

@ -23,6 +23,8 @@ public:
HostServices(); HostServices();
~HostServices() override = default; ~HostServices() override = default;
HostServices(HostServices&) = delete;
HostServices& operator=(const HostServices&) = delete;
bool Dispatch() override; bool Dispatch() override;

View File

@ -16,7 +16,7 @@
using namespace std; using namespace std;
using namespace scsi_defs; 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(eCmdModeSense6, "ModeSense6", &ModePageDevice::ModeSense6);
dispatcher.AddCommand(eCmdModeSense10, "ModeSense10", &ModePageDevice::ModeSense10); dispatcher.AddCommand(eCmdModeSense10, "ModeSense10", &ModePageDevice::ModeSense10);
@ -56,20 +56,20 @@ int ModePageDevice::AddModePages(const DWORD *cdb, BYTE *buf, int max_length) co
vector<BYTE> result; vector<BYTE> result;
vector<BYTE> page0; vector<BYTE> page0;
for (auto const& page : pages) { for (auto const& [index, data] : pages) {
// The specification mandates that page 0 must be returned after all others // The specification mandates that page 0 must be returned after all others
if (page.first) { if (index) {
size_t offset = result.size(); size_t offset = result.size();
// Page data // 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 // Page code, PS bit may already have been set
result[offset] |= page.first; result[offset] |= index;
// Page payload size // Page payload size
result[offset + 1] = page.second.size() - 2; result[offset + 1] = (BYTE)(data.size() - 2);
} }
else { else {
page0 = page.second; page0 = data;
} }
} }
@ -80,14 +80,14 @@ int ModePageDevice::AddModePages(const DWORD *cdb, BYTE *buf, int max_length) co
// Page data // Page data
result.insert(result.end(), page0.begin(), page0.end()); result.insert(result.end(), page0.begin(), page0.end());
// Page payload size // 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 // Do not return more than the requested number of bytes
size_t size = (size_t)max_length < result.size() ? max_length : result.size(); size_t size = (size_t)max_length < result.size() ? max_length : result.size();
memcpy(buf, result.data(), size); memcpy(buf, result.data(), size);
return size; return (int)size;
} }
void ModePageDevice::ModeSense6() void ModePageDevice::ModeSense6()

View File

@ -22,6 +22,8 @@ public:
explicit ModePageDevice(const string&); explicit ModePageDevice(const string&);
~ModePageDevice()override = default; ~ModePageDevice()override = default;
ModePageDevice(ModePageDevice&) = delete;
ModePageDevice& operator=(const ModePageDevice&) = delete;
bool Dispatch() override; bool Dispatch() override;

View File

@ -15,7 +15,7 @@
using namespace std; using namespace std;
using namespace scsi_defs; 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 // Mandatory SCSI primary commands
dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &PrimaryDevice::TestUnitReady); dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &PrimaryDevice::TestUnitReady);
@ -31,9 +31,9 @@ bool PrimaryDevice::Dispatch()
return dispatcher.Dispatch(this, ctrl->cmd[0]); 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(); ctrl = controller->GetCtrl();
} }
@ -59,12 +59,10 @@ void PrimaryDevice::Inquiry()
} }
memcpy(ctrl->buffer, buf.data(), allocation_length); memcpy(ctrl->buffer, buf.data(), allocation_length);
ctrl->length = allocation_length; ctrl->length = (uint32_t)allocation_length;
int lun = controller->GetEffectiveLun();
// Report if the device does not support the requested LUN // 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()) LOGTRACE("Reporting LUN %d for device ID %d as not supported", lun, GetId())
// Signal that the requested LUN does not exist // Signal that the requested LUN does not exist
@ -91,12 +89,12 @@ void PrimaryDevice::ReportLuns()
for (int lun = 0; lun < controller->GetMaxLuns(); lun++) { for (int lun = 0; lun < controller->GetMaxLuns(); lun++) {
if (controller->HasDeviceForLun(lun)) { if (controller->HasDeviceForLun(lun)) {
size += 8; size += 8;
buf[size + 7] = lun; buf[size + 7] = (BYTE)lun;
} }
} }
buf[2] = size >> 8; buf[2] = (BYTE)(size >> 8);
buf[3] = size; buf[3] = (BYTE)size;
size += 8; size += 8;
@ -131,7 +129,7 @@ void PrimaryDevice::RequestSense()
} }
memcpy(ctrl->buffer, buf.data(), allocation_length); memcpy(ctrl->buffer, buf.data(), allocation_length);
ctrl->length = allocation_length; ctrl->length = (uint32_t)allocation_length;
EnterDataInPhase(); EnterDataInPhase();
} }
@ -172,10 +170,10 @@ vector<BYTE> PrimaryDevice::HandleInquiry(device_type type, scsi_level level, bo
// buf[2] ... SCSI compliance level of command system // buf[2] ... SCSI compliance level of command system
// buf[3] ... SCSI compliance level of Inquiry response // buf[3] ... SCSI compliance level of Inquiry response
// buf[4] ... Inquiry additional data // buf[4] ... Inquiry additional data
buf[0] = type; buf[0] = (BYTE)type;
buf[1] = is_removable ? 0x80 : 0x00; buf[1] = is_removable ? 0x80 : 0x00;
buf[2] = level; buf[2] = (BYTE)level;
buf[3] = level >= scsi_level::SCSI_2 ? scsi_level::SCSI_2 : scsi_level::SCSI_1_CCS; buf[3] = (BYTE)(level >= scsi_level::SCSI_2 ? scsi_level::SCSI_2 : scsi_level::SCSI_1_CCS);
buf[4] = 0x1F; buf[4] = 0x1F;
// Padded vendor, product, revision // Padded vendor, product, revision
@ -198,10 +196,10 @@ vector<BYTE> PrimaryDevice::HandleRequestSense()
// Current error // Current error
buf[0] = 0x70; buf[0] = 0x70;
buf[2] = GetStatusCode() >> 16; buf[2] = (BYTE)(GetStatusCode() >> 16);
buf[7] = 10; buf[7] = 10;
buf[12] = GetStatusCode() >> 8; buf[12] = (BYTE)(GetStatusCode() >> 8);
buf[13] = GetStatusCode(); buf[13] = (BYTE)GetStatusCode();
LOGTRACE("%s Status $%02X, Sense Key $%02X, ASC $%02X",__PRETTY_FUNCTION__, ctrl->status, ctrl->buffer[2], ctrl->buffer[12]) LOGTRACE("%s Status $%02X, Sense Key $%02X, ASC $%02X",__PRETTY_FUNCTION__, ctrl->status, ctrl->buffer[2], ctrl->buffer[12])

View File

@ -25,6 +25,8 @@ public:
explicit PrimaryDevice(const string&); explicit PrimaryDevice(const string&);
~PrimaryDevice() override = default; ~PrimaryDevice() override = default;
PrimaryDevice(PrimaryDevice&) = delete;
PrimaryDevice& operator=(const PrimaryDevice&) = delete;
bool Dispatch() override; bool Dispatch() override;

View File

@ -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) || if (buf[9] != (BYTE)(sector_size >> 16) || buf[10] != (BYTE)(sector_size >> 8) ||
buf[11] != (BYTE)sector_size) { buf[11] != (BYTE)sector_size) {
// See below for details // 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); 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) { 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, // With rascsi it is not possible to permanently (by formatting) change the sector size,
// because the size is an externally configurable setting only // 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); throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
} }
has_valid_page_code = true; has_valid_page_code = true;
} }
else { else {
LOGWARN("Unknown MODE SELECT page code: $%02X", page); LOGWARN("Unknown MODE SELECT page code: $%02X", page)
} }
// Advance to the next page // Advance to the next page
@ -77,17 +77,12 @@ void scsi_command_util::EnrichFormatPage(map<int, vector<BYTE>>& pages, bool cha
if (changeable) { if (changeable) {
// The sector size is simulated to be changeable, see the MODE SELECT implementation for details // The sector size is simulated to be changeable, see the MODE SELECT implementation for details
vector<BYTE>& format_page = pages[3]; vector<BYTE>& format_page = pages[3];
format_page[12] = sector_size >> 8; format_page[12] = (BYTE)(sector_size >> 8);
format_page[13] = sector_size; format_page[13] = (BYTE)sector_size;
} }
} }
//--------------------------------------------------------------------------- void scsi_command_util::AddAppleVendorModePage(map<int, vector<BYTE>>& pages, int, bool changeable)
//
// Add Vendor special page to make drive Apple compatible
//
//---------------------------------------------------------------------------
void scsi_command_util::AddAppleVendorModePage(map<int, vector<BYTE>>& pages, int page, bool changeable)
{ {
// Page code 48 (30h) - Apple Vendor Mode Page // Page code 48 (30h) - Apple Vendor Mode Page
// Needed for SCCD for stock Apple driver support // Needed for SCCD for stock Apple driver support

View File

@ -21,6 +21,5 @@ namespace scsi_command_util
{ {
void ModeSelect(const DWORD *, const BYTE *, int, int); void ModeSelect(const DWORD *, const BYTE *, int, int);
void EnrichFormatPage(map<int, vector<BYTE>>&, bool, int); void EnrichFormatPage(map<int, vector<BYTE>>&, bool, int);
void AddAppleVendorModePage(map<int, vector<BYTE>>&, int, bool); void AddAppleVendorModePage(map<int, vector<BYTE>>&, int, bool);
} }

View File

@ -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 }; const BYTE SCSIDaynaPort::m_apple_talk_addr[6] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff };
// TODO Disk should not be the superclass // TODO Disk should not be the superclass
SCSIDaynaPort::SCSIDaynaPort() : Disk("SCDP"), dispatcher({}) SCSIDaynaPort::SCSIDaynaPort() : Disk("SCDP")
{ {
dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &SCSIDaynaPort::TestUnitReady); dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &SCSIDaynaPort::TestUnitReady);
dispatcher.AddCommand(eCmdRead6, "Read6", &SCSIDaynaPort::Read6); dispatcher.AddCommand(eCmdRead6, "Read6", &SCSIDaynaPort::Read6);
@ -86,7 +86,7 @@ bool SCSIDaynaPort::Init(const unordered_map<string, string>& params)
LOGDEBUG("Tap interface created") LOGDEBUG("Tap interface created")
} }
this->Reset(); Reset();
SetReady(true); SetReady(true);
SetReset(false); SetReset(false);
@ -161,7 +161,7 @@ vector<BYTE> SCSIDaynaPort::InquiryInternal() const
int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t) int SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, uint64_t)
{ {
int rx_packet_size = 0; 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]; int requested_length = cdb[4];
LOGTRACE("%s Read maximum length %d, (%04X)", __PRETTY_FUNCTION__, requested_length, requested_length) 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 // 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) // 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; bool send_message_to_host;
int read_count = 0; int read_count = 0;
while (read_count < MAX_READ_RETRIES) { 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. // breaks because of this, the work-around has to be re-evaluated.
size = 64; size = 64;
} }
buf[0] = size >> 8; buf[0] = (BYTE)(size >> 8);
buf[1] = size; buf[1] = (BYTE)size;
buf[2] = 0; buf[2] = 0;
buf[3] = 0; buf[3] = 0;
@ -315,7 +316,7 @@ int SCSIDaynaPort::WriteCheck(uint64_t)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool SCSIDaynaPort::WriteBytes(const DWORD *cdb, BYTE *buf, 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); WORD data_length = (WORD)cdb[4] + ((WORD)cdb[3] << 8);
if (data_format == 0x00){ 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 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); // memset(buffer,0,18);
// memcpy(&buffer[0],m_mac_addr,sizeof(m_mac_addr)); // memcpy(&buffer[0],m_mac_addr,sizeof(m_mac_addr));
@ -548,7 +549,7 @@ void SCSIDaynaPort::SetInterfaceMode()
void SCSIDaynaPort::SetMcastAddr() void SCSIDaynaPort::SetMcastAddr()
{ {
ctrl->length = (DWORD)ctrl->cmd[4]; ctrl->length = ctrl->cmd[4];
if (ctrl->length == 0) { if (ctrl->length == 0) {
LOGWARN("%s Not supported SetMcastAddr Command %02X", __PRETTY_FUNCTION__, (WORD)ctrl->cmd[2]) LOGWARN("%s Not supported SetMcastAddr Command %02X", __PRETTY_FUNCTION__, (WORD)ctrl->cmd[2])

View File

@ -44,6 +44,8 @@ class SCSIDaynaPort: public Disk
public: public:
SCSIDaynaPort(); SCSIDaynaPort();
~SCSIDaynaPort() final; ~SCSIDaynaPort() final;
SCSIDaynaPort(SCSIDaynaPort&) = delete;
SCSIDaynaPort& operator=(const SCSIDaynaPort&) = delete;
bool Init(const unordered_map<string, string>&) override; bool Init(const unordered_map<string, string>&) override;
void Open(const Filepath& path) override; void Open(const Filepath& path) override;

View File

@ -24,7 +24,7 @@
using namespace std; using namespace std;
using namespace scsi_defs; using namespace scsi_defs;
SCSIBR::SCSIBR() : Disk("SCBR"), dispatcher({}), fs(new CFileSys()) SCSIBR::SCSIBR() : Disk("SCBR"), fs(new CFileSys())
{ {
// Create host file system // Create host file system
fs->Reset(); fs->Reset();
@ -56,7 +56,7 @@ bool SCSIBR::Init(const unordered_map<string, string>& params)
tap = new CTapDriver(); tap = new CTapDriver();
m_bTapEnable = tap->Init(GetParams()); m_bTapEnable = tap->Init(GetParams());
if (!m_bTapEnable){ if (!m_bTapEnable){
LOGERROR("Unable to open the TAP interface"); LOGERROR("Unable to open the TAP interface")
return false; return false;
} }
@ -92,7 +92,7 @@ vector<BYTE> SCSIBR::InquiryInternal() const
vector<BYTE> b = HandleInquiry(device_type::COMMUNICATIONS, scsi_level::SCSI_2, false); vector<BYTE> b = HandleInquiry(device_type::COMMUNICATIONS, scsi_level::SCSI_2, false);
// The bridge returns 6 more additional bytes than the other devices // The bridge returns 6 more additional bytes than the other devices
vector<BYTE> buf = vector<BYTE>(0x1F + 8 + 5); auto buf = vector<BYTE>(0x1F + 8 + 5);
memcpy(buf.data(), b.data(), b.size()); memcpy(buf.data(), b.data(), b.size());
buf[4] = 0x1F + 8; buf[4] = 0x1F + 8;
@ -413,12 +413,11 @@ void SCSIBR::FS_InitDevice(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_CheckDir(BYTE *buf) void SCSIBR::FS_CheckDir(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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);
fsresult = fs->CheckDir(nUnit, pNamests); fsresult = fs->CheckDir(nUnit, pNamests);
} }
@ -430,12 +429,11 @@ void SCSIBR::FS_CheckDir(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_MakeDir(BYTE *buf) void SCSIBR::FS_MakeDir(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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);
fsresult = fs->MakeDir(nUnit, pNamests); fsresult = fs->MakeDir(nUnit, pNamests);
} }
@ -447,12 +445,11 @@ void SCSIBR::FS_MakeDir(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_RemoveDir(BYTE *buf) void SCSIBR::FS_RemoveDir(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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);
fsresult = fs->RemoveDir(nUnit, pNamests); fsresult = fs->RemoveDir(nUnit, pNamests);
} }
@ -464,15 +461,14 @@ void SCSIBR::FS_RemoveDir(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Rename(BYTE *buf) void SCSIBR::FS_Rename(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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); i += sizeof(Human68k::namests_t);
const Human68k::namests_t *pNamestsNew = (Human68k::namests_t*)&buf[i]; const Human68k::namests_t *pNamestsNew = (Human68k::namests_t*)&buf[i];
i += sizeof(Human68k::namests_t);
fsresult = fs->Rename(nUnit, pNamests, pNamestsNew); fsresult = fs->Rename(nUnit, pNamests, pNamestsNew);
} }
@ -484,12 +480,11 @@ void SCSIBR::FS_Rename(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Delete(BYTE *buf) void SCSIBR::FS_Delete(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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);
fsresult = fs->Delete(nUnit, pNamests); fsresult = fs->Delete(nUnit, pNamests);
} }
@ -501,16 +496,15 @@ void SCSIBR::FS_Delete(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Attribute(BYTE *buf) void SCSIBR::FS_Attribute(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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); i += sizeof(Human68k::namests_t);
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
DWORD nHumanAttribute = ntohl(*dp); DWORD nHumanAttribute = ntohl(*dp);
i += sizeof(DWORD);
fsresult = fs->Attribute(nUnit, pNamests, nHumanAttribute); fsresult = fs->Attribute(nUnit, pNamests, nHumanAttribute);
} }
@ -522,7 +516,7 @@ void SCSIBR::FS_Attribute(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Files(BYTE *buf) void SCSIBR::FS_Files(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -530,11 +524,10 @@ void SCSIBR::FS_Files(BYTE *buf)
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
i += sizeof(DWORD); 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); i += sizeof(Human68k::namests_t);
Human68k::files_t *files = (Human68k::files_t*)&buf[i]; auto files = (Human68k::files_t*)&buf[i];
i += sizeof(Human68k::files_t);
files->sector = ntohl(files->sector); files->sector = ntohl(files->sector);
files->offset = ntohs(files->offset); files->offset = ntohs(files->offset);
@ -564,7 +557,7 @@ void SCSIBR::FS_Files(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_NFiles(BYTE *buf) void SCSIBR::FS_NFiles(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -572,8 +565,7 @@ void SCSIBR::FS_NFiles(BYTE *buf)
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
i += sizeof(DWORD); i += sizeof(DWORD);
Human68k::files_t *files = (Human68k::files_t*)&buf[i]; auto files = (Human68k::files_t*)&buf[i];
i += sizeof(Human68k::files_t);
files->sector = ntohl(files->sector); files->sector = ntohl(files->sector);
files->offset = ntohs(files->offset); files->offset = ntohs(files->offset);
@ -603,7 +595,7 @@ void SCSIBR::FS_NFiles(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Create(BYTE *buf) void SCSIBR::FS_Create(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -611,19 +603,18 @@ void SCSIBR::FS_Create(BYTE *buf)
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
i += sizeof(DWORD); 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); 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); i += sizeof(Human68k::fcb_t);
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
DWORD nAttribute = ntohl(*dp); DWORD nAttribute = ntohl(*dp);
i += sizeof(DWORD); i += sizeof(DWORD);
BOOL *bp = (BOOL*)&buf[i]; auto bp = (BOOL*)&buf[i];
DWORD bForce = ntohl(*bp); DWORD bForce = ntohl(*bp);
i += sizeof(BOOL);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -653,7 +644,7 @@ void SCSIBR::FS_Create(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Open(BYTE *buf) void SCSIBR::FS_Open(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -661,11 +652,10 @@ void SCSIBR::FS_Open(BYTE *buf)
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
i += sizeof(DWORD); 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); 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);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -695,7 +685,7 @@ void SCSIBR::FS_Open(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Close(BYTE *buf) void SCSIBR::FS_Close(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -703,8 +693,7 @@ void SCSIBR::FS_Close(BYTE *buf)
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
i += sizeof(DWORD); i += sizeof(DWORD);
Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; auto pFcb = (Human68k::fcb_t*)&buf[i];
i += sizeof(Human68k::fcb_t);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -734,16 +723,15 @@ void SCSIBR::FS_Close(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Read(BYTE *buf) void SCSIBR::FS_Read(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
int i = sizeof(DWORD); 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); i += sizeof(Human68k::fcb_t);
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
DWORD nSize = ntohl(*dp); DWORD nSize = ntohl(*dp);
i += sizeof(DWORD);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -775,16 +763,15 @@ void SCSIBR::FS_Read(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Write(BYTE *buf) void SCSIBR::FS_Write(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
int i = sizeof(DWORD); 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); i += sizeof(Human68k::fcb_t);
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
DWORD nSize = ntohl(*dp); DWORD nSize = ntohl(*dp);
i += sizeof(DWORD);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -814,11 +801,11 @@ void SCSIBR::FS_Write(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Seek(BYTE *buf) void SCSIBR::FS_Seek(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
int i = sizeof(DWORD); 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); i += sizeof(Human68k::fcb_t);
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
@ -827,7 +814,6 @@ void SCSIBR::FS_Seek(BYTE *buf)
auto ip = (const int*)&buf[i]; auto ip = (const int*)&buf[i];
int nOffset = ntohl(*ip); int nOffset = ntohl(*ip);
i += sizeof(int);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -857,7 +843,7 @@ void SCSIBR::FS_Seek(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_TimeStamp(BYTE *buf) void SCSIBR::FS_TimeStamp(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -865,12 +851,11 @@ void SCSIBR::FS_TimeStamp(BYTE *buf)
DWORD nKey = ntohl(*dp); DWORD nKey = ntohl(*dp);
i += sizeof(DWORD); i += sizeof(DWORD);
Human68k::fcb_t *pFcb = (Human68k::fcb_t*)&buf[i]; auto pFcb = (Human68k::fcb_t*)&buf[i];
i += sizeof(Human68k::fcb_t); i += sizeof(Human68k::fcb_t);
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
DWORD nHumanTime = ntohl(*dp); DWORD nHumanTime = ntohl(*dp);
i += sizeof(DWORD);
pFcb->fileptr = ntohl(pFcb->fileptr); pFcb->fileptr = ntohl(pFcb->fileptr);
pFcb->mode = ntohs(pFcb->mode); pFcb->mode = ntohs(pFcb->mode);
@ -900,7 +885,7 @@ void SCSIBR::FS_TimeStamp(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_GetCapacity(BYTE *buf) void SCSIBR::FS_GetCapacity(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
Human68k::capacity_t cap; Human68k::capacity_t cap;
@ -922,11 +907,11 @@ void SCSIBR::FS_GetCapacity(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_CtrlDrive(BYTE *buf) void SCSIBR::FS_CtrlDrive(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); 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); fsresult = fs->CtrlDrive(nUnit, pCtrlDrive);
@ -941,7 +926,7 @@ void SCSIBR::FS_CtrlDrive(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_GetDPB(BYTE *buf) void SCSIBR::FS_GetDPB(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
Human68k::dpb_t dpb; Human68k::dpb_t dpb;
@ -965,7 +950,7 @@ void SCSIBR::FS_GetDPB(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_DiskRead(BYTE *buf) void SCSIBR::FS_DiskRead(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -975,7 +960,6 @@ void SCSIBR::FS_DiskRead(BYTE *buf)
dp = (DWORD*)&buf[i]; dp = (DWORD*)&buf[i];
DWORD nSize = ntohl(*dp); DWORD nSize = ntohl(*dp);
i += sizeof(DWORD);
fsresult = fs->DiskRead(nUnit, fsout, nSector, nSize); fsresult = fs->DiskRead(nUnit, fsout, nSector, nSize);
fsoutlen = 0x200; fsoutlen = 0x200;
@ -988,7 +972,7 @@ void SCSIBR::FS_DiskRead(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_DiskWrite(BYTE *buf) void SCSIBR::FS_DiskWrite(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
fsresult = fs->DiskWrite(nUnit); fsresult = fs->DiskWrite(nUnit);
@ -1001,7 +985,7 @@ void SCSIBR::FS_DiskWrite(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Ioctrl(BYTE *buf) void SCSIBR::FS_Ioctrl(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
int i = sizeof(DWORD); int i = sizeof(DWORD);
@ -1009,8 +993,7 @@ void SCSIBR::FS_Ioctrl(BYTE *buf)
DWORD nFunction = ntohl(*dp); DWORD nFunction = ntohl(*dp);
i += sizeof(DWORD); i += sizeof(DWORD);
Human68k::ioctrl_t *pIoctrl = (Human68k::ioctrl_t*)&buf[i]; auto pIoctrl = (Human68k::ioctrl_t*)&buf[i];
i += sizeof(Human68k::ioctrl_t);
switch (nFunction) { switch (nFunction) {
case 2: case 2:
@ -1048,7 +1031,7 @@ void SCSIBR::FS_Ioctrl(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Flush(BYTE *buf) void SCSIBR::FS_Flush(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
fsresult = fs->Flush(nUnit); fsresult = fs->Flush(nUnit);
@ -1061,7 +1044,7 @@ void SCSIBR::FS_Flush(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_CheckMedia(BYTE *buf) void SCSIBR::FS_CheckMedia(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
fsresult = fs->CheckMedia(nUnit); fsresult = fs->CheckMedia(nUnit);
@ -1074,7 +1057,7 @@ void SCSIBR::FS_CheckMedia(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SCSIBR::FS_Lock(BYTE *buf) void SCSIBR::FS_Lock(BYTE *buf)
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
DWORD nUnit = ntohl(*dp); DWORD nUnit = ntohl(*dp);
fsresult = fs->Lock(nUnit); fsresult = fs->Lock(nUnit);
@ -1087,7 +1070,7 @@ void SCSIBR::FS_Lock(BYTE *buf)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int SCSIBR::ReadFsResult(BYTE *buf) const int SCSIBR::ReadFsResult(BYTE *buf) const
{ {
DWORD *dp = (DWORD*)buf; auto dp = (DWORD*)buf;
*dp = htonl(fsresult); *dp = htonl(fsresult);
return sizeof(DWORD); return sizeof(DWORD);
} }

View File

@ -36,6 +36,8 @@ public:
SCSIBR(); SCSIBR();
~SCSIBR() final; ~SCSIBR() final;
SCSIBR(SCSIBR&) = delete;
SCSIBR& operator=(const SCSIBR&) = delete;
bool Init(const unordered_map<string, string>&) override; bool Init(const unordered_map<string, string>&) override;
bool Dispatch() override; bool Dispatch() override;

View File

@ -48,7 +48,7 @@ using namespace std;
using namespace scsi_defs; using namespace scsi_defs;
using namespace ras_util; using namespace ras_util;
SCSIPrinter::SCSIPrinter() : PrimaryDevice("SCLP"), ScsiPrinterCommands(), dispatcher({}) SCSIPrinter::SCSIPrinter() : PrimaryDevice("SCLP"), ScsiPrinterCommands()
{ {
dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &SCSIPrinter::TestUnitReady); dispatcher.AddCommand(eCmdTestUnitReady, "TestUnitReady", &SCSIPrinter::TestUnitReady);
dispatcher.AddCommand(eCmdReserve6, "ReserveUnit", &SCSIPrinter::ReserveUnit); dispatcher.AddCommand(eCmdReserve6, "ReserveUnit", &SCSIPrinter::ReserveUnit);
@ -148,12 +148,12 @@ void SCSIPrinter::Print()
length <<= 8; length <<= 8;
length |= ctrl->cmd[4]; 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, // TODO This device suffers from the statically allocated buffer size,
// see https://github.com/akuker/RASCSI/issues/669 // see https://github.com/akuker/RASCSI/issues/669
if (length > (uint32_t)ctrl->bufsize) { 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); 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.replace(file_position, 2, filename);
cmd = "sudo -u lp " + cmd; 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())) { 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); unlink(filename);
@ -206,9 +206,8 @@ void SCSIPrinter::SynchronizeBuffer()
void SCSIPrinter::SendDiagnostic() void SCSIPrinter::SendDiagnostic()
{ {
CheckReservation(); // Both command implemntations are identical
TestUnitReady();
EnterStatusPhase();
} }
void SCSIPrinter::StopPrint() void SCSIPrinter::StopPrint()
@ -226,16 +225,16 @@ bool SCSIPrinter::WriteByteSequence(BYTE *buf, uint32_t length)
strcpy(filename, TMP_FILE_PATTERN); strcpy(filename, TMP_FILE_PATTERN);
fd = mkstemp(filename); fd = mkstemp(filename);
if (fd == -1) { 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; 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; return num_written == length;
} }

View File

@ -28,6 +28,8 @@ public:
SCSIPrinter(); SCSIPrinter();
~SCSIPrinter() final; ~SCSIPrinter() final;
SCSIPrinter(SCSIPrinter&) = delete;
SCSIPrinter& operator=(const SCSIPrinter&) = delete;
bool Dispatch() override; bool Dispatch() override;

View File

@ -94,7 +94,7 @@ DWORD CDTrack::GetBlocks() const
ASSERT(first_lba < last_lba); ASSERT(first_lba < last_lba);
// Calculate from start LBA and end 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 int CDTrack::GetTrackNo() const

View File

@ -34,6 +34,7 @@ private:
CDTrack() = default; CDTrack() = default;
virtual ~CDTrack() final = default; virtual ~CDTrack() final = default;
CDTrack(CDTrack&) = delete;
public: public:
@ -65,14 +66,15 @@ private:
//=========================================================================== //===========================================================================
class SCSICD : public Disk, public ScsiMmcCommands, public FileSupport class SCSICD : public Disk, public ScsiMmcCommands, public FileSupport
{ {
// Maximum number of tracks
static const int TRACK_MAX = 96;
public: public:
enum {
TrackMax = 96 // Maximum number of tracks
};
explicit SCSICD(const unordered_set<uint32_t>&); explicit SCSICD(const unordered_set<uint32_t>&);
~SCSICD() override; ~SCSICD() override;
SCSICD(SCSICD&) = delete;
SCSICD& operator=(const SCSICD&) = delete;
bool Dispatch() override; bool Dispatch() override;
@ -89,6 +91,7 @@ protected:
void AddVendorPage(map<int, vector<BYTE>>&, int, bool) const override; void AddVendorPage(map<int, vector<BYTE>>&, int, bool) const override;
private: private:
using super = Disk; using super = Disk;
Dispatcher<SCSICD> dispatcher; Dispatcher<SCSICD> dispatcher;
@ -111,7 +114,7 @@ private:
// Track management // Track management
void ClearTrack(); // Clear the track void ClearTrack(); // Clear the track
int SearchTrack(DWORD lba) const; // Track search 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 tracks = 0; // Effective number of track objects
int dataindex = -1; // Current data track int dataindex = -1; // Current data track
int audioindex = -1; // Current audio track int audioindex = -1; // Current audio track

View File

@ -25,7 +25,7 @@ static const char *DEFAULT_PRODUCT = "SCSI HD";
SCSIHD::SCSIHD(const unordered_set<uint32_t>& sector_sizes, bool removable, scsi_defs::scsi_level level) SCSIHD::SCSIHD(const unordered_set<uint32_t>& sector_sizes, bool removable, scsi_defs::scsi_level level)
: Disk(removable ? "SCRM" : "SCHD") : Disk(removable ? "SCRM" : "SCHD")
{ {
this->scsi_level = level; scsi_level = level;
SetSectorSizes(sector_sizes); SetSectorSizes(sector_sizes);
} }

View File

@ -21,10 +21,13 @@
class SCSIHD : public Disk, public FileSupport class SCSIHD : public Disk, public FileSupport
{ {
public: public:
SCSIHD(const unordered_set<uint32_t>&, bool, scsi_defs::scsi_level = scsi_level::SCSI_2); SCSIHD(const unordered_set<uint32_t>&, 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); void FinalizeSetup(const Filepath&, off_t);

View File

@ -75,7 +75,7 @@ void SCSIHD_NEC::Open(const Filepath& path)
if (const char *ext = path.GetFileExt(); !strcasecmp(ext, ".hdn")) { if (const char *ext = path.GetFileExt(); !strcasecmp(ext, ".hdn")) {
// Assuming sector size 512, number of sectors 25, number of heads 8 as default settings // Assuming sector size 512, number of sectors 25, number of heads 8 as default settings
disk.image_offset = 0; disk.image_offset = 0;
image_size = size; image_size = (int)size;
sector_size = 512; sector_size = 512;
sectors = 25; sectors = 25;
heads = 8; heads = 8;
@ -100,7 +100,7 @@ void SCSIHD_NEC::Open(const Filepath& path)
heads = getWordLE(&root_sector[0x118]); heads = getWordLE(&root_sector[0x118]);
sectors = getWordLE(&root_sector[0x11a]); sectors = getWordLE(&root_sector[0x11a]);
sector_size = getWordLE(&root_sector[0x11c]); 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 { else {
throw io_exception("Invalid NEC image file format"); throw io_exception("Invalid NEC image file format");
@ -124,7 +124,7 @@ void SCSIHD_NEC::Open(const Filepath& path)
if (size <= 0 || size > 16) { if (size <= 0 || size > 16) {
throw io_exception("Invalid NEC disk size"); throw io_exception("Invalid NEC disk size");
} }
SetSectorSizeShiftCount(size); SetSectorSizeShiftCount((uint32_t)size);
// Number of blocks // Number of blocks
SetBlockCount(image_size >> disk.size); SetBlockCount(image_size >> disk.size);

View File

@ -30,6 +30,8 @@ public:
explicit SCSIHD_NEC() : SCSIHD(sector_sizes, false) {} explicit SCSIHD_NEC() : SCSIHD(sector_sizes, false) {}
~SCSIHD_NEC() override = default; ~SCSIHD_NEC() override = default;
SCSIHD_NEC(SCSIHD_NEC&) = delete;
SCSIHD_NEC& operator=(const SCSIHD_NEC&) = delete;
void Open(const Filepath& path) override; void Open(const Filepath& path) override;

View File

@ -20,7 +20,7 @@
#include "scsimo.h" #include "scsimo.h"
SCSIMO::SCSIMO(const unordered_set<uint32_t>& sector_sizes, const unordered_map<uint64_t, Geometry>& geometries) SCSIMO::SCSIMO(const unordered_set<uint32_t>& sector_sizes, const unordered_map<uint64_t, Geometry>& geometries)
: Disk("SCMO"), geometries({}) : Disk("SCMO")
{ {
SetSectorSizes(sector_sizes); SetSectorSizes(sector_sizes);
SetGeometries(geometries); SetGeometries(geometries);
@ -49,9 +49,6 @@ void SCSIMO::Open(const Filepath& path)
SetBlockCount(size >> GetSectorSizeShiftCount()); SetBlockCount(size >> GetSectorSizeShiftCount());
} }
// Effective size must be a multiple of the sector size
size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes();
SetReadOnly(false); SetReadOnly(false);
SetProtectable(true); SetProtectable(true);
SetProtected(false); SetProtected(false);
@ -219,8 +216,7 @@ void SCSIMO::AddVendorPage(map<int, vector<BYTE>>& pages, int page, bool changea
} }
bool SCSIMO::SetGeometryForCapacity(uint64_t capacity) { bool SCSIMO::SetGeometryForCapacity(uint64_t capacity) {
const auto& geometry = geometries.find(capacity); if (const auto& geometry = geometries.find(capacity); geometry != geometries.end()) {
if (geometry != geometries.end()) {
SetSectorSizeInBytes(geometry->second.first); SetSectorSizeInBytes(geometry->second.first);
SetBlockCount(geometry->second.second); SetBlockCount(geometry->second.second);

View File

@ -26,6 +26,8 @@ public:
SCSIMO(const unordered_set<uint32_t>&, const unordered_map<uint64_t, Geometry>&); SCSIMO(const unordered_set<uint32_t>&, const unordered_map<uint64_t, Geometry>&);
~SCSIMO() override = default; ~SCSIMO() override = default;
SCSIMO(SCSIMO&) = delete;
SCSIMO& operator=(const SCSIMO&) = delete;
void Open(const Filepath& path) override; void Open(const Filepath& path) override;
@ -43,7 +45,7 @@ private:
void AddOptionPage(map<int, vector<BYTE>>&, bool) const; void AddOptionPage(map<int, vector<BYTE>>&, bool) const;
void SetGeometries(const unordered_map<uint64_t, Geometry>& geometries) { this->geometries = geometries; } void SetGeometries(const unordered_map<uint64_t, Geometry>& g) { geometries = g; }
bool SetGeometryForCapacity(uint64_t); bool SetGeometryForCapacity(uint64_t);
// The mapping of supported capacities to block sizes and block counts, empty if there is no capacity restriction // The mapping of supported capacities to block sizes and block counts, empty if there is no capacity restriction

View File

@ -44,6 +44,9 @@ public:
Fileio() = default; Fileio() = default;
virtual ~Fileio(); virtual ~Fileio();
Fileio(Fileio&) = delete;
Fileio& operator=(const Fileio&) = delete;
BOOL Load(const Filepath& path, void *buffer, int size); // Load ROM, RAM BOOL Load(const Filepath& path, void *buffer, int size); // Load ROM, RAM
BOOL Save(const Filepath& path, const void *buffer, int size); // Save RAM BOOL Save(const Filepath& path, const void *buffer, int size); // Save RAM

View File

@ -46,7 +46,7 @@ void Filepath::SetPath(const char *path)
ASSERT(strlen(path) < _MAX_PATH); ASSERT(strlen(path) < _MAX_PATH);
// Copy pathname // Copy pathname
strcpy(m_szPath, (char *)path); strcpy(m_szPath, path);
// Split // Split
Split(); Split();

View File

@ -29,9 +29,12 @@ class Fileio;
//=========================================================================== //===========================================================================
class Filepath class Filepath
{ {
public: public:
Filepath(); Filepath();
virtual ~Filepath() = default; virtual ~Filepath() = default;
Filepath(Filepath&) = delete;
Filepath& operator=(const Filepath& path); Filepath& operator=(const Filepath& path);
void Clear(); void Clear();
@ -40,6 +43,7 @@ public:
const char *GetFileExt() const; // Get short name (LPCTSTR) const char *GetFileExt() const; // Get short name (LPCTSTR)
private: private:
void Split(); // Split the path void Split(); // Split the path
TCHAR m_szPath[_MAX_PATH]; // File path TCHAR m_szPath[_MAX_PATH]; // File path
TCHAR m_szDir[_MAX_DIR]; // Directory TCHAR m_szDir[_MAX_DIR]; // Directory

View File

@ -106,14 +106,14 @@
#define CONNECT_DESC "STANDARD" // Startup message #define CONNECT_DESC "STANDARD" // Startup message
// Select signal control mode // 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) // Control signal pin assignment (-1 means no control)
#define PIN_ACT 4 // ACTIVE const static int PIN_ACT = 4; // ACTIVE
#define PIN_ENB 5 // ENABLE const static int PIN_ENB = 5; // ENABLE
#define PIN_IND -1 // INITIATOR CTRL DIRECTION const static int PIN_IND = -1; // INITIATOR CTRL DIRECTION
#define PIN_TAD -1 // TARGET CTRL DIRECTION const static int PIN_TAD = -1; // TARGET CTRL DIRECTION
#define PIN_DTD -1 // DATA DIRECTION const static int PIN_DTD = -1; // DATA DIRECTION
// Control signal output logic // Control signal output logic
#define ACT_ON TRUE // ACTIVE SIGNAL ON #define ACT_ON TRUE // ACTIVE SIGNAL ON
@ -123,24 +123,24 @@
#define DTD_IN TRUE // DATA SIGNAL INPUT #define DTD_IN TRUE // DATA SIGNAL INPUT
// SCSI signal pin assignment // SCSI signal pin assignment
#define PIN_DT0 10 // Data 0 const static int PIN_DT0 = 10; // Data 0
#define PIN_DT1 11 // Data 1 const static int PIN_DT1 = 11; // Data 1
#define PIN_DT2 12 // Data 2 const static int PIN_DT2 = 12; // Data 2
#define PIN_DT3 13 // Data 3 const static int PIN_DT3 = 13; // Data 3
#define PIN_DT4 14 // Data 4 const static int PIN_DT4 = 14; // Data 4
#define PIN_DT5 15 // Data 5 const static int PIN_DT5 = 15; // Data 5
#define PIN_DT6 16 // Data 6 const static int PIN_DT6 = 16; // Data 6
#define PIN_DT7 17 // Data 7 const static int PIN_DT7 = 17; // Data 7
#define PIN_DP 18 // Data parity const static int PIN_DP = 18; // Data parity
#define PIN_ATN 19 // ATN const static int PIN_ATN = 19; // ATN
#define PIN_RST 20 // RST const static int PIN_RST = 20; // RST
#define PIN_ACK 21 // ACK const static int PIN_ACK = 21; // ACK
#define PIN_REQ 22 // REQ const static int PIN_REQ = 22; // REQ
#define PIN_MSG 23 // MSG const static int PIN_MSG = 23; // MSG
#define PIN_CD 24 // CD const static int PIN_CD = 24; // CD
#define PIN_IO 25 // IO const static int PIN_IO = 25; // IO
#define PIN_BSY 26 // BSY const static int PIN_BSY = 26; // BSY
#define PIN_SEL 27 // SEL const static int PIN_SEL = 27; // SEL
#endif #endif
#ifdef CONNECT_TYPE_FULLSPEC #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_DT5 = 15; // Data 5
const static int PIN_DT6 = 16; // Data 6 const static int PIN_DT6 = 16; // Data 6
const static int PIN_DT7 = 17; // Data 7 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_ATN = 19; // ATN
const static int PIN_RST = 20; // RST const static int PIN_RST = 20; // RST
const static int PIN_ACK = 21; // ACK const static int PIN_ACK = 21; // ACK
const static int PIN_REQ = 22; // REQ const static int PIN_REQ = 22; // REQ
const static int PIN_MSG = 23; // MSG const static int PIN_MSG = 23; // MSG
const static int PIN_CD = 24; // CD const static int PIN_CD = 24; // CD
const static int PIN_IO = 25; // IO const static int PIN_IO = 25; // IO
const static int PIN_BSY = 26; // BSY const static int PIN_BSY = 26; // BSY
const static int PIN_SEL = 27; // SEL const static int PIN_SEL = 27; // SEL
#endif #endif
@ -195,7 +195,7 @@ const static int PIN_SEL = 27; // SEL
#define CONNECT_DESC "AIBOM PRODUCTS version" // Startup message #define CONNECT_DESC "AIBOM PRODUCTS version" // Startup message
// Select signal control mode // 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 // Control signal output logic
#define ACT_ON TRUE // ACTIVE SIGNAL ON #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 #define DTD_IN FALSE // DATA SIGNAL INPUT
// Control signal pin assignment (-1 means no control) // Control signal pin assignment (-1 means no control)
#define PIN_ACT 4 // ACTIVE const static int PIN_ACT = 4; // ACTIVE
#define PIN_ENB 17 // ENABLE const static int PIN_ENB = 17; // ENABLE
#define PIN_IND 27 // INITIATOR CTRL DIRECTION const static int PIN_IND = 27; // INITIATOR CTRL DIRECTION
#define PIN_TAD -1 // TARGET CTRL DIRECTION const static int PIN_TAD = -1; // TARGET CTRL DIRECTION
#define PIN_DTD 18 // DATA DIRECTION const static int PIN_DTD = 18; // DATA DIRECTION
// SCSI signal pin assignment // SCSI signal pin assignment
#define PIN_DT0 6 // Data 0 const static int PIN_DT0 = 6; // Data 0
#define PIN_DT1 12 // Data 1 const static int PIN_DT1 = 12; // Data 1
#define PIN_DT2 13 // Data 2 const static int PIN_DT2 = 13; // Data 2
#define PIN_DT3 16 // Data 3 const static int PIN_DT3 = 16; // Data 3
#define PIN_DT4 19 // Data 4 const static int PIN_DT4 = 19; // Data 4
#define PIN_DT5 20 // Data 5 const static int PIN_DT5 = 20; // Data 5
#define PIN_DT6 26 // Data 6 const static int PIN_DT6 = 26; // Data 6
#define PIN_DT7 21 // Data 7 const static int PIN_DT7 = 21; // Data 7
#define PIN_DP 5 // Data parity const static int PIN_DP = 5; // Data parity
#define PIN_ATN 22 // ATN const static int PIN_ATN = 22; // ATN
#define PIN_RST 25 // RST const static int PIN_RST = 25; // RST
#define PIN_ACK 10 // ACK const static int PIN_ACK = 10; // ACK
#define PIN_REQ 7 // REQ const static int PIN_REQ = 7; // REQ
#define PIN_MSG 9 // MSG const static int PIN_MSG = 9; // MSG
#define PIN_CD 11 // CD const static int PIN_CD = 11; // CD
#define PIN_IO 23 // IO const static int PIN_IO = 23; // IO
#define PIN_BSY 24 // BSY const static int PIN_BSY = 24; // BSY
#define PIN_SEL 8 // SEL const static int PIN_SEL = 8; // SEL
#endif #endif
// TODO Is this type stil relevant? // 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 #define CONNECT_DESC "GAMERnium.com version"// Startup message
// Select signal control mode // 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 // Control signal output logic
#define ACT_ON TRUE // ACTIVE SIGNAL ON #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 #define DTD_IN TRUE // DATA SIGNAL INPUT
// Control signal pin assignment (-1 means no control) // Control signal pin assignment (-1 means no control)
#define PIN_ACT 14 // ACTIVE const static int PIN_ACT = 14; // ACTIVE
#define PIN_ENB 6 // ENABLE const static int PIN_ENB = 6; // ENABLE
#define PIN_IND 7 // INITIATOR CTRL DIRECTION const static int PIN_IND = 7; // INITIATOR CTRL DIRECTION
#define PIN_TAD 8 // TARGET CTRL DIRECTION const static int PIN_TAD = 8; // TARGET CTRL DIRECTION
#define PIN_DTD 5 // DATA DIRECTION const static int PIN_DTD = 5; // DATA DIRECTION
// SCSI signal pin assignment // SCSI signal pin assignment
#define PIN_DT0 21 // Data 0 const static int PIN_DT0 = 21; // Data 0
#define PIN_DT1 26 // Data 1 const static int PIN_DT1 = 26; // Data 1
#define PIN_DT2 20 // Data 2 const static int PIN_DT2 = 20; // Data 2
#define PIN_DT3 19 // Data 3 const static int PIN_DT3 = 19; // Data 3
#define PIN_DT4 16 // Data 4 const static int PIN_DT4 = 16; // Data 4
#define PIN_DT5 13 // Data 5 const static int PIN_DT5 = 13; // Data 5
#define PIN_DT6 12 // Data 6 const static int PIN_DT6 = 12; // Data 6
#define PIN_DT7 11 // Data 7 const static int PIN_DT7 = 11; // Data 7
#define PIN_DP 25 // Data parity const static int PIN_DP = 25; // Data parity
#define PIN_ATN 10 // ATN const static int PIN_ATN = 10; // ATN
#define PIN_RST 22 // RST const static int PIN_RST = 22; // RST
#define PIN_ACK 24 // ACK const static int PIN_ACK = 24; // ACK
#define PIN_REQ 15 // REQ const static int PIN_REQ = 15; // REQ
#define PIN_MSG 17 // MSG const static int PIN_MSG = 17; // MSG
#define PIN_CD 18 // CD const static int PIN_CD = 18; // CD
#define PIN_IO 4 // IO const static int PIN_IO = 4; // IO
#define PIN_BSY 27 // BSY const static int PIN_BSY = 27; // BSY
#define PIN_SEL 23 // SEL const static int PIN_SEL = 23; // SEL
#endif #endif
#define ALL_SCSI_PINS \ #define ALL_SCSI_PINS \

View File

@ -156,8 +156,7 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, stri
string filename = folder + "/" + dir->d_name; string filename = folder + "/" + dir->d_name;
struct stat st; if (struct stat st; dir->d_type == DT_REG && !stat(filename.c_str(), &st)) {
if (dir->d_type == DT_REG && !stat(filename.c_str(), &st)) {
if (!st.st_size) { if (!st.st_size) {
LOGWARN("File '%s' in image folder '%s' has a size of 0 bytes", dir->d_name, folder.c_str()) LOGWARN("File '%s' in image folder '%s' has a size of 0 bytes", dir->d_name, folder.c_str())
continue; 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) { if (file_pattern_lower.empty() || name_lower.find(file_pattern_lower) != string::npos) {
auto image_file = make_unique<PbImageFile>(); if (auto image_file = make_unique<PbImageFile>(); GetImageFile(image_file.get(), filename)) {
if (GetImageFile(image_file.get(), filename)) {
GetImageFile(image_files_info.add_image_files(), filename.substr(default_image_folder.length() + 1)); 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<PbDevicesInfo>().release(); auto devices_info = make_unique<PbDevicesInfo>().release();
result.set_allocated_devices_info(devices_info); result.set_allocated_devices_info(devices_info);
for (const auto& id_set : id_sets) { for (const auto& [id, lun] : id_sets) {
GetDevice(device_factory->GetDeviceByIdAndLun(id_set.first, id_set.second), devices_info->add_devices()); GetDevice(device_factory->GetDeviceByIdAndLun(id, lun), devices_info->add_devices());
} }
result.set_status(true); result.set_status(true);
@ -341,8 +339,8 @@ PbMappingInfo *RascsiResponse::GetMappingInfo(PbResult& result)
{ {
auto mapping_info = make_unique<PbMappingInfo>().release(); auto mapping_info = make_unique<PbMappingInfo>().release();
for (const auto& mapping : device_factory->GetExtensionMapping()) { for (const auto& [name, type] : device_factory->GetExtensionMapping()) {
(*mapping_info->mutable_mapping())[mapping.first] = mapping.second; (*mapping_info->mutable_mapping())[name] = type;
} }
result.set_status(true); result.set_status(true);

View File

@ -15,7 +15,7 @@ TEST(ControllerManagerTest, ControllerManager)
const int ID = 4; const int ID = 4;
const int LUN = 6; const int LUN = 6;
PrimaryDevice *device = static_cast<PrimaryDevice *>(device_factory.CreateDevice(UNDEFINED, "services", ID)); auto device = static_cast<PrimaryDevice *>(device_factory.CreateDevice(UNDEFINED, "services", ID));
device->SetId(ID); device->SetId(ID);
device->SetLun(LUN); device->SetLun(LUN);

View File

@ -16,9 +16,9 @@ class TestDevice : public Device
public: public:
TestDevice() : Device("test") {} TestDevice() : Device("test") {}
~TestDevice() = default; ~TestDevice() final = default;
bool Dispatch() { return false; } bool Dispatch() final { return false; }
}; };
TEST(DeviceTest, ProductData) TEST(DeviceTest, ProductData)

View File

@ -12,7 +12,7 @@
class TestFileSupport : public FileSupport class TestFileSupport : public FileSupport
{ {
void Open(const Filepath&) { void Open(const Filepath&) final {
// Do nothing when running unit tests // Do nothing when running unit tests
} }
}; };

View File

@ -61,7 +61,7 @@ public:
MOCK_METHOD(void, SetSignal, (int, bool), (override)); MOCK_METHOD(void, SetSignal, (int, bool), (override));
MockBus() = default; MockBus() = default;
~MockBus() = default; ~MockBus() final = default;
}; };
class MockAbstractController : public AbstractController class MockAbstractController : public AbstractController
@ -98,7 +98,7 @@ public:
MOCK_METHOD(void, Reset, (), (override)); MOCK_METHOD(void, Reset, (), (override));
explicit MockAbstractController(int target_id) : AbstractController(nullptr, target_id) {} explicit MockAbstractController(int target_id) : AbstractController(nullptr, target_id) {}
~MockAbstractController() = default; ~MockAbstractController() final = default;
}; };
class MockScsiController : public ScsiController class MockScsiController : public ScsiController
@ -136,8 +136,7 @@ public:
FRIEND_TEST(PrimaryDeviceTest, ReportLuns); FRIEND_TEST(PrimaryDeviceTest, ReportLuns);
FRIEND_TEST(PrimaryDeviceTest, UnknownCommand); FRIEND_TEST(PrimaryDeviceTest, UnknownCommand);
MockScsiController(BUS *bus, int target_id) : ScsiController(bus, target_id) {} using ScsiController::ScsiController;
~MockScsiController() = default;
}; };
class MockPrimaryDevice : public PrimaryDevice class MockPrimaryDevice : public PrimaryDevice
@ -147,7 +146,7 @@ public:
MOCK_METHOD(vector<BYTE>, InquiryInternal, (), (const)); MOCK_METHOD(vector<BYTE>, InquiryInternal, (), (const));
MockPrimaryDevice() : PrimaryDevice("test") {} MockPrimaryDevice() : PrimaryDevice("test") {}
~MockPrimaryDevice() = default; ~MockPrimaryDevice() final = default;
// Make protected methods visible for testing // Make protected methods visible for testing
@ -164,7 +163,7 @@ class MockModePageDevice : public ModePageDevice
public: public:
MockModePageDevice() : ModePageDevice("test") {} MockModePageDevice() : ModePageDevice("test") {}
~MockModePageDevice() = default; ~MockModePageDevice() final = default;
MOCK_METHOD(vector<BYTE>, InquiryInternal, (), (const)); MOCK_METHOD(vector<BYTE>, InquiryInternal, (), (const));
MOCK_METHOD(int, ModeSense6, (const DWORD *, BYTE *, int), ()); MOCK_METHOD(int, ModeSense6, (const DWORD *, BYTE *, int), ());
@ -191,7 +190,7 @@ class MockSCSIHD : public SCSIHD
FRIEND_TEST(ModePagesTest, SCSIHD_AddModePages); FRIEND_TEST(ModePagesTest, SCSIHD_AddModePages);
explicit MockSCSIHD(const unordered_set<uint32_t>& sector_sizes) : SCSIHD(sector_sizes, false) {} explicit MockSCSIHD(const unordered_set<uint32_t>& sector_sizes) : SCSIHD(sector_sizes, false) {}
~MockSCSIHD() = default; ~MockSCSIHD() final = default;
}; };
class MockSCSIHD_NEC : public SCSIHD_NEC class MockSCSIHD_NEC : public SCSIHD_NEC
@ -199,7 +198,7 @@ class MockSCSIHD_NEC : public SCSIHD_NEC
FRIEND_TEST(ModePagesTest, SCSIHD_NEC_AddModePages); FRIEND_TEST(ModePagesTest, SCSIHD_NEC_AddModePages);
MockSCSIHD_NEC() = default; MockSCSIHD_NEC() = default;
~MockSCSIHD_NEC() = default; ~MockSCSIHD_NEC() final = default;
}; };
class MockSCSICD : public SCSICD class MockSCSICD : public SCSICD
@ -207,7 +206,7 @@ class MockSCSICD : public SCSICD
FRIEND_TEST(ModePagesTest, SCSICD_AddModePages); FRIEND_TEST(ModePagesTest, SCSICD_AddModePages);
explicit MockSCSICD(const unordered_set<uint32_t>& sector_sizes) : SCSICD(sector_sizes) {} explicit MockSCSICD(const unordered_set<uint32_t>& sector_sizes) : SCSICD(sector_sizes) {}
~MockSCSICD() = default; ~MockSCSICD() final = default;
}; };
class MockSCSIMO : public SCSIMO class MockSCSIMO : public SCSIMO
@ -216,7 +215,7 @@ class MockSCSIMO : public SCSIMO
MockSCSIMO(const unordered_set<uint32_t>& sector_sizes, const unordered_map<uint64_t, Geometry>& geometries) MockSCSIMO(const unordered_set<uint32_t>& sector_sizes, const unordered_map<uint64_t, Geometry>& geometries)
: SCSIMO(sector_sizes, geometries) {} : SCSIMO(sector_sizes, geometries) {}
~MockSCSIMO() = default; ~MockSCSIMO() final = default;
}; };
class MockHostServices : public HostServices class MockHostServices : public HostServices
@ -224,5 +223,5 @@ class MockHostServices : public HostServices
FRIEND_TEST(ModePagesTest, HostServices_AddModePages); FRIEND_TEST(ModePagesTest, HostServices_AddModePages);
MockHostServices() = default; MockHostServices() = default;
~MockHostServices() = default; ~MockHostServices() final = default;
}; };