I have a question regarding FS automount functionality. Is there a way
to get a callback when file system is mounted and ready to be
accessed? Or the only way is to implement a polling loop like:
while ( access( "/mnt/sdcard0", F_OK ) != 0 )
{
sleep(1);
}
No, there will never never be callbacks from the OS into application
code. That is not the POSIX way. The POSIX way would use signals for
things like this.
Look in drivers/, there are many drivers that notify applications of
events via signals. Try searching for "notify".
Here is one of many examples that provides a signal when a button is
pressed: drivers/input/button_upper.c. That notification interface is
described in include/nuttx/buttons.h:
66 /* Command: BTNIOC_REGISTER
67 * Description: Register to receive a signal whenever there is
a change in
68 * the state of button inputs. This feature, of
course, depends
69 * upon interrupt GPIO support from the platform.
70 * Argument: A read-only pointer to an instance of struct
btn_notify_s
71 * Return: Zero (OK) on success. Minus one will be
returned on failure
72 * with the errno value set appropriately.
73 */
74
75 #define BTNIOC_REGISTER _BTNIOC(0x0003)
A similar notification interface could be added to the
fs/mount/fs_automounter logic to notify an application when a monitored
volume is mounted or unmounted.