distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::Littlefs1FileSystem Class Reference

#include "distortos/FileSystem/littlefs1/Littlefs1FileSystem.hpp"

Inheritance diagram for distortos::Littlefs1FileSystem:
[legend]
Collaboration diagram for distortos::Littlefs1FileSystem:
[legend]

Public Member Functions

constexpr Littlefs1FileSystem (devices::MemoryTechnologyDevice &memoryTechnologyDevice, const size_t readBlockSize={}, const size_t programBlockSize={}, const size_t eraseBlockSize={}, const size_t blocksCount={}, const size_t lookahead=32 *16)
 Littlefs1FileSystem's constructor. More...
 
 ~Littlefs1FileSystem () override
 Littlefs1FileSystem's destructor. More...
 
int format () override
 Formats associated device with the file system. More...
 
int getFileStatus (const char *path, struct stat &status) override
 Returns status of file. More...
 
int getStatus (struct statvfs &status) override
 Returns status of file system. More...
 
void lock () override
 Locks the file system for exclusive use by current thread. More...
 
int makeDirectory (const char *path, mode_t mode) override
 Makes a directory. More...
 
int mount () override
 Mounts file system on associated device. More...
 
std::pair< int, std::unique_ptr< Directory > > openDirectory (const char *path) override
 Opens directory. More...
 
std::pair< int, std::unique_ptr< File > > openFile (const char *path, int flags) override
 Opens file. More...
 
int remove (const char *path) override
 Removes file or directory. More...
 
int rename (const char *path, const char *newPath) override
 Renames file or directory. More...
 
void unlock () override
 Unlocks the file system which was previously locked by current thread. More...
 
int unmount () override
 Unmounts file system from associated device. More...
 
- Public Member Functions inherited from distortos::FileSystem
virtual ~FileSystem ()=default
 FileSystem's destructor. More...
 
 FileSystem (const FileSystem &)=delete
 
FileSystemoperator= (const FileSystem &)=delete
 

Private Attributes

lfs1_config configuration_
 configuration of littlefs More...
 
lfs1_t fileSystem_
 littlefs-v1 file system More...
 
distortos::Mutex mutex_
 mutex for serializing access to the object More...
 
std::unique_ptr< uint8_t[]> lookaheadBuffer_
 lookahead buffer More...
 
std::unique_ptr< uint8_t[]> programBuffer_
 program buffer More...
 
std::unique_ptr< uint8_t[]> readBuffer_
 read buffer More...
 
devices::MemoryTechnologyDevicememoryTechnologyDevice_
 reference to associated memory technology device More...
 
size_t readBlockSize_
 read block size, bytes, 0 to use default value of device More...
 
size_t programBlockSize_
 program block size, bytes, 0 to use default value of device More...
 
size_t eraseBlockSize_
 erase block size, bytes, 0 to use default value of device More...
 
size_t blocksCount_
 number of erase blocks used for file system, 0 to use max value of device More...
 
size_t lookahead_
 number of blocks to lookahead during block allocation More...
 
bool mounted_
 tells whether the file system is currently mounted on associated memory technology device (true) or not (false) More...
 

Friends

class Littlefs1Directory
 
class Littlefs1File
 

Detailed Description

Littlefs1FileSystem class is a littlefs-v1 file system.

Constructor & Destructor Documentation

◆ Littlefs1FileSystem()

constexpr distortos::Littlefs1FileSystem::Littlefs1FileSystem ( devices::MemoryTechnologyDevice memoryTechnologyDevice,
const size_t  readBlockSize = {},
const size_t  programBlockSize = {},
const size_t  eraseBlockSize = {},
const size_t  blocksCount = {},
const size_t  lookahead = 32 * 16 
)
inlineexplicit

Littlefs1FileSystem's constructor.

Parameters
[in]memoryTechnologyDeviceis a reference to memory technology device on which the file system will be mounted
[in]readBlockSizeis the read block size, bytes, 0 to use default value of device, default - 0
[in]programBlockSizeis the program block size, bytes, 0 to use default value of device, default - 0
[in]eraseBlockSizeis the erase block size, bytes, 0 to use default value of device, default - 0
[in]blocksCountis the number of erase blocks used for file system, 0 to use max value of device, default - 0
[in]lookaheadis the number of blocks to lookahead during block allocation, default - 512

◆ ~Littlefs1FileSystem()

distortos::Littlefs1FileSystem::~Littlefs1FileSystem ( )
override

Littlefs1FileSystem's destructor.

Warning
This function must not be called from interrupt context!
Precondition
File system is unmounted.

Member Function Documentation

◆ format()

int distortos::Littlefs1FileSystem::format ( )
overridevirtual

Formats associated device with the file system.

Warning
This function must not be called from interrupt context!
Precondition
File system is unmounted.
Returns
0 on success, error code otherwise:
  • ENOMEM - unable to allocate memory for file system;
  • converted error codes returned by lfs1_format();
  • error codes returned by MemoryTechnologyDevice::open();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ getFileStatus()

int distortos::Littlefs1FileSystem::getFileStatus ( const char *  path,
struct stat &  status 
)
overridevirtual

Returns status of file.

Similar to stat()

st_mode field is set in all cases, st_size field is set only for regular files. All other fields are zero-initialized.

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
path is valid.
Parameters
[in]pathis the path to file for which status should be returned, must be valid
[out]statusis a reference to stat struct into which status of file will be written
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_stat();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ getStatus()

int distortos::Littlefs1FileSystem::getStatus ( struct statvfs status)
overridevirtual

Returns status of file system.

Similar to statvfs()

