Storage
Storage support is split between file systems and their underlying block device support. The storage API page has more information on existing APIs in Mbed OS for both interfaces.
Block Device
Adding a block device implementation is required for backing filesystems on new hardware. 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) | |
virtual int | mount (BlockDevice *bd)=0 |
virtual int | unmount ()=0 |
virtual int | reformat (BlockDevice *bd=NULL) |
virtual int | remove (const char *path) |
virtual int | rename (const char *path, const char *newpath) |
virtual int | stat (const char *path, struct stat *st) |
virtual int | mkdir (const char *path, mode_t mode) |
virtual int | statvfs (const char *path, struct statvfs *buf) |
Public Member Functions inherited from mbed::FileSystemLike | |
FileSystemLike (const char *name=NULL) | |
FileHandle * | open (const char *path, int flags) |
DirHandle * | opendir (const char *path) |
Public Member Functions inherited from mbed::FileSystemHandle | |
virtual | ~FileSystemHandle () |
Public Member Functions inherited from mbed::FileBase | |
FileBase (const char *name, PathType t) | |
const char * | getName (void) |
PathType | getPathType (void) |
Protected Member Functions | |
virtual int | file_open (fs_file_t *file, const char *path, int flags)=0 |
virtual int | file_close (fs_file_t file)=0 |
virtual ssize_t | file_read (fs_file_t file, void *buffer, size_t size)=0 |
virtual ssize_t | file_write (fs_file_t file, const void *buffer, size_t size)=0 |
virtual int | file_sync (fs_file_t file) |
virtual int | file_isatty (fs_file_t file) |
virtual off_t | file_seek (fs_file_t file, off_t offset, int whence)=0 |
virtual off_t | file_tell (fs_file_t file) |
virtual void | file_rewind (fs_file_t file) |
virtual off_t | file_size (fs_file_t file) |
virtual int | dir_open (fs_dir_t *dir, const char *path) |
virtual int | dir_close (fs_dir_t dir) |
virtual ssize_t | dir_read (fs_dir_t dir, struct dirent *ent) |
virtual void | dir_seek (fs_dir_t dir, off_t offset) |
virtual off_t | dir_tell (fs_dir_t dir) |
virtual void | dir_rewind (fs_dir_t dir) |
virtual size_t | dir_size (fs_dir_t dir) |
virtual int | open (FileHandle **file, const char *path, int flags) |
virtual int | open (DirHandle **dir, const char *path) |
Friends | |
class | File |
class | Dir |
Additional Inherited Members | |
Static Public Member Functions inherited from mbed::FileBase | |
static FileBase * | lookup (const char *name, unsigned int len) |
static FileBase * | get (int n) |
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.