Hello,

This proposed patch add support for deleting usb devices by providing the
(exact) same string they were added with, thus enabling to remove a usb
device with the host string.
The old capability of deleting usb device by their internal port is not
harmed.

I had to move USBHostDevice to vl.h so that I will be able to reference it
from vl.c

and last, I've changed the output of info usb so that it will include the
saved string (for reference).

Please comment.


BR,
Yuval Kashtan.
diff -Naur qemu.orig/usb-linux.c qemu.usb/usb-linux.c
--- qemu.orig/usb-linux.c	2007-10-09 13:27:39.000000000 +0200
+++ qemu.usb/usb-linux.c	2007-10-09 15:04:46.000000000 +0200
@@ -56,27 +56,9 @@
 #define USBDEVFS_PATH "/proc/bus/usb"
 #define PRODUCT_NAME_SZ 32
 #define SIG_ISOCOMPLETE (SIGRTMIN+7)
-#define MAX_ENDPOINTS 16
 
 struct sigaction sigact;
 
-/* endpoint association data */
-struct endp_data {
-    uint8_t type;
-};
-
-/* FIXME: move USBPacket to PendingURB */
-typedef struct USBHostDevice {
-    USBDevice dev;
-    int fd;
-    USBPacket *packet;
-    struct endp_data endp_table[MAX_ENDPOINTS];
-    int configuration;
-    uint8_t descr[1024];
-    int descr_len;
-    int urbs_ready;
-} USBHostDevice;
-
 typedef struct PendingURB {
     struct usbdevfs_urb *urb;
     USBHostDevice *dev;
diff -Naur qemu.orig/vl.c qemu.usb/vl.c
--- qemu.orig/vl.c	2007-10-09 13:01:16.000000000 +0200
+++ qemu.usb/vl.c	2007-10-09 15:04:36.000000000 +0200
@@ -4743,6 +4743,9 @@
     free_usb_ports = port->next;
     port->next = used_usb_ports;
     used_usb_ports = port;
+    pstrcpy (((USBHostDevice *)dev)->szDeviceName,
+             20, 
+             devname);
     usb_attach(port, dev);
     return 0;
 }
@@ -4768,7 +4771,8 @@
 
     lastp = &used_usb_ports;
     port = used_usb_ports;
-    while (port && port->dev->addr != addr) {
+    while (port && port->dev->addr != addr && strcmp (((USBHostDevice *)(port->dev))->szDeviceName,
+                                                      devname) != 0) {
         lastp = &port->next;
         port = port->next;
     }
@@ -4830,8 +4834,8 @@
             speed_str = "?";
             break;
         }
-        term_printf("  Device %d.%d, Speed %s Mb/s, Product %s\n",
-                    0, dev->addr, speed_str, dev->devname);
+        term_printf("  Device %d.%d[%s], Speed %s Mb/s, Product %s\n",
+                    0, dev->addr, ((USBHostDevice *)dev)->szDeviceName, speed_str, dev->devname);
     }
 }
 
diff -Naur qemu.orig/vl.h qemu.usb/vl.h
--- qemu.orig/vl.h	2007-10-09 13:01:19.000000000 +0200
+++ qemu.usb/vl.h	2007-10-09 15:04:36.000000000 +0200
@@ -1394,6 +1394,30 @@
 
 #include "hw/usb.h"
 
+#if defined(__linux__)
+#include <linux/compiler.h>
+#include <linux/usbdevice_fs.h>
+
+#define MAX_ENDPOINTS 16
+
+/* endpoint association data */
+struct endp_data {
+    uint8_t type;
+};
+
+/* FIXME: move USBPacket to PendingURB */
+typedef struct USBHostDevice {
+    USBDevice dev;
+    int fd;
+    USBPacket *packet;
+    struct endp_data endp_table[MAX_ENDPOINTS];
+    int configuration;
+    uint8_t descr[1024];
+    int descr_len;
+    int urbs_ready;
+    char szDeviceName[20];
+} USBHostDevice;
+#endif
 /* usb ports of the VM */
 
 void qemu_register_usb_port(USBPort *port, void *opaque, int index,

Reply via email to