diff options
author | Burt P <pburt0@gmail.com> | 2020-01-01 11:15:21 -0600 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2020-01-03 09:31:10 -0800 |
commit | 112e399c0810f04248ca2a23886afd2bc3b25f83 (patch) | |
tree | ec65942595dca1f2d2d9b86b4770dc7ea1916ad4 | |
parent | 6a2a9112f97433707605cca1f6a25a43a6c369a4 (diff) |
storage: nvme pci info + udisks2_util vendor fixes
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | hardinfo/pci_util.c | 2 | ||||
-rw-r--r-- | hardinfo/udisks2_util.c | 45 | ||||
-rw-r--r-- | includes/udisks2_util.h | 2 | ||||
-rw-r--r-- | modules/devices/storage.c | 62 |
4 files changed, 88 insertions, 23 deletions
diff --git a/hardinfo/pci_util.c b/hardinfo/pci_util.c index 728e6356..6db14136 100644 --- a/hardinfo/pci_util.c +++ b/hardinfo/pci_util.c @@ -323,7 +323,7 @@ static gboolean pci_get_device_lspci(uint32_t dom, uint32_t bus, uint32_t dev, u } pcid *pci_get_device_str(const char *addy) { - uint32_t dom, bus, dev, func, cls; + uint32_t dom, bus, dev, func; int ec; if (addy) { ec = sscanf(addy, "%x:%x:%x.%x", &dom, &bus, &dev, &func); diff --git a/hardinfo/udisks2_util.c b/hardinfo/udisks2_util.c index dfb0b20f..e3cf255a 100644 --- a/hardinfo/udisks2_util.c +++ b/hardinfo/udisks2_util.c @@ -2,7 +2,6 @@ #include "udisks2_util.h" #include "hardinfo.h" #include "util_ids.h" -#include "pci_util.h" #define UDISKS2_INTERFACE "org.freedesktop.UDisks2" #define UDISKS2_MANAGER_INTERFACE "org.freedesktop.UDisks2.Manager" @@ -376,6 +375,7 @@ void udiskd_free(udiskd *u) { udisksa_free(u->smart_attributes); g_free(u->media); g_strfreev(u->media_compatibility); + pcid_free(u->nvme_controller); g_free(u); } } @@ -678,29 +678,36 @@ gpointer get_udisks2_drive_info(const char *blockdev, GDBusProxy *block, g_variant_unref(v); } - /* NVMe vendor from PCI device */ - if (strstr(u->block_dev, "nvme") - && (!u->vendor || !*u->vendor) - ) { - gchar *file = g_strdup_printf("/sys/block/%s/device/device/vendor", u->block_dev); - gchar *val = NULL; - if (g_file_get_contents(file, &val, NULL, NULL) ) { - unsigned long int id = strtoul(val, NULL, 16); - if (id) - u->vendor = pci_lookup_ids_vendor_str(id); - } - g_free(file); - g_free(val); + if (!u->vendor || !*u->vendor) { + const Vendor *v = vendor_match(u->model, NULL); + if (v) + u->vendor = g_strdup(v->name); } check_sdcard_vendor(u); - if (!u->vendors) { - const Vendor *v = NULL; - v = vendor_match(u->vendor, NULL); - if (v) - u->vendors = vendor_list_append(u->vendors, v); + u->vendors = vendor_list_append(u->vendors, vendor_match(u->vendor, NULL)); + + /* NVMe PCI device */ + if (strstr(u->block_dev, "nvme")) { + gchar *path = g_strdup_printf("/sys/block/%s/device/device", u->block_dev); + gchar *systarget = g_file_read_link(path, NULL); + gchar *target = systarget ? g_filename_to_utf8(systarget, -1, NULL, NULL, NULL) : NULL; + gchar *pci_addy = target ? g_path_get_basename(target) : NULL; + u->nvme_controller = pci_addy ? pci_get_device_str(pci_addy) : NULL; + g_free(path); + g_free(systarget); + g_free(target); + g_free(pci_addy); + if (u->nvme_controller) { + u->vendors = vendor_list_append(u->vendors, + vendor_match(u->nvme_controller->vendor_id_str, NULL)); + u->vendors = vendor_list_append(u->vendors, + vendor_match(u->nvme_controller->sub_vendor_id_str, NULL)); + } } + u->vendors = gg_slist_remove_null(u->vendors); + u->vendors = vendor_list_remove_duplicates_deep(u->vendors); return u; } diff --git a/includes/udisks2_util.h b/includes/udisks2_util.h index acd2282f..8f97f740 100644 --- a/includes/udisks2_util.h +++ b/includes/udisks2_util.h @@ -1,4 +1,5 @@ #include "vendor.h" +#include "pci_util.h" typedef struct udiskp { gchar *block; @@ -43,6 +44,7 @@ typedef struct udiskd { gint64 smart_bad_sectors; gint32 smart_temperature; udisksa *smart_attributes; + pcid *nvme_controller; vendor_list vendors; } udiskd; diff --git a/modules/devices/storage.c b/modules/devices/storage.c index 753246f6..2e969062 100644 --- a/modules/devices/storage.c +++ b/modules/devices/storage.c @@ -23,16 +23,66 @@ #include "devices.h" #include "udisks2_util.h" +#define UNKIFNULL_AC(f) (f != NULL) ? f : _("(Unknown)"); + gchar *storage_icons = NULL; +gchar *nvme_pci_sections(pcid *p) { + const gchar *vendor, *svendor, *product, *sproduct; + + if (!p) return NULL; + + vendor = UNKIFNULL_AC(p->vendor_id_str); + svendor = UNKIFNULL_AC(p->sub_vendor_id_str); + product = UNKIFNULL_AC(p->device_id_str); + sproduct = UNKIFNULL_AC(p->sub_device_id_str); + + gchar *vendor_device_str; + if (p->vendor_id == p->sub_vendor_id && p->device_id == p->sub_device_id) { + vendor_device_str = g_strdup_printf("[%s]\n" + /* Vendor */ "$^$%s=[%04x] %s\n" + /* Device */ "%s=[%04x] %s\n", + _("NVMe Controller"), + _("Vendor"), p->vendor_id, vendor, + _("Device"), p->device_id, product); + } else { + vendor_device_str = g_strdup_printf("[%s]\n" + /* Vendor */ "$^$%s=[%04x] %s\n" + /* Device */ "%s=[%04x] %s\n" + /* Sub-device vendor */ "$^$%s=[%04x] %s\n" + /* Sub-device */ "%s=[%04x] %s\n", + _("NVMe Controller"), + _("Vendor"), p->vendor_id, vendor, + _("Device"), p->device_id, product, + _("SVendor"), p->sub_vendor_id, svendor, + _("SDevice"), p->sub_device_id, sproduct); + } + + gchar *pcie_str; + if (p->pcie_width_curr) { + pcie_str = g_strdup_printf("[%s]\n" + /* Width (max) */ "%s=x%u\n" + /* Speed (max) */ "%s=%0.1f %s\n", + _("PCI Express"), + _("Maximum Link Width"), p->pcie_width_max, + _("Maximum Link Speed"), p->pcie_speed_max, _("GT/s") ); + } else + pcie_str = strdup(""); + + gchar *ret = g_strdup_printf("%s%s", vendor_device_str, pcie_str); + g_free(vendor_device_str); + g_free(pcie_str); + return ret; +} + gboolean __scan_udisks2_devices(void) { GSList *node, *drives; udiskd *disk; udiskp *part; udisksa *attrib; gchar *udisks2_storage_list = NULL, *features = NULL, *moreinfo = NULL; - gchar *devid, *label, *size, *tmp = NULL, *media_comp = NULL; - const gchar *url, *vendor_str, *ven_tag, *media_label, *alabel, *icon, *media_curr = NULL; + gchar *devid, *label, *size, *tmp = NULL, *media_comp = NULL, *ven_tag = NULL; + const gchar *url, *vendor_str, *media_label, *alabel, *icon, *media_curr = NULL; int n = 0, i, j; // http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Drive.html#gdbus-property-org-freedesktop-UDisks2-Drive.MediaCompatibility @@ -197,7 +247,7 @@ gboolean __scan_udisks2_devices(void) { } size = size_human_readable((gfloat) disk->size); - ven_tag = vendor_match_tag(vendor_str, params.fmt_opts); + ven_tag = vendor_list_ribbon(disk->vendors, params.fmt_opts); udisks2_storage_list = h_strdup_cprintf("$%s$%s=%s|%s\n", udisks2_storage_list, devid, label, ven_tag ? ven_tag : "", size); storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, label, icon); @@ -254,6 +304,12 @@ gboolean __scan_udisks2_devices(void) { if (disk->connection_bus && strlen(disk->connection_bus) > 0) { moreinfo = h_strdup_cprintf(_("Connection bus=%s\n"), moreinfo, disk->connection_bus); } + if (disk->nvme_controller) { + gchar *nvme = nvme_pci_sections(disk->nvme_controller); + if (nvme) + moreinfo = h_strdup_cprintf("%s", moreinfo, nvme); + g_free(nvme); + } if (disk->smart_enabled) { moreinfo = h_strdup_cprintf(_("[Self-monitoring (S.M.A.R.T.)]\n" "Status=%s\n" |