Skip to content

Commit

Permalink
Release 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Mar 29, 2024
1 parent 32f65be commit 7147d75
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
21 changes: 14 additions & 7 deletions cpp/command/command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ bool CommandExecutor::Eject(PrimaryDevice &device) const

if (!device.Eject(true)) {
warn("Ejecting {} failed", GetIdentifier(device));
return true;
}

PropertyHandler::Instance().RemoveProperties(fmt::format("device.{0}:{1}.params", device.GetId(), device.GetLun()));
if (!device.GetLun()) {
PropertyHandler::Instance().RemoveProperties(fmt::format("device.{}.params", device.GetId()));
}

return true;
Expand Down Expand Up @@ -343,6 +349,8 @@ bool CommandExecutor::Insert(const CommandContext &context, const PbDeviceDefini
storage_device->SetProtected(pb_device.protected_());
#endif

SetUpDeviceProperties(context, device);

return true;
}
#pragma GCC diagnostic pop
Expand All @@ -361,9 +369,9 @@ bool CommandExecutor::Detach(const CommandContext &context, PrimaryDevice &devic

if (!dryRun) {
// Remember some device data before they become invalid on removal
const string &identifier = GetIdentifier(device);
const int id = device.GetId();
const int lun = device.GetLun();
const string &identifier = GetIdentifier(device);

if (!controller->RemoveDevice(device)) {
return context.ReturnLocalizedError(LocalizationKey::ERROR_DETACH);
Expand All @@ -375,7 +383,7 @@ bool CommandExecutor::Detach(const CommandContext &context, PrimaryDevice &devic
}

// Consider both potential identifiers if the LUN is 0
PropertyHandler::Instance().RemoveProperties(fmt::format("device.{}.", identifier));
PropertyHandler::Instance().RemoveProperties(fmt::format("device.{0}:{1}.", id, lun));
if (!lun) {
PropertyHandler::Instance().RemoveProperties(fmt::format("device.{}.", id));
}
Expand All @@ -399,20 +407,19 @@ void CommandExecutor::SetUpDeviceProperties(const CommandContext &context, share
{
const string &identifier = fmt::format("device.{0}:{1}.", device->GetId(), device->GetLun());
PropertyHandler::Instance().AddProperty(identifier + "type", device->GetTypeString());
PropertyHandler::Instance().AddProperty(identifier + "product",
PropertyHandler::Instance().AddProperty(identifier + "name",
device->GetVendor() + ":" + device->GetProduct() + ":" + device->GetRevision());
const auto disk = dynamic_pointer_cast<Disk>(device);
if (disk && disk->GetConfiguredSectorSize()) {
PropertyHandler::Instance().AddProperty(identifier + "block_size", to_string(disk->GetConfiguredSectorSize()));

}
if (disk && !disk->GetFilename().empty()) {
if (string filename = disk->GetFilename(); filename.starts_with(context.GetDefaultFolder())) {
string filename = disk->GetFilename();
if (filename.starts_with(context.GetDefaultFolder())) {
filename = filename.substr(context.GetDefaultFolder().length() + 1);
}
else {
PropertyHandler::Instance().AddProperty(identifier + "params", filename);
}
PropertyHandler::Instance().AddProperty(identifier + "params", filename);
}
else if (!device->GetParams().empty()) {
vector<string> p;
Expand Down
13 changes: 13 additions & 0 deletions cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,14 @@ void Disk::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, int
// Set up the available pages in order to check for the right page size below
map<int, vector<byte>> pages;
SetUpModePages(pages, 0x3f, true);
for (const auto& [p, data] : PropertyHandler::Instance().GetCustomModePages(GetVendor(), GetProduct())) {
if (data.empty()) {
pages.erase(p);
}
else {
pages[p] = data;
}
}

// Parse the pages
while (length > 0) {
Expand All @@ -648,6 +656,11 @@ void Disk::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, int
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}

// Page 0 can contain anything and can have any length
if (!page_code) {
break;
}

if (length < 2) {
throw scsi_exception(sense_key::illegal_request, asc::parameter_list_length_error);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/s2p/s2p_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void S2p::SetDeviceProperties(PbDeviceDefinition &device, const string &key, con
else if (key == "caching_mode") {
device.set_caching_mode(ParseCachingMode(value));
}
else if (key == "product_data") {
else if (key == "name") {
SetProductData(device, value);
}
else if (key == "params") {
Expand Down
14 changes: 7 additions & 7 deletions cpp/s2p/s2p_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ property_map S2pParser::ParseArguments(span<char*> initial_args, bool &has_sasi)
string id_lun;
string type;
string scsi_level;
string product_data;
string name;
string block_size;
string caching_mode;
bool blue_scsi_mode = false;
Expand Down Expand Up @@ -159,7 +159,7 @@ property_map S2pParser::ParseArguments(span<char*> initial_args, bool &has_sasi)
continue;

case 'n':
product_data = optarg;
name = optarg;
continue;

case 't':
Expand Down Expand Up @@ -211,8 +211,8 @@ property_map S2pParser::ParseArguments(span<char*> initial_args, bool &has_sasi)
if (!scsi_level.empty()) {
properties[device_key + "scsi_level"] = scsi_level;
}
if (!product_data.empty()) {
properties[device_key + "product_data"] = product_data;
if (!name.empty()) {
properties[device_key + "name"] = name;
}
if (!params.empty()) {
properties[device_key + "params"] = params;
Expand All @@ -221,7 +221,7 @@ property_map S2pParser::ParseArguments(span<char*> initial_args, bool &has_sasi)
id_lun = "";
type = "";
scsi_level = "";
product_data = "";
name = "";
block_size = "";
caching_mode = "";
}
Expand Down Expand Up @@ -283,13 +283,13 @@ string S2pParser::ParseBlueScsiFilename(property_map &properties, const string &
}
// When there is no block_size number after the "_" separator the string is the product data
else {
properties[device_key + "product_data"] = components[1];
properties[device_key + "name"] = components[1];
}
}
properties[device_key + "block_size"] = block_size;

if (components.size() > 2) {
properties[device_key + "product_data"] = components[2];
properties[device_key + "name"] = components[2];
}

return device_key;
Expand Down
2 changes: 1 addition & 1 deletion cpp/s2pdump/s2pdump_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ void S2pDump::DisplayProperties(int id, int lun) const
cout << id_and_lun << "block_size=" << scsi_device_info.sector_size << "\n";
}

cout << id_and_lun << "product_name=" << regex_replace(scsi_device_info.vendor, regex(" +$"), "") << ":"
cout << id_and_lun << "name=" << regex_replace(scsi_device_info.vendor, regex(" +$"), "") << ":"
<< regex_replace(scsi_device_info.product, regex(" +$"), "") << ":"
<< regex_replace(scsi_device_info.revision, regex(" +$"), "") << "\n" << flush;

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 = 1;
const int s2p_revision = 0;
const int s2p_revision = 1;
const std::string s2p_suffix = "";
8 changes: 4 additions & 4 deletions cpp/test/s2p_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ TEST(S2pParserTest, ParseArguments_SCSI2Pi)
SetUpArgs(args, "-i1", "-n", "a:b:c", "test.hds");
properties = parser.ParseArguments(args, is_sasi);
EXPECT_EQ(2UL, properties.size());
EXPECT_EQ("a:b:c", properties["device.1.product_data"]);
EXPECT_EQ("a:b:c", properties["device.1.name"]);
EXPECT_EQ("test.hds", properties["device.1.params"]);
}

Expand Down Expand Up @@ -203,15 +203,15 @@ TEST(S2pParserTest, ParseArguments_BlueSCSI)
EXPECT_EQ(4UL, properties.size());
EXPECT_EQ("schd", properties["device.2.type"]);
EXPECT_EQ("512", properties["device.2.block_size"]);
EXPECT_EQ("vendor:product:revision", properties["device.2.product_data"]);
EXPECT_EQ("vendor:product:revision", properties["device.2.name"]);
EXPECT_EQ("HD2_vendor:product:revision.hds", properties["device.2.params"]);

SetUpArgs(args, "-B", "-n", "v:p:r", "HD2_vendor:product:revision.hds");
properties = parser.ParseArguments(args, is_sasi);
EXPECT_EQ(4UL, properties.size());
EXPECT_EQ("schd", properties["device.2.type"]);
EXPECT_EQ("512", properties["device.2.block_size"]);
EXPECT_EQ("v:p:r", properties["device.2.product_data"]) << "Explicit product data provided";
EXPECT_EQ("v:p:r", properties["device.2.name"]) << "Explicit product data provided";
EXPECT_EQ("HD2_vendor:product:revision.hds", properties["device.2.params"]);

SetUpArgs(args, "-B", "HD2vendor:product:revision.hds");
Expand All @@ -226,7 +226,7 @@ TEST(S2pParserTest, ParseArguments_BlueSCSI)
EXPECT_EQ(4UL, properties.size());
EXPECT_EQ("schd", properties["device.2.type"]);
EXPECT_EQ("4096", properties["device.2.block_size"]);
EXPECT_EQ("vendor:product:revision", properties["device.2.product_data"]);
EXPECT_EQ("vendor:product:revision", properties["device.2.name"]);
EXPECT_EQ("HD2_4096_vendor:product:revision.hds", properties["device.2.params"]);

SetUpArgs(args, "-B", "HD1.hds", "-B", "RE131.hds");
Expand Down

0 comments on commit 7147d75

Please sign in to comment.