Jump to main content

##

# 1.2.7.4.5 SYS_FS_EventHandlerSet Function

## C

    void SYS_FS_EventHandlerSet
    (
        const void * eventHandler,
        const uintptr_t context
    );

## Summary

Sets the pointer to the function (and it's context) to be called when mount/unmount event has occurred

## Description

This function allows a client to identify an event handling function for the File System to call back when mount/unmount operation has completed.

The file system will pass mount name back to the client by calling "eventHandler" when AutoMount feature is enabled for File system.

## Precondition

The SYS_FS_Initialize() routine must have been called.

## Parameters

Param | Description
--- | ---
eventHandler | Pointer to the event handler function implemented by the user
context | The value of parameter will be passed back to the client unchanged, when the eventHandler function is called. It can be used to identify any client specific data object that identifies the instance of the client module (for example, it may be a pointer to the client module's state structure).

## Returns

None.

## Example

    // Client registers an event handler with file system. This is done once.
    SYS_FS_EventHandlerSet(APP_SysFSEventHandler, (uintptr_t)NULL);

    // Event Processing Technique. Event is received when operation is done.
    void APP_SysFSEventHandler
    (
        SYS_FS_EVENT event,
        void* eventData,
        uintptr_t context
    )
    {
        switch(event)
        {
            case SYS_FS_EVENT_MOUNT:
            {
                if(strcmp((const char *)eventData,"/mnt/myDrive1") == 0)
                {
                    gSDCardMountFlag = true;
                }
                else if(strcmp((const char *)eventData,"/mnt/myDrive2") == 0)
                {
                    gNVMMountFlag = true;
                }
                break;
            }

            case SYS_FS_EVENT_MOUNT_WITH_NO_FILESYSTEM:
            {
                if(strcmp((const char *)eventData,"/mnt/myDrive1") == 0)
                {
                    gSDCardFormatRequired = true;
                }
                else if(strcmp((const char *)eventData,"/mnt/myDrive2") == 0)
                {
                    gNVMFormatRequired = true;
                }
                break;
            }

            case SYS_FS_EVENT_UNMOUNT:
            {
                if(strcmp((const char *)eventData,"/mnt/myDrive1") == 0)
                {
                    gSDCardMountFlag = false;
                }
                else if(strcmp((const char *)eventData,"/mnt/myDrive2") == 0)
                {
                    gNVMMountFlag = false;
                }
                break;
            }

            case SYS_FS_EVENT_ERROR:
            default:
            {
                break;
            }
        }
    }

## Remarks

On Mount/Un-Mount of a volume all the registered clients will be notified. The client should check if the mount name passed when event handler is called is the one it is expecting and then proceed as demonstrated in above example. If the client does not want to be notified when the mount/unmount operation has completed, it does not need to register a callback. Note: This API is Available only when SYS_FS_AUTOMOUNT_ENABLE is set to true.