From owner-p4-projects@FreeBSD.ORG Thu Sep 4 18:44:35 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 89F6C106571F; Thu, 4 Sep 2008 18:44:35 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 332261065670 for ; Thu, 4 Sep 2008 18:44:35 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 206858FC15 for ; Thu, 4 Sep 2008 18:44:35 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m84IiZJn008689 for ; Thu, 4 Sep 2008 18:44:35 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m84IiYc1008683 for perforce@freebsd.org; Thu, 4 Sep 2008 18:44:35 GMT (envelope-from hselasky@FreeBSD.org) Date: Thu, 4 Sep 2008 18:44:35 GMT Message-Id: <200809041844.m84IiYc1008683@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 149217 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Sep 2008 18:44:35 -0000 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 #define USB_DEVICE_NAME "usb" +#define USB_GENERIC_NAME "ugen" struct usb2_read_dir { void *urd_data;