Skip to content

Commit

Permalink
Support NVMe behind USB bridges.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashaduri committed May 31, 2024
1 parent afd6ce0 commit 25f1c62
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/applib/smartctl_json_ata_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down
15 changes: 15 additions & 0 deletions src/applib/smartctl_json_basic_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions src/applib/smartctl_json_nvme_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down
11 changes: 10 additions & 1 deletion src/applib/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
}
}

Expand Down

0 comments on commit 25f1c62

Please sign in to comment.