From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:35199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QzQUf-0000kT-IB for qemu-devel@nongnu.org; Fri, 02 Sep 2011 05:57:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QzQUe-0002Bc-Gl for qemu-devel@nongnu.org; Fri, 02 Sep 2011 05:57:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QzQUe-0002BK-8Z for qemu-devel@nongnu.org; Fri, 02 Sep 2011 05:57:00 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p829uxki010390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 2 Sep 2011 05:56:59 -0400 From: Gerd Hoffmann Date: Fri, 2 Sep 2011 11:56:39 +0200 Message-Id: <1314957407-29508-11-git-send-email-kraxel@redhat.com> In-Reply-To: <1314957407-29508-1-git-send-email-kraxel@redhat.com> References: <1314957407-29508-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 10/18] usb-host: parse port in /proc/bus/usb/devices scan List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Unfortunaly this is limited to root ports. Signed-off-by: Gerd Hoffmann --- usb-linux.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index ef29a76..7995178 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1483,7 +1483,8 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) FILE *f = NULL; char line[1024]; char buf[1024]; - int bus_num, addr, speed, device_count, class_id, product_id, vendor_id; + int bus_num, addr, speed, device_count; + int class_id, product_id, vendor_id, port; char product_name[512]; int ret = 0; @@ -1521,6 +1522,10 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) goto fail; } bus_num = atoi(buf); + if (get_tag_value(buf, sizeof(buf), line, "Port=", " ") < 0) { + goto fail; + } + port = atoi(buf); if (get_tag_value(buf, sizeof(buf), line, "Dev#=", " ") < 0) { goto fail; } @@ -1566,7 +1571,12 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) } if (device_count && (vendor_id || product_id)) { /* Add the last device. */ - ret = func(opaque, bus_num, addr, 0, class_id, vendor_id, + if (port > 0) { + snprintf(buf, sizeof(buf), "%d", port); + } else { + snprintf(buf, sizeof(buf), "?"); + } + ret = func(opaque, bus_num, addr, buf, class_id, vendor_id, product_id, product_name, speed); } the_end: -- 1.7.1