static int bind_device(char *busid) { int rc; rc = unbind_other(busid); if (rc == UNBIND_ST_FAILED) { err("could not unbind driver from device on busid %s", busid); return -1; } else if (rc == UNBIND_ST_USBIP_HOST) { err("device on busid %s is already bound to %s", busid, USBIP_HOST_DRV_NAME); return -1; } rc = modify_match_busid(busid, 1); if (rc < 0) { err("unable to bind device on %s", busid); return -1; } rc = bind_usbip(busid); if (rc < 0) { err("could not bind device to %s", USBIP_HOST_DRV_NAME); modify_match_busid(busid, 0); return -1; } printf("bind device on busid %s: complete\n", busid); return 0; }
static int bind_device(char *busid) { int rc; struct udev *udev; struct udev_device *dev; /* Check whether the device with this bus ID exists. */ udev = udev_new(); dev = udev_device_new_from_subsystem_sysname(udev, "usb", busid); if (!dev) { err("device with the specified bus ID does not exist"); return -1; } udev_unref(udev); rc = unbind_other(busid); if (rc == UNBIND_ST_FAILED) { err("could not unbind driver from device on busid %s", busid); return -1; } else if (rc == UNBIND_ST_USBIP_HOST) { err("device on busid %s is already bound to %s", busid, USBIP_HOST_DRV_NAME); return -1; } rc = modify_match_busid(busid, 1); if (rc < 0) { err("unable to bind device on %s", busid); return -1; } rc = bind_usbip(busid); if (rc < 0) { err("could not bind device to %s", USBIP_HOST_DRV_NAME); modify_match_busid(busid, 0); return -1; } info("bind device on busid %s: complete", busid); return 0; }