如何 重置 usb drive , 而不用 手動插拔
from https://marc.info/?l=linux-usb&m=121459435621262&q=p3
/* usbreset -- reset a USB device */
/*
$ gcc usbreset.c -o usbreset
$ sudo mv usbreset /usr/local/bin/
$ lsusb
Bus 001 Device 004: ID .....
$ sudo usbreset /dev/bus/usb/001/004
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
if (argc != 2) {
fprintf(stderr, "Usage: usbreset device-filename\n");
fprintf(stderr,"\
$ lsusb\n\
Bus 001 Device 004: ID .....\n\
$ sudo usbreset /dev/bus/usb/001/004\n\
");
return 1;
}
const char *filename = argv[1];
int fd = open(filename, O_WRONLY);
if (fd < 0) {
perror("Error opening output file");
return 1;
}
printf("Resetting USB device %s\n", filename);
int rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0) {
perror("Error in ioctl");
return 1;
}
printf("Reset successful\n");
close(fd);
return 0;
}
/* usbreset -- reset a USB device */
/*
$ gcc usbreset.c -o usbreset
$ sudo mv usbreset /usr/local/bin/
$ lsusb
Bus 001 Device 004: ID .....
$ sudo usbreset /dev/bus/usb/001/004
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "Usage: usbreset device-filename\n");
fprintf(stderr,"\
$ lsusb\n\
Bus 001 Device 004: ID .....\n\
$ sudo usbreset /dev/bus/usb/001/004\n\
");
return 1;
}
const char *filename = argv[1];
int fd = open(filename, O_WRONLY);
if (fd < 0) {
perror("Error opening output file");
return 1;
}
printf("Resetting USB device %s\n", filename);
int rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0) {
perror("Error in ioctl");
return 1;
}
printf("Reset successful\n");
close(fd);
return 0;
}
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