f_bsize, f_frsize, f_blocks, f_bfree, f_bavail and f_namemax fields are set in all cases. All other fields are zero-initialized.

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
Parameters
[out]statusis a reference to statvfs struct into which status of file system will be written
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_traverse();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ lock()

void distortos::Littlefs1FileSystem::lock ( )
overridevirtual

Locks the file system for exclusive use by current thread.

When the object is locked, any call to any member function from other thread will be blocked until the object is unlocked. Locking is optional, but may be useful when more than one operation must be done atomically.

Note
Locks are recursive.
Warning
This function must not be called from interrupt context!
Precondition
The number of recursive locks of file system is less than 65535.
Postcondition
File system is locked.

Implements distortos::FileSystem.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeDirectory()

int distortos::Littlefs1FileSystem::makeDirectory ( const char *  path,
mode_t  mode 
)
overridevirtual

Makes a directory.

Similar to mkdir()

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
path is valid.
Parameters
[in]pathis the path of the directory that will be created, must be valid
[in]modeis the value of permission bits of the created directory
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_mkdir();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ mount()

int distortos::Littlefs1FileSystem::mount ( )
overridevirtual

Mounts file system on associated device.

Warning
This function must not be called from interrupt context!
Precondition
File system is unmounted.
Returns
0 on success, error code otherwise:
  • ENOMEM - unable to allocate memory for file system;
  • converted error codes returned by lfs1_mount();
  • error codes returned by MemoryTechnologyDevice::open();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ openDirectory()

std::pair< int, std::unique_ptr< Directory > > distortos::Littlefs1FileSystem::openDirectory ( const char *  path)
overridevirtual

Opens directory.

Similar to opendir()

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
path is valid.
Parameters
[in]pathis the path of directory that will be opened, must be valid
Returns
pair with return code (0 on success, error code otherwise) and std::unique_ptr with opened directory; error codes:

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ openFile()

std::pair< int, std::unique_ptr< File > > distortos::Littlefs1FileSystem::openFile ( const char *  path,
int  flags 
)
overridevirtual

Opens file.

Similar to open()

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
path is valid.
flags are valid.
Parameters
[in]pathis the path of file that will be opened, must be valid
[in]flagsare file status flags, must be valid, for list of available flags and valid combinations see open()
Returns
pair with return code (0 on success, error code otherwise) and std::unique_ptr with opened file; error codes:

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ remove()

int distortos::Littlefs1FileSystem::remove ( const char *  path)
overridevirtual

Removes file or directory.

Similar to remove()

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
path is valid.
Parameters
[in]pathis the path of file or directory that will be removed, must be valid
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_remove();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ rename()

int distortos::Littlefs1FileSystem::rename ( const char *  path,
const char *  newPath 
)
overridevirtual

Renames file or directory.

Similar to rename()

Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
path and newPath are valid.
Parameters
[in]pathis the path of file or directory that will be renamed, must be valid
[in]newPathis the new path of file or directory, must be valid
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_rename();

Implements distortos::FileSystem.

Here is the call graph for this function:

◆ unlock()

void distortos::Littlefs1FileSystem::unlock ( )
overridevirtual

Unlocks the file system which was previously locked by current thread.

Note
Locks are recursive.
Warning
This function must not be called from interrupt context!
Precondition
This function is called by the thread that locked the file system.

Implements distortos::FileSystem.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmount()

int distortos::Littlefs1FileSystem::unmount ( )
overridevirtual

Unmounts file system from associated device.

Note
Even if error code is returned, the file system must not be used (until it is successfully mounted again).
Warning
This function must not be called from interrupt context!
Precondition
File system is mounted.
Postcondition
File system is unmounted.
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_unmount();
  • error codes returned by MemoryTechnologyDevice::close();

Implements distortos::FileSystem.

Here is the call graph for this function:

Member Data Documentation

◆ blocksCount_

size_t distortos::Littlefs1FileSystem::blocksCount_
private

number of erase blocks used for file system, 0 to use max value of device

◆ configuration_

lfs1_config distortos::Littlefs1FileSystem::configuration_
private

configuration of littlefs

◆ eraseBlockSize_

size_t distortos::Littlefs1FileSystem::eraseBlockSize_
private

erase block size, bytes, 0 to use default value of device

◆ fileSystem_

lfs1_t distortos::Littlefs1FileSystem::fileSystem_
private

littlefs-v1 file system

◆ lookahead_

size_t distortos::Littlefs1FileSystem::lookahead_
private

number of blocks to lookahead during block allocation

◆ lookaheadBuffer_

std::unique_ptr<uint8_t[]> distortos::Littlefs1FileSystem::lookaheadBuffer_
private

lookahead buffer

◆ memoryTechnologyDevice_

devices::MemoryTechnologyDevice& distortos::Littlefs1FileSystem::memoryTechnologyDevice_
private

reference to associated memory technology device

◆ mounted_

bool distortos::Littlefs1FileSystem::mounted_
private

tells whether the file system is currently mounted on associated memory technology device (true) or not (false)

◆ mutex_

distortos::Mutex distortos::Littlefs1FileSystem::mutex_
private

mutex for serializing access to the object

◆ programBlockSize_

size_t distortos::Littlefs1FileSystem::programBlockSize_
private

program block size, bytes, 0 to use default value of device

◆ programBuffer_

std::unique_ptr<uint8_t[]> distortos::Littlefs1FileSystem::programBuffer_
private

program buffer

◆ readBlockSize_

size_t distortos::Littlefs1FileSystem::readBlockSize_
private

read block size, bytes, 0 to use default value of device

◆ readBuffer_

std::unique_ptr<uint8_t[]> distortos::Littlefs1FileSystem::readBuffer_
private

read buffer


The documentation for this class was generated from the following files: