From: TJ <linux@tjworld.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [Patch] Auto-detect USB devfs in Linux
Date: Fri, 02 Nov 2007 12:14:09 +0000 [thread overview]
Message-ID: <1194005649.25014.11.camel@hephaestion> (raw)
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 <linux@tjworld.net> 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 <linux@tjworld.net> 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;
reply other threads:[~2007-11-02 12:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1194005649.25014.11.camel@hephaestion \
--to=linux@tjworld.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).