From amigus@migus.org Sun Feb 16 13:42:18 2003 Return-Path: Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1D1BE37B401 for ; Sun, 16 Feb 2003 13:42:18 -0800 (PST) Received: from garple.migus.org (pcp243391pcs.howard01.md.comcast.net [68.55.83.143]) by mx1.FreeBSD.org (Postfix) with ESMTP id 59B0343F93 for ; Sun, 16 Feb 2003 13:42:17 -0800 (PST) (envelope-from amigus@migus.org) Received: from ludo.migus.org (ludo.migus.org [192.168.4.1]) by garple.migus.org (8.12.6/8.12.6) with ESMTP id h1GLgGn2015070 for ; Sun, 16 Feb 2003 16:42:16 -0500 (EST) (envelope-from amigus@migus.org) Received: from ludo.migus.org (localhost [127.0.0.1]) by ludo.migus.org (8.12.6/8.12.6) with ESMTP id h1GLgGdf005647 for ; Sun, 16 Feb 2003 16:42:16 -0500 (EST) (envelope-from amigus@ludo.migus.org) Received: (from amigus@localhost) by ludo.migus.org (8.12.6/8.12.6/Submit) id h1GLgGLI005646; Sun, 16 Feb 2003 16:42:16 -0500 (EST) Message-Id: <200302162142.h1GLgGLI005646@ludo.migus.org> Date: Sun, 16 Feb 2003 16:42:16 -0500 (EST) From: Adam Migus Reply-To: Adam Migus To: FreeBSD-gnats-submit@freebsd.org Cc: Subject: [PATCH] usbd dynamic device list. X-Send-Pr-Version: 3.113 X-GNATS-Notify: >Number: 48342 >Category: usb >Synopsis: [usbd] [patch] usbd dynamic device list. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-usb >State: closed >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Feb 16 13:50:08 PST 2003 >Closed-Date: Thu Jun 05 09:53:40 UTC 2008 >Last-Modified: Thu Jun 05 09:53:40 UTC 2008 >Originator: Adam Migus >Release: FreeBSD 5.0-CURRENT i386 >Organization: Network Associates Laboratories >Environment: System: FreeBSD ludo.migus.org 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Tue Feb 4 00:52:29 EST 2003 amigus@ludo.migus.org:/obj/ufs2/sys/src/p4/user/amigus/perforce.freebsd.org/freebsd/src/sys/SMP i386 FreeBSD on a machine with > 4 usb controllers >Description: The code uses a static array of currently 4 devices. Thus devices are ignored. >How-To-Repeat: Plug in > 4 usb controllers. >Fix: The attached patch manages controllers in a list. >Release-Note: >Audit-Trail: From: Peter Pentchev To: Adam Migus Cc: bug-followup@FreeBSD.org Subject: Re: bin/48342: [PATCH] usbd dynamic device list. Date: Mon, 17 Feb 2003 10:48:52 +0200 On Sun, Feb 16, 2003 at 04:42:16PM -0500, Adam Migus wrote: > The attached patch manages controllers in a list. Err.. did you, by any chance, forget to actually attach a patch? :) [Please respond to this message, CC'ing bug-followup@FreeBSD.org, and keeping the subject line, so that the GNATS PR tracking system can add your response to the audit trail.] G'luck, Peter -- Peter Pentchev roam@ringlet.net roam@sbnd.net roam@FreeBSD.org PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 I am jealous of the first word in this sentence. From: Adam Migus To: Peter Pentchev Cc: bug-followup@FreeBSD.org Subject: Re: bin/48342: [PATCH] usbd dynamic device list. Date: Mon, 17 Feb 2003 18:51:27 -0500 This is a multi-part message in MIME format. --------------030103030808070900080107 Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit I guess I did. :-) Here it is... -- Adam Migus - Research Scientist Network Associates Laboratories (http://www.nailabs.com) TrustedBSD (http://www.trustedbsd.org) FreeBSD (http://www.freebsd.org) --------------030103030808070900080107 Content-Type: text/plain; name="usbd.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="usbd.diff" --- ../../../../freebsd/src/usr.sbin/usbd/usbd.c Thu Jan 23 05:36:35 2003 +++ usbd.c Tue Feb 11 21:21:55 2003 @@ -74,11 +74,6 @@ */ #define USBDEV "/dev/usb" -/* Maximum number of USB busses expected to be in a system - * XXX should be replaced by dynamic allocation. - */ -#define MAXUSBDEV 4 - /* Sometimes a device does not respond in time for interrupt * driven explore to find it. Therefore we run an exploration * at regular intervals to catch those. @@ -95,9 +90,13 @@ char *configfile = CONFIGFILE; /* name of configuration file */ -char *devs[MAXUSBDEV]; /* device names */ -int fds[MAXUSBDEV]; /* file descriptors for USBDEV\d+ */ -int ndevs = 0; /* number of entries in fds / devs */ +struct usb_dev { + char *ud_name; + int ud_fd; + LIST_ENTRY(usb_dev) ud_list; +}; +LIST_HEAD(usb_dev_list, usb_dev) _usb_devs; +struct usb_dev_list *uds = &_usb_devs; int fd = -1; /* file descriptor for USBDEV */ int lineno; @@ -758,6 +757,7 @@ pid_t pid; struct sigaction ign, intact, quitact; sigset_t newsigblock, oldsigblock; + struct usb_dev *ud; int status; int i; @@ -789,8 +789,9 @@ /* child here */ /* close all open file handles for USBDEV\d* devices */ - for (i = 0; i < ndevs; i++) - close(fds[i]); /* USBDEV\d+ */ + LIST_FOREACH(ud, uds, ud_list) { + close(ud->ud_fd); /* USBDEV\d+ */ + } close(fd); /* USBDEV */ /* Restore original signal dispositions and exec the command. */ @@ -936,6 +937,9 @@ fd_set r,w; int itimeout = TIMEOUT; /* timeout for select */ struct timeval tv; + struct usb_dev *ud = NULL, *ud0 = NULL; + int fds; + LIST_INIT(uds); if (modfind(USB_UHUB) < 0) { if (kldload(USB_KLD) < 0 || modfind(USB_UHUB) < 0) { @@ -960,8 +964,18 @@ explore_once = 1; break; case 'f': - if (ndevs < MAXUSBDEV) - devs[ndevs++] = optarg; + ud0 = ud; + ud = (struct usb_dev *)malloc(sizeof(*ud)); + if (ud == NULL) { + fprintf(stderr, + "can't alloc space for %s\n", buf); + return 1; + } + ud->ud_name = optarg; + if (ud0 != NULL && !(LIST_EMPTY(uds))) + LIST_INSERT_AFTER(ud0, ud, ud_list); + else + LIST_INSERT_HEAD(uds, ud, ud_list); break; case 'n': handle_events = 0; @@ -981,51 +995,64 @@ argv += optind; maxfd = 0; - if (ndevs == 0) { + if (LIST_EMPTY(uds)) { /* open all the USBDEVS\d+ devices */ - for (i = 0; i < MAXUSBDEV; i++) { + for (i = 0;; i++) { sprintf(buf, "%s%d", USBDEV, i); - fds[ndevs] = open(buf, O_RDWR); - if (fds[ndevs] >= 0) { - devs[ndevs] = strdup(buf); - if (devs[ndevs] == NULL) { - fprintf(stderr, "strdup returned NULL\n"); - return 1; - } - if (verbose) - printf("%s: opened %s\n", - __progname, devs[ndevs]); - if (fds[ndevs] > maxfd) - maxfd = fds[ndevs]; - ndevs++; - } else if (errno != ENXIO && errno != ENOENT) { - /* there was an error, on a device that does - * exist (device is configured) - */ - fprintf(stderr, "%s: Could not open %s, %s\n", - __progname, buf, strerror(errno)); - exit(1); + fds = open(buf, O_RDWR); + if (fds < 0) { + if (errno != ENXIO && errno != ENOENT) { + /* there was an error, on a device + that does exist */ + fprintf(stderr, "%s: could not open %s," " %s\n", __progname, buf, + strerror(errno)); + exit(1); + } else + break; + } + ud0 = ud; + ud = (struct usb_dev *)malloc(sizeof(*ud)); + if (ud == NULL) { + fprintf(stderr, + "can't alloc space for %s\n", buf); + return 1; } + ud->ud_name = strdup(buf); + if (ud->ud_name == NULL) { + fprintf(stderr, + "strdup failed for %s\n", buf); + return 1; + } + ud->ud_fd = fds; + if (verbose) + printf("%s: opened %s\n", + __progname, ud->ud_name); + if (fds > maxfd) + maxfd = fds; + if (ud0 != NULL && !(LIST_EMPTY(uds))) + LIST_INSERT_AFTER(ud0, ud, ud_list); + else + LIST_INSERT_HEAD(uds, ud, ud_list); } } else { /* open all the files specified with -f */ - for (i = 0; i < ndevs; i++) { - fds[i] = open(devs[i], O_RDWR); - if (fds[i] < 0) { + LIST_FOREACH(ud, uds, ud_list) { + ud->ud_fd = open(ud->ud_name, O_RDWR); + if (ud->ud_fd < 0) { fprintf(stderr, "%s: Could not open %s, %s\n", - __progname, devs[i], strerror(errno)); + __progname, ud->ud_name, strerror(errno)); exit(1); } else { if (verbose) printf("%s: opened %s\n", - __progname, devs[i]); - if (fds[i] > maxfd) - maxfd = fds[i]; + __progname, ud->ud_name); + if (ud->ud_fd > maxfd) + maxfd = ud->ud_fd; } } } - if (ndevs == 0) { + if (LIST_EMPTY(uds)) { fprintf(stderr, "No USB host controllers found\n"); exit(1); } @@ -1033,12 +1060,12 @@ /* Do the explore once and exit */ if (explore_once) { - for (i = 0; i < ndevs; i++) { - error = ioctl(fds[i], USB_DISCOVER); + LIST_FOREACH(ud, uds, ud_list) { + error = ioctl(ud->ud_fd, USB_DISCOVER); if (error < 0) { fprintf(stderr, "%s: ioctl(%s, USB_DISCOVER) " - "failed, %s\n", - __progname, devs[i], strerror(errno)); + "failed, %s\n", __progname, ud->ud_name, + strerror(errno)); exit(1); } } @@ -1075,8 +1102,9 @@ FD_ZERO(&w); if (handle_events) FD_SET(fd, &r); /* device USBDEV */ - for (i = 0; i < ndevs; i++) - FD_SET(fds[i], &w); /* device USBDEV\d+ */ + LIST_FOREACH(ud, uds, ud_list) { + FD_SET(ud->ud_fd, &w); /* device USBDEV\d+ */ + } tv.tv_usec = 0; tv.tv_sec = itimeout; error = select(maxfd+1, &r, &w, 0, itimeout ? &tv : 0); @@ -1087,16 +1115,16 @@ } /* USBDEV\d+ devices have signaled change, do a usb_discover */ - for (i = 0; i < ndevs; i++) { - if (error == 0 || FD_ISSET(fds[i], &w)) { + LIST_FOREACH(ud, uds, ud_list) { + if (error == 0 || FD_ISSET(ud->ud_fd, &w)) { if (verbose >= 2) printf("%s: doing %sdiscovery on %s\n", __progname, - (error? "":"timeout "), devs[i]); - if (ioctl(fds[i], USB_DISCOVER) < 0) { + (error? "":"timeout "), ud->ud_name); + if (ioctl(ud->ud_fd, USB_DISCOVER) < 0) { fprintf(stderr, "%s: ioctl(%s, " "USB_DISCOVER) failed, %s\n", - __progname, devs[i], + __progname, ud->ud_name, strerror(errno)); exit(1); } --------------030103030808070900080107-- Responsible-Changed-From-To: freebsd-bugs->joe Responsible-Changed-By: kris Responsible-Changed-When: Thu Jul 17 17:37:41 PDT 2003 Responsible-Changed-Why: Assign to USB maintainer http://www.freebsd.org/cgi/query-pr.cgi?pr=48342 Responsible-Changed-From-To: joe->freebsd-usb Responsible-Changed-By: joe Responsible-Changed-When: Wed Nov 10 11:05:55 GMT 2004 Responsible-Changed-Why: Hand this over to the usb mailling list. http://www.freebsd.org/cgi/query-pr.cgi?pr=48342 State-Changed-From-To: open->closed State-Changed-By: linimon State-Changed-When: Thu Jun 5 09:52:33 UTC 2008 State-Changed-Why: Unfortunately since this PR was submitted, usbd(8) was deprecated and replaced by dev(8). Thanks for submission and sorry that it didn't work out. http://www.freebsd.org/cgi/query-pr.cgi?pr=48342 >Unformatted: