From 54e43788c83d585c5a7b64a4fc68c8e656085638 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Wed, 6 Mar 2024 10:11:30 +0100 Subject: [PATCH] Release 3.0.1 --- cpp/controllers/generic_controller.cpp | 34 +++++++++++++------------- cpp/protobuf/command_context.h | 6 ++++- cpp/s2p/s2p_core.cpp | 4 +++ cpp/shared/s2p_util.cpp | 2 +- cpp/shared/s2p_version.cpp | 2 +- cpp/test/s2p_util_test.cpp | 11 --------- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/cpp/controllers/generic_controller.cpp b/cpp/controllers/generic_controller.cpp index 9a085655..22e594cc 100644 --- a/cpp/controllers/generic_controller.cpp +++ b/cpp/controllers/generic_controller.cpp @@ -139,35 +139,35 @@ void GenericController::Execute() ResetOffset(); SetTransferSize(0, 0); - int lun = GetEffectiveLun(); - if (!GetDeviceForLun(lun)) { - if (GetOpcode() != scsi_command::cmd_inquiry && GetOpcode() != scsi_command::cmd_request_sense) { + const auto opcode = GetOpcode(); + + auto device = GetDeviceForLun(GetEffectiveLun()); + const bool has_lun = device != nullptr; + + if (!has_lun) { + if (opcode != scsi_command::cmd_inquiry && opcode != scsi_command::cmd_request_sense) { Error(sense_key::illegal_request, asc::invalid_lun); return; } - assert(GetDeviceForLun(0)); - - lun = 0; - } - - // SCSI-2 section 8.2.5.1: Incorrect logical unit handling - if (GetOpcode() == scsi_command::cmd_inquiry && !GetDeviceForLun(lun)) { - GetBuffer().data()[0] = 0x7f; - return; + device = GetDeviceForLun(0); + assert(device); } - auto device = GetDeviceForLun(lun); - // Discard pending sense data from the previous command if the current command is not REQUEST SENSE - if (GetOpcode() != scsi_command::cmd_request_sense) { + if (opcode != scsi_command::cmd_request_sense) { SetStatus(status::good); device->SetStatus(sense_key::no_sense, asc::no_additional_sense_information); } - if (device->CheckReservation(initiator_id, GetOpcode(), GetCdbByte(4) & 0x01)) { + if (device->CheckReservation(GetInitiatorId(), opcode, GetCdbByte(4) & 0x01)) { try { - device->Dispatch(GetOpcode()); + device->Dispatch(opcode); + + // SCSI-2 section 8.2.5.1: Incorrect logical unit handling + if (opcode == scsi_command::cmd_inquiry && !has_lun) { + GetBuffer().data()[0] = 0x7f; + } } catch (const scsi_exception &e) { Error(e.get_sense_key(), e.get_asc()); diff --git a/cpp/protobuf/command_context.h b/cpp/protobuf/command_context.h index c45e6dbd..5d096a44 100644 --- a/cpp/protobuf/command_context.h +++ b/cpp/protobuf/command_context.h @@ -2,7 +2,7 @@ // // SCSI target emulator and SCSI tools for the Raspberry Pi // -// Copyright (C) 2021-2023 Uwe Seimet +// Copyright (C) 2021-2024 Uwe Seimet // //--------------------------------------------------------------------------- @@ -35,6 +35,10 @@ class CommandContext { default_folder = f; } + void SetLocale(string_view l) + { + locale = l; + } bool ReadCommand(); void WriteResult(const PbResult&) const; bool WriteSuccessResult(PbResult&) const; diff --git a/cpp/s2p/s2p_core.cpp b/cpp/s2p/s2p_core.cpp index 49ee8a56..bf76e51d 100644 --- a/cpp/s2p/s2p_core.cpp +++ b/cpp/s2p/s2p_core.cpp @@ -431,6 +431,10 @@ void S2p::ProcessScsiCommands() bool S2p::ExecuteCommand(CommandContext &context) { + if (const string &locale = GetParam(context.GetCommand(), "locale"); !locale.empty()) { + context.SetLocale(locale); + } + if (!access_token.empty() && access_token != GetParam(context.GetCommand(), "token")) { return context.ReturnLocalizedError(LocalizationKey::ERROR_AUTHENTICATION, UNAUTHORIZED); } diff --git a/cpp/shared/s2p_util.cpp b/cpp/shared/s2p_util.cpp index 37070d4e..dcf9af89 100644 --- a/cpp/shared/s2p_util.cpp +++ b/cpp/shared/s2p_util.cpp @@ -98,7 +98,7 @@ string s2p_util::ToLower(const string &s) string s2p_util::GetLocale() { - const char *locale = setlocale(LC_MESSAGES, nullptr); + const char *locale = setlocale(LC_MESSAGES, ""); if (locale == nullptr || !strcmp(locale, "C") || !strcmp(locale, "POSIX")) { locale = "en"; } diff --git a/cpp/shared/s2p_version.cpp b/cpp/shared/s2p_version.cpp index b886eece..b8c1ad39 100644 --- a/cpp/shared/s2p_version.cpp +++ b/cpp/shared/s2p_version.cpp @@ -10,5 +10,5 @@ const int s2p_major_version = 3; const int s2p_minor_version = 0; -const int s2p_revision = 0; +const int s2p_revision = 1; const std::string s2p_suffix = ""; diff --git a/cpp/test/s2p_util_test.cpp b/cpp/test/s2p_util_test.cpp index 7a8ec72f..b66a0b28 100644 --- a/cpp/test/s2p_util_test.cpp +++ b/cpp/test/s2p_util_test.cpp @@ -54,17 +54,6 @@ TEST(S2pUtilTest, ToLower) EXPECT_EQ("abc", ToLower("ABC")); } -TEST(S2pUtilTest, GetLocale) -{ - EXPECT_LE(2U, GetLocale().size()); - - setlocale(LC_MESSAGES, "C"); - EXPECT_EQ("en", GetLocale()); - - setlocale(LC_MESSAGES, "POSIX"); - EXPECT_EQ("en", GetLocale()); -} - TEST(S2pUtilTest, ProcessId) { int id = -1;