From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1InvPn-00026r-Vm for qemu-devel@nongnu.org; Fri, 02 Nov 2007 08:14:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1InvPn-00025e-4n for qemu-devel@nongnu.org; Fri, 02 Nov 2007 08:14:19 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1InvPm-00025N-VQ for qemu-devel@nongnu.org; Fri, 02 Nov 2007 08:14:19 -0400 Received: from [66.6.122.20] (helo=tjworld.net) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1InvPm-0004Ds-Ju for qemu-devel@nongnu.org; Fri, 02 Nov 2007 08:14:18 -0400 From: TJ Content-Type: text/plain Date: Fri, 02 Nov 2007 12:14:09 +0000 Message-Id: <1194005649.25014.11.camel@hephaestion> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [Patch] Auto-detect USB devfs in Linux Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 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 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;