You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Fotis Panagiotopoulos <f....@gmail.com> on 2021/01/10 12:29:07 UTC

SD Card automounter events

Hi everyone,

I am working on a NuttX application that will run on a board that has a
user-accessible SD card.

The user may insert or remove the card during runtime, so I am using the
NuttX automounter.
The automounter works nicely, mounting and unmounting the card when it is
inserted/removed.

However, I am looking for a way to inform the rest of the system about the
(un)mount event.

This is needed because:
1. If the SD card is present during system boot, the application
initialization has to wait for it to be properly mounted before proceeding.
2. If the card is inserted during the system operation, the application has
to read some files from the card, once inserted.

Unfortunately, I cannot see any proper way to achieve this.
Any suggestions?

Re: SD Card automounter events

Posted by Xiang Xiao <xi...@gmail.com>.
inotify is a very important addition to the NuttX filesystem, but the work
isn't small too.

On Thu, Jan 14, 2021 at 10:58 PM Fotis Panagiotopoulos <f....@gmail.com>
wrote:

> Hi,
>
> So, it seems that it is not possible without kernel modifications.
>
> I was about to create a new driver to notify my application for such
> events,
> but as you correctly state, the automounter has to be modified as the
> driver
> does not know when the automounter has finished, or what was its return
> code.
>
> Unfortunately, I am not sure when I will find time for this modification,
> so
> I will look for an alternative.
>
> How are others using the automounter? Has anyone ever had any similar use
> case?
>
> What about an inotify-like system in NuttX?
>
> Στις Κυρ, 10 Ιαν 2021 στις 10:57 μ.μ., ο/η Gregory Nutt <
> spudaneco@gmail.com>
> έγραψε:
>
> > Currently board-specific logic supports detection of when a card is
> > inserted or removed via a mechanical GPIO pin on the physical SD slot.
> > That notification is used by the SDIO-based card driver to check for a
> > valid card insertion/removal.
> >
> > For the case of the automounter with an SD card, the notification comes
> > from a lower half driver described in include/nuttx/fs/automount.h.  For
> > the case of the SD card, this notification probably derives from that
> > insertion/removal event.
> >
> > That is not very useful, however, because the automounter does not
> > depend on the SD card slot but could be set up for any removal media
> > (such as a USB flash drive).
> >
> > I think it seems reasonable to add work queue-based, subscriber
> > notifications (see included/nuttx/wqueue.h).  The automounter could then
> > "broadcast" such a notification when a file system is mounted or
> > unmounted.  Such a notification could solve half of your problem.
> >
> > The other half of the problem is that the work queue notification is
> > usable only within the OS and not by applications.  So perhaps some time
> > driver would also be needed to register to receive notifications, catch
> > the notifications, and signal an application.
> >
> > It is worth noting that the USB mass storage host driver already uses a
> > work-queue notification when USB flash drives are connected.  See
> > arm/kinetis/freedom-k28f/src/k28_usbhshost.c and
> > drivers/usbhost/usbhost_storage.c.  That latter file implements its only
> > automounter outside of fs_automount.c.  It would be good if those were
> > consolidated.
> >
> > On 1/10/2021 6:29 AM, Fotis Panagiotopoulos wrote:
> > > Hi everyone,
> > >
> > > I am working on a NuttX application that will run on a board that has a
> > > user-accessible SD card.
> > >
> > > The user may insert or remove the card during runtime, so I am using
> the
> > > NuttX automounter.
> > > The automounter works nicely, mounting and unmounting the card when it
> is
> > > inserted/removed.
> > >
> > > However, I am looking for a way to inform the rest of the system about
> > the
> > > (un)mount event.
> > >
> > > This is needed because:
> > > 1. If the SD card is present during system boot, the application
> > > initialization has to wait for it to be properly mounted before
> > proceeding.
> > > 2. If the card is inserted during the system operation, the application
> > has
> > > to read some files from the card, once inserted.
> > >
> > > Unfortunately, I cannot see any proper way to achieve this.
> > > Any suggestions?
> > >
> >
>

Re: SD Card automounter events

Posted by Fotis Panagiotopoulos <f....@gmail.com>.
Hi,

So, it seems that it is not possible without kernel modifications.

I was about to create a new driver to notify my application for such events,
but as you correctly state, the automounter has to be modified as the driver
does not know when the automounter has finished, or what was its return
code.

Unfortunately, I am not sure when I will find time for this modification, so
I will look for an alternative.

How are others using the automounter? Has anyone ever had any similar use
case?

