--- darwin.c.orig	2012-09-17 09:29:57.000000000 -0400
+++ darwin.c	2012-09-17 09:48:45.000000000 -0400
@@ -189,6 +189,8 @@
     return "invalid argument";
   case kIOReturnAborted:
     return "transaction aborted";
+  case kIOReturnNotResponding:
+    return "the device is not responding";
   default:
     return "unknown error";
   }
@@ -207,6 +209,7 @@
   case kIOUSBNoAsyncPortErr:
     return ENXIO;
   case kIOReturnExclusiveAccess:
+  case kIOReturnNotResponding:
     return EBUSY;
   case kIOUSBPipeStalled:
     return LUSBDARWINSTALL;
@@ -247,7 +250,8 @@
   io_cf_plugin_ref_t *plugInInterface = NULL;
   usb_device_t **device;
   io_service_t usbDevice;
-  long result, score;
+  IOReturn result;
+  SInt32 score;
 
   if (!IOIteratorIsValid (deviceIterator) || !(usbDevice = IOIteratorNext(deviceIterator)))
     return NULL;
@@ -447,7 +451,7 @@
   IOUSBFindInterfaceRequest request;
 
   struct darwin_dev_handle *device;
-  long score;
+  SInt32 score;
   int current_interface;
 
   device = dev->impl_info;
@@ -768,8 +772,8 @@
   struct rw_complete_arg *rw_arg = (struct rw_complete_arg *)refcon;
 
   if (usb_debug > 2)
-    fprintf(stderr, "io async operation completed: %s, size=%lu, result=0x%08x\n", darwin_error_str(result),
-	    (UInt32)io_size, result);
+    fprintf(stderr, "io async operation completed: %s, size=%llu, result=0x%08llx\n", darwin_error_str(result),
+	    (UInt64)io_size, (SInt64) result);
 
   rw_arg->io_size = (UInt32)io_size;
   rw_arg->result  = result;
@@ -838,19 +842,13 @@
 
   if (result == kIOReturnSuccess) {
     /* wait for write to complete */
-    if (CFRunLoopRunInMode(kCFRunLoopDefaultMode, (timeout+999)/1000, true) == kCFRunLoopRunTimedOut) {
-      (*(device->interface))->AbortPipe(device->interface, pipeRef);
-      CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); /* Pick up aborted callback */
-      if (usb_debug)
-	fprintf(stderr, "usb_bulk_read: input timed out\n");
-    }
+    CFRunLoopRun();
   }
 
   CFRunLoopRemoveSource(CFRunLoopGetCurrent(), cfSource, kCFRunLoopDefaultMode);
   
   /* Check the return code of both the write and completion functions. */
-  if (result != kIOReturnSuccess || (rw_arg.result != kIOReturnSuccess && 
-      rw_arg.result != kIOReturnAborted) ) {
+  if (result != kIOReturnSuccess || rw_arg.result != kIOReturnSuccess) {
     int error_code;
     char *error_str;
 
@@ -1064,7 +1062,7 @@
     result = (*(device))->GetDeviceAddress(device, (USBDeviceAddress *)&address);
 
     if (usb_debug >= 2)
-      fprintf(stderr, "usb_os_find_devices: Found USB device at location 0x%08lx\n", location);
+      fprintf(stderr, "usb_os_find_devices: Found USB device at location 0x%08llx\n", (UInt64) location);
 
     /* first byte of location appears to be associated with the device's bus */
     if (location >> 24 == bus_loc >> 24) {
@@ -1091,8 +1089,8 @@
       LIST_ADD(fdev, dev);
 
       if (usb_debug >= 2)
-	fprintf(stderr, "usb_os_find_devices: Found %s on %s at location 0x%08lx\n",
-		dev->filename, bus->dirname, location);
+	fprintf(stderr, "usb_os_find_devices: Found %s on %s at location 0x%08llx\n",
+		dev->filename, bus->dirname, (UInt64) location);
     }
 
     /* release the device now */
