linux-libusb done

Roman Divacky rdivacky at freebsd.org
Mon Oct 27 11:46:01 UTC 2008


On Mon, Oct 27, 2008 at 10:27:17AM +0100, Martin Laabs wrote:
> Hi,
> 
> On Sun, 26 Oct 2008 11:52:52 +0100, Roman Divacky <rdivacky at freebsd.org> wrote:
> 
> > please show us the linuxulator patch and I'll see what I can do about it...
> 
> I've append the patch for the linux.ko module as well as the patch for the
> bsd.c in libusb-0.12.


>diff -Naur linux/linux_ioctl.c linux.usb/linux_ioctl.c
>--- linux/linux_ioctl.c	2007-11-15 11:38:06.000000000 +0100
>+++ linux.usb/linux_ioctl.c	2008-10-26 11:49:59.000000000 +0100
>@@ -88,6 +88,8 @@
> static linux_ioctl_function_t linux_ioctl_drm;
> static linux_ioctl_function_t linux_ioctl_sg;
> static linux_ioctl_function_t linux_ioctl_special;
>+//for hacked libusb
>+static linux_ioctl_function_t linux_ioctl_usb;
 
Don't use // comments, I wont repeat that for every occurance
of this..

also you dont seem to be using proper indentation

> static struct linux_ioctl_handler cdrom_handler =
> { linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX };
>@@ -111,6 +113,9 @@
> { linux_ioctl_drm, LINUX_IOCTL_DRM_MIN, LINUX_IOCTL_DRM_MAX };
> static struct linux_ioctl_handler sg_handler =
> { linux_ioctl_sg, LINUX_IOCTL_SG_MIN, LINUX_IOCTL_SG_MAX };
>+//USB libusb compatibility mode ...
>+static struct linux_ioctl_handler usb_handler =
>+{ linux_ioctl_usb, LINUX_IOCTL_USB_MIN, LINUX_IOCTL_USB_MAX };
> 
> DATA_SET(linux_ioctl_handler_set, cdrom_handler);
> DATA_SET(linux_ioctl_handler_set, vfat_handler);
>@@ -123,6 +128,7 @@
> DATA_SET(linux_ioctl_handler_set, private_handler);
> DATA_SET(linux_ioctl_handler_set, drm_handler);
> DATA_SET(linux_ioctl_handler_set, sg_handler);
>+DATA_SET(linux_ioctl_handler_set, usb_handler);                                  
> 
> struct handler_element
> {
>@@ -2542,6 +2548,60 @@
> 	return ioctl(td, (struct ioctl_args *)args);
> }
> 
>+static int                                                                      
>+linux_ioctl_usb(struct thread *td, struct linux_ioctl_args *args)
>+{
>+       struct file *fp;
>+       int error;
>+
>+       if ((error = fget(td, args->fd, &fp)) != 0)
>+           return (error);
>+
>+#ifdef DEBUG
>+       printf("%s(): USB-ioctl %d\n", __func__,
>+                  args->cmd & 0xffff);
>+#endif
>+
>+	switch (args->cmd & 0xffff) {
>+	case LINUXBSD_IOCTL_USB_DEVICEINFO:
>+	  error = ioctl(td, (struct ioctl_args *)args);
>+	  break;
>+	case LINUXBSD_IOCTL_SET_CONFIG:
>+          error = ioctl(td, (struct ioctl_args *)args);
>+            break;
>+	case LINUXBSD_IOCTL_SET_ALTINTERFACE:
>+          error = ioctl(td, (struct ioctl_args *)args);
>+            break;
>+	case LINUXBSD_IOCTL_SET_TIMEOUT:
>+          error = ioctl(td, (struct ioctl_args *)args);
>+            break;
>+	case LINUXBSD_IOCTL_SET_SHORT_XFER:
>+          error = ioctl(td, (struct ioctl_args *)args);
>+            break;
>+	case LINUXBSD_IOCTL_DO_REQUEST:
>+          error = ioctl(td, (struct ioctl_args *)args);
>+            break;
>+	case LINUXBSD_IOCTL_GET_DEVICE_DESC:
>+          error = ioctl(td, (struct ioctl_args *)args);
>+            break;

Please collapse this into a fallthrough statement, ie.

case X:
case Y:
....
  break;

>+	default:                                                                
>+            /* XXX */                                                       
>+            linux_msg(td,                                                   
>+            "usb ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented",
>+            args->fd, (int)(args->cmd & 0xffff),
>+            (int)(args->cmd & 0xff00) >> 8,
>+            (int)(args->cmd & 0xff));
>+	    error=ENOIOCTL;
>+            break;
>+	}
>+	fdrop(fp, td);
>+#ifdef DEBUG
>+printf("%s(): USB returning %d\n", __func__, error);
>+#endif
>+        return (error);
>+}
>+
> static int
> linux_ioctl_sg(struct thread *td, struct linux_ioctl_args *args)
> {
>diff -Naur linux/linux_ioctl.h linux.usb/linux_ioctl.h
>--- linux/linux_ioctl.h	2007-11-15 11:38:06.000000000 +0100
>+++ linux.usb/linux_ioctl.h	2008-10-25 14:16:13.000000000 +0200
>@@ -171,6 +171,15 @@
> #define	LINUX_IOCTL_VFAT_MIN	LINUX_VFAT_READDIR_BOTH
> #define	LINUX_IOCTL_VFAT_MAX	LINUX_VFAT_READDIR_BOTH
> 
>+
>+/*
>+ * USB libusb compatibility mode ...
>+ */
>+ 
>+#define LINUX_IOCTL_USB_MIN	0x5503
>+#define LINUX_IOCTL_USB_MAX	0x5573
>+ 
>+ 
> /*
>  * console
>  */
>@@ -567,6 +576,14 @@
> #define	LINUX_IOCTL_DRM_MIN	0x6400
> #define	LINUX_IOCTL_DRM_MAX	0x64ff
> 
>+#define LINUXBSD_IOCTL_USB_DEVICEINFO	0x5504
>+#define LINUXBSD_IOCTL_SET_CONFIG 0x5565
>+#define LINUXBSD_IOCTL_SET_ALTINTERFACE 0x5567
>+#define LINUXBSD_IOCTL_SET_TIMEOUT 0x5572
>+#define LINUXBSD_IOCTL_SET_SHORT_XFER 0x5571
>+#define LINUXBSD_IOCTL_DO_REQUEST 0x556f
>+#define LINUXBSD_IOCTL_GET_DEVICE_DESC 0x5569
>+
> /*
>  * This doesn't really belong here, but I can't think of a better
>  * place to put it.

please fix those trivial bugs and submit once more. I believe
it's commit ready by then (it's quite trivial :) )

thnx for the great work!

roman


More information about the freebsd-emulation mailing list