Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LittleFileSystem Class Reference
LittleFileSystem, a little filesystem. More...
#include <LittleFileSystem.h>
Inherits mbed::FileSystem.
Public Member Functions | |
LittleFileSystem (const char *name=NULL, BlockDevice *bd=NULL, lfs_size_t read_size=MBED_LFS_READ_SIZE, lfs_size_t prog_size=MBED_LFS_PROG_SIZE, lfs_size_t block_size=MBED_LFS_BLOCK_SIZE, lfs_size_t lookahead=MBED_LFS_LOOKAHEAD) | |
Lifetime of the LittleFileSystem. | |
virtual int | mount (BlockDevice *bd) |
Mounts a filesystem to a block device. | |
virtual int | unmount () |
Unmounts a filesystem from the underlying block device. | |
virtual int | reformat (BlockDevice *bd) |
Reformats a filesystem, results in an empty and mounted filesystem. | |
virtual int | remove (const char *path) |
Remove a file from the filesystem. | |
virtual int | rename (const char *path, const char *newpath) |
Rename a file in the filesystem. | |
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 filesystem. | |
virtual int | statvfs (const char *path, struct statvfs *buf) |
Store information about the mounted filesystem 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 int | format (BlockDevice *bd, lfs_size_t read_size=MBED_LFS_READ_SIZE, lfs_size_t prog_size=MBED_LFS_PROG_SIZE, lfs_size_t block_size=MBED_LFS_BLOCK_SIZE, lfs_size_t lookahead=MBED_LFS_LOOKAHEAD) |
Formats a block device with the LittleFileSystem. | |
Protected Member Functions | |
virtual int | file_open (mbed::fs_file_t *file, const char *path, int flags) |
Open a file on the filesystem. | |
virtual int | file_close (mbed::fs_file_t file) |
Close a file. | |
virtual ssize_t | file_read (mbed::fs_file_t file, void *buffer, size_t size) |
Read the contents of a file into a buffer. | |
virtual ssize_t | file_write (mbed::fs_file_t file, const void *buffer, size_t size) |
Write the contents of a buffer to a file. | |
virtual int | file_sync (mbed::fs_file_t file) |
Flush any buffers associated with the file. | |
virtual off_t | file_seek (mbed::fs_file_t file, off_t offset, int whence) |
Move the file position to a given offset from from a given location. | |
virtual off_t | file_tell (mbed::fs_file_t file) |
Get the file position of the file. | |
virtual off_t | file_size (mbed::fs_file_t file) |
Get the size of the file. | |
virtual int | dir_open (mbed::fs_dir_t *dir, const char *path) |
Open a directory on the filesystem. | |
virtual int | dir_close (mbed::fs_dir_t dir) |
Close a directory. | |
virtual ssize_t | dir_read (mbed::fs_dir_t dir, struct dirent *ent) |
Read the next directory entry. | |
virtual void | dir_seek (mbed::fs_dir_t dir, off_t offset) |
Set the current position of the directory. | |
virtual off_t | dir_tell (mbed::fs_dir_t dir) |
Get the current position of the directory. | |
virtual void | dir_rewind (mbed::fs_dir_t dir) |
Rewind the current position to the beginning of the directory. | |
virtual int | file_isatty (fs_file_t file) |
Check if the file in an interactive terminal device If so, line buffered behaviour is used by default. | |
virtual void | file_rewind (fs_file_t file) |
Rewind the file position to the beginning of the file. | |
virtual size_t | dir_size (fs_dir_t dir) |
Get the sizeof 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
LittleFileSystem, a little filesystem.
Definition at line 30 of file LittleFileSystem.h.
Constructor & Destructor Documentation
LittleFileSystem | ( | const char * | name = NULL , |
BlockDevice * | bd = NULL , |
||
lfs_size_t | read_size = MBED_LFS_READ_SIZE , |
||
lfs_size_t | prog_size = MBED_LFS_PROG_SIZE , |
||
lfs_size_t | block_size = MBED_LFS_BLOCK_SIZE , |
||
lfs_size_t | lookahead = MBED_LFS_LOOKAHEAD |
||
) |
Lifetime of the LittleFileSystem.
- Parameters:
-
name Name to add filesystem to tree as bd BlockDevice to mount, may be passed instead to mount call read_size Minimum size of a block read. This determines the size of read buffers. This may be larger than the physical read size to improve performance by caching more of the block device. prog_size Minimum size of a block program. This determines the size of program buffers. This may be larger than the physical program size to improve performance by caching more of the block device. block_size Size of an erasable block. This does not impact ram consumption and may be larger than the physical erase size. However, this should be kept small as each file currently takes up an entire block. lookahead Number of blocks to lookahead during block allocation. A larger lookahead reduces the number of passes required to allocate a block. The lookahead buffer requires only 1 bit per block so it can be quite large with little ram impact. Should be a multiple of 32.
Definition at line 113 of file LittleFileSystem.cpp.
Member Function Documentation
virtual int dir_close | ( | mbed::fs_dir_t | dir ) | [protected, virtual] |
Close a directory.
- Parameters:
-
dir Dir handle return 0 on success, negative error code on failure
Reimplemented from FileSystem.
virtual int dir_open | ( | mbed::fs_dir_t * | dir, |
const char * | path | ||
) | [protected, virtual] |
Open a directory on the filesystem.
- Parameters:
-
dir Destination for the handle to the directory path Name of the directory to open
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
virtual ssize_t dir_read | ( | mbed::fs_dir_t | dir, |
struct dirent * | ent | ||
) | [protected, virtual] |
Read the next directory entry.
- Parameters:
-
dir Dir handle ent The directory entry to fill out
- Returns:
- 1 on reading a filename, 0 at end of directory, negative error on failure
Reimplemented from FileSystem.
virtual void dir_rewind | ( | mbed::fs_dir_t | dir ) | [protected, virtual] |
Rewind the current position to the beginning of the directory.
- Parameters:
-
dir Dir handle
Reimplemented from FileSystem.
virtual void dir_seek | ( | mbed::fs_dir_t | dir, |
off_t | offset | ||
) | [protected, virtual] |
Set the current position of the directory.
- Parameters:
-
dir Dir handle offset Offset of the location to seek to, must be a value returned from dir_tell
Reimplemented from FileSystem.
virtual size_t dir_size | ( | fs_dir_t | dir ) | [protected, virtual, inherited] |
virtual off_t dir_tell | ( | mbed::fs_dir_t | dir ) | [protected, virtual] |
Get the current position of the directory.
- Parameters:
-
dir Dir handle
- Returns:
- Position of the directory that can be passed to dir_rewind
Reimplemented from FileSystem.
virtual int file_close | ( | mbed::fs_file_t | file ) | [protected, virtual] |
Close a file.
- Parameters:
-
file File handle return 0 on success, negative error code on failure
Implements FileSystem.
virtual int file_isatty | ( | fs_file_t | file ) | [protected, virtual, inherited] |
Check if the file in an interactive terminal device If so, line buffered behaviour is used by default.
- Parameters:
-
file File handle
- Returns:
- True if the file is a terminal
virtual int file_open | ( | mbed::fs_file_t * | file, |
const char * | path, | ||
int | flags | ||
) | [protected, virtual] |
Open a file on the filesystem.
- Parameters:
-
file Destination for the handle to a newly created file path The name of the file to open flags The 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 FileSystem.
virtual ssize_t file_read | ( | mbed::fs_file_t | file, |
void * | buffer, | ||
size_t | size | ||
) | [protected, virtual] |
Read the contents of a file into a buffer.
- Parameters:
-
file File handle buffer The buffer to read in to size The number of bytes to read
- Returns:
- The number of bytes read, 0 at end of file, negative error on failure
Implements FileSystem.
virtual void file_rewind | ( | fs_file_t | file ) | [protected, virtual, inherited] |
Rewind the file position to the beginning of the file.
- Parameters:
-
file File handle
- Note:
- This is equivalent to file_seek(file, 0, FS_SEEK_SET)
virtual off_t file_seek | ( | mbed::fs_file_t | file, |
off_t | offset, | ||
int | whence | ||
) | [protected, virtual] |
Move the file position to a given offset from from a given location.
- Parameters:
-
file File handle offset The offset from whence to move to whence The start of where to seek SEEK_SET to start from beginning of file, SEEK_CUR to start from current position in file, SEEK_END to start from end of file
- Returns:
- The new offset of the file
Implements FileSystem.
virtual off_t file_size | ( | mbed::fs_file_t | file ) | [protected, virtual] |
Get the size of the file.
- Parameters:
-
file File handle
- Returns:
- Size of the file in bytes
Reimplemented from FileSystem.
virtual int file_sync | ( | mbed::fs_file_t | file ) | [protected, virtual] |
Flush any buffers associated with the file.
- Parameters:
-
file File handle
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
virtual off_t file_tell | ( | mbed::fs_file_t | file ) | [protected, virtual] |
Get the file position of the file.
- Parameters:
-
file File handle
- Returns:
- The current offset in the file
Reimplemented from FileSystem.
virtual ssize_t file_write | ( | mbed::fs_file_t | file, |
const void * | buffer, | ||
size_t | size | ||
) | [protected, virtual] |
Write the contents of a buffer to a file.
- Parameters:
-
file File handle buffer The buffer to write from size The number of bytes to write
- Returns:
- The number of bytes written, negative error on failure
Implements FileSystem.
int format | ( | BlockDevice * | bd, |
lfs_size_t | read_size = MBED_LFS_READ_SIZE , |
||
lfs_size_t | prog_size = MBED_LFS_PROG_SIZE , |
||
lfs_size_t | block_size = MBED_LFS_BLOCK_SIZE , |
||
lfs_size_t | lookahead = MBED_LFS_LOOKAHEAD |
||
) | [static] |
Formats a block device with the LittleFileSystem.
The block device to format should be mounted when this function is called.
- Parameters:
-
bd This is the block device that will be formated. read_size Minimum size of a block read. This determines the size of read buffers. This may be larger than the physical read size to improve performance by caching more of the block device. prog_size Minimum size of a block program. This determines the size of program buffers. This may be larger than the physical program size to improve performance by caching more of the block device. block_size Size of an erasable block. This does not impact ram consumption and may be larger than the physical erase size. However, this should be kept small as each file currently takes up an entire block. lookahead Number of blocks to lookahead during block allocation. A larger lookahead reduces the number of passes required to allocate a block. The lookahead buffer requires only 1 bit per block so it can be quite large with little ram impact. Should be a multiple of 32.
Definition at line 200 of file LittleFileSystem.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 non copyable happens.
If you see this warning, your code is probably doing something unspecified. Copy of non copyable resources can lead to resource leak and random error.
Definition at line 171 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 non copyable happens.
If you see this warning, your code is probably doing something unspecified. Copy of non copyable 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:
-
path The name of the file to open flags The 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 filesystem.
- Parameters:
-
path The name of the directory to create. mode The permissions with which to create the directory
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
Definition at line 317 of file LittleFileSystem.cpp.
int mount | ( | BlockDevice * | bd ) | [virtual] |
Mounts a filesystem to a block device.
- Parameters:
-
bd BlockDevice to mount to
- Returns:
- 0 on success, negative error code on failure
Implements FileSystem.
Definition at line 131 of file LittleFileSystem.cpp.
virtual int open | ( | DirHandle ** | dir, |
const char * | path | ||
) | [protected, virtual, inherited] |
Open a directory on the filesystem.
- Parameters:
-
dir Destination for the handle to the directory path Name of the directory to open
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystemHandle.
virtual int open | ( | FileHandle ** | file, |
const char * | filename, | ||
int | flags | ||
) | [protected, virtual, inherited] |
Open a file on the filesystem.
- Parameters:
-
file Destination for the handle to a newly created file filename The name of the file to open flags The 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.
int reformat | ( | BlockDevice * | bd ) | [virtual] |
Reformats a filesystem, results in an empty and mounted filesystem.
- Parameters:
-
bd BlockDevice to reformat and mount. If NULL, the mounted block device will be 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 254 of file LittleFileSystem.cpp.
int remove | ( | const char * | path ) | [virtual] |
Remove a file from the filesystem.
- Parameters:
-
path The name of the file to remove.
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
Definition at line 297 of file LittleFileSystem.cpp.
int rename | ( | const char * | path, |
const char * | newpath | ||
) | [virtual] |
Rename a file in the filesystem.
- Parameters:
-
path The name of the file to rename. newpath The name to rename it to
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
Definition at line 307 of file LittleFileSystem.cpp.
int stat | ( | const char * | path, |
struct stat * | st | ||
) | [virtual] |
Store information about the file in a stat structure.
- Parameters:
-
path The name of the file to find information about st The stat buffer to write to
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
Definition at line 327 of file LittleFileSystem.cpp.
int statvfs | ( | const char * | path, |
struct statvfs * | buf | ||
) | [virtual] |
Store information about the mounted filesystem in a statvfs structure.
- Parameters:
-
path The name of the file to find information about buf The stat buffer to write to
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileSystem.
Definition at line 346 of file LittleFileSystem.cpp.
int unmount | ( | ) | [virtual] |
Unmounts a filesystem from the underlying block device.
- Returns:
- 0 on success, negative error code on failure
Implements FileSystem.
Definition at line 173 of file LittleFileSystem.cpp.
Generated on Tue Jul 12 2022 14:26:47 by
