Jump to main content

##

# 1.2.7.4.1 SYS_FS_Initialize Function

## C

    SYS_FS_RESULT SYS_FS_Initialize
    (
        const void* initData
    );

## Summary

Initializes the file system abstraction layer (sys_fs layer).

## Description

This function initializes the abstraction layer (sys_fs layer) and sets up the necessary parameters.

## Precondition

This is the first function to be called during usage of sys_fs. Calling other functions of sys_fs without initializing the sys_fs will cause unpredictable behavior.

## Parameters

Param | Description
--- | ---
initData | Pointer to an array of type SYS_FS_REGISTRATION_TABLE. The number of elements of array is decided by the definition SYS_FS_MAX_FILE_SYSTEM_TYPE. If the application uses one file system (say only FAT FS), SYS_FS_MAX_FILE_SYSTEM_TYPE is defined to be 1. Otherwise, if the application uses 2 file systems (say FAT FS and MPFS2), SYS_FS_MAX_FILE_SYSTEM_TYPE is defined to be 2.

## Returns

SYS_FS_RES_SUCCESS - SYS FS Layer was initialized successfully.

SYS_FS_RES_FAILURE - SYS FS Layer initialization failed. The reason for the failure can be retrieved with SYS_FS_Error.

## Example

    // This code shows an example of how the SYS FS is initialized
    // Only one file system is used

    #define SYS_FS_MAX_FILE_SYSTEM_TYPE 1

    // Function pointer table for FAT FS
    const SYS_FS_FUNCTIONS FatFsFunctions =
    {
        .mount = FATFS_mount,
        .unmount = FATFS_unmount,
        .open = FATFS_open,
        .read = FATFS_read,
        .write = FATFS_write,
        .close = FATFS_close,
        .seek = FATFS_lseek,
        .tell = FATFS_tell,
        .eof = FATFS_eof,
        .size = FATFS_size,
        .fstat = FATFS_stat,
    };

    const SYS_FS_REGISTRATION_TABLE sysFSInit [ SYS_FS_MAX_FILE_SYSTEM_TYPE ] =
    {
        {
            .nativeFileSystemType = FAT,
            .nativeFileSystemFunctions = &FatFsFunctions
        }
    };

    SYS_FS_Initialize((const void *)sysFSInit);