What about an inotify-like system in NuttX?

Στις Κυρ, 10 Ιαν 2021 στις 10:57 μ.μ., ο/η Gregory Nutt <sp...@gmail.com>
έγραψε:

> Currently board-specific logic supports detection of when a card is
> inserted or removed via a mechanical GPIO pin on the physical SD slot.
> That notification is used by the SDIO-based card driver to check for a
> valid card insertion/removal.
>
> For the case of the automounter with an SD card, the notification comes
> from a lower half driver described in include/nuttx/fs/automount.h.  For
> the case of the SD card, this notification probably derives from that
> insertion/removal event.
>
> That is not very useful, however, because the automounter does not
> depend on the SD card slot but could be set up for any removal media
> (such as a USB flash drive).
>
> I think it seems reasonable to add work queue-based, subscriber
> notifications (see included/nuttx/wqueue.h).  The automounter could then
> "broadcast" such a notification when a file system is mounted or
> unmounted.  Such a notification could solve half of your problem.
>
> The other half of the problem is that the work queue notification is
> usable only within the OS and not by applications.  So perhaps some time
> driver would also be needed to register to receive notifications, catch
> the notifications, and signal an application.
>
> It is worth noting that the USB mass storage host driver already uses a
> work-queue notification when USB flash drives are connected.  See
> arm/kinetis/freedom-k28f/src/k28_usbhshost.c and
> drivers/usbhost/usbhost_storage.c.  That latter file implements its only
> automounter outside of fs_automount.c.  It would be good if those were
> consolidated.
>
> On 1/10/2021 6:29 AM, Fotis Panagiotopoulos wrote:
> > Hi everyone,
> >
> > I am working on a NuttX application that will run on a board that has a
> > user-accessible SD card.
> >
> > The user may insert or remove the card during runtime, so I am using the
> > NuttX automounter.
> > The automounter works nicely, mounting and unmounting the card when it is
> > inserted/removed.
> >
> > However, I am looking for a way to inform the rest of the system about
> the
> > (un)mount event.
> >
> > This is needed because:
> > 1. If the SD card is present during system boot, the application
> > initialization has to wait for it to be properly mounted before
> proceeding.
> > 2. If the card is inserted during the system operation, the application
> has
> > to read some files from the card, once inserted.
> >
> > Unfortunately, I cannot see any proper way to achieve this.
> > Any suggestions?
> >
>

Re: SD Card automounter events

Posted by Gregory Nutt <sp...@gmail.com>.
Currently board-specific logic supports detection of when a card is 
inserted or removed via a mechanical GPIO pin on the physical SD slot.  
That notification is used by the SDIO-based card driver to check for a 
valid card insertion/removal.

For the case of the automounter with an SD card, the notification comes 
from a lower half driver described in include/nuttx/fs/automount.h.  For 
the case of the SD card, this notification probably derives from that 
insertion/removal event.

That is not very useful, however, because the automounter does not 
depend on the SD card slot but could be set up for any removal media 
(such as a USB flash drive).

I think it seems reasonable to add work queue-based, subscriber 
notifications (see included/nuttx/wqueue.h).  The automounter could then 
"broadcast" such a notification when a file system is mounted or 
unmounted.  Such a notification could solve half of your problem.

The other half of the problem is that the work queue notification is 
usable only within the OS and not by applications.  So perhaps some time 
driver would also be needed to register to receive notifications, catch 
the notifications, and signal an application.

It is worth noting that the USB mass storage host driver already uses a 
work-queue notification when USB flash drives are connected.  See 
arm/kinetis/freedom-k28f/src/k28_usbhshost.c and 
drivers/usbhost/usbhost_storage.c.  That latter file implements its only 
automounter outside of fs_automount.c.  It would be good if those were 
consolidated.

On 1/10/2021 6:29 AM, Fotis Panagiotopoulos wrote:
> Hi everyone,
>
> I am working on a NuttX application that will run on a board that has a
> user-accessible SD card.
>
> The user may insert or remove the card during runtime, so I am using the
> NuttX automounter.
> The automounter works nicely, mounting and unmounting the card when it is
> inserted/removed.
>
> However, I am looking for a way to inform the rest of the system about the
> (un)mount event.
>
> This is needed because:
> 1. If the SD card is present during system boot, the application
> initialization has to wait for it to be properly mounted before proceeding.
> 2. If the card is inserted during the system operation, the application has
> to read some files from the card, once inserted.
>
> Unfortunately, I cannot see any proper way to achieve this.
> Any suggestions?
>