Updated the TODOs
[cerebrum.git] / tools / usbreset.c
blob49e7a5f4fe9ea470c04ee3e62d981dd089e17ca9
1 #include <stdio.h>
2 #include <errno.h>
3 #include <string.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6 #include <linux/usbdevice_fs.h>
7 #include <unistd.h>
9 //Resets an USB device (akin to disconnecting and re-connecting it)
10 //See http://www.roman10.net/how-to-reset-usb-device-in-linux/
11 //Compile with gcc -Wall -o usbreset usbreset.c
13 int main(int argc, char **argv){
14 int fd = open(argv[1], O_WRONLY);
15 if(fd == -1){
16 fprintf(stderr, "Cannot open the given USB device: %s\n", strerror(errno));
17 return 1;
19 if(ioctl(fd, USBDEVFS_RESET, 0)){
20 fprintf(stderr, "Error while invoking the ioctl on the given device: %s\n", strerror(errno));
21 close(fd);
22 return 2;
23 }else{
24 close(fd);
25 return 0;