Advertisement
Guest User

Untitled

a guest
Sep 9th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. /* usbreset -- send a USB port reset to a USB device */
  2.  
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6. #include <errno.h>
  7. #include <sys/ioctl.h>
  8.  
  9. #include <linux/usbdevice_fs.h>
  10.  
  11.  
  12. int main(int argc, char **argv)
  13. {
  14. const char *filename;
  15. int fd;
  16. int rc;
  17.  
  18. if (argc != 2) {
  19. fprintf(stderr, "Usage: usbreset device-filename\n");
  20. return 1;
  21. }
  22. filename = argv[1];
  23.  
  24. fd = open(filename, O_WRONLY);
  25. if (fd < 0) {
  26. perror("Error opening output file");
  27. return 1;
  28. }
  29.  
  30. printf("Resetting USB device %s\n", filename);
  31. rc = ioctl(fd, USBDEVFS_RESET, 0);
  32. if (rc < 0) {
  33. perror("Error in ioctl");
  34. return 1;
  35. }
  36. printf("Reset successful\n");
  37.  
  38. close(fd);
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement