File System Component  Version 6.6
MDK-Professional Middleware for Devices with Flash File System
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Embedded File System (EFS)

The Embedded File System (EFS) is a proprietary file system used on the NOR flash devices. Basic features are:

Memory Organization

A flash device is divided into sectors which are named blocks in the File System Component. Typically, a block is a 64 KB memory page. Blocks can be divided into memory cells, which are written sequentially. The memory cell size depends on the device architecture and is 8- (byte), 16- (half word) or 32-bit wide (word).

Each block contains its own allocation Information written to the file allocation table located on top of the memory. The file name and file content are stored in lower memory regions. If the file size exceeds a single block, then the file is stored across several blocks. Several smaller files are stored into a single block.

fs_memoryorg.png
Flash Memory Organization

When the file content is modified, the old file content is invalidated and a new memory block is allocated. Block is erased when all the data stored in it have been invalidated.

Allocation Information

Allocation Information is stored at the top of a block and is written in descending order. Each allocation information record consists of 8 bytes. Each file fragment has its own allocation record. The first file fragment starts in block at offset 0. It is always assumed that the first file block starts at the beginning of a flash block.

fs_allocinfo.png
Flash Block Allocation

The file allocation information record has the following components:

  • end is the end address of the file fragment.
  • fileID is the file identification number and is associated with the file name.
  • index is the file fragment ordering number, which starts at 0 for each file.
struct falloc {
uint32_t end;
uint16_t fileID;
uint16_t index;
};

The file allocation information is written when:

  • The file is opened for writing and the File System Core creates a filename information record.
  • The file is closed and the file handle released.
  • The file is flushed and the number of bytes from a file buffer is not a multiple of 4.
  • The Flash Block is full and there is no more free space.

File Data Fragments

File Data Fragments are of variable size and are fully defined through the file allocation information record.

To make the best use of the Flash block, create big file fragments to reduce the total number of file fragments. It is not optimal to open a file for appending or writing a byte to it and close the file again. This approach creates huge file allocation information records, which consume 12 bytes of Flash in total; 8 bytes for the file allocation information and 4 bytes for the information. In addition, such an approach creates slow access times to files.

Limitations

The following restrictions are applicable to the EFS:

  • Maximum file name length is limited to 31 characters.
  • Directories or folders are not supported.
  • Seeking (fseek) within files works only for files opened in read mode.
  • File update modes (r+, w+, a+) (fopen) are not supported.
  • Timestamp information is not supported for a file.
  • Drive partitions are not supported.
  • This file system is not compatible with the FAT file system and cannot be used with an USB mass storage device.