ioscanner wrote: ↑
Thu Aug 15, 2019 6:40 pm
I got libcomposite working. Seems I have to do the setup of mouse, keyboard and storage at the same time for all to run at once. Then I can turn off and on Lun.0 with the file I want to share.
Be careful doing that. Without a secondary coms channel between the USB host and your code there is no way to know when it is safe to do this. All but the most basic of USB hosts will be using read and write caching, all the mass storage drive sees is a requiest to read or write N bytes starting at address A and has no idea if further writes are coming. Even that little data doesn't appear to be exposed to userland.
Turning off Lun 0 while the host has pending reads isn't likely to cause problems on the Pi end but likely will to the host. Turning it off during writes or when the host hasn't flushed its write cache is likely to cause problems on both ends upto and including file/SD card corruptuion on the Pi end.
If you're expecting/intending to have simultaneous read/write access to the shared storage from both linux on the Pi and the USB host you should rethink things as a mass_storage gadget can't cope reliably or well with this. Put simply: both sides use read/write caching, both sides expect exclusive access, and neither side tells the other what it's doing or whether it has more data to write in its cache. Any writes made on one side will not be seen without unmounting and remounting on the other.
Lastly, I'm concerned about "with the file I want to share". The mass storage gadget appears as a block device (hdd etc) to the host. Any file you give it will be treated as such so you can't give it, say, a text file and expect the host to see it as such. The file parameter given to g_mass_storage/libcomposite can be either a partition (e.g. /dev/sda1) or a file (e.g. /foo/bar) but the file will be treated as if it were a partition so will need to be formatted in a way the host can understand just the same as a USB stick or HDD would need to be.
Appologies if I've misinterpreted your post and you're aware of the above.
This space unintentionally left blank.