Patch by Pete Goodeve fixing #9311. Thanks.

* Respect device's declared max packet size.
  This improve support of USB midi controlers which don't support
  arbitrary bulk read size, like iCON ones.
* Fix an logic inversion regarding O_RDONLY/O_WRONLY
  and output or input ports only devices.