Skip to content

Commit

Permalink
Releasse 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 6, 2024
1 parent 5e50862 commit 1ec203f
Show file tree
Hide file tree
Showing 35 changed files with 245 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ jobs:
--define sonar.host.url=$SONAR_SERVER_URL \
--define sonar.projectKey=$SONAR_PROJECT_KEY \
--define sonar.organization=$SONAR_ORGANIZATION \
--define sonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR \
--define sonar.scm.provider=git \
--define sonar.sourceEncoding=UTF-8 \
--define sonar.cfamily.compile-commands=$BUILD_WRAPPER_OUT_DIR/compile_commands.json \
--define sonar.cfamily.gcov.reportsPath=. \
--define sonar.c.file.suffixes= \
--define sonar.cpp.file.suffixes=.cpp,.h \
Expand Down
7 changes: 6 additions & 1 deletion cpp/base/primary_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void PrimaryDevice::Dispatch(scsi_command cmd)
command();
}
else {
LogTrace(fmt::format("Received unsupported command: ${:02x}", static_cast<int>(cmd)));
LogTrace(fmt::format("Device received unsupported command: ${:02x}", static_cast<int>(cmd)));
throw scsi_exception(sense_key::illegal_request, asc::invalid_command_operation_code);
}
}
Expand Down Expand Up @@ -175,6 +175,11 @@ void PrimaryDevice::ReportLuns()

void PrimaryDevice::RequestSense()
{
// The descriptor format is not supported
if (GetController()->GetCdb()[1] & 0x01) {
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_cdb);
}

int effective_lun = GetController()->GetEffectiveLun();

// According to the specification the LUN handling for REQUEST SENSE for non-existing LUNs does not result
Expand Down
1 change: 1 addition & 0 deletions cpp/buses/bus_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ BusFactory::BusFactory()
AddCommand(scsi_command::start_stop, 6, "START STOP UNIT/STOP PRINT");
AddCommand(scsi_command::send_diagnostic, 6, "SEND DIAGNOSTIC");
AddCommand(scsi_command::prevent_allow_medium_removal, 6, "PREVENT ALLOW MEDIUM REMOVAL");
AddCommand(scsi_command::read_format_capacities, 10, "READ FORMAT CAPACITIES");
AddCommand(scsi_command::read_capacity10, 10, "READ CAPACITY(10)");
AddCommand(scsi_command::read10, 10, "READ(10)");
AddCommand(scsi_command::write10, 10, "WRITE(10)");
Expand Down
24 changes: 14 additions & 10 deletions cpp/command/command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool CommandExecutor::Attach(const CommandContext &context, const PbDeviceDefini

const string &filename = GetParam(pb_device, "file");

const auto device = CreateDevice(context, type, lun, filename);
const auto device = CreateDevice(context, pb_device, filename);
if (!device) {
return false;
}
Expand Down Expand Up @@ -447,10 +447,10 @@ void CommandExecutor::DisplayDeviceInfo(const PrimaryDevice &device)
info(msg);
}

