Mbed OS Reference
Loading...
Searching...
No Matches
FATFileSystem Class Reference

FAT file system based on ChaN's FAT file system library v0.8. More...

#include <FATFileSystem.h>

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

Public Member Functions

 FATFileSystem (const char *name=NULL, BlockDevice *bd=NULL)
 Lifetime of the FAT file system. More...
 
virtual int mount (BlockDevice *bd)
 Mount a file system to a block device. More...
 
virtual int unmount ()
 Unmount a file system from the underlying block device. More...
 
virtual int reformat (BlockDevice *bd, int allocation_unit)
 Reformat a file system, results in an empty and mounted file system. More...
 
virtual int reformat (BlockDevice *bd=NULL)
 Reformat a file system, results in an empty and mounted 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 int format (BlockDevice *bd, bd_size_t cluster_size=0)
 Format a logical drive, FDISK partitioning rule. More...
 
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

FAT file system based on ChaN's FAT file system library v0.8.

Synchronization level: Thread safe

Definition at line 41 of file FATFileSystem.h.

Constructor & Destructor Documentation

◆ FATFileSystem()

FATFileSystem ( const char *  name = NULL,
BlockDevice bd = NULL 
)

Lifetime of the FAT file system.

Parameters
nameName of the file system in the tree.
bdBlock device to mount. Mounted immediately if not NULL.

Member Function Documentation

◆ format()

static int format ( BlockDevice bd,
bd_size_t  cluster_size = 0 
)
static

Format a logical drive, FDISK partitioning rule.

The block device to format should be mounted when this function is called.

Parameters
bdThis is the block device that will be formatted.
cluster_sizeThis is the number of bytes per cluster. A larger cluster size decreases the overhead of the FAT table, but also increases the minimum file size. The cluster size must be a multiple of the underlying device's allocation unit and is currently limited to a max of 32,768 bytes. If the cluster size is set to zero, a cluster size is determined from the device's allocation unit. Defaults to zero.
Returns
0 on success, negative error code on failure.

◆ mount()

virtual int mount ( BlockDevice bd)
virtual

Mount a file system to a block device.

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

Implements FileSystem.

◆ unmount()

virtual int unmount ( )
virtual

Unmount a file system from the underlying block device.

Returns
0 on success, negative error code on failure.

Implements FileSystem.

◆ reformat() [1/2]

virtual int reformat ( BlockDevice bd,
int  allocation_unit 
)
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
allocation_unitThis is the number of bytes per cluster size. The valid value is N times the sector size. N is a power of 2, from 1 to 128, for the FAT volume, and up to 16MiB for the exFAT volume. If zero is given, the default allocation unit size is selected by the underlying file system, which depends on the volume size.
Returns
0 on success, negative error code on failure.

◆ reformat() [2/2]

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

Definition at line 109 of file FATFileSystem.h.

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

◆ rename()

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

Rename a file in the file system.

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

Reimplemented from FileSystem.

◆ 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 store information about.
stThe stat buffer to write to.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystem.

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

◆ 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 store information about.
bufThe stat buffer to write to.
Returns
0 on success, negative error code on failure.

Reimplemented from FileSystem.

◆ get_default_instance()

static FileSystem * get_default_instance ( )
staticinherited

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

◆ open() [1/2]

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

defined(DOXYGEN_ONLY)

Implements FileSystemHandle.

◆ open() [2/2]

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

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.