SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "shared/piscsi_exceptions.h"
|
2022-11-11 20:08:48 +00:00
|
|
|
#include "device_logger.h"
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
#include "scsi_command_util.h"
|
2022-11-11 20:08:48 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cassert>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
|
|
|
|
using namespace scsi_defs;
|
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
void scsi_command_util::ModeSelect(const DeviceLogger& logger, scsi_command cmd, const vector<int>& cdb,
|
|
|
|
const vector<uint8_t>& buf, int length, int sector_size)
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
assert(cmd == scsi_command::eCmdModeSelect6 || cmd == scsi_command::eCmdModeSelect10);
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
assert(length >= 0);
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
// PF
|
|
|
|
if (!(cdb[1] & 0x10)) {
|
2022-11-02 14:36:19 +00:00
|
|
|
// Vendor-specific parameters (SCSI-1) are not supported.
|
|
|
|
// Do not report an error in order to support Apple's HD SC Setup.
|
|
|
|
return;
|
2022-10-01 15:56:06 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 06:16:47 +00:00
|
|
|
// Skip block descriptors
|
|
|
|
int offset;
|
2022-10-23 19:51:39 +00:00
|
|
|
if (cmd == scsi_command::eCmdModeSelect10) {
|
2022-10-10 06:16:47 +00:00
|
|
|
offset = 8 + GetInt16(buf, 6);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
offset = 4 + buf[3];
|
2022-10-01 15:56:06 +00:00
|
|
|
}
|
2022-10-10 06:16:47 +00:00
|
|
|
length -= offset;
|
|
|
|
|
|
|
|
bool has_valid_page_code = false;
|
2022-10-01 15:56:06 +00:00
|
|
|
|
2022-10-10 06:16:47 +00:00
|
|
|
// Parse the pages
|
2022-10-01 15:56:06 +00:00
|
|
|
while (length > 0) {
|
|
|
|
// Format device page
|
|
|
|
if (int page = buf[offset]; page == 0x03) {
|
2022-10-10 06:16:47 +00:00
|
|
|
if (length < 14) {
|
|
|
|
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
// With this page the sector size for a subsequent FORMAT can be selected, but only very few
|
|
|
|
// drives support this, e.g FUJITSU M2624S
|
|
|
|
// We are fine as long as the current sector size remains unchanged
|
2022-10-10 06:16:47 +00:00
|
|
|
if (GetInt16(buf, offset + 12) != sector_size) {
|
2022-12-05 17:58:23 +00:00
|
|
|
// With piscsi it is not possible to permanently (by formatting) change the sector size,
|
2022-10-01 15:56:06 +00:00
|
|
|
// because the size is an externally configurable setting only
|
2022-12-05 17:58:23 +00:00
|
|
|
logger.Warn("In order to change the sector size use the -b option when launching piscsi");
|
2022-10-08 17:26:04 +00:00
|
|
|
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
has_valid_page_code = true;
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
2022-10-01 15:56:06 +00:00
|
|
|
else {
|
2022-11-11 20:08:48 +00:00
|
|
|
stringstream s;
|
|
|
|
s << "Unknown MODE SELECT page code: $" << setfill('0') << setw(2) << hex << page;
|
|
|
|
logger.Warn(s.str());
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
// Advance to the next page
|
2022-11-02 14:36:19 +00:00
|
|
|
const int size = buf[offset + 1] + 2;
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
length -= size;
|
|
|
|
offset += size;
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
2022-10-01 15:56:06 +00:00
|
|
|
|
|
|
|
if (!has_valid_page_code) {
|
2022-10-08 17:26:04 +00:00
|
|
|
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 06:27:51 +00:00
|
|
|
void scsi_command_util::EnrichFormatPage(map<int, vector<byte>>& pages, bool changeable, int sector_size)
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
{
|
|
|
|
if (changeable) {
|
|
|
|
// The sector size is simulated to be changeable, see the MODE SELECT implementation for details
|
2022-11-02 14:36:19 +00:00
|
|
|
SetInt16(pages[3], 12, sector_size);
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-08 02:37:07 +00:00
|
|
|
|
2022-09-21 06:27:51 +00:00
|
|
|
void scsi_command_util::AddAppleVendorModePage(map<int, vector<byte>>& pages, bool changeable)
|
2022-09-08 02:37:07 +00:00
|
|
|
{
|
|
|
|
// Page code 48 (30h) - Apple Vendor Mode Page
|
|
|
|
// Needed for SCCD for stock Apple driver support
|
|
|
|
// Needed for SCHD for stock Apple HD SC Setup
|
2022-11-02 14:36:19 +00:00
|
|
|
pages[48] = vector<byte>(30);
|
2022-09-08 02:37:07 +00:00
|
|
|
|
|
|
|
// No changeable area
|
|
|
|
if (!changeable) {
|
2022-09-21 06:27:51 +00:00
|
|
|
const char APPLE_DATA[] = "APPLE COMPUTER, INC ";
|
2022-11-02 14:36:19 +00:00
|
|
|
memcpy(&pages[48].data()[2], APPLE_DATA, sizeof(APPLE_DATA));
|
2022-09-08 02:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-25 21:49:24 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
int scsi_command_util::GetInt16(const vector<uint8_t>& buf, int offset)
|
2022-10-10 06:16:47 +00:00
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 1);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
return (static_cast<int>(buf[offset]) << 8) | buf[offset + 1];
|
2022-10-10 06:16:47 +00:00
|
|
|
}
|
|
|
|
|
2022-09-25 21:49:24 +00:00
|
|
|
int scsi_command_util::GetInt16(const vector<int>& buf, int offset)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 1);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-09-25 21:49:24 +00:00
|
|
|
return (buf[offset] << 8) | buf[offset + 1];
|
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
int scsi_command_util::GetInt24(const vector<int>& buf, int offset)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 2);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
return (buf[offset] << 16) | (buf[offset + 1] << 8) | buf[offset + 2];
|
|
|
|
}
|
|
|
|
|
2022-09-25 21:49:24 +00:00
|
|
|
uint32_t scsi_command_util::GetInt32(const vector<int>& buf, int offset)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 3);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
return (static_cast<uint32_t>(buf[offset]) << 24) | (static_cast<uint32_t>(buf[offset + 1]) << 16) |
|
|
|
|
(static_cast<uint32_t>(buf[offset + 2]) << 8) | static_cast<uint32_t>(buf[offset + 3]);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t scsi_command_util::GetInt64(const vector<int>& buf, int offset)
|
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 7);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
return (static_cast<uint64_t>(buf[offset]) << 56) | (static_cast<uint64_t>(buf[offset + 1]) << 48) |
|
|
|
|
(static_cast<uint64_t>(buf[offset + 2]) << 40) | (static_cast<uint64_t>(buf[offset + 3]) << 32) |
|
|
|
|
(static_cast<uint64_t>(buf[offset + 4]) << 24) | (static_cast<uint64_t>(buf[offset + 5]) << 16) |
|
|
|
|
(static_cast<uint64_t>(buf[offset + 6]) << 8) | static_cast<uint64_t>(buf[offset + 7]);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
void scsi_command_util::SetInt16(vector<byte>& buf, int offset, int value)
|
2022-09-25 21:49:24 +00:00
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 1);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
buf[offset] = static_cast<byte>(value >> 8);
|
|
|
|
buf[offset + 1] = static_cast<byte>(value);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-01 15:56:06 +00:00
|
|
|
void scsi_command_util::SetInt32(vector<byte>& buf, int offset, uint32_t value)
|
2022-09-25 21:49:24 +00:00
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 3);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
buf[offset] = static_cast<byte>(value >> 24);
|
|
|
|
buf[offset + 1] = static_cast<byte>(value >> 16);
|
|
|
|
buf[offset + 2] = static_cast<byte>(value >> 8);
|
|
|
|
buf[offset + 3] = static_cast<byte>(value);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
void scsi_command_util::SetInt16(vector<uint8_t>& buf, int offset, int value)
|
2022-09-25 21:49:24 +00:00
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 1);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
buf[offset] = static_cast<uint8_t>(value >> 8);
|
|
|
|
buf[offset + 1] = static_cast<uint8_t>(value);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
void scsi_command_util::SetInt32(vector<uint8_t>& buf, int offset, uint32_t value)
|
2022-09-25 21:49:24 +00:00
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 3);
|
2022-10-10 06:16:47 +00:00
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
buf[offset] = static_cast<uint8_t>(value >> 24);
|
|
|
|
buf[offset + 1] = static_cast<uint8_t>(value >> 16);
|
|
|
|
buf[offset + 2] = static_cast<uint8_t>(value >> 8);
|
|
|
|
buf[offset + 3] = static_cast<uint8_t>(value);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
void scsi_command_util::SetInt64(vector<uint8_t>& buf, int offset, uint64_t value)
|
2022-09-25 21:49:24 +00:00
|
|
|
{
|
2022-11-02 06:36:25 +00:00
|
|
|
assert(buf.size() > static_cast<size_t>(offset) + 7);
|
|
|
|
|
|
|
|
buf[offset] = static_cast<uint8_t>(value >> 56);
|
|
|
|
buf[offset + 1] = static_cast<uint8_t>(value >> 48);
|
|
|
|
buf[offset + 2] = static_cast<uint8_t>(value >> 40);
|
|
|
|
buf[offset + 3] = static_cast<uint8_t>(value >> 32);
|
|
|
|
buf[offset + 4] = static_cast<uint8_t>(value >> 24);
|
|
|
|
buf[offset + 5] = static_cast<uint8_t>(value >> 16);
|
|
|
|
buf[offset + 6] = static_cast<uint8_t>(value >> 8);
|
|
|
|
buf[offset + 7] = static_cast<uint8_t>(value);
|
2022-09-25 21:49:24 +00:00
|
|
|
}
|