Mbed OS Reference
Loading...
Searching...
No Matches
FileSystem Class Referenceabstract

A file system object. More...

#include <FileSystem.h>

Inheritance diagram for FileSystem:
FileSystemLike FileSystemHandle FileBase NonCopyable< FileSystemLike > NonCopyable< FileSystemHandle > NonCopyable< FileBase > FATFileSystem LittleFileSystem LittleFileSystem2

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...
 

Static Public Member Functions

static FileSystemget_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...
 

Detailed Description

A file system object.

Provides file system operations and file operations for the File and Dir classes on a block device.

Implementations must provide at minimum file operations and mount operations for block devices.

Note
Synchronization level: Set by subclass

Definition at line 50 of file FileSystem.h.

Constructor & Destructor Documentation

◆ FileSystem()

FileSystem ( const char *  name = NULL)

File system lifetime.

Parameters
nameName to add file system to tree as.

Member Function Documentation

◆ get_default_instance()

static FileSystem * get_default_instance ( )
static

Return the default file system.

Returns the default file system based on the default block device configuration. Use the components in target.json or application config to change the default block device and affect the default filesystem. SD block device => FAT filesystem QSPIF, SPIF, DATAFLASH or FLAHIAP block device => LITTLE filesystem

An application can override all target settings by implementing FileSystem::get_default_instance() - the default definition is weak, and calls get_target_default_instance().

◆ mount()

virtual int mount ( BlockDevice bd)
pure virtual

Mount a file system to a block device.

Parameters
bdBlock device to mount to.
Returns
0 on success, negative error code on failure.

Implemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ unmount()

virtual int unmount ( )
pure virtual

Unmount a file system from the underlying block device.

Returns
0 on success, negative error code on failure.

Implemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ reformat()

virtual int reformat ( BlockDevice bd = NULL)
virtual

Reformat a file system.

Results in an empty and mounted file system.

Parameters
bdBlock device to reformat and mount. If NULL, the mounted Block device is used. Note: If mount fails, bd must be provided. Default: NULL
Returns
0 on success, negative error code on failure.

Reimplemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ remove()

virtual int remove ( const char *  path)
virtual

Remove a file from the file system.

Parameters
pathThe name of the file to remove.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystemHandle.

Reimplemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ rename()

virtual int rename ( const char *  path,
const char *  newpath 
)
virtual

Rename a file in the file system.

Parameters
pathThe existing name of the file to rename.
newpathThe new name of the file.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystemHandle.

Reimplemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ stat()

virtual int stat ( const char *  path,
struct stat st 
)
virtual

Store information about the file in a stat structure.

Parameters
pathThe name of the file to find information about.
stThe stat buffer to write to.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystemHandle.

Reimplemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ mkdir()

virtual int mkdir ( const char *  path,
mode_t  mode 
)
virtual

Create a directory in the file system.

Parameters
pathThe name of the directory to create.
modeThe permissions with which to create the directory.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystemHandle.

Reimplemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ statvfs()

virtual int statvfs ( const char *  path,
struct statvfs buf 
)
virtual

Store information about the mounted file system in a statvfs structure.

Parameters
pathThe name of the file to find information about.
bufThe stat buffer to write to.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystemHandle.

Reimplemented in FATFileSystem, LittleFileSystem, and LittleFileSystem2.

◆ open() [1/2]

virtual int open ( FileHandle **  file,
const char *  path,
int  flags 
)
protectedvirtual

defined(DOXYGEN_ONLY)

Implements FileSystemHandle.

◆ open() [2/2]

virtual int open ( DirHandle **  dir,
const char *  path 
)
protectedvirtual

Open a directory on the filesystem.

Parameters
dirDestination for the handle to the directory
pathName of the directory to open
Returns
0 on success, negative error code on failure

Reimplemented from FileSystemHandle.