Skip to content

Commit

Permalink
Release 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Mar 6, 2024
1 parent bbad56e commit 54e4378
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
34 changes: 17 additions & 17 deletions cpp/controllers/generic_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion cpp/protobuf/command_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions cpp/s2p/s2p_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/shared/s2p_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/shared/s2p_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
11 changes: 0 additions & 11 deletions cpp/test/s2p_util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 54e4378

Please sign in to comment.