2022-02-17 02:04:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-08-26 01:01:39 +00:00
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
2022-02-17 02:04:42 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
// Implementation of a SCSI printer (see SCSI-2 specification for a command description)
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//
|
|
|
|
// How to print:
|
|
|
|
//
|
2022-10-23 19:51:39 +00:00
|
|
|
// 1. The client sends the data to be printed with one or several PRINT commands. The maximum
|
|
|
|
// transfer size per PRINT command is currently limited to 4096 bytes.
|
|
|
|
// 2. The client triggers printing with SYNCHRONIZE BUFFER. Each SYNCHRONIZE BUFFER results in
|
2022-02-27 21:58:01 +00:00
|
|
|
// the print command for this printer (see below) to be called for the data not yet printed.
|
2022-02-17 02:04:42 +00:00
|
|
|
//
|
2022-10-25 08:29:57 +00:00
|
|
|
// It is recommended to reserve the printer device before printing and to release it afterwards.
|
2022-02-17 02:04:42 +00:00
|
|
|
// The command to be used for printing can be set with the "cmd" property when attaching the device.
|
2022-02-18 20:06:33 +00:00
|
|
|
// By default the data to be printed are sent to the printer unmodified, using "lp -oraw %f". This
|
2022-02-17 02:04:42 +00:00
|
|
|
// requires that the client uses a printer driver compatible with the respective printer, or that the
|
2022-02-18 20:06:33 +00:00
|
|
|
// printing service on the Pi is configured to do any necessary conversions, or that the print command
|
|
|
|
// applies any conversions on the file to be printed (%f) before passing it to the printing service.
|
2022-02-20 17:40:30 +00:00
|
|
|
// 'enscript' is an example for a conversion tool.
|
2022-02-17 02:04:42 +00:00
|
|
|
// By attaching different devices/LUNs multiple printers (i.e. different print commands) are possible.
|
|
|
|
//
|
|
|
|
// With STOP PRINT printing can be cancelled before SYNCHRONIZE BUFFER was sent.
|
|
|
|
//
|
|
|
|
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "shared/rascsi_exceptions.h"
|
2022-10-01 15:56:06 +00:00
|
|
|
#include "scsi_command_util.h"
|
2022-02-17 02:04:42 +00:00
|
|
|
#include "scsi_printer.h"
|
2022-11-02 14:36:19 +00:00
|
|
|
#include <sys/stat.h>
|
2022-10-25 08:29:57 +00:00
|
|
|
#include <filesystem>
|
2022-02-17 02:04:42 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2022-10-25 08:29:57 +00:00
|
|
|
using namespace filesystem;
|
2022-02-17 02:04:42 +00:00
|
|
|
using namespace scsi_defs;
|
2022-10-01 15:56:06 +00:00
|
|
|
using namespace scsi_command_util;
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
SCSIPrinter::SCSIPrinter(int lun) : PrimaryDevice(SCLP, lun)
|
|
|
|
{
|
|
|
|
SupportsParams(true);
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:36:19 +00:00
|
|
|
bool SCSIPrinter::Init(const unordered_map<string, string>& params)
|
2022-02-17 02:04:42 +00:00
|
|
|
{
|
2022-11-02 14:36:19 +00:00
|
|
|
PrimaryDevice::Init(params);
|
|
|
|
|
|
|
|
AddCommand(scsi_command::eCmdTestUnitReady, [this] { TestUnitReady(); });
|
|
|
|
AddCommand(scsi_command::eCmdPrint, [this] { Print(); });
|
|
|
|
AddCommand(scsi_command::eCmdSynchronizeBuffer, [this] { SynchronizeBuffer(); });
|
2022-10-25 08:29:57 +00:00
|
|
|
// STOP PRINT is identical with TEST UNIT READY, it just returns the status
|
2022-11-02 14:36:19 +00:00
|
|
|
AddCommand(scsi_command::eCmdStopPrint, [this] { TestUnitReady(); });
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
// Required also in this class in order to fulfill the ScsiPrinterCommands interface contract
|
2022-11-02 14:36:19 +00:00
|
|
|
AddCommand(scsi_command::eCmdReserve6, [this] { ReserveUnit(); });
|
|
|
|
AddCommand(scsi_command::eCmdRelease6, [this] { ReleaseUnit(); });
|
|
|
|
AddCommand(scsi_command::eCmdSendDiagnostic, [this] { SendDiagnostic(); });
|
|
|
|
|
|
|
|
if (GetParam("cmd").find("%f") == string::npos) {
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Trace("Missing filename specifier %f");
|
2022-11-02 14:36:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-10-11 15:04:17 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
error_code error;
|
|
|
|
file_template = temp_directory_path(error); //NOSONAR Publicly writable directory is fine here
|
|
|
|
file_template += PRINTER_FILE_PATTERN;
|
|
|
|
|
2022-10-11 15:04:17 +00:00
|
|
|
SetReady(true);
|
2022-02-18 20:06:33 +00:00
|
|
|
|
2022-02-17 02:04:42 +00:00
|
|
|
return 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
|
|
|
void SCSIPrinter::TestUnitReady()
|
2022-02-17 02:04:42 +00:00
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
// The printer is always ready
|
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
|
|
|
EnterStatusPhase();
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 14:36:19 +00:00
|
|
|
vector<uint8_t> SCSIPrinter::InquiryInternal() const
|
2022-02-17 02:04:42 +00:00
|
|
|
{
|
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
|
|
|
return HandleInquiry(device_type::PRINTER, scsi_level::SCSI_2, false);
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
void SCSIPrinter::Print()
|
2022-02-17 02:04:42 +00:00
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
const uint32_t length = GetInt24(GetController()->GetCmd(), 2);
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Trace("Receiving " + to_string(length) + " byte(s) to be printed");
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
if (length > GetController()->GetBuffer().size()) {
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Error("Transfer buffer overflow: Buffer size is " + to_string(GetController()->GetBuffer().size()) +
|
|
|
|
" bytes, " + to_string(length) + " bytes expected");
|
2022-02-20 17:40:30 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB);
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
GetController()->SetLength(length);
|
|
|
|
GetController()->SetByteTransfer(true);
|
2022-02-17 02:04:42 +00:00
|
|
|
|
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
|
|
|
EnterDataOutPhase();
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
void SCSIPrinter::SynchronizeBuffer()
|
2022-02-17 02:04:42 +00:00
|
|
|
{
|
2022-10-25 08:29:57 +00:00
|
|
|
if (!out.is_open()) {
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Warn("Nothing to print");
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
throw scsi_exception(sense_key::ABORTED_COMMAND);
|
|
|
|
}
|
2022-02-17 02:04:42 +00:00
|
|
|
|
|
|
|
string cmd = GetParam("cmd");
|
2022-10-08 17:26:04 +00:00
|
|
|
const size_t file_position = cmd.find("%f");
|
2022-02-18 20:06:33 +00:00
|
|
|
assert(file_position != string::npos);
|
|
|
|
cmd.replace(file_position, 2, filename);
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
error_code error;
|
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Trace("Printing file '" + filename + "' with " + to_string(file_size(path(filename), error)) + " byte(s)");
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Debug("Executing '" + cmd + "'");
|
2022-02-17 02:04:42 +00:00
|
|
|
|
|
|
|
if (system(cmd.c_str())) {
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Error("Printing file '" + filename + "' failed, the printing system might not be configured");
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
Cleanup();
|
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
|
|
|
throw scsi_exception(sense_key::ABORTED_COMMAND);
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
Cleanup();
|
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
|
|
|
|
|
|
|
EnterStatusPhase();
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
bool SCSIPrinter::WriteByteSequence(vector<uint8_t>& buf, uint32_t length)
|
2022-02-17 02:04:42 +00:00
|
|
|
{
|
2022-10-25 08:29:57 +00:00
|
|
|
if (!out.is_open()) {
|
|
|
|
vector<char> f(file_template.begin(), file_template.end());
|
|
|
|
f.push_back(0);
|
|
|
|
|
|
|
|
// There is no C++ API that generates a file with a unique name
|
|
|
|
const int fd = mkstemp(f.data());
|
2022-02-17 02:04:42 +00:00
|
|
|
if (fd == -1) {
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Error("Can't create printer output file for pattern '" + filename + "': " + strerror(errno));
|
2022-02-17 02:04:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-10-25 08:29:57 +00:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
filename = f.data();
|
|
|
|
|
|
|
|
out.open(filename, ios::binary);
|
|
|
|
if (out.fail()) {
|
|
|
|
throw scsi_exception(sense_key::ABORTED_COMMAND);
|
|
|
|
}
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Trace("Created printer output file '" + filename + "'");
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
GetLogger().Trace("Appending " + to_string(length) + " byte(s) to printer output file ''" + filename + "'");
|
2022-10-25 08:29:57 +00:00
|
|
|
|
|
|
|
out.write((const char*)buf.data(), length);
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
return !out.fail();
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SCSIPrinter::Cleanup()
|
|
|
|
{
|
2022-10-25 08:29:57 +00:00
|
|
|
if (out.is_open()) {
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
error_code error;
|
|
|
|
remove(path(filename), error);
|
2022-02-17 02:04:42 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
filename = "";
|
2022-02-17 02:04:42 +00:00
|
|
|
}
|
|
|
|
}
|