mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-26 22:05:34 +00:00
Support NVMe behind USB bridges.
This commit is contained in:
@@ -213,6 +213,21 @@ hz::ExpectedVoid<SmartctlParserError> SmartctlJsonAtaParser::parse_section_info(
|
||||
}
|
||||
},
|
||||
|
||||
{"device/protocol", _("Smartctl Device Protocol"), // NVMe, ...
|
||||
[](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name)
|
||||
-> hz::ExpectedValue<StorageProperty, SmartctlParserError>
|
||||
{
|
||||
if (auto jval = get_node_data<std::string>(root_node, "device/protocol"); jval.has_value()) {
|
||||
StorageProperty p;
|
||||
p.set_name(key, key, displayable_name);
|
||||
p.value = jval.value();
|
||||
p.show_in_ui = false;
|
||||
return p;
|
||||
}
|
||||
return hz::Unexpected(SmartctlParserError::KeyNotFound, std::format("Error getting key {} from JSON data.", key));
|
||||
}
|
||||
},
|
||||
|
||||
{"model_family", _("Model Family"), string_formatter()},
|
||||
{"model_name", _("Device Model"), string_formatter()},
|
||||
{"serial_number", _("Serial Number"), string_formatter()},
|
||||
|
||||
@@ -90,6 +90,21 @@ hz::ExpectedVoid<SmartctlParserError> SmartctlJsonBasicParser::parse_section_bas
|
||||
}
|
||||
},
|
||||
|
||||
{"device/protocol", _("Smartctl Device Protocol"), // NVMe, ...
|
||||
[](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name)
|
||||
-> hz::ExpectedValue<StorageProperty, SmartctlParserError>
|
||||
{
|
||||
if (auto jval = get_node_data<std::string>(root_node, "device/protocol"); jval.has_value()) {
|
||||
StorageProperty p;
|
||||
p.set_name(key, key, displayable_name);
|
||||
p.value = jval.value();
|
||||
p.show_in_ui = false;
|
||||
return p;
|
||||
}
|
||||
return hz::Unexpected(SmartctlParserError::KeyNotFound, std::format("Error getting key {} from JSON data.", key));
|
||||
}
|
||||
},
|
||||
|
||||
{"vendor", _("Vendor"), string_formatter()}, // Flash drive
|
||||
{"scsi_vendor", _("Vendor"), string_formatter()}, // Flash drive
|
||||
|
||||
|
||||
@@ -129,6 +129,21 @@ hz::ExpectedVoid<SmartctlParserError> SmartctlJsonNvmeParser::parse_section_info
|
||||
}
|
||||
},
|
||||
|
||||
{"device/protocol", _("Smartctl Device Protocol"), // NVMe, ...
|
||||
[](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name)
|
||||
-> hz::ExpectedValue<StorageProperty, SmartctlParserError>
|
||||
{
|
||||
if (auto jval = get_node_data<std::string>(root_node, "device/protocol"); jval.has_value()) {
|
||||
StorageProperty p;
|
||||
p.set_name(key, key, displayable_name);
|
||||
p.value = jval.value();
|
||||
p.show_in_ui = false;
|
||||
return p;
|
||||
}
|
||||
return hz::Unexpected(SmartctlParserError::KeyNotFound, std::format("Error getting key {} from JSON data.", key));
|
||||
}
|
||||
},
|
||||
|
||||
{"model_name", _("Device Model"), string_formatter()},
|
||||
{"serial_number", _("Serial Number"), string_formatter()},
|
||||
{"firmware_version", _("Firmware Version"), string_formatter()},
|
||||
|
||||
@@ -597,6 +597,11 @@ void StorageDevice::detect_drive_type_from_properties(const StoragePropertyRepos
|
||||
// Note: USB flash drives in non-scsi mode do not have this property.
|
||||
const auto& smartctl_type = device_type_prop.get_value<std::string>();
|
||||
|
||||
std::string lowercase_protocol;
|
||||
if (auto device_protocol_prop = property_repo.lookup_property("device/protocol"); !device_protocol_prop.empty()) {
|
||||
lowercase_protocol = hz::string_to_lower_copy(device_protocol_prop.get_value<std::string>());
|
||||
}
|
||||
|
||||
if (smartctl_type == "scsi") { // USB flash in scsi mode, optical, scsi, etc.
|
||||
if (BuildEnv::is_kernel_linux() && get_device_base().starts_with("sr")) {
|
||||
set_detected_type(StorageDeviceDetectedType::CdDvd);
|
||||
@@ -616,9 +621,13 @@ void StorageDevice::detect_drive_type_from_properties(const StoragePropertyRepos
|
||||
} else if (smartctl_type == "nvme") { // NVMe SSD
|
||||
set_detected_type(StorageDeviceDetectedType::Nvme);
|
||||
|
||||
// Try protocol (type may be a USB bridge name)
|
||||
} else if (lowercase_protocol == "nvme") { // nvme behind USB bridge like "sntrealtek"
|
||||
set_detected_type(StorageDeviceDetectedType::Nvme);
|
||||
|
||||
} else {
|
||||
// TODO Detect unsupported RAID
|
||||
debug_out_warn("app", "Unsupported type " << smartctl_type << " reported by smartctl for " << get_device_with_type() << "\n");
|
||||
debug_out_warn("app", "Unsupported type " << smartctl_type << " (protocol: " << lowercase_protocol << ") reported by smartctl for " << get_device_with_type() << "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user