On Sat, 21 Nov 2015, Greg KH wrote:

> > I saved a copy when you first posted it and have used it on quite a few
> > occasions.  Maybe the tool should be added to the usbutils collection so
> > it could reach a somewhat wider audience?  Yes, I know the usecases are
> > all weird, but that still doesn't mean than everyone with a usecase will
> > read this list :)
> 
> I've considered it in the past, but didn't want to deal with all of the
> "this doesn't work on my hardware" emails.  Maybe if the code prints out
> a big message when it's run it might help...

It does print out a message, though not a big one.  Would you like it
to do something more specific?  A more verbose "usage" message,
perhaps?

For convenience, the source code is included below.

Alan Stern



/* usbreset -- send a USB port reset to a USB device */
/* To build:  gcc -o usbreset usbreset.c */

#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)
{
        const char *filename;
        int fd;
        int rc;

        if (argc != 2) {
                fprintf(stderr, "Usage: usbreset device-filename\n");
                return 1;
        }
        filename = argv[1];

        fd = open(filename, O_WRONLY);
        if (fd < 0) {
                perror("Error opening output file");
                return 1;
        }

        printf("Resetting USB device %s\n", filename);
        rc = ioctl(fd, USBDEVFS_RESET, 0);
        if (rc < 0) {
                perror("Error in ioctl");
                return 1;
        }
        printf("Reset successful\n");

        close(fd);
        return 0;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to