Out of date: This is not the most recent version of this page. Please see the most recent version

File system

The file system API provides a common interface for implementing a file system on a block-based storage device. The file system API is a class-based interface, but implementing the file system API provides the standard POSIX file API familiar to C users.


Here is what it looks like to use the file system in mbed OS:

FAT file system example

Declaring a file system

The FileSystem class provides the core API for file system operations. You must provide a block device to back the file system. When you declare a file system with a name, you can open files on the file system through standard POSIX functions (see open or fopen.

Existing file systems:

The FAT file system is a standard file system.

The BlockDevice class provides the underlying API for representing block-based storage that can be used to back a file system. mbed OS provides standard interfaces for the more common storage media, and you can extend the BlockDevice class to provide support for unsupported storage.

Existing block devices:

Additionally, two utility block devices give you better control over how storage is allocated. The slicing block device allows you to partition storage into smaller block devices that you can use independentally, and the chaining block device allows you to chain multiple block devices together and extend the usable amount of storage.

Note: Some file systems may provide a format function for cleanly initializing a file system on an underlying block device or require external tools to set up the file system before the first use.

C++ classes

The FileSystem class provides the core user interface with general functions that map directly to their global POSIX counterparts. mbed OS provides File and Dir classes that represent files and directories in a C++ API that uses object-oriented features in C++.

To implement a new file system in mbed OS, an implementor just needs to provide the abstract functions in the file system interface. The FAT file system provides an excellent example, you can find tests of the POSIX API here.

Minimal file system operations required:

Minimal file operations required:

Minimal directory operations required: