From 4979bb6cbbbe39eb44c32530cd13f86bf44e5d77 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 19 Jun 2017 14:38:48 -0500 Subject: Import Upstream version 0.5c --- arch/linux/common/alsa.h | 2 +- arch/linux/common/battery.h | 84 +++++++- arch/linux/common/boots.h | 9 +- arch/linux/common/devmemory.h | 2 +- arch/linux/common/dmi.h | 160 +++++++++++++++ arch/linux/common/filesystem.h | 18 +- arch/linux/common/inputdevices.h | 18 +- arch/linux/common/loadavg.h | 2 +- arch/linux/common/memory.h | 2 +- arch/linux/common/modules.h | 30 ++- arch/linux/common/net.h | 406 ++++++++++++++++++++++++++++----------- arch/linux/common/os.h | 57 ++++-- arch/linux/common/pci.h | 56 +++++- arch/linux/common/resources.h | 103 ++++++++++ arch/linux/common/samba.h | 2 +- arch/linux/common/sensors.h | 17 +- arch/linux/common/storage.h | 161 +++++++++------- arch/linux/common/uptime.h | 2 +- arch/linux/common/usb.h | 213 +++++++++++++++----- 19 files changed, 1054 insertions(+), 290 deletions(-) create mode 100644 arch/linux/common/dmi.h create mode 100644 arch/linux/common/resources.h (limited to 'arch/linux/common') diff --git a/arch/linux/common/alsa.h b/arch/linux/common/alsa.h index 8f4cc2ac..5609471c 100644 --- a/arch/linux/common/alsa.h +++ b/arch/linux/common/alsa.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/arch/linux/common/battery.h b/arch/linux/common/battery.h index 4a38b842..7dfa5423 100644 --- a/arch/linux/common/battery.h +++ b/arch/linux/common/battery.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +18,82 @@ #include +const struct { + gchar *key, *name; +} ups_fields[] = { + { "UPS Status", NULL }, + { "STATUS", "Status" }, + { "TIMELEFT", "Time Left" }, + { "LINEV", "Line Voltage" }, + { "LOADPCT", "Load Percent" }, + + { "UPS Battery Information", NULL }, + { "BATTV", "Battery Voltage" }, + { "BCHARGE", "Battery Charge" }, + { "BATTDATE", "Battery Date" }, + + { "UPS Information", NULL }, + { "APCMODEL", "Model" }, + { "FIRMWARE", "Firmware Version" }, + { "SERIALNO", "Serial Number" }, + { "UPSMODE", "UPS Mode" }, + { "CABLE", "Cable" }, + { "UPSNAME", "UPS Name" }, + + { "UPS Nominal Values", NULL }, + { "NOMINV", "Voltage" }, + { "NOMBATTV", "Battery Voltage" }, + { "NOMPOWER", "Power" } +}; + + +static void +__scan_battery_apcupsd(void) +{ + GHashTable *ups_data; + FILE *apcaccess; + char buffer[512], *apcaccess_path; + int i; + + apcaccess_path = find_program("apcaccess"); + + if ((apcaccess = popen(apcaccess_path, "r"))) { + /* first line isn't important */ + if (fgets(buffer, 512, apcaccess)) { + /* allocate the key, value hash table */ + ups_data = g_hash_table_new(g_str_hash, g_str_equal); + + /* read up all the apcaccess' output, saving it in the key, value hash table */ + while (fgets(buffer, 512, apcaccess)) { + buffer[9] = '\0'; + + g_hash_table_insert(ups_data, + g_strdup(g_strstrip(buffer)), + g_strdup(g_strstrip(buffer + 10))); + } + + /* builds the ups info string, respecting the field order as found in ups_fields */ + for (i = 0; i < G_N_ELEMENTS(ups_fields); i++) { + if (!ups_fields[i].name) { + /* there's no name: make a group with the key as its name */ + battery_list = h_strdup_cprintf("[%s]\n", battery_list, ups_fields[i].key); + } else { + /* there's a name: adds a line */ + battery_list = h_strdup_cprintf("%s=%s\n", battery_list, + ups_fields[i].name, + g_hash_table_lookup(ups_data, ups_fields[i].key)); + } + } + + g_hash_table_destroy(ups_data); + } + + pclose(apcaccess); + } + + g_free(apcaccess_path); +} + static void __scan_battery_acpi(void) { @@ -31,11 +107,6 @@ __scan_battery_acpi(void) gchar *state = NULL, *rate = NULL; gchar *remaining = NULL; - if (battery_list) { - g_free(battery_list); - } - battery_list = g_strdup(""); - acpi_path = g_strdup("/proc/acpi/battery"); if (g_file_test(acpi_path, G_FILE_TEST_EXISTS)) { GDir *acpi; @@ -209,6 +280,7 @@ __scan_battery(void) __scan_battery_acpi(); __scan_battery_apm(); + __scan_battery_apcupsd(); if (*battery_list == '\0') { g_free(battery_list); diff --git a/arch/linux/common/boots.h b/arch/linux/common/boots.h index d3428ea9..8a3c11fa 100644 --- a/arch/linux/common/boots.h +++ b/arch/linux/common/boots.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira + * Copyright (C) 2003-2007 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,11 +47,10 @@ scan_boots_real(void) } } - tmp = g_strsplit(buffer, " ", 5); - computer->os->boots = h_strdup_cprintf("\n%s=Kernel %s", + tmp = g_strsplit(buffer, " ", 0); + computer->os->boots = h_strdup_cprintf("\n%s %s %s %s=%s|%s", computer->os->boots, - tmp[4], - tmp[3]); + tmp[4], tmp[5], tmp[6], tmp[7], tmp[3], tmp[8]); g_strfreev(tmp); } } diff --git a/arch/linux/common/devmemory.h b/arch/linux/common/devmemory.h index 5eafe599..e3921cdd 100644 --- a/arch/linux/common/devmemory.h +++ b/arch/linux/common/devmemory.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira + * Copyright (C) 2003-2007 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/arch/linux/common/dmi.h b/arch/linux/common/dmi.h new file mode 100644 index 00000000..f69fdc21 --- /dev/null +++ b/arch/linux/common/dmi.h @@ -0,0 +1,160 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2007 Leandro A. F. Pereira + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* + * DMI support based on patch by Stewart Adam + */ +#include +#include + +typedef struct _DMIInfo DMIInfo; + +struct _DMIInfo { + const gchar *name; + const gchar *file; /* for sysfs */ + const gchar *param; /* for dmidecode */ +}; + +DMIInfo dmi_info_table[] = { + { "$BIOS", NULL, NULL }, + { "Date", "/sys/class/dmi/id/bios_date", "bios-release-date" }, + { "Vendor", "/sys/class/dmi/id/bios_vendor", "bios-vendor" }, + { "Version", "/sys/class/dmi/id/bios_version", "bios-version" }, + { "$Board", NULL, NULL }, + { "Name", "/sys/class/dmi/id/board_name", "baseboard-product-name" }, + { "Vendor", "/sys/class/dmi/id/board_vendor", "baseboard-manufacturer" }, +}; + +static gchar *dmi_info = NULL; + +gboolean dmi_get_info_dmidecode() +{ + FILE *dmi_pipe; + gchar buffer[256]; + DMIInfo *info; + gboolean dmi_failed = FALSE; + gint i; + + if (dmi_info) { + g_free(dmi_info); + dmi_info = NULL; + } + + for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) { + info = &dmi_info_table[i]; + + if (*(info->name) == '$') { + dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, + (info->name) + 1); + } else { + gchar *temp; + + if (!info->param) + continue; + + temp = g_strconcat("dmidecode -s ", info->param, NULL); + if ((dmi_pipe = popen(temp, "r"))) { + g_free(temp); + + fgets(buffer, 256, dmi_pipe); + if (pclose(dmi_pipe)) { + dmi_failed = TRUE; + break; + } + + dmi_info = h_strdup_cprintf("%s=%s\n", + dmi_info, + info->name, + buffer); + } else { + g_free(temp); + dmi_failed = TRUE; + break; + } + } + } + + if (dmi_failed) { + g_free(dmi_info); + dmi_info = NULL; + } + + return !dmi_failed; +} + +gboolean dmi_get_info_sys() +{ + FILE *dmi_file; + gchar buffer[256]; + DMIInfo *info; + gboolean dmi_failed = FALSE; + gint i; + + if (dmi_info) { + g_free(dmi_info); + dmi_info = NULL; + } + + for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) { + info = &dmi_info_table[i]; + + if (*(info->name) == '$') { + dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, + (info->name) + 1); + } else { + if (!info->file) + continue; + + if ((dmi_file = fopen(info->file, "r"))) { + fgets(buffer, 256, dmi_file); + fclose(dmi_file); + + dmi_info = h_strdup_cprintf("%s=%s\n", + dmi_info, + info->name, + buffer); + } else { + dmi_failed = TRUE; + break; + } + } + } + + if (dmi_failed) { + g_free(dmi_info); + dmi_info = NULL; + } + + return !dmi_failed; +} + +void __scan_dmi() +{ + gboolean dmi_ok; + + dmi_ok = dmi_get_info_sys(); + + if (!dmi_ok) { + dmi_ok = dmi_get_info_dmidecode(); + } + + if (!dmi_ok) { + dmi_info = g_strdup("[No DMI information]\n" + "There was an error retrieving the information.=\n" + "Please try running HardInfo as root.=\n"); + } +} diff --git a/arch/linux/common/filesystem.h b/arch/linux/common/filesystem.h index d8166fc3..1eff0818 100644 --- a/arch/linux/common/filesystem.h +++ b/arch/linux/common/filesystem.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,10 +51,22 @@ scan_filesystems(void) tmp = g_strsplit(buf, " ", 0); if (!statfs(tmp[1], &sfs)) { + gfloat use_ratio; + size = (float) sfs.f_bsize * (float) sfs.f_blocks; avail = (float) sfs.f_bsize * (float) sfs.f_bavail; used = size - avail; + if (size == 0.0f) { + continue; + } + + if (avail == 0.0f) { + use_ratio = 100.0f; + } else { + use_ratio = 100.0f * (used / size); + } + gchar *strsize = size_human_readable(size), *stravail = size_human_readable(avail), *strused = size_human_readable(used); @@ -81,9 +93,9 @@ scan_filesystems(void) stravail); g_hash_table_insert(moreinfo, g_strdup_printf("FS%d", ++count), strhash); - fs_list = h_strdup_cprintf("$FS%d$%s=%s total, %s free\n", + fs_list = h_strdup_cprintf("$FS%d$%s=%.2f %% (%s of %s)|%s\n", fs_list, - count, tmp[0], strsize, stravail); + count, tmp[0], use_ratio, stravail, strsize, tmp[1]); g_free(strsize); g_free(stravail); diff --git a/arch/linux/common/inputdevices.h b/arch/linux/common/inputdevices.h index 8d2d8427..20e4289c 100644 --- a/arch/linux/common/inputdevices.h +++ b/arch/linux/common/inputdevices.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -115,9 +115,19 @@ __scan_input_devices(void) } strhash = h_strdup_cprintf("Product=0x%x\n" - "Version=0x%x\n" - "Connected to=%s\n", - strhash, product, version, phys); + "Version=0x%x\n", + strhash, product, version); + + if (phys[1] != 0) { + strhash = h_strdup_cprintf("Connected to=%s\n", + strhash, phys); + } + + if (strstr(phys,"ir")) { + strhash = h_strdup_cprintf("InfraRed port=yes\n", + strhash); + } + g_hash_table_insert(moreinfo, tmp, strhash); g_free(phys); diff --git a/arch/linux/common/loadavg.h b/arch/linux/common/loadavg.h index 28132b5f..7c028679 100644 --- a/arch/linux/common/loadavg.h +++ b/arch/linux/common/loadavg.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/arch/linux/common/memory.h b/arch/linux/common/memory.h index def4cc1d..c87359b9 100644 --- a/arch/linux/common/memory.h +++ b/arch/linux/common/memory.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/arch/linux/common/modules.h b/arch/linux/common/modules.h index 6fbe13bd..7ea238b7 100644 --- a/arch/linux/common/modules.h +++ b/arch/linux/common/modules.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,11 +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]; + gchar *lsmod_path; + + if (!_module_hash_table) { + _module_hash_table = g_hash_table_new(g_str_hash, g_str_equal); + } if (module_list) { g_free(module_list); @@ -42,9 +49,12 @@ scan_modules_do(void) module_list = NULL; g_hash_table_foreach_remove(moreinfo, remove_module_devices, NULL); - lsmod = popen("/sbin/lsmod", "r"); - if (!lsmod) + lsmod_path = find_program("lsmod"); + lsmod = popen(lsmod_path, "r"); + if (!lsmod) { + g_free(lsmod_path); return; + } fgets(buffer, 1024, lsmod); /* Discards the first line */ @@ -95,7 +105,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", @@ -119,7 +137,7 @@ scan_modules_do(void) "License=%s\n", NONE_IF_NULL(filename), memory / 1024.0, - NONE_IF_NULL(modname), + modname, NONE_IF_NULL(description), NONE_IF_NULL(vermagic), NONE_IF_NULL(author), @@ -146,4 +164,6 @@ scan_modules_do(void) g_free(filename); } pclose(lsmod); + + g_free(lsmod_path); } diff --git a/arch/linux/common/net.h b/arch/linux/common/net.h index 527da1df..755c6936 100644 --- a/arch/linux/common/net.h +++ b/arch/linux/common/net.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2008 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,36 +15,146 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -static gchar *network_interfaces = NULL, - *network_icons = NULL; - -#include -#include -#include -#include -#include +/* + * Wireless Extension Example + * http://www.krugle.org/examples/p-OZYzuisV6gyQIaTu/iwconfig.c + */ +static gchar *network_interfaces = NULL, *network_icons = NULL; #include #include -#include /* for strncpy */ +#include + +#include #include #include + #include +#include + #include +#ifdef HAS_LINUX_WE +#include +#include +#else +#include +#endif /* HAS_LINUX_WE */ typedef struct _NetInfo NetInfo; struct _NetInfo { - char name[16]; - int mtu; + char name[16]; + int mtu; unsigned char mac[8]; char ip[16]; char mask[16]; char broadcast[16]; + +#ifdef HAS_LINUX_WE + char wi_essid[IW_ESSID_MAX_SIZE + 1]; + int wi_rate; + int wi_mode, wi_status; + gboolean wi_has_txpower; + struct iw_param wi_txpower; + int wi_quality_level, wi_signal_level, wi_noise_level; + gboolean is_wireless; +#endif }; -void get_net_info(char *if_name, NetInfo *netinfo) +#ifdef HAS_LINUX_WE +const gchar *wi_operation_modes[] = { "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Unknown" }; + +void get_wireless_info(int fd, NetInfo *netinfo) +{ + FILE *wrls; + char wbuf[256]; + struct iwreq wi_req; + int r, trash; + + netinfo->is_wireless = FALSE; + + if ((wrls = fopen("/proc/net/wireless", "r"))) { + while (fgets(wbuf, 256, wrls)) { + if (strchr(wbuf, ':') && strstr(wbuf, netinfo->name)) { + gchar *buf1 = wbuf; + + netinfo->is_wireless = TRUE; + + buf1 = strchr(buf1, ':') + 1; + + if (strstr(buf1, ".")) { + sscanf(buf1, "%d %d. %d %d %d %d %d %d %d %d", + &(netinfo->wi_status), + &(netinfo->wi_quality_level), + &(netinfo->wi_signal_level), + &(netinfo->wi_noise_level), + &trash, &trash, &trash, &trash, &trash, &trash); + } else { + sscanf(buf1, "%d %d %d %d %d %d %d %d %d %d", + &(netinfo->wi_status), + &(netinfo->wi_quality_level), + &(netinfo->wi_signal_level), + &(netinfo->wi_noise_level), + &trash, &trash, &trash, &trash, &trash, + &trash); + } + + break; + } + } + fclose(wrls); + } + + if (!netinfo->is_wireless) + return; + + strncpy(wi_req.ifr_name, netinfo->name, 16); + + /* obtain essid */ + wi_req.u.essid.pointer = netinfo->wi_essid; + wi_req.u.essid.length = IW_ESSID_MAX_SIZE + 1; + wi_req.u.essid.flags = 0; + + if ((r = ioctl(fd, SIOCGIWESSID, &wi_req) < 0)) { + strcpy(netinfo->wi_essid, ""); + } else { + netinfo->wi_essid[wi_req.u.essid.length] = '\0'; + } + + /* obtain bit rate */ + if ((r = ioctl(fd, SIOCGIWRATE, &wi_req) < 0)) { + netinfo->wi_rate = 0; + } else { + netinfo->wi_rate = wi_req.u.bitrate.value; + } + + /* obtain operation mode */ + if ((r = ioctl(fd, SIOCGIWMODE, &wi_req) < 0)) { + netinfo->wi_mode = 0; + } else { + if (wi_req.u.mode >= 0 && wi_req.u.mode < 6) { + netinfo->wi_mode = wi_req.u.mode; + } else { + netinfo->wi_mode = 6; + } + } + +#if WIRELESS_EXT >= 10 + /* obtain txpower */ + if ((r = ioctl(fd, SIOCGIWTXPOW, &wi_req) < 0)) { + netinfo->wi_has_txpower = FALSE; + } else { + netinfo->wi_has_txpower = TRUE; + + memcpy(&netinfo->wi_txpower, &wi_req.u.txpower, sizeof(struct iw_param)); + } +#else + netinfo->wi_has_txpower = FALSE; +#endif /* WIRELESS_EXT >= 10 */ +} +#endif /* HAS_LINUX_WE */ + +void get_net_info(char *if_name, NetInfo * netinfo) { struct ifreq ifr; int fd; @@ -58,44 +168,55 @@ void get_net_info(char *if_name, NetInfo *netinfo) /* MTU */ strcpy(ifr.ifr_name, if_name); if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) { - netinfo->mtu = 0; + netinfo->mtu = 0; } else { - netinfo->mtu = ifr.ifr_mtu; + netinfo->mtu = ifr.ifr_mtu; } /* HW Address */ strcpy(ifr.ifr_name, if_name); if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { - memset(netinfo->mac, 0, 8); + memset(netinfo->mac, 0, 8); } else { - memcpy(netinfo->mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 8); + memcpy(netinfo->mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 8); } - + /* IP Address */ strcpy(ifr.ifr_name, if_name); if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) { - netinfo->ip[0] = 0; + netinfo->ip[0] = 0; } else { - sprintf(netinfo->ip, "%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + sprintf(netinfo->ip, "%s", + inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)-> + sin_addr)); } - + /* Mask Address */ strcpy(ifr.ifr_name, if_name); if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) { - netinfo->mask[0] = 0; + netinfo->mask[0] = 0; } else { - sprintf(netinfo->mask, "%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + sprintf(netinfo->mask, "%s", + inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)-> + sin_addr)); } /* Broadcast Address */ strcpy(ifr.ifr_name, if_name); if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) { - netinfo->broadcast[0] = 0; + netinfo->broadcast[0] = 0; } else { - sprintf(netinfo->broadcast, "%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + sprintf(netinfo->broadcast, "%s", + inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)-> + sin_addr)); } +#ifdef HAS_LINUX_WE + get_wireless_info(fd, netinfo); +#endif + shutdown(fd, 0); + close(fd); } static struct { @@ -103,33 +224,46 @@ static struct { char *label; char *icon; } netdev2type[] = { - { "eth", "Ethernet", "network" }, - { "lo", "Loopback", "network-generic" }, - { "ppp", "Point-to-Point", "modem" }, - { "ath", "Wireless", "wireless" }, - { "wlan", "Wireless", "wireless" }, - { "tun", "Virtual Point-to-Point (TUN)", "network-generic" }, - { "tap", "Ethernet (TAP)", "network-generic" }, - { "plip", "Parallel Line Internet Protocol", "network" }, - { "irlan", "Infrared", "network-generic" }, - { "slip", "Serial Line Internet Protocol", "network-generic" }, - { "isdn", "Integrated Services Digital Network", "modem" }, - { "sit", "IPv6-over-IPv4 Tunnel", "network-generic" }, + { "eth", "Ethernet", "network-interface" }, + { "lo", "Loopback", "network" }, + { "ppp", "Point-to-Point", "modem" }, + { "ath", "Wireless", "wireless" }, + { "wlan", "Wireless", "wireless" }, + { "ra", "Wireless", "wireless" }, + { "wl", "Wireless", "wireless" }, + { "tun", "Virtual Point-to-Point (TUN)", "network" }, + { "tap", "Ethernet (TAP)", "network" }, + { "plip", "Parallel Line Internet Protocol", "network" }, + { "irlan", "Infrared", "network" }, + { "slip", "Serial Line Internet Protocol", "network" }, + { "isdn", "Integrated Services Digital Network", "modem" }, + { "sit", "IPv6-over-IPv4 Tunnel", "network" }, { "vmnet8", "VMWare Virtual Network Interface (NAT)", "computer" }, - { "vmnet", "VMWare Virtual Network Interface", "computer"}, - { NULL, "Unknown", "network-generic" }, + { "vmnet", "VMWare Virtual Network Interface", "computer" }, + { "pan", "Personal Area Network (PAN)", "bluetooth" }, + { "bnep", "Bluetooth", "bluetooth" }, + { "br", "Bridge Interface", "network" }, + { NULL, "Unknown", "network" }, }; -static void -net_get_iface_type(gchar *name, gchar **type, gchar **icon) +static void net_get_iface_type(gchar * name, gchar ** type, gchar ** icon, NetInfo *ni) { int i; - + +#ifdef HAS_LINUX_WE + if (ni->is_wireless) { + *type = "Wireless"; + *icon = "wireless"; + + return; + } +#endif + for (i = 0; netdev2type[i].type; i++) { - if (g_str_has_prefix(name, netdev2type[i].type)) - break; + if (g_str_has_prefix(name, netdev2type[i].type)) + break; } - + *type = netdev2type[i].label; *icon = netdev2type[i].icon; } @@ -140,49 +274,51 @@ remove_net_devices(gpointer key, gpointer value, gpointer data) return g_str_has_prefix(key, "NET"); } -static void -scan_net_interfaces_24(void) +static void scan_net_interfaces_24(void) { FILE *proc_net; NetInfo ni; gchar buffer[256]; gchar *devid, *detailed; - gulong recv_bytes; - gulong recv_errors; - gulong recv_packets; - - gulong trans_bytes; - gulong trans_errors; - gulong trans_packets; - + gdouble recv_bytes; + gdouble recv_errors; + gdouble recv_packets; + + gdouble trans_bytes; + gdouble trans_errors; + gdouble trans_packets; + if (!g_file_test("/proc/net/dev", G_FILE_TEST_EXISTS)) { - if (network_interfaces) { - g_free(network_interfaces); - network_interfaces = g_strdup("[Network Interfaces]\n" - "None found=\n"); - } + if (network_interfaces) { + g_free(network_interfaces); + network_interfaces = g_strdup("[Network Interfaces]\n" + "None found=\n"); + } return; } if (network_interfaces) { - g_free(network_interfaces); + g_free(network_interfaces); } - + if (network_icons) { - g_free(network_icons); + g_free(network_icons); } - + network_interfaces = g_strdup("[Network Interfaces]\n"); network_icons = g_strdup(""); proc_net = fopen("/proc/net/dev", "r"); + if (!proc_net) + return; + while (fgets(buffer, 256, proc_net)) { if (strchr(buffer, ':')) { gint trash; gchar ifacename[16]; gchar *buf = buffer; - gchar *iface_type, *iface_icon, *ip; + gchar *iface_type, *iface_icon; gint i; buf = g_strstrip(buf); @@ -196,71 +332,107 @@ scan_net_interfaces_24(void) buf = strchr(buf, ':') + 1; /* iface: bytes packets errs drop fifo frame compressed multicast */ - sscanf(buf, "%ld %ld %ld %d %d %d %d %d %ld %ld %ld", + sscanf(buf, "%lf %lf %lf %d %d %d %d %d %lf %lf %lf", &recv_bytes, &recv_packets, &recv_errors, &trash, &trash, &trash, &trash, - &trash, &trans_bytes, &trans_packets, - &trans_errors); + &trash, &trans_bytes, &trans_packets, &trans_errors); - gfloat recv_mb = recv_bytes / 1048576.0; - gfloat trans_mb = trans_bytes / 1048576.0; - - get_net_info(ifacename, &ni); + gdouble recv_mb = recv_bytes / 1048576.0; + gdouble trans_mb = trans_bytes / 1048576.0; + + get_net_info(ifacename, &ni); + + devid = g_strdup_printf("NET%s", ifacename); + + network_interfaces = + h_strdup_cprintf + ("$%s$%s=%s|%.2lfMiB|%.2lfMiB\n", + network_interfaces, devid, ifacename, ni.ip[0] ? ni.ip : "", + trans_mb, recv_mb); + net_get_iface_type(ifacename, &iface_type, &iface_icon, &ni); - devid = g_strdup_printf("NET%s", ifacename); - - ip = g_strdup_printf(" (%s)", ni.ip); - network_interfaces = h_strdup_cprintf("$%s$%s=Sent %.2fMiB, received %.2fMiB%s\n", - network_interfaces, - devid, - ifacename, - trans_mb, - recv_mb, - ni.ip[0] ? ip: ""); - g_free(ip); - - net_get_iface_type(ifacename, &iface_type, &iface_icon); network_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", - network_icons, devid, - ifacename, iface_icon); + network_icons, devid, + ifacename, iface_icon); + + detailed = g_strdup_printf("[Network Adapter Properties]\n" + "Interface Type=%s\n" + "Hardware Address (MAC)=%02x:%02x:%02x:%02x:%02x:%02x\n" + "MTU=%d\n" + "[Transfer Details]\n" + "Bytes Received=%.0lf (%.2fMiB)\n" + "Bytes Sent=%.0lf (%.2fMiB)\n", + iface_type, + ni.mac[0], ni.mac[1], + ni.mac[2], ni.mac[3], + ni.mac[4], ni.mac[5], + ni.mtu, + recv_bytes, recv_mb, + trans_bytes, trans_mb); - detailed = g_strdup_printf("[Network Adapter Properties]\n" - "Interface Type=%s\n" - "Hardware Address (MAC)=%02x:%02x:%02x:%02x:%02x:%02x\n" - "MTU=%d\n" - "[Transfer Details]\n" - "Bytes Received=%ld (%.2fMiB)\n" - "Bytes Sent=%ld (%.2fMiB)\n", - iface_type, - ni.mac[0], ni.mac[1], - ni.mac[2], ni.mac[3], - ni.mac[4], ni.mac[5], - ni.mtu, - recv_bytes, recv_mb, - trans_bytes, trans_mb); - - if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) { - detailed = h_strdup_cprintf("\n[Internet Protocol (IPv4)]\n" - "IP Address=%s\n" - "Mask=%s\n" - "Broadcast Address=%s\n", - detailed, - ni.ip[0] ? ni.ip : "Not set", - ni.mask[0] ? ni.mask : "Not set", - ni.broadcast[0] ? ni.broadcast : "Not set"); - } +#ifdef HAS_LINUX_WE + if (ni.is_wireless) { + gchar *txpower; - g_hash_table_insert(moreinfo, devid, detailed); + if (ni.wi_has_txpower) { + gint mw, dbm; + + if (ni.wi_txpower.flags & IW_TXPOW_MWATT) { + mw = ni.wi_txpower.value; + dbm = (int) ceil(10.0 * log10((double) ni.wi_txpower.value)); + } else { + dbm = ni.wi_txpower.value; + mw = (int) floor(pow(10.0, ((double) dbm / 10.0))); + } + + txpower = g_strdup_printf("%ddBm (%dmW)", dbm, mw); + } else { + txpower = g_strdup("Unknown"); + } + + detailed = h_strdup_cprintf("\n[Wireless Properties]\n" + "Network Name (SSID)=%s\n" + "Bit Rate=%dMb/s\n" + "Transmission Power=%s\n" + "Mode=%s\n" + "Status=%d\n" + "Link Quality=%d\n" + "Signal / Noise=%d / %d\n", + detailed, + ni.wi_essid, + ni.wi_rate / 1000000, + txpower, + wi_operation_modes[ni.wi_mode], + ni.wi_status, + ni.wi_quality_level, + ni.wi_signal_level, + ni.wi_noise_level); + + g_free(txpower); + } +#endif + + if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) { + detailed = + h_strdup_cprintf("\n[Internet Protocol (IPv4)]\n" + "IP Address=%s\n" "Mask=%s\n" + "Broadcast Address=%s\n", detailed, + ni.ip[0] ? ni.ip : "Not set", + ni.mask[0] ? ni.mask : "Not set", + ni.broadcast[0] ? ni. + broadcast : "Not set"); + } + + g_hash_table_insert(moreinfo, devid, detailed); } } fclose(proc_net); } -static void -scan_net_interfaces(void) +static void scan_net_interfaces(void) { /* FIXME: See if we're running Linux 2.6 and if /sys is mounted, then use - that instead of /proc/net/dev */ + that instead of /proc/net/dev */ /* remove old devices from global device table */ g_hash_table_foreach_remove(moreinfo, remove_net_devices, NULL); diff --git a/arch/linux/common/os.h b/arch/linux/common/os.h index e4f35e95..01853123 100644 --- a/arch/linux/common/os.h +++ b/arch/linux/common/os.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,6 +16,34 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +static gchar * +get_default_gcc_version(void) +{ + char *buf; + + if (g_spawn_command_line_sync("gcc -v", + NULL, + &buf, + NULL, + NULL)) { + char *return_value; + + if (!(return_value = strstr(buf, "gcc version "))) { + goto err; + } + + return_value += sizeof("gcc version"); + return_value = g_strdup_printf("GNU C Compiler version %s", return_value); + + g_free(buf); + + return return_value; + } + +err: + return g_strdup("Unknown"); +} + static gchar * get_libc_version(void) { @@ -66,27 +94,23 @@ detect_desktop_environment(OperatingSystem * os) { const gchar *tmp = g_getenv("GNOME_DESKTOP_SESSION_ID"); FILE *version; - int maj, min; + char vers[16]; if (tmp) { /* FIXME: this might not be true, as the gnome-panel in path may not be the one that's running. see where the user's running panel is and run *that* to obtain the version. */ - version = popen("gnome-panel --version", "r"); + version = popen("gnome-about --gnome-version", "r"); if (version) { - char gnome[10]; - - fscanf(version, "%s gnome-panel %d.%d", gnome, &maj, &min); + fscanf(version, "Version: %s", vers); if (pclose(version)) goto unknown; } else { goto unknown; } - os->desktop = - g_strdup_printf("GNOME %d.%d (session name: %s)", maj, min, - tmp); + os->desktop = g_strdup_printf("GNOME %s", vers); } else if (g_getenv("KDE_FULL_SESSION")) { version = popen("kcontrol --version", "r"); if (version) { @@ -94,14 +118,14 @@ detect_desktop_environment(OperatingSystem * os) fgets(buf, 32, version); - fscanf(version, "KDE: %d.%d", &maj, &min); + fscanf(version, "KDE: %s", vers); if (pclose(version)) goto unknown; } else { goto unknown; } - os->desktop = g_strdup_printf("KDE %d.%d", maj, min); + os->desktop = g_strdup_printf("KDE %s", vers); } else { unknown: if (!g_getenv("DISPLAY")) { @@ -147,11 +171,13 @@ computer_get_os(void) gchar buffer[128]; release = popen("lsb_release -d", "r"); - fgets(buffer, 128, release); - pclose(release); + if (release) { + fgets(buffer, 128, release); + pclose(release); - os->distro = buffer; - os->distro = g_strdup(os->distro + strlen("Description:\t")); + os->distro = buffer; + os->distro = g_strdup(os->distro + strlen("Description:\t")); + } } for (i = 0;; i++) { @@ -210,6 +236,7 @@ computer_get_os(void) os->username = g_strdup_printf("%s (%s)", g_get_user_name(), g_get_real_name()); os->libc = get_libc_version(); + os->gcc = get_default_gcc_version(); scan_languages(os); detect_desktop_environment(os); diff --git a/arch/linux/common/pci.h b/arch/linux/common/pci.h index 388ce9aa..a1ea1021 100644 --- a/arch/linux/common/pci.h +++ b/arch/linux/common/pci.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,25 +16,47 @@ * 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) { FILE *lspci; gchar buffer[256], *buf, *strhash = NULL, *strdevice = NULL; - gchar *category = NULL, *name = NULL, *icon; + gchar *category = NULL, *name = NULL, *icon, *lspci_path, *command_line; gint n = 0, x = 0; + + if ((lspci_path = find_program("lspci")) == NULL) { + goto pci_error; + } else { + command_line = g_strdup_printf("%s -v", lspci_path); + } + + 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)) { DEBUG("using system-provided PCI IDs"); g_free(buf); - if (!(lspci = popen(LSPCI, "r"))) { + if (!(lspci = popen(command_line, "r"))) { goto pci_error; } } else { gchar *tmp; - tmp = g_strdup_printf("%s -i '%s'", LSPCI, buf); + tmp = g_strdup_printf("%s -i '%s'", command_line, buf); g_free(buf); buf = tmp; @@ -83,10 +105,21 @@ __scan_pci(void) strdevice = h_strdup_cprintf("Latency=%d\n", strdevice, latency); strdevice = h_strdup_cprintf("Bus Master=%s\n", strdevice, bus_master ? "Yes" : "No"); + } else if (!strncmp(buf, "Kernel modules", 14)) { + WALK_UNTIL(' '); + WALK_UNTIL(':'); + buf++; + + strdevice = h_strdup_cprintf("Kernel modules=%s\n", strdevice, buf); } else if (!strncmp(buf, "Subsystem", 9)) { WALK_UNTIL(' '); buf++; - strdevice = h_strdup_cprintf("OEM Vendor=%s\n", strdevice, buf); + const gchar *oem_vendor_url = vendor_get_url(buf); + if (oem_vendor_url) + strdevice = h_strdup_cprintf("OEM Vendor=%s (%s)\n", + strdevice, + vendor_get_name(buf), + oem_vendor_url); } else if (!strncmp(buf, "Capabilities", 12) && !strstr(buf, "only to root") && !strstr(buf, "access denied")) { @@ -114,7 +147,7 @@ __scan_pci(void) prefetch ? "prefetchable" : "non-prefetchable"); - } else if (!strncmp(buf, "I/O", 3)) { + } else if (!strncmp(buf, "I/O ports at", 12)) { guint io_addr, io_size; sscanf(buf, "I/O ports at %x [size=%d]", &io_addr, &io_size); @@ -122,7 +155,7 @@ __scan_pci(void) strdevice = h_strdup_cprintf("I/O ports at#%d=0x%x - 0x%x\n", strdevice, ++x, io_addr, - io_addr + io_size); + io_addr + io_size - 1); } else if ((buf[0] >= '0' && buf[0] <= '9') && (buf[4] == ':' || buf[2] == ':')) { gint bus, device, function, domain; gpointer start, end; @@ -164,6 +197,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" @@ -182,6 +218,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); @@ -199,4 +238,7 @@ pci_error: g_free(category); g_free(name); } + + g_free(lspci_path); + g_free(command_line); } diff --git a/arch/linux/common/resources.h b/arch/linux/common/resources.h new file mode 100644 index 00000000..20db65e9 --- /dev/null +++ b/arch/linux/common/resources.h @@ -0,0 +1,103 @@ +/* + * HardInfo - Displays System Information + * Copyright (C) 2003-2008 Leandro A. F. Pereira + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +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); + if (temp) { + return temp; + } + } else if (g_regex_match(_regex_module, name, 0, NULL)) { + temp = module_call_method_param("computer::getKernelModuleDescription", name); + if (temp) { + return temp; + } + } + + return g_strdup(name); +} +#else +static gchar *_resource_obtain_name(gchar *name) +{ + return g_strdup(name); +} +#endif + +void scan_device_resources(gboolean reload) +{ + SCAN_START(); + FILE *io; + gchar buffer[256]; + gint i; + + struct { + gchar *file; + gchar *description; + } resources[] = { + { "/proc/ioports", "[I/O Ports]\n" }, + { "/proc/iomem", "[Memory]\n" }, + { "/proc/dma", "[DMA]\n" } + }; + + g_free(_resources); + _resources = g_strdup(""); + + for (i = 0; i < G_N_ELEMENTS(resources); i++) { + if ((io = fopen(resources[i].file, "r"))) { + _resources = h_strconcat(_resources, resources[i].description, NULL); + + while (fgets(buffer, 256, io)) { + gchar **temp = g_strsplit(buffer, ":", 2); + gchar *name = _resource_obtain_name(temp[1]); + + _resources = h_strdup_cprintf("%s=%s\n", _resources, + temp[0], name); + + g_strfreev(temp); + g_free(name); + } + + fclose(io); + } + } + + SCAN_END(); +} + +gchar *callback_device_resources(void) +{ + return _resources; +} diff --git a/arch/linux/common/samba.h b/arch/linux/common/samba.h index 7c7d8bb7..65cdc890 100644 --- a/arch/linux/common/samba.h +++ b/arch/linux/common/samba.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/arch/linux/common/sensors.h b/arch/linux/common/sensors.h index 1c4fd69f..17637764 100644 --- a/arch/linux/common/sensors.h +++ b/arch/linux/common/sensors.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,9 +31,16 @@ static void read_sensor_labels(gchar * driver) g_free, g_free); sensor_compute = g_hash_table_new(g_str_hash, g_str_equal); - conf = fopen("/etc/sensors.conf", "r"); - if (!conf) - return; + /* Try to open lm-sensors config file sensors3.conf */ + conf = fopen("/etc/sensors3.conf", "r"); + + /* If it fails, try to open sensors.conf */ + if (!conf) conf = fopen("/etc/sensors.conf", "r"); + + if (!conf) { + /* Cannot open config file. */ + return; + } while (fgets(buf, 256, conf)) { line = buf; @@ -100,7 +107,7 @@ static void read_sensor_labels(gchar * driver) for (i = 1; chips[i]; i++) { strend(chips[i], '*'); - if (g_str_has_prefix(driver, chips[i] + 1)) { + if (g_str_has_prefix(chips[i] + 1, driver)) { lock = TRUE; break; } diff --git a/arch/linux/common/storage.h b/arch/linux/common/storage.h index 71c206cd..5208f028 100644 --- a/arch/linux/common/storage.h +++ b/arch/linux/common/storage.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,7 @@ __scan_scsi_devices(void) gint scsi_id; gint scsi_lun; gchar *vendor = NULL, *revision = NULL, *model = NULL; + gchar *scsi_storage_list; /* remove old devices from global device table */ g_hash_table_foreach_remove(moreinfo, remove_scsi_devices, NULL); @@ -43,7 +44,7 @@ __scan_scsi_devices(void) if (!g_file_test("/proc/scsi/scsi", G_FILE_TEST_EXISTS)) return; - storage_list = g_strconcat(storage_list, "\n[SCSI Disks]\n", NULL); + scsi_storage_list = g_strdup("\n[SCSI Disks]\n"); proc_scsi = fopen("/proc/scsi/scsi", "r"); while (fgets(buffer, 256, proc_scsi)) { @@ -55,29 +56,13 @@ __scan_scsi_devices(void) n++; } else if (!strncmp(buf, "Vendor: ", 8)) { - char *p; - char *rev = strstr(buf, "Rev: "); - - model = strstr(buf, "Model: "); - - if (model == NULL) { - model = buf + strlen(buf); - } - p = model; - while (*(--p) == ' '); - *(++p) = 0; - vendor = g_strdup(buf + 8); - - if (rev != NULL) { - revision = g_strdup(rev + 5); - } else { - rev = model + strlen(model); - } - p = rev; - while (*(--p) == ' '); - *(++p) = 0; - model = g_strdup_printf("%s %s", vendor, model + 7); - + buf[17] = '\0'; + buf[41] = '\0'; + buf[53] = '\0'; + + vendor = g_strdup(g_strstrip(buf + 8)); + model = g_strdup_printf("%s %s", vendor, g_strstrip(buf + 24)); + revision = g_strdup(g_strstrip(buf + 46)); } else if (!strncmp(buf, "Type: ", 8)) { char *p; gchar *type = NULL, *icon = NULL; @@ -98,43 +83,59 @@ __scan_scsi_devices(void) { "Direct-Access", "Disk", "hdd"}, { "Sequential-Access", "Tape", "tape"}, { "Printer", "Printer", "lpr"}, - { "WORM", "CD-ROM", "cd"}, - { "CD-ROM", "CD-ROM", "cd"}, + { "WORM", "CD-ROM", "cdrom"}, + { "CD-ROM", "CD-ROM", "cdrom"}, { "Scanner", "Scanner", "scanner"}, + { "Flash Disk", "USB Flash Disk", "usbfldisk" }, { NULL, "Generic", "scsi"} }; int i; - - for (i = 0; type2icon[i].type != NULL; i++) - if (g_str_equal(buf + 8, type2icon[i].type)) - break; - - type = type2icon[i].label; - icon = type2icon[i].icon; + + if (strstr(model, "Flash Disk")) { + type = "Flash Disk"; + icon = "usbfldisk"; + } else { + for (i = 0; type2icon[i].type != NULL; i++) + if (g_str_equal(buf + 8, type2icon[i].type)) + break; + + type = type2icon[i].label; + icon = type2icon[i].icon; + } } gchar *devid = g_strdup_printf("SCSI%d", n); - storage_list = h_strdup_cprintf("$%s$%s=\n", storage_list, devid, model); + scsi_storage_list = h_strdup_cprintf("$%s$%s=\n", scsi_storage_list, devid, model); storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, model, icon); - + gchar *strhash = g_strdup_printf("[Device Information]\n" - "Model=%s\n" - "Vendor=%s (%s)\n" - "Type=%s\n" - "Revision=%s\n" - "[SCSI Controller]\n" - "Controller=scsi%d\n" - "Channel=%d\n" - "ID=%d\n" "LUN=%d\n", - model, - vendor_get_name(model), - vendor_get_url(model), - type, - revision, - scsi_controller, - scsi_channel, - scsi_id, - scsi_lun); + "Model=%s\n", model); + + const gchar *url = vendor_get_url(model); + if (url) { + strhash = h_strdup_cprintf("Vendor=%s (%s)\n", + strhash, + vendor_get_name(model), + url); + } else { + strhash = h_strdup_cprintf("Vendor=%s\n", + strhash, + vendor_get_name(model)); + } + + strhash = h_strdup_cprintf("Type=%s\n" + "Revision=%s\n" + "[SCSI Controller]\n" + "Controller=scsi%d\n" + "Channel=%d\n" + "ID=%d\n" "LUN=%d\n", + strhash, + type, + revision, + scsi_controller, + scsi_channel, + scsi_id, + scsi_lun); g_hash_table_insert(moreinfo, devid, strhash); g_free(model); @@ -143,6 +144,11 @@ __scan_scsi_devices(void) } } fclose(proc_scsi); + + if (n) { + storage_list = h_strconcat(storage_list, scsi_storage_list, NULL); + g_free(scsi_storage_list); + } } static gboolean @@ -158,12 +164,12 @@ __scan_ide_devices(void) gchar *device, iface, *model, *media, *pgeometry = NULL, *lgeometry = NULL; gint n = 0, i = 0, cache, nn = 0; - gchar *capab = NULL, *speed = NULL, *driver = NULL; + gchar *capab = NULL, *speed = NULL, *driver = NULL, *ide_storage_list; /* remove old devices from global device table */ g_hash_table_foreach_remove(moreinfo, remove_ide_devices, NULL); - - storage_list = g_strconcat(storage_list, "\n[IDE Disks]\n", NULL); + + ide_storage_list = g_strdup("\n[IDE Disks]\n"); iface = 'a'; for (i = 0; i <= 16; i++) { @@ -285,24 +291,36 @@ __scan_ide_devices(void) gchar *devid = g_strdup_printf("IDE%d", n); - storage_list = h_strdup_cprintf("$%s$%s=\n", storage_list, + ide_storage_list = h_strdup_cprintf("$%s$%s=\n", ide_storage_list, devid, model); storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, model, g_str_equal(media, "cdrom") ? \ "cdrom" : "hdd"); - + gchar *strhash = g_strdup_printf("[Device Information]\n" - "Model=%s\n" - "Vendor=%s (%s)\n" - "Device Name=hd%c\n" - "Media=%s\n" - "Cache=%dkb\n", - model, - vendor_get_name(model), - vendor_get_url(model), - iface, - media, - cache); + "Model=%s\n", + model); + + const gchar *url = vendor_get_url(model); + + if (url) { + strhash = h_strdup_cprintf("Vendor=%s (%s)\n", + strhash, + vendor_get_name(model), + url); + } else { + strhash = h_strdup_cprintf("Vendor=%s\n", + strhash, + vendor_get_name(model)); + } + + strhash = h_strdup_cprintf("Device Name=hd%c\n" + "Media=%s\n" + "Cache=%dkb\n", + strhash, + iface, + media, + cache); if (driver) { strhash = h_strdup_cprintf("%s\n", strhash, driver); @@ -345,4 +363,9 @@ __scan_ide_devices(void) iface++; } + + if (n) { + storage_list = h_strconcat(storage_list, ide_storage_list, NULL); + g_free(ide_storage_list); + } } diff --git a/arch/linux/common/uptime.h b/arch/linux/common/uptime.h index 9225c85c..b2412cd2 100644 --- a/arch/linux/common/uptime.h +++ b/arch/linux/common/uptime.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2006 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/arch/linux/common/usb.h b/arch/linux/common/usb.h index f2592648..cb939ff8 100644 --- a/arch/linux/common/usb.h +++ b/arch/linux/common/usb.h @@ -1,6 +1,6 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira + * Copyright (C) 2003-2008 Leandro A. F. Pereira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +15,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - +/* + * FIXME: + * - listing with sysfs does not generate device hierarchy + */ static gboolean remove_usb_devices(gpointer key, gpointer value, gpointer data) { @@ -23,8 +26,106 @@ remove_usb_devices(gpointer key, gpointer value, gpointer data) } static gchar *usb_list = NULL; -void -__scan_usb(void) + +void __scan_usb_sysfs_add_device(gchar * endpoint, int n) +{ + gchar *manufacturer, *product, *mxpwr, *tmp, *strhash; + gint bus, classid, vendor, prodid; + gfloat version, speed; + + classid = h_sysfs_read_int(endpoint, "bDeviceClass"); + vendor = h_sysfs_read_int(endpoint, "idVendor"); + prodid = h_sysfs_read_int(endpoint, "idProduct"); + bus = h_sysfs_read_int(endpoint, "busnum"); + speed = h_sysfs_read_float(endpoint, "speed"); + version = h_sysfs_read_float(endpoint, "version"); + + if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) { + mxpwr = g_strdup("0 mA"); + } + + if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) { + manufacturer = g_strdup("Unknown"); + } + + if (!(product = h_sysfs_read_string(endpoint, "product"))) { + if (classid == 9) { + product = g_strdup_printf("USB %.2f Hub", version); + } else { + product = g_strdup_printf("Unknown USB %.2f Device (class %d)", version, classid); + } + } + + const gchar *url = vendor_get_url(manufacturer); + if (url) { + tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url); + + g_free(manufacturer); + manufacturer = tmp; + } + + tmp = g_strdup_printf("USB%d", n); + usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); + + strhash = g_strdup_printf("[Device Information]\n" + "Product=%s\n" + "Manufacturer=%s\n" + "Speed=%.2fMbit/s\n" + "Max Current=%s\n" + "[Misc]\n" + "USB Version=%.2f\n" + "Class=0x%x\n" + "Vendor=0x%x\n" + "Product ID=0x%x\n" + "Bus=%d\n", + product, + manufacturer, + speed, + mxpwr, + version, classid, vendor, prodid, bus); + + g_hash_table_insert(moreinfo, tmp, strhash); + + g_free(manufacturer); + g_free(product); + g_free(mxpwr); +} + +void __scan_usb_sysfs(void) +{ + GDir *sysfs; + gchar *filename; + const gchar *sysfs_path = "/sys/class/usb_endpoint"; + gint usb_device_number = 0; + + if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) { + return; + } + + if (usb_list) { + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); + g_free(usb_list); + } + usb_list = g_strdup("[USB Devices]\n"); + + while ((filename = (gchar *) g_dir_read_name(sysfs))) { + gchar *endpoint = + g_build_filename(sysfs_path, filename, "device", NULL); + gchar *temp; + + temp = g_build_filename(endpoint, "idVendor", NULL); + if (g_file_test(temp, G_FILE_TEST_EXISTS)) { + __scan_usb_sysfs_add_device(endpoint, ++usb_device_number); + } + + g_free(temp); + g_free(endpoint); + } + + g_dir_close(sysfs); +} + +int __scan_usb_procfs(void) { FILE *dev; gchar buffer[128]; @@ -36,13 +137,13 @@ __scan_usb(void) dev = fopen("/proc/bus/usb/devices", "r"); if (!dev) - return; + return 0; if (usb_list) { g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); g_free(usb_list); } - usb_list = g_strdup(""); + usb_list = g_strdup("[USB Devices]\n"); while (fgets(buffer, 128, dev)) { tmp = buffer; @@ -73,52 +174,60 @@ __scan_usb(void) mxpwr = strstr(buffer, "MxPwr=") + 6; tmp = g_strdup_printf("USB%d", ++n); - + if (*product == '\0') { - g_free(product); - if (classid == 9) { - product = g_strdup_printf("USB %.2f Hub", ver); - } else { - product = g_strdup_printf("Unknown USB %.2f Device (class %d)", - ver, classid); - } + g_free(product); + if (classid == 9) { + product = g_strdup_printf("USB %.2f Hub", ver); + } else { + product = + g_strdup_printf + ("Unknown USB %.2f Device (class %d)", ver, + classid); + } } - + if (classid == 9) { /* hub */ - usb_list = h_strdup_cprintf("[%s#%d]\n", - usb_list, product, n); - } else { /* everything else */ - usb_list = h_strdup_cprintf("$%s$%s=\n", - usb_list, tmp, product); - - const gchar *url = vendor_get_url(manuf); - if (url) { - gchar *tmp = g_strdup_printf("%s (%s)", manuf, url); - g_free(manuf); - manuf = tmp; - } - - gchar *strhash = g_strdup_printf("[Device Information]\n" - "Product=%s\n" - "Manufacturer=%s\n" - "[Port #%d]\n" - "Speed=%.2fMbit/s\n" - "Max Current=%s\n" - "[Misc]\n" - "USB Version=%.2f\n" - "Revision=%.2f\n" - "Class=0x%x\n" - "Vendor=0x%x\n" - "Product ID=0x%x\n" - "Bus=%d\n" "Level=%d\n", - product, manuf, - port, speed, mxpwr, - ver, rev, classid, - vendor, prodid, bus, level); - - g_hash_table_insert(moreinfo, tmp, strhash); - } + usb_list = h_strdup_cprintf("[%s#%d]\n", + usb_list, product, n); + } else { /* everything else */ + usb_list = h_strdup_cprintf("$%s$%s=\n", + usb_list, tmp, product); + + const gchar *url = vendor_get_url(manuf); + if (url) { + gchar *tmp = + g_strdup_printf("%s (%s)", vendor_get_name(manuf), + url); + g_free(manuf); + manuf = tmp; + } + + gchar *strhash = g_strdup_printf("[Device Information]\n" + "Product=%s\n", + product); + if (manuf && strlen(manuf)) + strhash = h_strdup_cprintf("Manufacturer=%s\n", + strhash, manuf); + + strhash = h_strdup_cprintf("[Port #%d]\n" + "Speed=%.2fMbit/s\n" + "Max Current=%s\n" + "[Misc]\n" + "USB Version=%.2f\n" + "Revision=%.2f\n" + "Class=0x%x\n" + "Vendor=0x%x\n" + "Product ID=0x%x\n" + "Bus=%d\n" "Level=%d\n", + strhash, + port, speed, mxpwr, + ver, rev, classid, + vendor, prodid, bus, level); + + g_hash_table_insert(moreinfo, tmp, strhash); + } g_free(manuf); g_free(product); @@ -128,4 +237,12 @@ __scan_usb(void) } fclose(dev); + + return n; +} + +void __scan_usb(void) +{ + if (!__scan_usb_procfs()) + __scan_usb_sysfs(); } -- cgit v1.2.3