Date: Thu, 4 Sep 2008 18:44:35 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 149217 for review Message-ID: <200809041844.m84IiYc1008683@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=149217 Change 149217 by hselasky@hselasky_laptop001 on 2008/09/04 18:44:10 Bugfixs to USB file interface: 1) Use bcmp instead of strcmp, else we match the wrong string. Else it is not possible to access /dev/ugenX.Y.Z.T . Previously only access to /dev/ugenX.Y worked. 2) Add support for FIODTYPE ioctl so that the "dd" utility can be used on /dev/ugen . Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#27 edit .. //depot/projects/usb/src/sys/dev/usb2/include/usb2_ioctl.h#14 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#27 (text+ko) ==== @@ -1314,37 +1314,55 @@ * usb2_clone - cdev callback * * This function is the kernel clone callback for "/dev/usbX.Y". + * + * NOTE: This function assumes that the clone and device open + * operation is atomic. *------------------------------------------------------------------------*/ static void usb2_clone(void *arg, USB_UCRED char *name, int namelen, struct cdev **dev) { enum { USB_DNAME_LEN = sizeof(USB_DEVICE_NAME) - 1, + USB_GNAME_LEN = sizeof(USB_GENERIC_NAME) - 1, }; if (*dev) { /* someone else has created a device */ return; } - if (usb2_last_devloc != (uint32_t)(0 - 1)) { - /* - * XXX can we assume that the clone and open operation is - * atomic ? - */ - DPRINTFN(2, "Clone race!\n"); - } - if (strcmp(name, USB_DEVICE_NAME)) { - usb2_last_devloc = - usb2_lookup_symlink(name, namelen); - } else { + /* reset device location */ + usb2_last_devloc = (uint32_t)(0 - 1); + + /* + * Check if we are matching "usb", "ugen" or an internal + * symbolic link: + */ + if ((namelen >= USB_DNAME_LEN) && + (bcmp(name, USB_DEVICE_NAME, USB_DNAME_LEN) == 0)) { if (namelen == USB_DNAME_LEN) { + /* USB management device location */ usb2_last_devloc = (uint32_t)(0 - 2); } else { + /* USB endpoint */ usb2_last_devloc = usb2_path_convert(name + USB_DNAME_LEN); } + } else if ((namelen >= USB_GNAME_LEN) && + (bcmp(name, USB_GENERIC_NAME, USB_GNAME_LEN) == 0)) { + if (namelen == USB_GNAME_LEN) { + /* USB management device location */ + usb2_last_devloc = (uint32_t)(0 - 2); + } else { + /* USB endpoint */ + usb2_last_devloc = + usb2_path_convert(name + USB_GNAME_LEN); + } + } + if (usb2_last_devloc == (uint32_t)(0 - 1)) { + /* Search for symbolic link */ + usb2_last_devloc = + usb2_lookup_symlink(name, namelen); } - if (usb2_last_devloc == (uint32_t)(0 - 1)) { /* invalid location */ return; @@ -1449,6 +1467,10 @@ int error = 0; switch (cmd) { + case FIODTYPE: + *(int *)addr = 0; /* character device */ + break; + case FIONBIO: /* handled by upper FS layer */ break; ==== //depot/projects/usb/src/sys/dev/usb2/include/usb2_ioctl.h#14 (text+ko) ==== @@ -32,6 +32,7 @@ #include <sys/ioccom.h> #define USB_DEVICE_NAME "usb" +#define USB_GENERIC_NAME "ugen" struct usb2_read_dir { void *urd_data;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809041844.m84IiYc1008683>