usbd patch (MAXUSBDEV no more)
This patch makes usbd track a dynamic number of devices using a list instead of the static array of 4 devices. It's implemented as a list but it's very easy to change. -- Adam Migus - Research Scientist Network Associates Laboratories (http://www.nailabs.com) TrustedBSD (http://www.trustedbsd.org) FreeBSD (http://www.freebsd.org) --- ../../../../freebsd/src/usr.sbin/usbd/usbd.cThu 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) { +
Re: usbd patch (MAXUSBDEV no more)
On Thu, 13 Feb 2003, Adam Migus wrote: :This patch makes usbd track a dynamic number of devices using a list :instead of the static array of 4 devices. It's implemented as a list :but it's very easy to change. Does this list want a lock to protect it? I am unfamiliar with usb locking at the moment, so ignore if stupid. Cheers, Andrew -- Andrew R. Reiter [EMAIL PROTECTED] [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: usbd patch (MAXUSBDEV no more)
Me too, so if it does require one someone please tell me. I obviously read the code and from my understanding no locking is fine but I could be wrong. On Thu, Feb 13, 2003 at 11:13:31AM -0500, Andrew R. Reiter wrote: On Thu, 13 Feb 2003, Adam Migus wrote: :This patch makes usbd track a dynamic number of devices using a list :instead of the static array of 4 devices. It's implemented as a list :but it's very easy to change. Does this list want a lock to protect it? I am unfamiliar with usb locking at the moment, so ignore if stupid. Cheers, Andrew -- Andrew R. Reiter [EMAIL PROTECTED] [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: usbd patch (MAXUSBDEV no more)
On Thu, 13 Feb 2003 11:13:31 -0500 (EST) Andrew R. Reiter [EMAIL PROTECTED] wrote: On Thu, 13 Feb 2003, Adam Migus wrote: :This patch makes usbd track a dynamic number of devices using a list :instead of the static array of 4 devices. It's implemented as a list :but it's very easy to change. Does this list want a lock to protect it? I am unfamiliar with usb locking at the moment, so ignore if stupid. There is nothing to be familiar with at the moment. UBS stack relies on spls on -stable and Giant on -current to protect the data access. -- Alexander Kabaev To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message
Re: usbd patch (MAXUSBDEV no more)
On Thu, Feb 13, 2003 at 11:02:29AM -0500, Adam Migus wrote: This patch makes usbd track a dynamic number of devices using a list instead of the static array of 4 devices. It's implemented as a list but it's very easy to change. Thanks, although I'm not clear as to the future of usbd. With the advent of devd most of usbd's functionality will probably me implemented over there instead. I've not spent a great deal of time looking at devd yet to be sure. Joe -- Josef Karthauser ([EMAIL PROTECTED]) http://www.josef-k.net/ FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/ Physics Particle Theory (student) http://www.pact.cpes.sussex.ac.uk/ An eclectic mix of fact and theory. = msg52302/pgp0.pgp Description: PGP signature
Re: usbd patch (MAXUSBDEV no more)
Joe, funny you should mention. I actually tried posting this patch three times. The first two times I actually said in the (more elaborate) explanation of the patch that I as well am moving toward devd. So, I see your point and it's why I didn't bother spending more than 30 minutes doing this patch. I'd like to see usbd go away. I'd like to help devd take it's place. Adam On Thu, Feb 13, 2003 at 05:01:28PM +, Josef Karthauser wrote: On Thu, Feb 13, 2003 at 11:02:29AM -0500, Adam Migus wrote: This patch makes usbd track a dynamic number of devices using a list instead of the static array of 4 devices. It's implemented as a list but it's very easy to change. Thanks, although I'm not clear as to the future of usbd. With the advent of devd most of usbd's functionality will probably me implemented over there instead. I've not spent a great deal of time looking at devd yet to be sure. Joe -- Josef Karthauser ([EMAIL PROTECTED])http://www.josef-k.net/ FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/ Physics Particle Theory (student) http://www.pact.cpes.sussex.ac.uk/ An eclectic mix of fact and theory. = To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-current in the body of the message