int detach_port(char *port) { int ret; uint8_t portnum; unsigned int i; for (i=0; i < strlen(port); i++) if (!isdigit(port[i])) { err("invalid port %s", port); return -1; } /* check max port */ portnum = atoi(port); ret = usbip_vhci_driver_open(); if (ret < 0) { err("open vhci_driver"); return -1; } ret = usbip_vhci_detach_device(portnum); if (ret < 0) return -1; usbip_vhci_driver_close(); return ret; }
static int detach_port(char *port) { int ret; uint8_t portnum; char path[PATH_MAX+1]; unsigned int port_len = strlen(port); for (unsigned int i = 0; i < port_len; i++) if (!isdigit(port[i])) { err("invalid port %s", port); return -1; } /* check max port */ portnum = atoi(port); /* remove the port state file */ snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", portnum); remove(path); rmdir(VHCI_STATE_PATH); ret = usbip_vhci_driver_open(); if (ret < 0) { err("open vhci_driver"); return -1; } ret = usbip_vhci_detach_device(portnum); if (ret < 0) return -1; usbip_vhci_driver_close(); return ret; }