platform = udev_device_get_parent(vhci_driver->hc_device); if (platform == NULL) return -1;
n = scandir(udev_device_get_syspath(platform), &namelist, vhci_hcd_filter, NULL); if (n < 0)
err("scandir failed"); else { for (int i = 0; i < n; i++)
free(namelist[i]);
free(namelist);
}
return n;
}
/* * Read the given port's record. * * To avoid buffer overflow we will read the entire line and * validate each part's size. The initial buffer is padded by 4 to * accommodate the 2 spaces, 1 newline and an additional character * which is needed to properly validate the 3rd part without it being * truncated to an acceptable length.
*/ staticint read_record(int rhport, char *host, unsignedlong host_len, char *port, unsignedlong port_len, char *busid)
{ int part;
FILE *file; char path[PATH_MAX+1]; char *buffer, *start, *end; char delim[] = {' ', ' ', '\n'}; int max_len[] = {(int)host_len, (int)port_len, SYSFS_BUS_ID_SIZE};
size_t buffer_len = host_len + port_len + SYSFS_BUS_ID_SIZE + 4;
buffer = malloc(buffer_len); if (!buffer) return -1;
/* validate the length of each of the 3 parts */
start = buffer; for (part = 0; part < 3; part++) {
end = strchr(start, delim[part]); if (end == NULL || (end - start) > max_len[part]) {
free(buffer); return -1;
}
start = end + 1;
}
/* will be freed in usbip_driver_close() */
hc_device =
udev_device_new_from_subsystem_sysname(udev_context,
USBIP_VHCI_BUS_TYPE,
USBIP_VHCI_DEVICE_NAME); if (!hc_device) {
err("udev_device_new_from_subsystem_sysname failed"); goto err;
}
nports = get_nports(hc_device); if (nports <= 0) {
err("no available ports"); goto err;
}
dbg("available ports: %d", nports);
int usbip_vhci_get_free_port(uint32_t speed)
{ for (int i = 0; i < vhci_driver->nports; i++) {
switch (speed) { case USB_SPEED_SUPER: if (vhci_driver->idev[i].hub != HUB_SPEED_SUPER) continue; break; default: if (vhci_driver->idev[i].hub != HUB_SPEED_HIGH) continue; break;
}
if (vhci_driver->idev[i].status == VDEV_ST_NULL) return vhci_driver->idev[i].port;
}
return -1;
}
int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
uint32_t speed) { char buff[200]; /* what size should be ? */ char attach_attr_path[SYSFS_PATH_MAX]; char attr_attach[] = "attach"; constchar *path; int ret;
/* will be removed */ int usbip_vhci_attach_device(uint8_t port, int sockfd, uint8_t busnum,
uint8_t devnum, uint32_t speed)
{ int devid = get_devid(busnum, devnum);
int usbip_vhci_detach_device(uint8_t port)
{ char detach_attr_path[SYSFS_PATH_MAX]; char attr_detach[] = "detach"; char buff[200]; /* what size should be ? */ constchar *path; int ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.