File System Component  Version 6.16.6
MDK Middleware for Devices with Flash File System
FAT File System

The FAT File System was initially used on PC operating systems such as MS-DOS and early versions of Microsoft Windows. Still, it is widely used on USB memory sticks or memory cards for file storage. It is simple, robust and offers good performance especially in embedded applications.

FAT is an acronym for File Allocation Table. This table provides the index of the files in the system and is statically allocated at the time of formatting the drive. It contains an entry for each cluster (a data storage area). The FAT's entries contain either the number of the next cluster in the file, or a marker indicating EOF (end of file), unused disk space, or other areas of the drive that are specially reserved. The drive's root directory contains the number of the first cluster of each file in the directory; the operating system traverses the FAT table, looking up the cluster number of each successive part of the file, until the end of the file is reached. Likewise, sub-directories are implemented as special files containing the directory entries of their respective files.

Since the first implementation, the maximum number of clusters of a drive has increased dramatically, and so the number of bits used to identify each cluster has grown. The versions of the FAT format are named after the number of table element bits: FAT12, FAT16, and FAT32. Each of these variants is is supported by the File System Component.

Layout

The actual FAT file system is made up of four different sections:

Section Description
Boot sector Contains machine startup code
File Allocation Table Contains the data region map; multiple entries might exist for redundancy purposes
Root Directory Stores information about the files and directories located in the root directory (FAT12/FAT16 only)
File Data Region Actual stored file data

Volume name

Volume label for FAT12, FAT16 or FAT32 volume must be maximum 11 characters long and cannot contain the following characters: * ? / \ | , ; : + = < > [ ] "" .

Path name handling

Path name format used to specify either a drive, directory or file:

  • [drive:][directory separator][path]

Depending on the usage case, each specifier can be optional:

  • drive specifier must consist of drive letter followed by optional drive number and a semicolon.
  • directory separator can be slash (/) or backslash (\)
  • path can consist of multiple directory names and a file name

Absolute and relative path

The table below explains how to specify either absolute or relative path.

Path name Type Description
\ Absolute Root directory
\ .. Absolute Root directory
. Relative Current directory
.. Relative Parent directory
M:\file.txt Absolute A file in root directory of the drive M0
M:file.txt Relative A file in current directory of the drive M0
\file.txt Absolute A file in the root directory of the current drive
file.txt Relative A file in the current directory of the current drive
folder1\ .. Relative Current directory

Long and Short File Name handling

File System Component is provided with the library with long (LFN) and short (SFN or 8.3) filename support. Since there is no compulsory algorithm for creating the 8.3 name from an LFN, File System Component uses convention described below.

  • Uppercased or lowercased name which is 8.3 valid, is stored uppercased in a single SFN entry
    • Example: "TEXTFILE.TXT" is stored as "TEXTFILE.TXT" (SFN)
    • Example: "textfile.txt" is stored as "TEXTFILE.TXT" (SFN)
  • Mixedcase name which is 8.3 valid, is stored mixed-case in LFN entry and SFN entry is created, which is concluded with tilde and a numeric value.
    • Example: "TextFile.txt" is stored as "TextFile.txt" (LFN) and "TEXTFI~1.TXT" (SFN)
  • Name which is not 8.3 valid is stored in LFN entry and SFN entry. Name writen in SFN entry is uppercased, stripped of invalid 8.3 characters which are replaced with underscore "_" and concluded with tilde and a numeric value.
    • Example: "Tex+File.txt" is stored as "Tex+File.txt" (LFN) and "TEX_FI~1.TXT (SFN)"

Time Stamping Support

The File System Component fully supports time stamping for files and directories. it supports:

  • Create time
  • Create date
  • Last access date
  • Write time
  • Write date

To be able to use the time information provided by an on-chip RTC, the user application needs to implement the function fs_get_time(). The fsTime structure must be filled with the data returned from the RTC driver. If the fs_get_time() function is not implemented in the user application (which is the default), predefined time and date stamps are used.

FAT System Design Limitations

By design, FAT carries a few limitations:

  • Maximum file size is limited to 4,294,967,295 bytes
  • Maximum files within folder is 65,536 (i.e. a directory must not be larger than 2,097,152 bytes).
  • A root directory on FAT12 and FAT16 can hold max 512 files/folders (there is no such limitation for FAT32)
  • FAT type depends on maximum and minimum number of clusters:
    • FAT12 maximum clusters: 4,084
    • FAT16 minimum clusters: 4,085
    • FAT16 maximum clusters: 65,524
    • FAT32 minimum clusters: 65,525
  • Maximum volume size depends on FAT type:
    • FAT12: 256MB (for 64kB clusters)
    • FAT16: 4GB (for 64kB clusters)
    • FAT32: 2TB (4G of 512B sectors)

FAT Implementation Limitations

The actual FAT implementation of the File System Component has the following limitations:

  • Multiple partitions are not supported and will not be detected
  • Multiple active file handles per file are allowed only for files opened in read mode.
  • Maximum path length is 260 bytes for FAT with LFN support and 80 bytes for FAT without LFN support.
  • Seeking within files is limited to the area of two gigabytes due to the fseek and ftell limitation set by ANSI C Standard library
  • UTF-16 and UTF-8 character encoding is not supported