Search code examples
linuxlinux-kernelusblinux-device-driverusb-mass-storage

Pass param to USB ioctl


I have a problem for read/write data to USB mass storage device, with 'Device or resource busy' error for below command:

ioctl(usbFD, USBDEVFS_CLAIMINTERFACE, &interface_num) 

So i need to release interface before. But i don't know How can i pass interface_num correctly to this command:

ioctl(usbFD, USBDEVFS_RELEASEINTERFACE, &interface_num), 

If it's not defined, is there any function to found this interface number. Please help me! Thanks.


Solution

  • The documentation states:

    USBDEVFS_RELEASEINTERFACE

    This is used to release the claim usbfs made on interface, either implicitly or because of a USBDEVFS_CLAIMINTERFACE call, before the file descriptor is closed. The ioctl parameter is an integer holding the number of the interface (bInterfaceNumber from descriptor); File modification time is not updated by this request.

    But it seems here "parameter is an integer" still means that a pointer to an integer should be passed, just like you're showing. If you have the descriptor, you can find the interface number.