Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

FileSystem Class Reference

A file system object. More...

#include <FileSystem.h>

Inherits mbed::FileSystemLike.

Inherited by FATFileSystem, and LittleFileSystem.

Public Member Functions

 FileSystem (const char *name=NULL)
 File system lifetime.
virtual int mount (BlockDevice *bd)=0
 Mount a file system to a block device.
virtual int unmount ()=0
 Unmount a file system from the underlying block device.
virtual int reformat (BlockDevice *bd=NULL)
 Reformat a file system.
virtual int remove (const char *path)
 Remove a file from the file system.
virtual int rename (const char *path, const char *newpath)
 Rename a file in the file system.
virtual int stat (const char *path, struct stat *st)
 Store information about the file in a stat structure.
virtual int mkdir (const char *path, mode_t mode)
 Create a directory in the file system.
virtual int statvfs (const char *path, struct statvfs *buf)
 Store information about the mounted file system in a statvfs structure.
 MBED_DEPRECATED_SINCE ("mbed-os-5.5","Replaced by `int open(FileHandle **, ...)` for propagating error codes") FileHandle *open(const char *path
 Open a file on the filesystem.

Static Public Member Functions

static FileSystemget_default_instance ()
 Return the default file system.

Protected Member Functions

virtual int file_open (fs_file_t *file, const char *path, int flags)=0
 Open a file on the file system.
virtual int file_close (fs_file_t file)=0
 Close a file.
virtual ssize_t file_read (fs_file_t file, void *buffer, size_t size)=0
 Read the contents of a file into a buffer.
virtual ssize_t file_write (fs_file_t file, const void *buffer, size_t size)=0
 Write the contents of a buffer to a file.
virtual int file_sync (fs_file_t file)
 Flush any buffers associated with the file.
virtual int file_isatty (fs_file_t file)
 Check whether the file is an interactive terminal device.
virtual off_t file_seek (fs_file_t file, off_t offset, int whence)=0
 Move the file position to a given offset from a given location.
virtual off_t file_tell (fs_file_t file)
 Get the file position of the file.
virtual void file_rewind (fs_file_t file)
 Rewind the file position to the beginning of the file.
virtual off_t file_size (fs_file_t file)
 Get the size of the file.
virtual int file_truncate (fs_file_t file, off_t length)
 Truncate or extend a file.
virtual int dir_open (fs_dir_t *dir, const char *path)
 Open a directory on the file system.
virtual int dir_close (fs_dir_t dir)
 Close a directory.
virtual ssize_t dir_read (fs_dir_t dir, struct dirent *ent)
 Read the next directory entry.
virtual void dir_seek (fs_dir_t dir, off_t offset)
 Set the current position of the directory.
virtual off_t dir_tell (fs_dir_t dir)
 Get the current position of the directory.
virtual void dir_rewind (fs_dir_t dir)
 Rewind the current position to the beginning of the directory.
virtual size_t dir_size (fs_dir_t dir)
 Get the size of the directory.
virtual int open (FileHandle **file, const char *path, int flags)
 Open a file on the filesystem.
virtual int open (DirHandle **dir, const char *path)
 Open a directory on the filesystem.
 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

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 49 of file FileSystem.h.


Constructor & Destructor Documentation

FileSystem ( const char *  name = NULL )

File system lifetime.

Parameters:
nameName to add file system to tree as.

Definition at line 24 of file FileSystem.cpp.


Member Function Documentation

int dir_close ( fs_dir_t  dir ) [protected, virtual]

Close a directory.

Parameters:
dirDir handle.
Returns:
0 on success, negative error code on failure.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 97 of file FileSystem.cpp.

int dir_open ( fs_dir_t *  dir,
const char *  path 
) [protected, virtual]

Open a directory on the file system.

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

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 92 of file FileSystem.cpp.

ssize_t dir_read ( fs_dir_t  dir,
struct dirent *  ent 
) [protected, virtual]

Read the next directory entry.

Parameters:
dirDir handle.
entThe directory entry to fill out.
Returns:
1 on reading a filename, 0 at the end of the directory, negative error on failure.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 102 of file FileSystem.cpp.

void dir_rewind ( fs_dir_t  dir ) [protected, virtual]

Rewind the current position to the beginning of the directory.

Parameters:
dirDir handle.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 116 of file FileSystem.cpp.

void dir_seek ( fs_dir_t  dir,
off_t  offset 
) [protected, virtual]

Set the current position of the directory.

Parameters:
dirDir handle.
offsetOffset of the location to seek to, must be a value returned from dir_tell.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 107 of file FileSystem.cpp.

size_t dir_size ( fs_dir_t  dir ) [protected, virtual]

Get the size of the directory.

Parameters:
dirDir handle.
Returns:
Number of files in the directory.

Definition at line 122 of file FileSystem.cpp.

off_t dir_tell ( fs_dir_t  dir ) [protected, virtual]

Get the current position of the directory.

Parameters:
dirDir handle.
Returns:
Directory position, which can be passed to dir_rewind.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 111 of file FileSystem.cpp.

virtual int file_close ( fs_file_t  file ) [protected, pure virtual]

Close a file.

Parameters:
fileFile handle. return 0 on success, negative error code on failure.

Implemented in FATFileSystem, and LittleFileSystem.

int file_isatty ( fs_file_t  file ) [protected, virtual]

Check whether the file is an interactive terminal device.

If so, line buffered behavior is used by default.

Parameters:
fileFile handle.
Returns:
True if the file is a terminal.

Definition at line 64 of file FileSystem.cpp.

virtual int file_open ( fs_file_t *  file,
const char *  path,
int  flags 
) [protected, pure virtual]

Open a file on the file system.

Parameters:
fileDestination of the newly created handle to the referenced file.
pathThe name of the file to open.
flagsThe flags that trigger opening of the file. These flags are O_RDONLY, O_WRONLY, and O_RDWR, with an O_CREAT, O_TRUNC, or O_APPEND bitwise OR operator.
Returns:
0 on success, negative error code on failure.

Implemented in FATFileSystem, and LittleFileSystem.

virtual ssize_t file_read ( fs_file_t  file,
void *  buffer,
size_t  size 
) [protected, pure virtual]

Read the contents of a file into a buffer.

Parameters:
fileFile handle.
bufferThe buffer to read in to.
sizeThe number of bytes to read.
Returns:
The number of bytes read, 0 at the end of the file, negative error on failure.

Implemented in FATFileSystem, and LittleFileSystem.

void file_rewind ( fs_file_t  file ) [protected, virtual]

Rewind the file position to the beginning of the file.

Parameters:
fileFile handle.
Note:
This is equivalent to file_seek(file, 0, FS_SEEK_SET)

Definition at line 74 of file FileSystem.cpp.

virtual off_t file_seek ( fs_file_t  file,
off_t  offset,
int  whence 
) [protected, pure virtual]

Move the file position to a given offset from a given location.

Parameters:
fileFile handle.
offsetThe offset from whence to move to.
whenceThe start of where to seek. SEEK_SET to start from the beginning of the file, SEEK_CUR to start from the current position in the file, SEEK_END to start from the end of the file.
Returns:
The new offset of the file

Implemented in FATFileSystem, and LittleFileSystem.

off_t file_size ( fs_file_t  file ) [protected, virtual]

Get the size of the file.

Parameters:
fileFile handle.
Returns:
Size of the file in bytes.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 79 of file FileSystem.cpp.

int file_sync ( fs_file_t  file ) [protected, virtual]

Flush any buffers associated with the file.

Parameters:
fileFile handle.
Returns:
0 on success, negative error code on failure.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 59 of file FileSystem.cpp.

off_t file_tell ( fs_file_t  file ) [protected, virtual]

Get the file position of the file.

Parameters:
fileFile handle.
Returns:
The current offset in the file.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 69 of file FileSystem.cpp.

int file_truncate ( fs_file_t  file,
off_t  length 
) [protected, virtual]

Truncate or extend a file.

The file's length is set to the specified value. The seek pointer is not changed. If the file is extended, the extended area appears as if it were zero-filled.

Parameters:
fileFile handle.
lengthThe requested new length for the file.
Returns:
0 on success, negative error code on failure.

Reimplemented in FATFileSystem, and LittleFileSystem.

Definition at line 87 of file FileSystem.cpp.

virtual ssize_t file_write ( fs_file_t  file,
const void *  buffer,
size_t  size 
) [protected, pure virtual]

Write the contents of a buffer to a file.

Parameters:
fileFile handle.
bufferThe buffer to write from.
sizeThe number of bytes to write.
Returns:
The number of bytes written, negative error on failure.

Implemented in FATFileSystem, and LittleFileSystem.

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

Definition at line 172 of file SystemStorage.cpp.

MBED_DEPRECATED ( "Invalid copy construction of a NonCopyable< FileBase > resource."   ) const [protected, inherited]

NonCopyable copy constructor.

A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.

If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.

Definition at line 191 of file NonCopyable.h.

MBED_DEPRECATED ( "Invalid copy assignment of a NonCopyable< FileBase > resource."   ) [protected, inherited]

NonCopyable copy assignment operator.

A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.

If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.

MBED_DEPRECATED_SINCE ( "mbed-os-5.5"  ,
"Replaced by `int open(FileHandle **, ...)` for propagating error codes"   
) const [inherited]

Open a file on the filesystem.

Parameters:
pathThe name of the file to open
flagsThe flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
Returns:
A file handle on success, NULL on failure
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, and LittleFileSystem.

Definition at line 49 of file FileSystem.cpp.

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, and LittleFileSystem.

int open ( DirHandle **  dir,
const char *  path 
) [protected, virtual]

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.

Definition at line 168 of file FileSystem.cpp.

int open ( FileHandle **  file,
const char *  filename,
int  flags 
) [protected, virtual]

Open a file on the filesystem.

Parameters:
fileDestination for the handle to a newly created file
filenameThe name of the file to open
flagsThe flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
Returns:
0 on success, negative error code on failure

Implements FileSystemHandle.

Definition at line 155 of file FileSystem.cpp.

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, and LittleFileSystem.

Definition at line 29 of file FileSystem.cpp.

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, and LittleFileSystem.

Definition at line 34 of file FileSystem.cpp.

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, and LittleFileSystem.

Definition at line 39 of file FileSystem.cpp.

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, and LittleFileSystem.

Definition at line 44 of file FileSystem.cpp.

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, and LittleFileSystem.

Definition at line 54 of file FileSystem.cpp.

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, and LittleFileSystem.