string CommandExecutor::SetReservedIds(string_view ids)
string CommandExecutor::SetReservedIds(const string &ids)
{
set<int> ids_to_reserve;
stringstream ss(ids.data());
stringstream ss(ids);
string id;
while (getline(ss, id, ',')) {
int res_id;
Expand Down Expand Up @@ -507,7 +507,9 @@ bool CommandExecutor::ValidateImageFile(const CommandContext &context, StorageDe
try {
storage_device.Open();
}
catch (const io_exception&) {
catch (const io_exception& e) {
error(e.what());

return context.ReturnLocalizedError(LocalizationKey::ERROR_FILE_OPEN, storage_device.GetFilename());
}
#endif
Expand Down Expand Up @@ -611,16 +613,18 @@ bool CommandExecutor::EnsureLun0(const CommandContext &context, const PbCommand
true : context.ReturnLocalizedError(LocalizationKey::ERROR_MISSING_LUN0, to_string((*it).first));
}

shared_ptr<PrimaryDevice> CommandExecutor::CreateDevice(const CommandContext &context, const PbDeviceType type,
int lun, const string &filename) const
shared_ptr<PrimaryDevice> CommandExecutor::CreateDevice(const CommandContext &context,
const PbDeviceDefinition &pb_device, const string &filename) const
{
auto device = DeviceFactory::Instance().CreateDevice(type, lun, filename);
auto device = DeviceFactory::Instance().CreateDevice(pb_device.type(), pb_device.unit(), filename);
if (!device) {
if (type == UNDEFINED) {
context.ReturnLocalizedError(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, filename);
if (pb_device.type() == UNDEFINED) {
context.ReturnLocalizedError(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, to_string(pb_device.id()),
to_string(pb_device.unit()), filename);
}
else {
context.ReturnLocalizedError(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, PbDeviceType_Name(type));
context.ReturnLocalizedError(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, to_string(pb_device.id()),
to_string(pb_device.unit()), PbDeviceType_Name(pb_device.type()));
}

return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions cpp/command/command_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class CommandExecutor
bool Insert(const CommandContext&, const PbDeviceDefinition&, const shared_ptr<PrimaryDevice>&, bool) const;
bool Detach(const CommandContext&, PrimaryDevice&, bool) const;
void DetachAll() const;
string SetReservedIds(string_view);
string SetReservedIds(const string&);
bool ValidateImageFile(const CommandContext&, StorageDevice&, const string&) const;
bool EnsureLun0(const CommandContext&, const PbCommand&) const;
bool ValidateDevice(const CommandContext&, const PbDeviceDefinition&) const;
shared_ptr<PrimaryDevice> CreateDevice(const CommandContext&, const PbDeviceType, int, const string&) const;
shared_ptr<PrimaryDevice> CreateDevice(const CommandContext&, const PbDeviceDefinition&, const string&) const;
bool SetBlockSize(const CommandContext&, shared_ptr<PrimaryDevice>, int) const;

mutex& GetExecutionLocker()
Expand Down
28 changes: 15 additions & 13 deletions cpp/command/command_localizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,24 @@ CommandLocalizer::CommandLocalizer()
Add(LocalizationKey::ERROR_NON_EXISTING_UNIT, "es", "Comando para ID %1 inexistente, unidad %2");
Add(LocalizationKey::ERROR_NON_EXISTING_UNIT, "zh", "不存在的 ID %1, 单元 %2 的指令");

Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "en", "Unknown device type %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "de", "Unbekannter Gerätetyp %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "sv", "Obekant enhetstyp: %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "fr", "Type de périphérique inconnu %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "es", "Tipo de dispositivo desconocido %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "zh", "未知设备类型 %1");

Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "en", "Device type required for unknown extension of file '%1'");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "en", "%1:%2: Unknown device type %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "de", "%1:%2: Unbekannter Gerätetyp %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "sv", "%1:%2: Obekant enhetstyp: %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "fr", "%1:%2: Type de périphérique inconnu %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "es", "%1:%2: Tipo de dispositivo desconocido %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "zh", "%1:%2: 未知设备类型 %1");

Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "en",
"%1:%2: Device type required for unknown extension of file '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "de",
"Gerätetyp erforderlich für unbekannte Extension der Datei '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "sv", "Man måste ange enhetstyp för obekant filändelse '%1'");
"%1:%2: Gerätetyp erforderlich für unbekannte Extension der Datei '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "sv",
"%1:%2: Man måste ange enhetstyp för obekant filändelse '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "fr",
"Type de périphérique requis pour extension inconnue du fichier '%1'");
"%1:%2: Type de périphérique requis pour extension inconnue du fichier '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "es",
"Tipo de dispositivo requerido para la extensión desconocida del archivo '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "zh", "文件'%1'的未知扩展名所需的设备类型");
"%1:%2: Tipo de dispositivo requerido para la extensión desconocida del archivo '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "zh", "%1:%2: 文件'%1'的未知扩展名所需的设备类型");

Add(LocalizationKey::ERROR_DUPLICATE_ID, "en", "Duplicate ID %1, unit %2");
Add(LocalizationKey::ERROR_DUPLICATE_ID, "de", "Doppelte ID %1, Einheit %2");
Expand Down
4 changes: 3 additions & 1 deletion cpp/command/command_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ void CommandResponse::GetDeviceProperties(shared_ptr<PrimaryDevice> device, PbDe

if (device->SupportsParams()) {
for (const auto& [key, value] : device->GetDefaultParams()) {
(*properties.mutable_default_params())[key] = value;
if (!value.empty()) {
(*properties.mutable_default_params())[key] = value;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/controllers/abstract_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AbstractController : public PhaseHandler
shutdown_mode ProcessOnController(int);

void CopyToBuffer(const void*, size_t);
auto& GetBuffer()
auto& GetBuffer() const
{
return buffer;
}
Expand Down Expand Up @@ -140,8 +140,8 @@ class AbstractController : public PhaseHandler

array<int, 16> cdb = { };

// Transfer data buffer, dynamically resized, initial size matches the biggest block size supported
vector<uint8_t> buffer = vector<uint8_t>(4096);
// Shared ransfer data buffer, dynamically resized
inline static vector<uint8_t> buffer = vector<uint8_t>(512);
// Transfer offset
int offset = 0;
// Total number of bytes to be transferred
Expand Down
2 changes: 1 addition & 1 deletion cpp/controllers/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Controller::Command()
const int actual_count = GetBus().CommandHandShake(buf);
if (actual_count <= 0) {
if (!actual_count) {
LogDebug(fmt::format("Received unknown command: ${:02x}", buf[0]));
LogDebug(fmt::format("Controller received unknown command: ${:02x}", buf[0]));
Error(sense_key::illegal_request, asc::invalid_command_operation_code);
}
else {
Expand Down
33 changes: 30 additions & 3 deletions cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace memory_util;
using namespace s2p_util;

Disk::Disk(PbDeviceType type, scsi_level level, int lun, bool supports_mode_select, bool supports_save_parameters,
const unordered_set<uint32_t> &s)
const set<uint32_t> &s)
: StorageDevice(type, level, lun, supports_mode_select, supports_save_parameters, s)
{
SetStoppable(true);
Expand Down Expand Up @@ -115,6 +115,10 @@ bool Disk::SetUp()
{
ReadCapacity16_ReadLong16();
});
AddCommand(scsi_command::read_format_capacities, [this]
{
ReadFormatCapacities();
});

return StorageDevice::SetUp();
}
Expand Down Expand Up @@ -175,8 +179,8 @@ void Disk::FormatUnit()
{
CheckReady();

// FMTDATA=1 is not supported (but OK if there is no DEFECT LIST)
if ((GetCdbByte(1) & 0x10) && GetCdbByte(4)) {
// FMTDATA is not supported
if (GetCdbByte(1) & 0x10) {
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_cdb);
}

Expand Down Expand Up @@ -504,6 +508,29 @@ void Disk::ReadCapacity16()
DataInPhase(min(32, static_cast<int>(GetCdbInt32(10))));
}

void Disk::ReadFormatCapacities()
{
CheckReady();

auto &buf = GetController()->GetBuffer();
SetInt32(buf, 4, static_cast<uint32_t>(GetBlockCount()));
SetInt32(buf, 8, GetBlockSize());

int offset = 12;
if (!IsReadOnly()) {
// Return the list of default block sizes
for (const auto size : GetSupportedBlockSizes()) {
SetInt32(buf, offset, static_cast<uint32_t>(GetBlockSize() * GetBlockCount() / size));
SetInt32(buf, offset + 4, size);
offset += 8;
}
}

SetInt32(buf, 0, offset - 4);

DataInPhase(min(offset, GetCdbInt16(7)));
}

void Disk::ReadCapacity16_ReadLong16()
{
// The service action determines the actual command
Expand Down
3 changes: 2 additions & 1 deletion cpp/devices/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Disk : public StorageDevice, public ScsiBlockCommands

protected:

Disk(PbDeviceType, scsi_level, int, bool, bool, const unordered_set<uint32_t>&);
Disk(PbDeviceType, scsi_level, int, bool, bool, const set<uint32_t>&);

void ValidateFile() override;

Expand Down Expand Up @@ -106,6 +106,7 @@ class Disk : public StorageDevice, public ScsiBlockCommands
void Seek10();
void ReadCapacity10() override;
void ReadCapacity16() override;
void ReadFormatCapacities();
void FormatUnit() override;
void Seek6();
void Read(access_mode);
Expand Down
15 changes: 9 additions & 6 deletions cpp/devices/sasi_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "sasi_hd.h"
#include "shared/s2p_exceptions.h"

SasiHd::SasiHd(int lun, const unordered_set<uint32_t> &sector_sizes) : Disk(SAHD, scsi_level::none, lun, false, false,
SasiHd::SasiHd(int lun, const set<uint32_t> &sector_sizes) : Disk(SAHD, scsi_level::none, lun, false, false,
sector_sizes)
{
SetProduct("SASI HD");
Expand Down Expand Up @@ -42,17 +42,20 @@ void SasiHd::Inquiry()
vector<uint8_t> SasiHd::InquiryInternal() const
{
assert(false);
return vector<uint8_t>();
return {};
}

void SasiHd::RequestSense()
{
// Transfer 4 bytes when size is 0 (Shugart Associates System Interface specification)
//vector<uint8_t> buf(allocation_length ? allocation_length : 4);
// Transfer 4 bytes when size is 0 (SASI specification)
int allocation_length = GetCdbByte(4);
if (!allocation_length) {
allocation_length = 4;
}

// SASI fixed to non-extended format
// Non-extended format
const array<uint8_t, 4> buf = { static_cast<uint8_t>(GetSenseKey()), static_cast<uint8_t>(GetLun() << 5) };
GetController()->CopyToBuffer(buf.data(), buf.size());
GetController()->CopyToBuffer(buf.data(), allocation_length);

DataInPhase(buf.size());
}
2 changes: 1 addition & 1 deletion cpp/devices/sasi_hd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SasiHd : public Disk

public:

explicit SasiHd(int, const unordered_set<uint32_t>& = { 256, 512, 1024 });
explicit SasiHd(int, const set<uint32_t>& = { 256, 512, 1024 });
~SasiHd() override = default;

void Open() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using namespace memory_util;

ScsiHd::ScsiHd(int lun, bool removable, bool apple, bool scsi1, const unordered_set<uint32_t> &sector_sizes)
ScsiHd::ScsiHd(int lun, bool removable, bool apple, bool scsi1, const set<uint32_t> &sector_sizes)
: Disk(removable ? SCRM : SCHD, scsi1 ? scsi_level::scsi_1_ccs : scsi_level::scsi_2, lun, true, true, sector_sizes)
{
// Some Apple tools require a particular drive identification.
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_hd.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ScsiHd : public Disk

public:

ScsiHd(int, bool, bool, bool, const unordered_set<uint32_t>& = { 512, 1024, 2048, 4096 });
ScsiHd(int, bool, bool, bool, const set<uint32_t>& = { 512, 1024, 2048, 4096 });
~ScsiHd() override = default;

void FinalizeSetup();
Expand Down
Loading

0 comments on commit 1ec203f

Please sign in to comment.