Resolve TODO

This commit is contained in:
Uwe Seimet 2023-09-29 16:29:00 +02:00
parent ce383c5a9c
commit e0d2bcc088
5 changed files with 18 additions and 15 deletions

View File

@ -61,9 +61,6 @@ protected:
void AddCommand(scsi_command, const operation&);
// TODO Try to get rid of this accessor
const DeviceLogger& GetLogger() const { return device_logger; }
vector<uint8_t> HandleInquiry(scsi_defs::device_type, scsi_level, bool) const;
virtual vector<uint8_t> InquiryInternal() const = 0;
void CheckReady();

View File

@ -8,26 +8,26 @@
//---------------------------------------------------------------------------
#include "shared/piscsi_exceptions.h"
#include "device_logger.h"
#include "scsi_command_util.h"
#include <spdlog/spdlog.h>
#include <cstring>
#include <sstream>
#include <iomanip>
using namespace scsi_defs;
// TODO Get rid of the logger argument
void scsi_command_util::ModeSelect(const DeviceLogger& logger, scsi_command cmd, cdb_t cdb, span<const uint8_t> buf,
int length, int sector_size)
string scsi_command_util::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, int length, int sector_size)
{
assert(cmd == scsi_command::eCmdModeSelect6 || cmd == scsi_command::eCmdModeSelect10);
assert(length >= 0);
string result;
// PF
if (!(cdb[1] & 0x10)) {
// Vendor-specific parameters (SCSI-1) are not supported.
// Do not report an error in order to support Apple's HD SC Setup.
return;
return result;
}
// Skip block descriptors
@ -56,7 +56,7 @@ void scsi_command_util::ModeSelect(const DeviceLogger& logger, scsi_command cmd,
if (GetInt16(buf, offset + 12) != sector_size) {
// With piscsi it is not possible to permanently (by formatting) change the sector size,
// because the size is an externally configurable setting only
logger.Warn("In order to change the sector size use the -b option when launching piscsi");
spdlog::warn("In order to change the sector size use the -b option when launching piscsi");
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}
@ -65,7 +65,7 @@ void scsi_command_util::ModeSelect(const DeviceLogger& logger, scsi_command cmd,
else {
stringstream s;
s << "Unknown MODE SELECT page code: $" << setfill('0') << setw(2) << hex << page;
logger.Warn(s.str());
result = s.str();
}
// Advance to the next page
@ -78,6 +78,8 @@ void scsi_command_util::ModeSelect(const DeviceLogger& logger, scsi_command cmd,
if (!has_valid_page_code) {
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}
return result;
}
void scsi_command_util::EnrichFormatPage(map<int, vector<byte>>& pages, bool changeable, int sector_size)

View File

@ -20,11 +20,9 @@
using namespace std;
class DeviceLogger;
namespace scsi_command_util
{
void ModeSelect(const DeviceLogger&, scsi_defs::scsi_command, cdb_t, span<const uint8_t>, int, int);
string ModeSelect(scsi_defs::scsi_command, cdb_t, span<const uint8_t>, int, int);
void EnrichFormatPage(map<int, vector<byte>>&, bool, int);
void AddAppleVendorModePage(map<int, vector<byte>>&, bool);

View File

@ -86,7 +86,10 @@ vector<uint8_t> SCSIHD::InquiryInternal() const
void SCSIHD::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, int length) const
{
scsi_command_util::ModeSelect(GetLogger(), cmd, cdb, buf, length, 1 << GetSectorSizeShiftCount());
if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, 1 << GetSectorSizeShiftCount());
!result.empty()) {
LogWarn(result);
}
}
void SCSIHD::AddFormatPage(map<int, vector<byte>>& pages, bool changeable) const

View File

@ -92,7 +92,10 @@ void SCSIMO::AddOptionPage(map<int, vector<byte>>& pages, bool) const
void SCSIMO::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, int length) const
{
scsi_command_util::ModeSelect(GetLogger(), cmd, cdb, buf, length, 1 << GetSectorSizeShiftCount());
if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, 1 << GetSectorSizeShiftCount());
!result.empty()) {
LogWarn(result);
}
}
//