Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Static Public Member Functions | Protected Member Functions
LittleFileSystem Class Reference

#include <LittleFileSystem.h>

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

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)
 
virtual int mount (BlockDevice *bd)
 
virtual int unmount ()
 
virtual int reformat (BlockDevice *bd)
 
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::FileSystem
 FileSystem (const char *name=NULL)
 
- Public Member Functions inherited from mbed::FileSystemLike
 FileSystemLike (const char *name=NULL)
 
FileHandleopen (const char *path, int flags)
 
DirHandleopendir (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)
 

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)
 
- Static Public Member Functions inherited from mbed::FileBase
static FileBaselookup (const char *name, unsigned int len)
 
static FileBaseget (int n)
 

Protected Member Functions

virtual int file_open (mbed::fs_file_t *file, const char *path, int flags)
 
virtual int file_close (mbed::fs_file_t file)
 
virtual ssize_t file_read (mbed::fs_file_t file, void *buffer, size_t size)
 
virtual ssize_t file_write (mbed::fs_file_t file, const void *buffer, size_t size)
 
virtual int file_sync (mbed::fs_file_t file)
 
virtual off_t file_seek (mbed::fs_file_t file, off_t offset, int whence)
 
virtual off_t file_tell (mbed::fs_file_t file)
 
virtual off_t file_size (mbed::fs_file_t file)
 
virtual int dir_open (mbed::fs_dir_t *dir, const char *path)
 
virtual int dir_close (mbed::fs_dir_t dir)
 
virtual ssize_t dir_read (mbed::fs_dir_t dir, struct dirent *ent)
 
virtual void dir_seek (mbed::fs_dir_t dir, off_t offset)
 
virtual off_t dir_tell (mbed::fs_dir_t dir)
 
virtual void dir_rewind (mbed::fs_dir_t dir)
 
- Protected Member Functions inherited from mbed::FileSystem
virtual int file_isatty (fs_file_t file)
 
virtual void file_rewind (fs_file_t file)
 
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)
 

Detailed Description

LittleFileSystem, a little filesystem

Constructor & Destructor Documentation

LittleFileSystem::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
nameName to add filesystem to tree as
bdBlockDevice to mount, may be passed instead to mount call
read_sizeMinimum 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_sizeMinimum 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_sizeSize 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.
lookaheadNumber 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.

Member Function Documentation

int LittleFileSystem::dir_close ( mbed::fs_dir_t  dir)
protectedvirtual

Close a directory

Parameters
dirDir handle return 0 on success, negative error code on failure

Reimplemented from mbed::FileSystem.

int LittleFileSystem::dir_open ( mbed::fs_dir_t *  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 mbed::FileSystem.

ssize_t LittleFileSystem::dir_read ( mbed::fs_dir_t  dir,
struct dirent ent 
)
protectedvirtual

Read the next directory entry

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

Reimplemented from mbed::FileSystem.

void LittleFileSystem::dir_rewind ( mbed::fs_dir_t  dir)
protectedvirtual

Rewind the current position to the beginning of the directory

Parameters
dirDir handle

Reimplemented from mbed::FileSystem.

void LittleFileSystem::dir_seek ( mbed::fs_dir_t  dir,
off_t  offset 
)
protectedvirtual

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

off_t LittleFileSystem::dir_tell ( mbed::fs_dir_t  dir)
protectedvirtual

Get the current position of the directory

Parameters
dirDir handle
Returns
Position of the directory that can be passed to dir_rewind

Reimplemented from mbed::FileSystem.

int LittleFileSystem::file_close ( mbed::fs_file_t  file)
protectedvirtual

Close a file

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

Implements mbed::FileSystem.

int LittleFileSystem::file_open ( mbed::fs_file_t *  file,
const char *  path,
int  flags 
)
protectedvirtual

Open a file on the filesystem

Parameters
fileDestination for the handle to a newly created file
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
0 on success, negative error code on failure

Implements mbed::FileSystem.

ssize_t LittleFileSystem::file_read ( mbed::fs_file_t  file,
void *  buffer,
size_t  size 
)
protectedvirtual

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 end of file, negative error on failure

Implements mbed::FileSystem.

off_t LittleFileSystem::file_seek ( mbed::fs_file_t  file,
off_t  offset,
int  whence 
)
protectedvirtual

Move the file position to a given offset from 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 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 mbed::FileSystem.

off_t LittleFileSystem::file_size ( mbed::fs_file_t  file)
protectedvirtual

Get the size of the file

Parameters
fileFile handle
Returns
Size of the file in bytes

Reimplemented from mbed::FileSystem.

int LittleFileSystem::file_sync ( mbed::fs_file_t  file)
protectedvirtual

Flush any buffers associated with the file

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

Reimplemented from mbed::FileSystem.

off_t LittleFileSystem::file_tell ( mbed::fs_file_t  file)
protectedvirtual

Get the file position of the file

Parameters
fileFile handle
Returns
The current offset in the file

Reimplemented from mbed::FileSystem.

ssize_t LittleFileSystem::file_write ( mbed::fs_file_t  file,
const void *  buffer,
size_t  size 
)
protectedvirtual

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

Implements mbed::FileSystem.

int LittleFileSystem::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
bdThis is the block device that will be formated.
read_sizeMinimum 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_sizeMinimum 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_sizeSize 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.
lookaheadNumber 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.
int LittleFileSystem::mkdir ( const char *  path,
mode_t  mode 
)
virtual

Create a directory in the filesystem.

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 mbed::FileSystem.

int LittleFileSystem::mount ( BlockDevice bd)
virtual

Mounts a filesystem to a block device

Parameters
bdBlockDevice to mount to
Returns
0 on success, negative error code on failure

Implements mbed::FileSystem.

int LittleFileSystem::reformat ( BlockDevice bd)
virtual

Reformats a filesystem, results in an empty and mounted filesystem

Parameters
bdBlockDevice 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 mbed::FileSystem.

int LittleFileSystem::remove ( const char *  path)
virtual

Remove a file from the filesystem.

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

Reimplemented from mbed::FileSystem.

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

Rename a file in the filesystem.

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

Reimplemented from mbed::FileSystem.

int LittleFileSystem::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 mbed::FileSystem.

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

Store information about the mounted filesystem 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 mbed::FileSystem.

int LittleFileSystem::unmount ( )
virtual

Unmounts a filesystem from the underlying block device

Returns
0 on success, negative error code on failure

Implements mbed::FileSystem.


The documentation for this class was generated from the following files:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.