static int refresh_exported_devices(void) { struct sysfs_device *suinf; /* sysfs_device of usb_interface */ struct dlist *suinf_list; struct sysfs_device *sudev; /* sysfs_device of usb_device */ struct dlist *sudev_list; sudev_list = dlist_new_with_delete(sizeof(struct sysfs_device), delete_nothing); suinf_list = sysfs_get_driver_devices(stub_driver->sysfs_driver); if (!suinf_list) { printf("Bind usbip.ko to a usb device to be exportable!\n"); goto bye; } /* collect unique USB devices (not interfaces) */ dlist_for_each_data(suinf_list, suinf, struct sysfs_device) { /* get usb device of this usb interface */ sudev = sysfs_get_device_parent(suinf); if (!sudev) { err("get parent dev of %s", suinf->name); continue; } if (check_new(sudev_list, sudev)) { dlist_unshift(sudev_list, sudev); } }
static int refresh_exported_devices(void) { /* sysfs_device of usb_interface */ struct sysfs_device *suintf; struct dlist *suintf_list; /* sysfs_device of usb_device */ struct sysfs_device *sudev; struct dlist *sudev_list; struct usbip_exported_device *edev; sudev_list = dlist_new_with_delete(sizeof(struct sysfs_device), delete_nothing); suintf_list = sysfs_get_driver_devices(host_driver->sysfs_driver); if (!suintf_list) { /* * Not an error condition. There are simply no devices bound to * the driver yet. */ dbg("bind " USBIP_HOST_DRV_NAME ".ko to a usb device to be " "exportable!"); return 0; } /* collect unique USB devices (not interfaces) */ dlist_for_each_data(suintf_list, suintf, struct sysfs_device) { /* get usb device of this usb interface */ sudev = sysfs_get_device_parent(suintf); if (!sudev) { dbg("sysfs_get_device_parent failed: %s", suintf->name); continue; } if (check_new(sudev_list, sudev)) { /* insert item at head of list */ dlist_unshift(sudev_list, sudev); } }
int main(int argc, char *argv[]) { char *bus = NULL, path[SYSFS_PATH_MAX]; struct sysfs_driver *driver = NULL; struct sysfs_device *device = NULL; struct dlist *devlist = NULL; struct sysfs_attribute *attr = NULL; if (argc != 3) { print_usage(); return 1; } memset(path, 0, SYSFS_PATH_MAX); if ((sysfs_get_mnt_path(path, SYSFS_PATH_MAX)) != 0) { fprintf(stdout, "Sysfs not mounted?\n"); return 1; } strcat(path, "/"); strcat(path, SYSFS_BUS_NAME); strcat(path, "/"); strcat(path, argv[1]); strcat(path, "/"); strcat(path, SYSFS_DRIVERS_NAME); strcat(path, "/"); strcat(path, argv[2]); driver = sysfs_open_driver_path(path); if (driver == NULL) { fprintf(stdout, "Driver %s not found\n", argv[1]); free(bus); return 1; } devlist = sysfs_get_driver_devices(driver); if (devlist != NULL) { fprintf(stdout, "%s is used by:\n", argv[2]); dlist_for_each_data(devlist, device, struct sysfs_device) fprintf(stdout, "\t\t%s\n", device->bus_id); } else