wok-current rev 1773
hardinfo: fix usb
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Nov 28 17:23:48 2008 +0000 (2008-11-28) |
parents | 497da1516e30 |
children | 22791a4ca944 |
files | hardinfo/receipt hardinfo/stuff/modules.patch hardinfo/stuff/usb.patch |
line diff
1.1 --- a/hardinfo/receipt Thu Nov 27 16:12:32 2008 +0000 1.2 +++ b/hardinfo/receipt Fri Nov 28 17:23:48 2008 +0000 1.3 @@ -25,6 +25,7 @@ 1.4 languages.patch 1.5 boots.patch 1.6 os.patch 1.7 +usb.patch 1.8 EOT 1.9 ./configure \ 1.10 --prefix=/usr \
2.1 --- a/hardinfo/stuff/modules.patch Thu Nov 27 16:12:32 2008 +0000 2.2 +++ b/hardinfo/stuff/modules.patch Fri Nov 28 17:23:48 2008 +0000 2.3 @@ -1,11 +1,13 @@ 2.4 --- arch/linux/common/modules.h Sun Nov 4 14:14:30 2007 2.5 +++ arch/linux/common/modules.h Sun Apr 20 23:49:38 2008 2.6 -@@ -42,7 +42,7 @@ 2.7 - module_list = NULL; 2.8 +@@ -43,6 +43,10 @@ 2.9 g_hash_table_foreach_remove(moreinfo, remove_module_devices, NULL); 2.10 2.11 -- lsmod = popen("/sbin/lsmod", "r"); 2.12 -+ lsmod = popen("/bin/lsmod", "r"); 2.13 + lsmod = popen("/sbin/lsmod", "r"); 2.14 ++ 2.15 ++ if (!lsmod) 2.16 ++ lsmod = popen("/bin/lsmod", "r"); 2.17 ++ 2.18 if (!lsmod) 2.19 return; 2.20
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/hardinfo/stuff/usb.patch Fri Nov 28 17:23:48 2008 +0000 3.3 @@ -0,0 +1,316 @@ 3.4 +--- util.c 3.5 ++++ util.c 3.6 +@@ -1048,3 +1048,55 @@ 3.7 + h_hash_table_remove_all_true, 3.8 + NULL); 3.9 + } 3.10 ++ 3.11 ++gfloat 3.12 ++h_sysfs_read_float(gchar *endpoint, gchar *entry) 3.13 ++{ 3.14 ++ gchar *tmp, *buffer; 3.15 ++ gfloat return_value = 0.0f; 3.16 ++ 3.17 ++ tmp = g_build_filename(endpoint, entry, NULL); 3.18 ++ if (g_file_get_contents(tmp, &buffer, NULL, NULL)) 3.19 ++ return_value = atof(buffer); 3.20 ++ 3.21 ++ g_free(tmp); 3.22 ++ g_free(buffer); 3.23 ++ 3.24 ++ return return_value; 3.25 ++} 3.26 ++ 3.27 ++gint 3.28 ++h_sysfs_read_int(gchar *endpoint, gchar *entry) 3.29 ++{ 3.30 ++ gchar *tmp, *buffer; 3.31 ++ gint return_value = 0.0f; 3.32 ++ 3.33 ++ tmp = g_build_filename(endpoint, entry, NULL); 3.34 ++ if (g_file_get_contents(tmp, &buffer, NULL, NULL)) 3.35 ++ return_value = atoi(buffer); 3.36 ++ 3.37 ++ g_free(tmp); 3.38 ++ g_free(buffer); 3.39 ++ 3.40 ++ return return_value; 3.41 ++} 3.42 ++ 3.43 ++gchar * 3.44 ++h_sysfs_read_string(gchar *endpoint, gchar *entry) 3.45 ++{ 3.46 ++ gchar *tmp, *return_value; 3.47 ++ 3.48 ++ tmp = g_build_filename(endpoint, entry, NULL); 3.49 ++ if (!g_file_get_contents(tmp, &return_value, NULL, NULL)) { 3.50 ++ g_free(return_value); 3.51 ++ 3.52 ++ return_value = NULL; 3.53 ++ } else { 3.54 ++ return_value = g_strstrip(return_value); 3.55 ++ } 3.56 ++ 3.57 ++ g_free(tmp); 3.58 ++ 3.59 ++ return return_value; 3.60 ++} 3.61 ++ 3.62 + 3.63 +--- arch/linux/common/usb.h 3.64 ++++ arch/linux/common/usb.h 3.65 +@@ -15,7 +15,6 @@ 3.66 + * along with this program; if not, write to the Free Software 3.67 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 3.68 + */ 3.69 +- 3.70 + static gboolean 3.71 + remove_usb_devices(gpointer key, gpointer value, gpointer data) 3.72 + { 3.73 +@@ -23,8 +22,113 @@ 3.74 + } 3.75 + 3.76 + static gchar *usb_list = NULL; 3.77 +-void 3.78 +-__scan_usb(void) 3.79 ++ 3.80 ++void __scan_usb_sysfs_add_device(gchar * endpoint, int n) 3.81 ++{ 3.82 ++ gchar *manufacturer, *product, *mxpwr, *tmp, *strhash; 3.83 ++ gint bus, classid, vendor, prodid; 3.84 ++ gchar *version, *speed; 3.85 ++ 3.86 ++ classid = h_sysfs_read_int(endpoint, "bDeviceClass"); 3.87 ++ vendor = h_sysfs_read_int(endpoint, "idVendor"); 3.88 ++ prodid = h_sysfs_read_int(endpoint, "idProduct"); 3.89 ++ bus = h_sysfs_read_int(endpoint, "busnum"); 3.90 ++ if (!(speed = h_sysfs_read_string(endpoint, "speed"))) { 3.91 ++ speed = g_strdup("12"); 3.92 ++ } 3.93 ++ 3.94 ++ if (!(version = h_sysfs_read_string(endpoint, "version"))) { 3.95 ++ version = g_strdup(" 1.0 "); 3.96 ++ } 3.97 ++ 3.98 ++ if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) { 3.99 ++ mxpwr = g_strdup("0 mA"); 3.100 ++ } 3.101 ++ 3.102 ++ if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) { 3.103 ++ manufacturer = g_strdup("Unknown"); 3.104 ++ } 3.105 ++ 3.106 ++ if (!(product = h_sysfs_read_string(endpoint, "product"))) { 3.107 ++ if (classid == 9) { 3.108 ++ product = g_strdup_printf("USB %.2f Hub", version); 3.109 ++ } else { 3.110 ++ product = g_strdup_printf("Unknown USB %.2f Device (class %d)", version, classid); 3.111 ++ } 3.112 ++ } 3.113 ++ 3.114 ++ const gchar *url = vendor_get_url(manufacturer); 3.115 ++ if (url) { 3.116 ++ tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url); 3.117 ++ 3.118 ++ g_free(manufacturer); 3.119 ++ manufacturer = tmp; 3.120 ++ } 3.121 ++ 3.122 ++ tmp = g_strdup_printf("USB%d", n); 3.123 ++ usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); 3.124 ++ 3.125 ++ strhash = g_strdup_printf("[Device Information]\n" 3.126 ++ "Product=%s\n" 3.127 ++ "Manufacturer=%s\n" 3.128 ++ "Speed=%sMbit/s\n" 3.129 ++ "Max Current=%s\n" 3.130 ++ "[Misc]\n" 3.131 ++ "USB Version=%s\n" 3.132 ++ "Class=0x%x\n" 3.133 ++ "Vendor=0x%x\n" 3.134 ++ "Product ID=0x%x\n" 3.135 ++ "Bus=%d\n", 3.136 ++ product, 3.137 ++ manufacturer, 3.138 ++ speed, 3.139 ++ mxpwr, 3.140 ++ version, classid, vendor, prodid, bus); 3.141 ++ 3.142 ++ g_hash_table_insert(moreinfo, tmp, strhash); 3.143 ++ 3.144 ++ g_free(manufacturer); 3.145 ++ g_free(product); 3.146 ++ g_free(mxpwr); 3.147 ++ g_free(speed); 3.148 ++ g_free(version); 3.149 ++} 3.150 ++ 3.151 ++void __scan_usb_sysfs(void) 3.152 ++{ 3.153 ++ GDir *sysfs; 3.154 ++ gchar *filename; 3.155 ++ const gchar *sysfs_path = "/sys/class/usb_endpoint"; 3.156 ++ gint usb_device_number = 0; 3.157 ++ 3.158 ++ if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) { 3.159 ++ return; 3.160 ++ } 3.161 ++ 3.162 ++ if (usb_list) { 3.163 ++ g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); 3.164 ++ g_free(usb_list); 3.165 ++ } 3.166 ++ usb_list = g_strdup("[USB Devices]\n"); 3.167 ++ 3.168 ++ while ((filename = (gchar *) g_dir_read_name(sysfs))) { 3.169 ++ gchar *endpoint = 3.170 ++ g_build_filename(sysfs_path, filename, "device", NULL); 3.171 ++ gchar *temp; 3.172 ++ 3.173 ++ temp = g_build_filename(endpoint, "idVendor", NULL); 3.174 ++ if (g_file_test(temp, G_FILE_TEST_EXISTS)) { 3.175 ++ __scan_usb_sysfs_add_device(endpoint, ++usb_device_number); 3.176 ++ } 3.177 ++ 3.178 ++ g_free(temp); 3.179 ++ g_free(endpoint); 3.180 ++ } 3.181 ++ 3.182 ++ g_dir_close(sysfs); 3.183 ++} 3.184 ++ 3.185 ++int __scan_usb_procfs(void) 3.186 + { 3.187 + FILE *dev; 3.188 + gchar buffer[128]; 3.189 +@@ -36,13 +140,13 @@ 3.190 + 3.191 + dev = fopen("/proc/bus/usb/devices", "r"); 3.192 + if (!dev) 3.193 +- return; 3.194 ++ return 0; 3.195 + 3.196 + if (usb_list) { 3.197 + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); 3.198 + g_free(usb_list); 3.199 + } 3.200 +- usb_list = g_strdup(""); 3.201 ++ usb_list = g_strdup("[USB Devices]\n"); 3.202 + 3.203 + while (fgets(buffer, 128, dev)) { 3.204 + tmp = buffer; 3.205 +@@ -73,52 +177,60 @@ 3.206 + mxpwr = strstr(buffer, "MxPwr=") + 6; 3.207 + 3.208 + tmp = g_strdup_printf("USB%d", ++n); 3.209 +- 3.210 ++ 3.211 + if (*product == '\0') { 3.212 +- g_free(product); 3.213 +- if (classid == 9) { 3.214 +- product = g_strdup_printf("USB %.2f Hub", ver); 3.215 +- } else { 3.216 +- product = g_strdup_printf("Unknown USB %.2f Device (class %d)", 3.217 +- ver, classid); 3.218 +- } 3.219 ++ g_free(product); 3.220 ++ if (classid == 9) { 3.221 ++ product = g_strdup_printf("USB %.2f Hub", ver); 3.222 ++ } else { 3.223 ++ product = 3.224 ++ g_strdup_printf 3.225 ++ ("Unknown USB %.2f Device (class %d)", ver, 3.226 ++ classid); 3.227 ++ } 3.228 + } 3.229 +- 3.230 ++ 3.231 + 3.232 + if (classid == 9) { /* hub */ 3.233 +- usb_list = h_strdup_cprintf("[%s#%d]\n", 3.234 +- usb_list, product, n); 3.235 +- } else { /* everything else */ 3.236 +- usb_list = h_strdup_cprintf("$%s$%s=\n", 3.237 +- usb_list, tmp, product); 3.238 +- 3.239 +- const gchar *url = vendor_get_url(manuf); 3.240 +- if (url) { 3.241 +- gchar *tmp = g_strdup_printf("%s (%s)", manuf, url); 3.242 +- g_free(manuf); 3.243 +- manuf = tmp; 3.244 +- } 3.245 +- 3.246 +- gchar *strhash = g_strdup_printf("[Device Information]\n" 3.247 +- "Product=%s\n" 3.248 +- "Manufacturer=%s\n" 3.249 +- "[Port #%d]\n" 3.250 +- "Speed=%.2fMbit/s\n" 3.251 +- "Max Current=%s\n" 3.252 +- "[Misc]\n" 3.253 +- "USB Version=%.2f\n" 3.254 +- "Revision=%.2f\n" 3.255 +- "Class=0x%x\n" 3.256 +- "Vendor=0x%x\n" 3.257 +- "Product ID=0x%x\n" 3.258 +- "Bus=%d\n" "Level=%d\n", 3.259 +- product, manuf, 3.260 +- port, speed, mxpwr, 3.261 +- ver, rev, classid, 3.262 +- vendor, prodid, bus, level); 3.263 ++ usb_list = h_strdup_cprintf("[%s#%d]\n", 3.264 ++ usb_list, product, n); 3.265 ++ } else { /* everything else */ 3.266 ++ usb_list = h_strdup_cprintf("$%s$%s=\n", 3.267 ++ usb_list, tmp, product); 3.268 ++ 3.269 ++ const gchar *url = vendor_get_url(manuf); 3.270 ++ if (url) { 3.271 ++ gchar *tmp = 3.272 ++ g_strdup_printf("%s (%s)", vendor_get_name(manuf), 3.273 ++ url); 3.274 ++ g_free(manuf); 3.275 ++ manuf = tmp; 3.276 ++ } 3.277 ++ 3.278 ++ gchar *strhash = g_strdup_printf("[Device Information]\n" 3.279 ++ "Product=%s\n", 3.280 ++ product); 3.281 ++ if (manuf && strlen(manuf)) 3.282 ++ strhash = h_strdup_cprintf("Manufacturer=%s\n", 3.283 ++ strhash, manuf); 3.284 ++ 3.285 ++ strhash = h_strdup_cprintf("[Port #%d]\n" 3.286 ++ "Speed=%.2fMbit/s\n" 3.287 ++ "Max Current=%s\n" 3.288 ++ "[Misc]\n" 3.289 ++ "USB Version=%.2f\n" 3.290 ++ "Revision=%.2f\n" 3.291 ++ "Class=0x%x\n" 3.292 ++ "Vendor=0x%x\n" 3.293 ++ "Product ID=0x%x\n" 3.294 ++ "Bus=%d\n" "Level=%d\n", 3.295 ++ strhash, 3.296 ++ port, speed, mxpwr, 3.297 ++ ver, rev, classid, 3.298 ++ vendor, prodid, bus, level); 3.299 + 3.300 +- g_hash_table_insert(moreinfo, tmp, strhash); 3.301 +- } 3.302 ++ g_hash_table_insert(moreinfo, tmp, strhash); 3.303 ++ } 3.304 + 3.305 + g_free(manuf); 3.306 + g_free(product); 3.307 +@@ -128,4 +240,12 @@ 3.308 + } 3.309 + 3.310 + fclose(dev); 3.311 ++ 3.312 ++ return n; 3.313 ++} 3.314 ++ 3.315 ++void __scan_usb(void) 3.316 ++{ 3.317 ++ if (!__scan_usb_procfs()) 3.318 ++ __scan_usb_sysfs(); 3.319 + }