Storage
Mbed OS provides various storage solutions, all built on top of the BlockDevice interface.
When you add a new platform, you must add the supported block devices to the list of components in the targets.json
file. The block devices are located in the components folder. To enable a block device in the COMPONENT_<component name>
folder, add the <component name>
string to the component list for the target in the targets.json
file. For example, for the internal memory block device, COMPONENT_FLASHIAP
, add "components_add": ["FLASHIAP"]
to your target section in the targets.json
file.
For more information about existing storage solutions in Mbed OS, see the Storage API page.
Block Device
You might have to add a block device implementation if you have new storage hardware that is not supported by the existing block devices. You can extend the BlockDevice class to provide support for unsupported storage.
If you want to port a new file system to Mbed OS on existing storage options you can skip to the following section.
File systems
To implement a new file system in Mbed OS, an implementor needs to provide the abstract functions in the file system interface. The FAT file system provides an excellent example.
A minimal file system needs to provide the following functions:
file_open
.file_close
.file_read
.file_write
.file_seek
.
Here is the full API that a file system may implement:
Public Member Functions | |
FileSystem (const char *name=NULL) | |
File system lifetime. More... | |
virtual int | mount (BlockDevice *bd)=0 |
Mount a file system to a block device. More... | |
virtual int | unmount ()=0 |
Unmount a file system from the underlying block device. More... | |
virtual int | reformat (BlockDevice *bd=NULL) |
Reformat a file system. More... | |
virtual int | remove (const char *path) |
Remove a file from the file system. More... | |
virtual int | rename (const char *path, const char *newpath) |
Rename a file in the file system. More... | |
virtual int | stat (const char *path, struct stat *st) |
Store information about the file in a stat structure. More... | |
virtual int | mkdir (const char *path, mode_t mode) |
Create a directory in the file system. More... | |
virtual int | statvfs (const char *path, struct statvfs *buf) |
Store information about the mounted file system in a statvfs structure. More... | |
FileHandle * | open (const char *path, int flags) |
Open a file on the filesystem. More... | |
DirHandle * | opendir (const char *path) |
Open a directory on the filesystem. More... |
Static Public Member Functions | |
static FileSystem * | get_default_instance () |
Return the default file system. More... |
Protected Member Functions | |
virtual int | open (FileHandle **file, const char *path, int flags) |
defined(DOXYGEN_ONLY) More... | |
virtual int | open (DirHandle **dir, const char *path) |
Open a directory on the filesystem. More... |
File systems must be backed by a block device in Mbed OS. If you are using supported hardware, then you can use the Mbed OS block device classes. Otherwise, view the block device porting section earlier in this guide.