You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2 KiB

  1. /* Found at https://www.linuxquestions.org/questions/linux-hardware-18/how-to-unclaim-usb-device-558138/#post3406986 */
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <linux/ioctl.h>
  7. #include <linux/usbdevice_fs.h>
  8. int main(int argc, char**argv)
  9. {
  10. struct usbdevfs_ioctl command;
  11. int ret;
  12. int fd;
  13. int i;
  14. if (argc>1) {
  15. fd = open(argv[1],O_RDWR);
  16. if (fd<1){
  17. perror("unable to open file");
  18. return 1;
  19. }
  20. for (i=0;i<255;i++){ // hack: should fetch how many interface there is.
  21. command.ifno = i;
  22. command.ioctl_code = USBDEVFS_DISCONNECT;
  23. command.data = NULL;
  24. ret = ioctl(fd, USBDEVFS_IOCTL, &command);
  25. if(ret!=-1)
  26. printf("un claimed interface %d %d\n",i,ret);
  27. }
  28. } else {
  29. printf ("usage: %s /dev/bus/usb/BUS/DEVICE\n",argv[0]);
  30. printf("Release all interfaces of this usb device for usage in virtualisation\n");
  31. }
  32. }