wok diff hardinfo/stuff/usb.patch @ rev 5744
audacity: Fix BUILD_DEPENDS
author | Eric Joseph-Alexandre <erjo@slitaz.org> |
---|---|
date | Sun Jun 27 11:06:04 2010 +0200 (2010-06-27) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/hardinfo/stuff/usb.patch Sun Jun 27 11:06:04 2010 +0200 1.3 @@ -0,0 +1,316 @@ 1.4 +--- util.c 1.5 ++++ util.c 1.6 +@@ -1048,3 +1048,55 @@ 1.7 + h_hash_table_remove_all_true, 1.8 + NULL); 1.9 + } 1.10 ++ 1.11 ++gfloat 1.12 ++h_sysfs_read_float(gchar *endpoint, gchar *entry) 1.13 ++{ 1.14 ++ gchar *tmp, *buffer; 1.15 ++ gfloat return_value = 0.0f; 1.16 ++ 1.17 ++ tmp = g_build_filename(endpoint, entry, NULL); 1.18 ++ if (g_file_get_contents(tmp, &buffer, NULL, NULL)) 1.19 ++ return_value = atof(buffer); 1.20 ++ 1.21 ++ g_free(tmp); 1.22 ++ g_free(buffer); 1.23 ++ 1.24 ++ return return_value; 1.25 ++} 1.26 ++ 1.27 ++gint 1.28 ++h_sysfs_read_int(gchar *endpoint, gchar *entry) 1.29 ++{ 1.30 ++ gchar *tmp, *buffer; 1.31 ++ gint return_value = 0.0f; 1.32 ++ 1.33 ++ tmp = g_build_filename(endpoint, entry, NULL); 1.34 ++ if (g_file_get_contents(tmp, &buffer, NULL, NULL)) 1.35 ++ return_value = atoi(buffer); 1.36 ++ 1.37 ++ g_free(tmp); 1.38 ++ g_free(buffer); 1.39 ++ 1.40 ++ return return_value; 1.41 ++} 1.42 ++ 1.43 ++gchar * 1.44 ++h_sysfs_read_string(gchar *endpoint, gchar *entry) 1.45 ++{ 1.46 ++ gchar *tmp, *return_value; 1.47 ++ 1.48 ++ tmp = g_build_filename(endpoint, entry, NULL); 1.49 ++ if (!g_file_get_contents(tmp, &return_value, NULL, NULL)) { 1.50 ++ g_free(return_value); 1.51 ++ 1.52 ++ return_value = NULL; 1.53 ++ } else { 1.54 ++ return_value = g_strstrip(return_value); 1.55 ++ } 1.56 ++ 1.57 ++ g_free(tmp); 1.58 ++ 1.59 ++ return return_value; 1.60 ++} 1.61 ++ 1.62 + 1.63 +--- arch/linux/common/usb.h 1.64 ++++ arch/linux/common/usb.h 1.65 +@@ -15,7 +15,6 @@ 1.66 + * along with this program; if not, write to the Free Software 1.67 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1.68 + */ 1.69 +- 1.70 + static gboolean 1.71 + remove_usb_devices(gpointer key, gpointer value, gpointer data) 1.72 + { 1.73 +@@ -23,8 +22,113 @@ 1.74 + } 1.75 + 1.76 + static gchar *usb_list = NULL; 1.77 +-void 1.78 +-__scan_usb(void) 1.79 ++ 1.80 ++void __scan_usb_sysfs_add_device(gchar * endpoint, int n) 1.81 ++{ 1.82 ++ gchar *manufacturer, *product, *mxpwr, *tmp, *strhash; 1.83 ++ gint bus, classid, vendor, prodid; 1.84 ++ gchar *version, *speed; 1.85 ++ 1.86 ++ classid = h_sysfs_read_int(endpoint, "bDeviceClass"); 1.87 ++ vendor = h_sysfs_read_int(endpoint, "idVendor"); 1.88 ++ prodid = h_sysfs_read_int(endpoint, "idProduct"); 1.89 ++ bus = h_sysfs_read_int(endpoint, "busnum"); 1.90 ++ if (!(speed = h_sysfs_read_string(endpoint, "speed"))) { 1.91 ++ speed = g_strdup("12"); 1.92 ++ } 1.93 ++ 1.94 ++ if (!(version = h_sysfs_read_string(endpoint, "version"))) { 1.95 ++ version = g_strdup(" 1.0 "); 1.96 ++ } 1.97 ++ 1.98 ++ if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) { 1.99 ++ mxpwr = g_strdup("0 mA"); 1.100 ++ } 1.101 ++ 1.102 ++ if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) { 1.103 ++ manufacturer = g_strdup("Unknown"); 1.104 ++ } 1.105 ++ 1.106 ++ if (!(product = h_sysfs_read_string(endpoint, "product"))) { 1.107 ++ if (classid == 9) { 1.108 ++ product = g_strdup_printf("USB %.2f Hub", version); 1.109 ++ } else { 1.110 ++ product = g_strdup_printf("Unknown USB %.2f Device (class %d)", version, classid); 1.111 ++ } 1.112 ++ } 1.113 ++ 1.114 ++ const gchar *url = vendor_get_url(manufacturer); 1.115 ++ if (url) { 1.116 ++ tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url); 1.117 ++ 1.118 ++ g_free(manufacturer); 1.119 ++ manufacturer = tmp; 1.120 ++ } 1.121 ++ 1.122 ++ tmp = g_strdup_printf("USB%d", n); 1.123 ++ usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); 1.124 ++ 1.125 ++ strhash = g_strdup_printf("[Device Information]\n" 1.126 ++ "Product=%s\n" 1.127 ++ "Manufacturer=%s\n" 1.128 ++ "Speed=%sMbit/s\n" 1.129 ++ "Max Current=%s\n" 1.130 ++ "[Misc]\n" 1.131 ++ "USB Version=%s\n" 1.132 ++ "Class=0x%x\n" 1.133 ++ "Vendor=0x%x\n" 1.134 ++ "Product ID=0x%x\n" 1.135 ++ "Bus=%d\n", 1.136 ++ product, 1.137 ++ manufacturer, 1.138 ++ speed, 1.139 ++ mxpwr, 1.140 ++ version, classid, vendor, prodid, bus); 1.141 ++ 1.142 ++ g_hash_table_insert(moreinfo, tmp, strhash); 1.143 ++ 1.144 ++ g_free(manufacturer); 1.145 ++ g_free(product); 1.146 ++ g_free(mxpwr); 1.147 ++ g_free(speed); 1.148 ++ g_free(version); 1.149 ++} 1.150 ++ 1.151 ++void __scan_usb_sysfs(void) 1.152 ++{ 1.153 ++ GDir *sysfs; 1.154 ++ gchar *filename; 1.155 ++ const gchar *sysfs_path = "/sys/class/usb_endpoint"; 1.156 ++ gint usb_device_number = 0; 1.157 ++ 1.158 ++ if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) { 1.159 ++ return; 1.160 ++ } 1.161 ++ 1.162 ++ if (usb_list) { 1.163 ++ g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); 1.164 ++ g_free(usb_list); 1.165 ++ } 1.166 ++ usb_list = g_strdup("[USB Devices]\n"); 1.167 ++ 1.168 ++ while ((filename = (gchar *) g_dir_read_name(sysfs))) { 1.169 ++ gchar *endpoint = 1.170 ++ g_build_filename(sysfs_path, filename, "device", NULL); 1.171 ++ gchar *temp; 1.172 ++ 1.173 ++ temp = g_build_filename(endpoint, "idVendor", NULL); 1.174 ++ if (g_file_test(temp, G_FILE_TEST_EXISTS)) { 1.175 ++ __scan_usb_sysfs_add_device(endpoint, ++usb_device_number); 1.176 ++ } 1.177 ++ 1.178 ++ g_free(temp); 1.179 ++ g_free(endpoint); 1.180 ++ } 1.181 ++ 1.182 ++ g_dir_close(sysfs); 1.183 ++} 1.184 ++ 1.185 ++int __scan_usb_procfs(void) 1.186 + { 1.187 + FILE *dev; 1.188 + gchar buffer[128]; 1.189 +@@ -36,13 +140,13 @@ 1.190 + 1.191 + dev = fopen("/proc/bus/usb/devices", "r"); 1.192 + if (!dev) 1.193 +- return; 1.194 ++ return 0; 1.195 + 1.196 + if (usb_list) { 1.197 + g_hash_table_foreach_remove(moreinfo, remove_usb_devices, NULL); 1.198 + g_free(usb_list); 1.199 + } 1.200 +- usb_list = g_strdup(""); 1.201 ++ usb_list = g_strdup("[USB Devices]\n"); 1.202 + 1.203 + while (fgets(buffer, 128, dev)) { 1.204 + tmp = buffer; 1.205 +@@ -73,52 +177,60 @@ 1.206 + mxpwr = strstr(buffer, "MxPwr=") + 6; 1.207 + 1.208 + tmp = g_strdup_printf("USB%d", ++n); 1.209 +- 1.210 ++ 1.211 + if (*product == '\0') { 1.212 +- g_free(product); 1.213 +- if (classid == 9) { 1.214 +- product = g_strdup_printf("USB %.2f Hub", ver); 1.215 +- } else { 1.216 +- product = g_strdup_printf("Unknown USB %.2f Device (class %d)", 1.217 +- ver, classid); 1.218 +- } 1.219 ++ g_free(product); 1.220 ++ if (classid == 9) { 1.221 ++ product = g_strdup_printf("USB %.2f Hub", ver); 1.222 ++ } else { 1.223 ++ product = 1.224 ++ g_strdup_printf 1.225 ++ ("Unknown USB %.2f Device (class %d)", ver, 1.226 ++ classid); 1.227 ++ } 1.228 + } 1.229 +- 1.230 ++ 1.231 + 1.232 + if (classid == 9) { /* hub */ 1.233 +- usb_list = h_strdup_cprintf("[%s#%d]\n", 1.234 +- usb_list, product, n); 1.235 +- } else { /* everything else */ 1.236 +- usb_list = h_strdup_cprintf("$%s$%s=\n", 1.237 +- usb_list, tmp, product); 1.238 +- 1.239 +- const gchar *url = vendor_get_url(manuf); 1.240 +- if (url) { 1.241 +- gchar *tmp = g_strdup_printf("%s (%s)", manuf, url); 1.242 +- g_free(manuf); 1.243 +- manuf = tmp; 1.244 +- } 1.245 +- 1.246 +- gchar *strhash = g_strdup_printf("[Device Information]\n" 1.247 +- "Product=%s\n" 1.248 +- "Manufacturer=%s\n" 1.249 +- "[Port #%d]\n" 1.250 +- "Speed=%.2fMbit/s\n" 1.251 +- "Max Current=%s\n" 1.252 +- "[Misc]\n" 1.253 +- "USB Version=%.2f\n" 1.254 +- "Revision=%.2f\n" 1.255 +- "Class=0x%x\n" 1.256 +- "Vendor=0x%x\n" 1.257 +- "Product ID=0x%x\n" 1.258 +- "Bus=%d\n" "Level=%d\n", 1.259 +- product, manuf, 1.260 +- port, speed, mxpwr, 1.261 +- ver, rev, classid, 1.262 +- vendor, prodid, bus, level); 1.263 ++ usb_list = h_strdup_cprintf("[%s#%d]\n", 1.264 ++ usb_list, product, n); 1.265 ++ } else { /* everything else */ 1.266 ++ usb_list = h_strdup_cprintf("$%s$%s=\n", 1.267 ++ usb_list, tmp, product); 1.268 ++ 1.269 ++ const gchar *url = vendor_get_url(manuf); 1.270 ++ if (url) { 1.271 ++ gchar *tmp = 1.272 ++ g_strdup_printf("%s (%s)", vendor_get_name(manuf), 1.273 ++ url); 1.274 ++ g_free(manuf); 1.275 ++ manuf = tmp; 1.276 ++ } 1.277 ++ 1.278 ++ gchar *strhash = g_strdup_printf("[Device Information]\n" 1.279 ++ "Product=%s\n", 1.280 ++ product); 1.281 ++ if (manuf && strlen(manuf)) 1.282 ++ strhash = h_strdup_cprintf("Manufacturer=%s\n", 1.283 ++ strhash, manuf); 1.284 ++ 1.285 ++ strhash = h_strdup_cprintf("[Port #%d]\n" 1.286 ++ "Speed=%.2fMbit/s\n" 1.287 ++ "Max Current=%s\n" 1.288 ++ "[Misc]\n" 1.289 ++ "USB Version=%.2f\n" 1.290 ++ "Revision=%.2f\n" 1.291 ++ "Class=0x%x\n" 1.292 ++ "Vendor=0x%x\n" 1.293 ++ "Product ID=0x%x\n" 1.294 ++ "Bus=%d\n" "Level=%d\n", 1.295 ++ strhash, 1.296 ++ port, speed, mxpwr, 1.297 ++ ver, rev, classid, 1.298 ++ vendor, prodid, bus, level); 1.299 + 1.300 +- g_hash_table_insert(moreinfo, tmp, strhash); 1.301 +- } 1.302 ++ g_hash_table_insert(moreinfo, tmp, strhash); 1.303 ++ } 1.304 + 1.305 + g_free(manuf); 1.306 + g_free(product); 1.307 +@@ -128,4 +240,12 @@ 1.308 + } 1.309 + 1.310 + fclose(dev); 1.311 ++ 1.312 ++ return n; 1.313 ++} 1.314 ++ 1.315 ++void __scan_usb(void) 1.316 ++{ 1.317 ++ if (!__scan_usb_procfs()) 1.318 ++ __scan_usb_sysfs(); 1.319 + }