From 7147d757439e8b72a206acee07e8e168ec9b9648 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Fri, 29 Mar 2024 18:43:08 +0100 Subject: [PATCH] Release 3.1.1 --- cpp/command/command_executor.cpp | 21 ++++++++++++++------- cpp/devices/disk.cpp | 13 +++++++++++++ cpp/s2p/s2p_core.cpp | 2 +- cpp/s2p/s2p_parser.cpp | 14 +++++++------- cpp/s2pdump/s2pdump_core.cpp | 2 +- cpp/shared/s2p_version.cpp | 2 +- cpp/test/s2p_parser_test.cpp | 8 ++++---- 7 files changed, 41 insertions(+), 21 deletions(-) diff --git a/cpp/command/command_executor.cpp b/cpp/command/command_executor.cpp index 5d7ec066..5518d4d0 100644 --- a/cpp/command/command_executor.cpp +++ b/cpp/command/command_executor.cpp @@ -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; @@ -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 @@ -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); @@ -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)); } @@ -399,7 +407,7 @@ 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(device); if (disk && disk->GetConfiguredSectorSize()) { @@ -407,12 +415,11 @@ void CommandExecutor::SetUpDeviceProperties(const CommandContext &context, share } 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 p; diff --git a/cpp/devices/disk.cpp b/cpp/devices/disk.cpp index 2ba581f8..2039e1d8 100644 --- a/cpp/devices/disk.cpp +++ b/cpp/devices/disk.cpp @@ -638,6 +638,14 @@ void Disk::ModeSelect(scsi_command cmd, cdb_t cdb, span buf, int // Set up the available pages in order to check for the right page size below map> 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) { @@ -648,6 +656,11 @@ void Disk::ModeSelect(scsi_command cmd, cdb_t cdb, span 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); } diff --git a/cpp/s2p/s2p_core.cpp b/cpp/s2p/s2p_core.cpp index 1eaef74a..6c73af0b 100644 --- a/cpp/s2p/s2p_core.cpp +++ b/cpp/s2p/s2p_core.cpp @@ -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") { diff --git a/cpp/s2p/s2p_parser.cpp b/cpp/s2p/s2p_parser.cpp index d56a9ea6..9685ede3 100644 --- a/cpp/s2p/s2p_parser.cpp +++ b/cpp/s2p/s2p_parser.cpp @@ -107,7 +107,7 @@ property_map S2pParser::ParseArguments(span 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; @@ -159,7 +159,7 @@ property_map S2pParser::ParseArguments(span initial_args, bool &has_sasi) continue; case 'n': - product_data = optarg; + name = optarg; continue; case 't': @@ -211,8 +211,8 @@ property_map S2pParser::ParseArguments(span 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; @@ -221,7 +221,7 @@ property_map S2pParser::ParseArguments(span initial_args, bool &has_sasi) id_lun = ""; type = ""; scsi_level = ""; - product_data = ""; + name = ""; block_size = ""; caching_mode = ""; } @@ -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; diff --git a/cpp/s2pdump/s2pdump_core.cpp b/cpp/s2pdump/s2pdump_core.cpp index 2ae313a5..fe09729a 100644 --- a/cpp/s2pdump/s2pdump_core.cpp +++ b/cpp/s2pdump/s2pdump_core.cpp @@ -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; diff --git a/cpp/shared/s2p_version.cpp b/cpp/shared/s2p_version.cpp index e1fb28ec..65a5c7d4 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 = 1; -const int s2p_revision = 0; +const int s2p_revision = 1; const std::string s2p_suffix = ""; diff --git a/cpp/test/s2p_parser_test.cpp b/cpp/test/s2p_parser_test.cpp index 93c20263..4483c126 100644 --- a/cpp/test/s2p_parser_test.cpp +++ b/cpp/test/s2p_parser_test.cpp @@ -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"]); } @@ -203,7 +203,7 @@ 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"); @@ -211,7 +211,7 @@ 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("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"); @@ -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");