diff options
Diffstat (limited to 'hardinfo2/arch/linux/common')
-rw-r--r-- | hardinfo2/arch/linux/common/modules.h | 16 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/pci.h | 22 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/resources.h | 44 |
3 files changed, 78 insertions, 4 deletions
diff --git a/hardinfo2/arch/linux/common/modules.h b/hardinfo2/arch/linux/common/modules.h index 46f73d2f..32c9c0d6 100644 --- a/hardinfo2/arch/linux/common/modules.h +++ b/hardinfo2/arch/linux/common/modules.h @@ -29,12 +29,18 @@ remove_module_devices(gpointer key, gpointer value, gpointer data) return g_str_has_prefix(key, "MOD"); } +static GHashTable *_module_hash_table = NULL; + static void scan_modules_do(void) { FILE *lsmod; gchar buffer[1024]; + if (!_module_hash_table) { + _module_hash_table = g_hash_table_new(g_str_hash, g_str_equal); + } + if (module_list) { g_free(module_list); } @@ -95,7 +101,15 @@ scan_modules_do(void) if (description && g_str_equal(description, "<none>")) { g_free(description); description = g_strdup(""); - } + + g_hash_table_insert(_module_hash_table, + g_strdup(modname), + g_strdup_printf("Kernel module (%s)", modname)); + } else { + g_hash_table_insert(_module_hash_table, + g_strdup(modname), + g_strdup(description)); + } /* append this module to the list of modules */ module_list = h_strdup_cprintf("$%s$%s=%s\n", diff --git a/hardinfo2/arch/linux/common/pci.h b/hardinfo2/arch/linux/common/pci.h index a89c8841..4ea03356 100644 --- a/hardinfo2/arch/linux/common/pci.h +++ b/hardinfo2/arch/linux/common/pci.h @@ -16,6 +16,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/* + * TODO: This thing must be rewritten. We really should have a struct with all the + * PCI stuff we'll present to the user, and hash them by the PCI ID + * (domain:bus:device.function). + * This way we'll have ways to better organize the output, instead of relying + * on the order the information appears on lspci's output. + * Also, the "Resources" thing might be better implemented (and we won't need + * copies of information scattered everywhere like we do today). + */ + +GHashTable *_pci_devices = NULL; + void __scan_pci(void) { @@ -23,6 +35,10 @@ __scan_pci(void) gchar buffer[256], *buf, *strhash = NULL, *strdevice = NULL; gchar *category = NULL, *name = NULL, *icon; gint n = 0, x = 0; + + if (!_pci_devices) { + _pci_devices = g_hash_table_new(g_str_hash, g_str_equal); + } buf = g_build_filename(g_get_home_dir(), ".hardinfo", "pci.ids", NULL); if (!g_file_test(buf, G_FILE_TEST_EXISTS)) { @@ -169,6 +185,9 @@ __scan_pci(void) else icon = "pci"; name = g_strdup(buf); + g_hash_table_insert(_pci_devices, + g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), + name); strhash = g_strdup_printf("PCI%d", n); strdevice = g_strdup_printf("[Device Information]\n" @@ -187,6 +206,9 @@ __scan_pci(void) url); } + g_hash_table_insert(_pci_devices, + g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), + g_strdup(name)); pci_list = h_strdup_cprintf("$PCI%d$%s=%s\n", pci_list, n, category, name); diff --git a/hardinfo2/arch/linux/common/resources.h b/hardinfo2/arch/linux/common/resources.h index 581d7eba..5e767caa 100644 --- a/hardinfo2/arch/linux/common/resources.h +++ b/hardinfo2/arch/linux/common/resources.h @@ -17,6 +17,41 @@ */ gchar *_resources = NULL; + +#if GLIB_CHECK_VERSION(2,14,0) +static GRegex *_regex_pci = NULL, + *_regex_module = NULL; +static gchar *_resource_obtain_name(gchar *name) +{ + gchar *temp; + + if (!_regex_pci && !_regex_module) { + _regex_pci = g_regex_new("^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\\.[0-9a-fA-F]{1}$", + 0, 0, NULL); + _regex_module = g_regex_new("^[0-9a-zA-Z\\_\\-]+$", 0, 0, NULL); + } + + name = g_strstrip(name); + + if (g_regex_match(_regex_pci, name, 0, NULL)) { + temp = module_call_method_param("devices::getPCIDeviceDescription", name); + return temp ? temp : name; + } + + if (g_regex_match(_regex_module, name, 0, NULL)) { + temp = module_call_method_param("computer::getKernelModuleDescription", name); + return temp ? temp : name; + } + + return name; +} +#else +static gchar *_resource_obtain_name(gchar *name) +{ + return name; +} +#endif + void scan_device_resources(gboolean reload) { SCAN_START(); @@ -32,7 +67,8 @@ void scan_device_resources(gboolean reload) while (fgets(buffer, 256, io)) { gchar **temp = g_strsplit(buffer, ":", 2); - _resources = h_strdup_cprintf("%s=%s\n", _resources, temp[0], temp[1]); + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], _resource_obtain_name(temp[1])); g_strfreev(temp); } @@ -46,7 +82,8 @@ void scan_device_resources(gboolean reload) while (fgets(buffer, 256, io)) { gchar **temp = g_strsplit(buffer, ":", 2); - _resources = h_strdup_cprintf("%s=%s\n", _resources, temp[0], temp[1]); + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], _resource_obtain_name(temp[1])); g_strfreev(temp); } @@ -60,7 +97,8 @@ void scan_device_resources(gboolean reload) while (fgets(buffer, 256, io)) { gchar **temp = g_strsplit(buffer, ":", 2); - _resources = h_strdup_cprintf("%s=%s\n", _resources, temp[0], temp[1]); + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], _resource_obtain_name(temp[1])); g_strfreev(temp); } |