@jdstrand, I use configfs to control libcomposite which is used to combine several USB peripheral functions on one USB peripheral controller. For example to have USB Ethernet + USB Mass Storage. Or Audio + HID. Or Video + Audio + HID. Or custom functions with their corresponding kernel modules.
With configfs you can do it dynamically. For example, like in any smartphone, a user enters passcode, turns on mass storage function, copies files over the USB to PC and disables this function for security reasons.
As an Option 1 there could be a place to control it statically, once for every boot, but even for that there is no place. Everything is read only. But still in general dynamic control is more interesting.
The path is: $CONFIGFS_HOME/usb_gadget/
You start by creating a new USB gadget:
And then you write to its internal structure.
@ogra, @niemeyer, indeed now I see it mounted after clean reboot with mount snap disabled. Thanks for pointing it out. I clearly remember once it didn’t appear somehow and I decided it’s permanent behavior.
configfs on /sys/kernel/config type configfs (rw,relatime)