Problem: How can I detect when the gadget is or is not connected to a host from the gadget itself?
g_mass_storage Linux kernel module can be used to provide a mass storage device via a USB OTG port. I would like to use this to allow for file transfer over a USB to a device running Linux and this module.
Unfortunately this is not directly supported my the module, having both client and host access the storage can be flaky at best. But I could avoid this by controlling the Linux machine (USB client) so that is only reads of writes from the storage when the USB host is not connected.
One very naive solution would be to parse the
dmesg output. That at least clearly tells me when it is plugged in, but not when it is removed.
My research shows that somewhere in
/sys/ there is a gadget status flag, see this chain, but I'm not sure where.
Going the other way around, plugging the gadget into a Linux machine, I know I could use
udev monitor does not seem to say anything about the state of the gadget on the gadget itself.