RASCSI/cpp/devices/host_services.cpp

144 lines
3.8 KiB
C++
Raw Normal View History

Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
//
Added support for SCSI printer device (SCLP) (#670) * Fixed buster compile-time issue * Host services inherit from ModePageDevice * Call base class * Visibility update * Updated includes * Updated dispatcher * Added TODOs * Logging update * Code cleanup * Use namespace instead of class for ScsiDefs * Renaming * Cleanup * Use dispatcher template in order to remove duplicate code * Updated all dispatchers * Clean up commands * Removed duplicate code * Removed duplicate code * Updated template definition * Fixed typo * Fixed warning * Code cleanup * Device list must be static * Cleanup * Logging update * Added comments * Cleanup * Base class update * SCSIBR is not a subclass of Disk anymore, but of PrimaryDevice * Updated includes * Fixed compile-time issue on the Pi * Header file cleanup * Interface cleanup * Removed wrong override * include file cleanup * Removed obsolete usage of streams * Removed more stream usages * Stream usage cleanup * Include cleanup * Renaming * Include cleanup * Interface update * SCLP device skeleton * Initial RELEASE/RESERVE UNIT * Added full set of commands * Extracted command phase code * Stripped SCSI controller code * Removed unused code * Commented out code * Initial naive implementation * Added debug output * Disable printing for now * Updated file handling * Updated DataOut() * Added comment * Updated assertion * Comment update * Updated assertion * Code cleanup * Reset bytes to transfer * Reverted change * Refactoring * Moved assertion * Updated ReceiveBytes() * Removed override * Added interface * Code cleanup * Updated TEST UNIT READY * Added flag for byte-oriented transfer * Updated TEST UNIT READY * Length handling update * Updated bytecount handling * Fixed warning * Added TODO * Updated assertion * Enabled priting * Updated error handling * Code cleanup * Logging update * First working version * Use temporary file * Logging update * Handle parameters * Updated format string * Updated logging * File handling update * Code cleanup * Fixed buffer size * Updated file handling * Manpage update * Initial reservation handling * Updated reservation handling * Initial reservation testing * Remember initiator ID * Extract initiator ID * Updated SCSI initiator ID handling * Logging update * Added reservation timeout * Updated timeout handling * Code cleanup * Only pass initiator ID to *SCSI* controller * Added comments * Added comment * Implemented STOP PRINT * Comment update * Comment update * Comment update * Added comment * Comment update * Removed useless comments * Updated printer parameter handling * Updated parameter handling * Manpage update * Manpage update * Comment update * Default printer product name update * Renaming * Updated logging * Logging update * Logging update * Comment update * Code cleanup * Added printer shortcut * Comment update * Comment update * Output formatting update * Updated error handling * Code cleanup * More cleanup * Revert "More cleanup" This reverts commit 05708986ee161c118bb0d3a17c1ddf2f201ccfb8. * Output formatting update * Output format update * Sort parameters * Comment update * Improved parsing of parameters * Manpage update * Updated SCSI level * Removed magic constants * Removed magic constant * Template update * Template usage update * Get rid of SASIDEV for printer * Get rid of SASIDEV for host services * Moved initiator_id field * Moved field * Moved field * Added comment * Error handling must use effective LUN * Removed obsolete casts * Removed unused method declarations * Comment update * Code cleanup * More code cleanup * Optimization * Removed duplicate code * Logging update * Fixed warning * Code cleanup * Added TODOs * TODO update * Backwards compatibility update * Comment update
2022-02-17 02:04:42 +00:00
// Host Services with realtime clock and shutdown support
//
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
//---------------------------------------------------------------------------
//
// Features of the host services device:
//
// 1. Vendor-specific mode page 0x20 returns the current date and time, see mode_page_datetime
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
//
// 2. START/STOP UNIT shuts down PiSCSI or shuts down/reboots the Raspberry Pi
// a) !start && !load (STOP): Shut down PiSCSI
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
// b) !start && load (EJECT): Shut down the Raspberry Pi
2022-02-23 03:08:22 +00:00
// c) start && load (LOAD): Reboot the Raspberry Pi
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
//
#include "shared/piscsi_exceptions.h"
#include "controllers/scsi_controller.h"
#include "scsi_command_util.h"
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
#include "host_services.h"
#include <algorithm>
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
using namespace scsi_defs;
using namespace scsi_command_util;
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
bool HostServices::Init(const unordered_map<string, string>& params)
{
ModePageDevice::Init(params);
AddCommand(scsi_command::eCmdTestUnitReady, [this] { TestUnitReady(); });
AddCommand(scsi_command::eCmdStartStop, [this] { StartStopUnit(); });
SetReady(true);
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
return true;
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +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 HostServices::TestUnitReady()
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
{
// Always successful
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();
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}
vector<uint8_t> HostServices::InquiryInternal() const
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +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::PROCESSOR, scsi_level::SPC_3, false);
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}
void HostServices::StartStopUnit() const
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
{
const bool start = GetController()->GetCmd(4) & 0x01;
const bool load = GetController()->GetCmd(4) & 0x02;
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
if (!start) {
if (load) {
GetController()->ScheduleShutdown(AbstractController::piscsi_shutdown_mode::STOP_PI);
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}
else {
GetController()->ScheduleShutdown(AbstractController::piscsi_shutdown_mode::STOP_PISCSI);
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}
}
else if (load) {
GetController()->ScheduleShutdown(AbstractController::piscsi_shutdown_mode::RESTART_PI);
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}
2022-02-23 03:08:22 +00:00
else {
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB);
2022-02-23 03:08:22 +00:00
}
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
EnterStatusPhase();
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}
int HostServices::ModeSense6(const vector<int>& cdb, vector<uint8_t>& buf) const
{
Code cleanup, in particular related to MODE SENSE (#699) * Replace member functions * Fixed TODO * Added TODOs * Added TODOs * Removed duplicate code * Fixed return value * CD-ROM mode pages are provided by the CD-ROM implementation * MO mode pages are provided by the MO implementation * Comment update * Removed duplicate code * Removed more duplicate code * Optimization * Updated mode page size handling * Addec TODO * Started more flexible mode page handling * Map mode pages * Page 0 must be last * Error handling update * Updated size handling * Updated map handling * Use map references * Move superclass call * Added comment * Host services also support mode page 0x3f (all pages) * Updated handling of page 0 * Removed duplicate code * Updated buffer size handling * Code cleanup * Removed duplicate code * Use calloc() * Removed duplicate code * Comment update * Fixed buffer offset * Fixed TODO * Added buffer size check * Comment udpate * Logging update * Updated logging * Avoid potential memory leak * Updated handling of page 0 * Added TODO * Comment update * Fixed error message * Use vector instead of byte array * Optimization * More optimizations * Removed duplicate code * Do not try to add more pages when buffer is full * Updated error message * Comment update, fixed host services message length handling * Code cleanup, optimizations * Updated payload handling for page 0 * Fixed TODO * Updated handling of PS field * Fixed offsets * Updated handling for page 0 * Code cleanup * More cleanup * Updated block descriptor handling * Result of REPORT LUNS must not depend on whether a device is ready or not * Printer uses a dynamically allocated buffer * Use realloc * Updated memory handling * Added assertion * Comment update * Fixed initialization * Reset byte transfer flag * Updated usage of realloc * Reverted some changes * Re-added buffer size check * Renaming * Inquiry for hard disk must also work when drive is not ready * Primary device checks EVPD * Added page code check to Inquiry * Explicitly set response level format * Added comment * Removed useless cast * Fixed inconsistencies in setting the additional length * Logging uodate * Updated logging * Made methods const * Moved code * Added TODO * Added vendor page * Reduced visibility * Code cleanup * Mark override * Removed duplicate cast * Synchronized host services mode page handling with other code * Added TODO * Signature update * Moved code * Removed duplicate code * Fixed TODO * Removed duplicate code * Added buffer size check * Improved buffer size check * Code cleanup * Removed useless assertions * Cleanup * Renaming * Added overrides * Removed unnecessary casts * Cleanup * Added TODO * Removed obsolete memset * Removed duplicate code * Logging update * Logging update * Assertion update * Removed useless comments * Code cleanup * Removed obsolete casts * User super typedef * Updated log messages * Fixed #712 * Updated error handling * Removed useless assertions * Reduced casts to Disk* * Updated sector size list argument * Removed obsolete casts * Removed comment
2022-02-27 21:58:01 +00:00
// Block descriptors cannot be returned
if (!(cdb[1] & 0x08)) {
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB);
Code cleanup, in particular related to MODE SENSE (#699) * Replace member functions * Fixed TODO * Added TODOs * Added TODOs * Removed duplicate code * Fixed return value * CD-ROM mode pages are provided by the CD-ROM implementation * MO mode pages are provided by the MO implementation * Comment update * Removed duplicate code * Removed more duplicate code * Optimization * Updated mode page size handling * Addec TODO * Started more flexible mode page handling * Map mode pages * Page 0 must be last * Error handling update * Updated size handling * Updated map handling * Use map references * Move superclass call * Added comment * Host services also support mode page 0x3f (all pages) * Updated handling of page 0 * Removed duplicate code * Updated buffer size handling * Code cleanup * Removed duplicate code * Use calloc() * Removed duplicate code * Comment update * Fixed buffer offset * Fixed TODO * Added buffer size check * Comment udpate * Logging update * Updated logging * Avoid potential memory leak * Updated handling of page 0 * Added TODO * Comment update * Fixed error message * Use vector instead of byte array * Optimization * More optimizations * Removed duplicate code * Do not try to add more pages when buffer is full * Updated error message * Comment update, fixed host services message length handling * Code cleanup, optimizations * Updated payload handling for page 0 * Fixed TODO * Updated handling of PS field * Fixed offsets * Updated handling for page 0 * Code cleanup * More cleanup * Updated block descriptor handling * Result of REPORT LUNS must not depend on whether a device is ready or not * Printer uses a dynamically allocated buffer * Use realloc * Updated memory handling * Added assertion * Comment update * Fixed initialization * Reset byte transfer flag * Updated usage of realloc * Reverted some changes * Re-added buffer size check * Renaming * Inquiry for hard disk must also work when drive is not ready * Primary device checks EVPD * Added page code check to Inquiry * Explicitly set response level format * Added comment * Removed useless cast * Fixed inconsistencies in setting the additional length * Logging uodate * Updated logging * Made methods const * Moved code * Added TODO * Added vendor page * Reduced visibility * Code cleanup * Mark override * Removed duplicate cast * Synchronized host services mode page handling with other code * Added TODO * Signature update * Moved code * Removed duplicate code * Fixed TODO * Removed duplicate code * Added buffer size check * Improved buffer size check * Code cleanup * Removed useless assertions * Cleanup * Renaming * Added overrides * Removed unnecessary casts * Cleanup * Added TODO * Removed obsolete memset * Removed duplicate code * Logging update * Logging update * Assertion update * Removed useless comments * Code cleanup * Removed obsolete casts * User super typedef * Updated log messages * Fixed #712 * Updated error handling * Removed useless assertions * Reduced casts to Disk* * Updated sector size list argument * Removed obsolete casts * Removed comment
2022-02-27 21:58:01 +00:00
}
const auto length = static_cast<int>(min(buf.size(), static_cast<size_t>(cdb[4])));
fill_n(buf.begin(), length, 0);
// 4 bytes basic information
const int size = AddModePages(cdb, buf, 4, length, 255);
buf[0] = (uint8_t)size;
return size;
}
int HostServices::ModeSense10(const vector<int>& cdb, vector<uint8_t>& buf) const
{
Code cleanup, in particular related to MODE SENSE (#699) * Replace member functions * Fixed TODO * Added TODOs * Added TODOs * Removed duplicate code * Fixed return value * CD-ROM mode pages are provided by the CD-ROM implementation * MO mode pages are provided by the MO implementation * Comment update * Removed duplicate code * Removed more duplicate code * Optimization * Updated mode page size handling * Addec TODO * Started more flexible mode page handling * Map mode pages * Page 0 must be last * Error handling update * Updated size handling * Updated map handling * Use map references * Move superclass call * Added comment * Host services also support mode page 0x3f (all pages) * Updated handling of page 0 * Removed duplicate code * Updated buffer size handling * Code cleanup * Removed duplicate code * Use calloc() * Removed duplicate code * Comment update * Fixed buffer offset * Fixed TODO * Added buffer size check * Comment udpate * Logging update * Updated logging * Avoid potential memory leak * Updated handling of page 0 * Added TODO * Comment update * Fixed error message * Use vector instead of byte array * Optimization * More optimizations * Removed duplicate code * Do not try to add more pages when buffer is full * Updated error message * Comment update, fixed host services message length handling * Code cleanup, optimizations * Updated payload handling for page 0 * Fixed TODO * Updated handling of PS field * Fixed offsets * Updated handling for page 0 * Code cleanup * More cleanup * Updated block descriptor handling * Result of REPORT LUNS must not depend on whether a device is ready or not * Printer uses a dynamically allocated buffer * Use realloc * Updated memory handling * Added assertion * Comment update * Fixed initialization * Reset byte transfer flag * Updated usage of realloc * Reverted some changes * Re-added buffer size check * Renaming * Inquiry for hard disk must also work when drive is not ready * Primary device checks EVPD * Added page code check to Inquiry * Explicitly set response level format * Added comment * Removed useless cast * Fixed inconsistencies in setting the additional length * Logging uodate * Updated logging * Made methods const * Moved code * Added TODO * Added vendor page * Reduced visibility * Code cleanup * Mark override * Removed duplicate cast * Synchronized host services mode page handling with other code * Added TODO * Signature update * Moved code * Removed duplicate code * Fixed TODO * Removed duplicate code * Added buffer size check * Improved buffer size check * Code cleanup * Removed useless assertions * Cleanup * Renaming * Added overrides * Removed unnecessary casts * Cleanup * Added TODO * Removed obsolete memset * Removed duplicate code * Logging update * Logging update * Assertion update * Removed useless comments * Code cleanup * Removed obsolete casts * User super typedef * Updated log messages * Fixed #712 * Updated error handling * Removed useless assertions * Reduced casts to Disk* * Updated sector size list argument * Removed obsolete casts * Removed comment
2022-02-27 21:58:01 +00:00
// Block descriptors cannot be returned
if (!(cdb[1] & 0x08)) {
throw scsi_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_CDB);
}
const auto length = static_cast<int>(min(buf.size(), static_cast<size_t>(GetInt16(cdb, 7))));
fill_n(buf.begin(), length, 0);
// 8 bytes basic information
const int size = AddModePages(cdb, buf, 8, length, 65535);
SetInt16(buf, 0, size);
return size;
}
void HostServices::SetUpModePages(map<int, vector<byte>>& pages, int page, bool changeable) const
Code cleanup, in particular related to MODE SENSE (#699) * Replace member functions * Fixed TODO * Added TODOs * Added TODOs * Removed duplicate code * Fixed return value * CD-ROM mode pages are provided by the CD-ROM implementation * MO mode pages are provided by the MO implementation * Comment update * Removed duplicate code * Removed more duplicate code * Optimization * Updated mode page size handling * Addec TODO * Started more flexible mode page handling * Map mode pages * Page 0 must be last * Error handling update * Updated size handling * Updated map handling * Use map references * Move superclass call * Added comment * Host services also support mode page 0x3f (all pages) * Updated handling of page 0 * Removed duplicate code * Updated buffer size handling * Code cleanup * Removed duplicate code * Use calloc() * Removed duplicate code * Comment update * Fixed buffer offset * Fixed TODO * Added buffer size check * Comment udpate * Logging update * Updated logging * Avoid potential memory leak * Updated handling of page 0 * Added TODO * Comment update * Fixed error message * Use vector instead of byte array * Optimization * More optimizations * Removed duplicate code * Do not try to add more pages when buffer is full * Updated error message * Comment update, fixed host services message length handling * Code cleanup, optimizations * Updated payload handling for page 0 * Fixed TODO * Updated handling of PS field * Fixed offsets * Updated handling for page 0 * Code cleanup * More cleanup * Updated block descriptor handling * Result of REPORT LUNS must not depend on whether a device is ready or not * Printer uses a dynamically allocated buffer * Use realloc * Updated memory handling * Added assertion * Comment update * Fixed initialization * Reset byte transfer flag * Updated usage of realloc * Reverted some changes * Re-added buffer size check * Renaming * Inquiry for hard disk must also work when drive is not ready * Primary device checks EVPD * Added page code check to Inquiry * Explicitly set response level format * Added comment * Removed useless cast * Fixed inconsistencies in setting the additional length * Logging uodate * Updated logging * Made methods const * Moved code * Added TODO * Added vendor page * Reduced visibility * Code cleanup * Mark override * Removed duplicate cast * Synchronized host services mode page handling with other code * Added TODO * Signature update * Moved code * Removed duplicate code * Fixed TODO * Removed duplicate code * Added buffer size check * Improved buffer size check * Code cleanup * Removed useless assertions * Cleanup * Renaming * Added overrides * Removed unnecessary casts * Cleanup * Added TODO * Removed obsolete memset * Removed duplicate code * Logging update * Logging update * Assertion update * Removed useless comments * Code cleanup * Removed obsolete casts * User super typedef * Updated log messages * Fixed #712 * Updated error handling * Removed useless assertions * Reduced casts to Disk* * Updated sector size list argument * Removed obsolete casts * Removed comment
2022-02-27 21:58:01 +00:00
{
if (page == 0x20 || page == 0x3f) {
AddRealtimeClockPage(pages, changeable);
}
}
void HostServices::AddRealtimeClockPage(map<int, vector<byte>>& pages, bool changeable) const
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
{
pages[32] = vector<byte>(10);
Code cleanup, in particular related to MODE SENSE (#699) * Replace member functions * Fixed TODO * Added TODOs * Added TODOs * Removed duplicate code * Fixed return value * CD-ROM mode pages are provided by the CD-ROM implementation * MO mode pages are provided by the MO implementation * Comment update * Removed duplicate code * Removed more duplicate code * Optimization * Updated mode page size handling * Addec TODO * Started more flexible mode page handling * Map mode pages * Page 0 must be last * Error handling update * Updated size handling * Updated map handling * Use map references * Move superclass call * Added comment * Host services also support mode page 0x3f (all pages) * Updated handling of page 0 * Removed duplicate code * Updated buffer size handling * Code cleanup * Removed duplicate code * Use calloc() * Removed duplicate code * Comment update * Fixed buffer offset * Fixed TODO * Added buffer size check * Comment udpate * Logging update * Updated logging * Avoid potential memory leak * Updated handling of page 0 * Added TODO * Comment update * Fixed error message * Use vector instead of byte array * Optimization * More optimizations * Removed duplicate code * Do not try to add more pages when buffer is full * Updated error message * Comment update, fixed host services message length handling * Code cleanup, optimizations * Updated payload handling for page 0 * Fixed TODO * Updated handling of PS field * Fixed offsets * Updated handling for page 0 * Code cleanup * More cleanup * Updated block descriptor handling * Result of REPORT LUNS must not depend on whether a device is ready or not * Printer uses a dynamically allocated buffer * Use realloc * Updated memory handling * Added assertion * Comment update * Fixed initialization * Reset byte transfer flag * Updated usage of realloc * Reverted some changes * Re-added buffer size check * Renaming * Inquiry for hard disk must also work when drive is not ready * Primary device checks EVPD * Added page code check to Inquiry * Explicitly set response level format * Added comment * Removed useless cast * Fixed inconsistencies in setting the additional length * Logging uodate * Updated logging * Made methods const * Moved code * Added TODO * Added vendor page * Reduced visibility * Code cleanup * Mark override * Removed duplicate cast * Synchronized host services mode page handling with other code * Added TODO * Signature update * Moved code * Removed duplicate code * Fixed TODO * Removed duplicate code * Added buffer size check * Improved buffer size check * Code cleanup * Removed useless assertions * Cleanup * Renaming * Added overrides * Removed unnecessary casts * Cleanup * Added TODO * Removed obsolete memset * Removed duplicate code * Logging update * Logging update * Assertion update * Removed useless comments * Code cleanup * Removed obsolete casts * User super typedef * Updated log messages * Fixed #712 * Updated error handling * Removed useless assertions * Reduced casts to Disk* * Updated sector size list argument * Removed obsolete casts * Removed comment
2022-02-27 21:58:01 +00:00
if (!changeable) {
time_t t = time(nullptr);
tm localtime;
localtime_r(&t, &localtime);
mode_page_datetime datetime;
datetime.major_version = 0x01;
datetime.minor_version = 0x00;
datetime.year = (uint8_t)localtime.tm_year;
datetime.month = (uint8_t)localtime.tm_mon;
datetime.day = (uint8_t)localtime.tm_mday;
datetime.hour = (uint8_t)localtime.tm_hour;
datetime.minute = (uint8_t)localtime.tm_min;
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
// Ignore leap second for simplicity
datetime.second = (uint8_t)(localtime.tm_sec < 60 ? localtime.tm_sec : 59);
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
memcpy(&pages[32][2], &datetime, sizeof(datetime));
}
Host services (SCHS) with realtime clock and shutdown, improved device inheritance (#647) * Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
2022-02-10 18:54:48 +00:00
}