[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [Patch] Auto-detect USB devfs in Linux
From: |
TJ |
Subject: |
[Qemu-devel] [Patch] Auto-detect USB devfs in Linux |
Date: |
Fri, 02 Nov 2007 12:14:09 +0000 |
Since Linux kernel 2.6.14 the USB device file-system has moved from
'/proc/bus/usb' to '/dev/bus/usb' but qemu has '/proc/bus/usb'
hard-coded in usb-linux.c
I explored the option of moving USBDEVFS_PATH to config.h but it would
require several additions to the configure script as well as the changes
to usb-linux.c
Therefore I have opted to detect which USB file-system is in use by
extending the error-detection in usb_host_scan() to first try
'/dev/bus/usb' and if that fails, then try the pre-2.6.14
'/proc/bus/usb'.
The new code uses a (new) static char 'usb_devfs_path' set to the path
that works, and it is subsequently used in usb_host_device_open().
TJ.
Index: usb-linux.c
===================================================================
RCS file: /sources/qemu/qemu/usb-linux.c,v
retrieving revision 1.15
diff -u -r1.15 usb-linux.c
--- usb-linux.c 31 Oct 2007 00:27:50 -0000 1.15
+++ usb-linux.c 2 Nov 2007 11:31:57 -0000
@@ -52,7 +52,17 @@
//#define DEBUG_ISOCH
//#define USE_ASYNCIO
-#define USBDEVFS_PATH "/proc/bus/usb"
+/*
+ * TJ <address@hidden> 2007-11-02
+ * Now defaults to /dev/bus/usb/devices which was introduced into kernel
version 2.6.14 with
+ * commit fbf82fd2e1f4e679c60516d772d1862c941ca845 on Jul 31st 2005.
+ *
+ * If the 'devices' file doesn't exist, code checks for the older
"/proc/bus/usb/devices"
+ * before reporting an error.
+*/
+static unsigned char usb_devfs_path[64];
+#define USB_DEVFS_PATH_PRE_2_6_14 "/proc/bus/usb"
+#define USB_DEVFS_PATH "/dev/bus/usb"
#define PRODUCT_NAME_SZ 32
#define SIG_ISOCOMPLETE (SIGRTMIN+7)
#define MAX_ENDPOINTS 16
@@ -614,7 +624,7 @@
devname) < 0)
return NULL;
- snprintf(buf, sizeof(buf), USBDEVFS_PATH "/%03d/%03d",
+ snprintf(buf, sizeof(buf), "%s/%03d/%03d", usb_devfs_path,
bus_num, addr);
fd = open(buf, O_RDWR | O_NONBLOCK);
if (fd < 0) {
@@ -737,11 +747,25 @@
int bus_num, addr, speed, device_count, class_id, product_id, vendor_id;
int ret;
char product_name[512];
-
- f = fopen(USBDEVFS_PATH "/devices", "r");
+
+ /* TJ <address@hidden> 2007-11-02
+ * Auto-detect USB devices file-system location
+ * pre 2.6.14 kernels used /proc/bus/usb
+ * Standard location is now /dev/bus/usb
+ * Retain correct location in static variable for use by
usb_host_device_open()
+ */
+ snprintf(usb_devfs_path, sizeof(usb_devfs_path), "%s", USB_DEVFS_PATH);
+ /* use buf temporarily to build path to devices file */
+ snprintf(buf, sizeof(buf), "%s/devices", usb_devfs_path);
+ f = fopen(buf, "r");
if (!f) {
- term_printf("Could not open %s\n", USBDEVFS_PATH "/devices");
- return 0;
+ snprintf(usb_devfs_path, sizeof(usb_devfs_path), "%s",
USB_DEVFS_PATH_PRE_2_6_14);
+ snprintf(buf, sizeof(buf), "%s/devices", usb_devfs_path);
+ f = fopen(buf, "r");
+ if (!f) {
+ term_printf("Could not open USB devices file %s\n", buf);
+ return 0;
+ }
}
device_count = 0;
bus_num = addr = speed = class_id = product_id = vendor_id = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [Patch] Auto-detect USB devfs in Linux,
TJ <=