$NetBSD: patch-ad,v 1.9 2007/10/11 18:25:19 drochner Exp $ --- bsd.c.orig 2006-03-04 03:52:46.000000000 +0100 +++ bsd.c @@ -25,8 +25,8 @@ * for both read and write. */ -#if defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) -#define __FreeBSD_kernel__ __FreeBSD__ +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) +#define FreeBSD_like_device_names 1 #endif #include @@ -39,14 +39,18 @@ #include #include +#if (__DragonFly__) +#include +#else #include +#endif #include "usbi.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef HAVE_OLD_DEV_USB_USB_H +#if defined(HAVE_OLD_DEV_USB_USB_H) && !defined(__DragonFly__) /* * It appears some of the BSD's (OpenBSD atleast) have switched over to a * new naming convention, so we setup some macro's for backward @@ -146,7 +150,7 @@ int usb_os_open(usb_dev_handle *dev) USB_ERROR(-ENOMEM); dev->impl_info = info; -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names snprintf(ctlpath, PATH_MAX, "%s", dev->device->filename); #else snprintf(ctlpath, PATH_MAX, "%s.00", dev->device->filename); @@ -259,7 +263,7 @@ static int ensure_ep_open(usb_dev_handle ep = UE_GET_ADDR(ep); if (info->ep_fd[ep] < 0) { -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names snprintf(buf, sizeof(buf) - 1, "%s.%d", dev->device->filename, ep); #else snprintf(buf, sizeof(buf) - 1, "%s.%02d", dev->device->filename, ep); @@ -290,7 +294,7 @@ int usb_bulk_write(usb_dev_handle *dev, fd = ensure_ep_open(dev, ep, O_WRONLY); if (fd < 0) { if (usb_debug >= 2) { -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names fprintf (stderr, "usb_bulk_write: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep)); #else fprintf (stderr, "usb_bulk_write: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep)); @@ -306,7 +310,7 @@ int usb_bulk_write(usb_dev_handle *dev, ret = write(fd, bytes, size); if (ret < 0) -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names USB_ERROR_STR(-errno, "error writing to bulk endpoint %s.%d: %s", dev->device->filename, UE_GET_ADDR(ep), strerror(errno)); #else @@ -328,7 +332,7 @@ int usb_bulk_read(usb_dev_handle *dev, i fd = ensure_ep_open(dev, ep, O_RDONLY); if (fd < 0) { if (usb_debug >= 2) { -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names fprintf (stderr, "usb_bulk_read: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep)); #else fprintf (stderr, "usb_bulk_read: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep)); @@ -347,7 +351,7 @@ int usb_bulk_read(usb_dev_handle *dev, i ret = read(fd, bytes, size); if (ret < 0) -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names USB_ERROR_STR(-errno, "error reading from bulk endpoint %s.%d: %s", dev->device->filename, UE_GET_ADDR(ep), strerror(errno)); #else @@ -369,7 +373,7 @@ int usb_interrupt_write(usb_dev_handle * fd = ensure_ep_open(dev, ep, O_WRONLY); if (fd < 0) { if (usb_debug >= 2) { -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names fprintf (stderr, "usb_interrupt_write: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep)); #else fprintf (stderr, "usb_interrupt_write: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep)); @@ -386,7 +390,7 @@ int usb_interrupt_write(usb_dev_handle * do { ret = write(fd, bytes+sent, size-sent); if (ret < 0) -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names USB_ERROR_STR(-errno, "error writing to interrupt endpoint %s.%d: %s", dev->device->filename, UE_GET_ADDR(ep), strerror(errno)); #else @@ -403,7 +407,7 @@ int usb_interrupt_write(usb_dev_handle * int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout) { - int fd, ret, retrieved = 0, one = 1; + int fd, ret, retrieved = 0, one = 1, requested; /* Ensure the endpoint address is correct */ ep |= USB_ENDPOINT_IN; @@ -411,7 +415,7 @@ int usb_interrupt_read(usb_dev_handle *d fd = ensure_ep_open(dev, ep, O_RDONLY); if (fd < 0) { if (usb_debug >= 2) { -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names fprintf (stderr, "usb_interrupt_read: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep)); #else fprintf (stderr, "usb_interrupt_read: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep)); @@ -429,9 +433,10 @@ int usb_interrupt_read(usb_dev_handle *d USB_ERROR_STR(-errno, "error setting short xfer: %s", strerror(errno)); do { - ret = read(fd, bytes+retrieved, size-retrieved); + requested = size - retrieved; + ret = read(fd, bytes+retrieved, requested); if (ret < 0) -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%d: %s", dev->device->filename, UE_GET_ADDR(ep), strerror(errno)); #else @@ -439,7 +444,7 @@ int usb_interrupt_read(usb_dev_handle *d dev->device->filename, UE_GET_ADDR(ep), strerror(errno)); #endif retrieved += ret; - } while (ret > 0 && retrieved < size); + } while (ret > 0 && retrieved < size && ret == requested); return retrieved; } @@ -477,7 +482,7 @@ int usb_control_msg(usb_dev_handle *dev, USB_ERROR_STR(-errno, "error sending control message: %s", strerror(errno)); - return UGETW(req.ucr_request.wLength); + return req.ucr_actlen; } int usb_os_find_busses(struct usb_bus **busses) @@ -548,7 +553,7 @@ int usb_os_find_devices(struct usb_bus * /* best not to play with things we don't understand */ continue; -#ifdef __FreeBSD_kernel__ +#ifdef FreeBSD_like_device_names snprintf(buf, sizeof(buf) - 1, "/dev/%s", di.udi_devnames[0]); #else snprintf(buf, sizeof(buf) - 1, "/dev/%s.00", di.udi_devnames[0]); @@ -574,7 +579,7 @@ int usb_os_find_devices(struct usb_bus * /* we need to report the device name as /dev/ugenx NOT /dev/ugenx.00 * This seemed easier than having 2 variables... */ -#if (__NetBSD__ || __OpenBSD__) +#if !defined(FreeBSD_like_device_names) snprintf(buf, sizeof(buf) - 1, "/dev/%s", di.udi_devnames[0]); #endif