just a short question: I'd like to have my USB stick attached to USB high speed
host automounted as vfat.
Would it be acceptable to call mount/umount directly in the usbhost_storage.c
where the blockdriver is registered/unregistered?
For sure switchable with Kconfig options.
I tried to setup a fs_automount instance, but I lack an
IRQ/callback/connectionstate from host or msc I could use.
Calling mount or umount from a driver is a very bad idea (but has
nothing to do with PROTECTED or KERNEL build modes). It is a bad idea
because it is a horrible violation of the modular architecture of the
OS. Device drivers should not mount file systems; they should manage
devices and report device-related events.
I think you should consider adding a notification event. Look, for
example, at the work queue notifiers in include/nutttx/wqueue.h. A
notification for USB device insertion, removal events would be a natural
extension. With such a notification event, it should be pretty easy to
integrate with the existing event-based automounter. Look at
./boards/arm/kinetis/twr-k64f120m/src/k66_automount.c which handles SDHC
automounter events. USB events could be handled in an analogous way.
Instead of a new new notification event, you would also use the USB host
polling thread. Look, for example at,
boards/arm/imxrt/imxrt1060-evk/src/imxrt_usbhost.c. The polling loop is
the function ehci_waiter in this case.
static int ehci_waiter(int argc, char *argv[])
{
FAR struct usbhost_hubport_s *hport;
uinfo("ehci_waiter: Running\n");
for (; ; )
{
/* Wait for the device to change state */
DEBUGVERIFY(CONN_WAIT(g_ehciconn, &hport));
syslog(LOG_INFO, "ehci_waiter: %s\n",
hport->connected ? "connected" : "disconnected");
/* Did we just become connected? */
if (hport->connected)
{
/* Yes.. enumerate the newly connected device */
CONN_ENUMERATE(g_ehciconn, hport);
}
}
/* Keep the compiler from complaining */
return 0;
}
You could also integrate the automounter into this loop. Instead of an
asynchronous event kicking off the automount, it would be the successful
enumeration of a USB storage device.