updated on Sat Jan 21 20:03:50 UTC 2012
[aur-mirror.git] / usbreset / usbreset.c
blobe42e4d97ad99f82e54a3c6407bf3272f7759f897
1 /* usbreset -- send a USB port reset to a USB device */
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <errno.h>
7 #include <sys/ioctl.h>
9 #include <linux/usbdevice_fs.h>
11 int main(int argc, char **argv)
13 const char *filename;
14 int fd;
15 int rc;
17 if (argc != 2) {
18 fprintf(stderr, "Usage: usbreset device-filename\n");
19 return 1;
21 filename = argv[1];
23 fd = open(filename, O_WRONLY);
24 if (fd < 0) {
25 perror("Error opening output file");
26 return 1;
29 printf("Resetting USB device %s\n", filename);
30 rc = ioctl(fd, USBDEVFS_RESET, 0);
31 if (rc < 0) {
32 perror("Error in ioctl");
33 return 1;
35 printf("Reset successful\n");
37 close(fd);
38 return 0;