Formatting

A volume, once it is open, may need to be formatted before files or directories can be created. The default format is selected by passing a NULL pointer as the second parameter of FSVol_Fmt(). Alternatively, the exact properties of the file system can be configured with a FS_FAT_SYS_CFG structure. An example of populating and using the FAT configuration is shown in Listing - Example device format. If the configuration is invalid, an error will be returned from FSVol_Fmt(). For more information about the FS_FAT_SYS_CFG structure, see FS_FAT_SYS_CFG.

Listing - Example device format
void  App_InitFS (void)
{
    FS_ERR          err;
    FS_FAT_SYS_CFG  fat_cfg;
    .
    .
    .
    fat_cfg.ClusSize        =   4;                  /* Cluster size        = 4 * 512-B = 2-kB.*/
    fat_cfg.RsvdAreaSize    =   1;                  /* Reserved area       = 1 sector.        */
    fat_cfg.RootDirEntryCnt = 512;                  /* Entries in root dir = 512.             */
    fat_cfg.FAT_Type        =  12;                  /* FAT type            = FAT12.           */
    fat_cfg.NbrFATs         =   2;                  /* Number of FATs      = 2.               */
    FSVol_Fmt("ram:0:", &fat_cfg, &err);
    if (err != FS_ERR_NONE) {
        APP_TRACE_DEBUG(("Format failded.\r\n"));
    }
    .
    .
    .
}