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

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

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

Public Member Functions

 ~Littlefs1File () override
 Littlefs1File's destructor. More...
 
int close () override
 Closes file. More...
 
std::pair< int, off_t > getPosition () override
 Returns current file offset. More...
 
std::pair< int, off_t > getSize () override
 Returns size of file. More...
 
int getStatus (struct stat &status) override
 Returns status of file. More...
 
std::pair< int, bool > isATerminal () override
 Tells whether the file is a terminal. More...
 
void lock () override
 Locks the file for exclusive use by current thread. More...
 
std::pair< int, size_t > read (void *buffer, size_t size) override
 Reads data from file. More...
 
int rewind () override
 Resets current file offset. More...
 
std::pair< int, off_t > seek (Whence whence, off_t offset) override
 Moves file offset. More...
 
int synchronize () override
 Synchronizes state of a file, ensuring all cached writes are finished. More...
 
void unlock () override
 Unlocks the file which was previously locked by current thread. More...
 
std::pair< int, size_t > write (const void *buffer, size_t size) override
 Writes data to file. More...
 
- Public Member Functions inherited from distortos::File
virtual ~File ()=default
 File's destructor. More...
 
 File (const File &)=delete
 
Fileoperator= (const File &)=delete
 

Private Member Functions

constexpr Littlefs1File (Littlefs1FileSystem &fileSystem)
 Littlefs1File's constructor. More...
 
int open (const char *path, int flags)
 Opens file. More...
 

Private Attributes

std::unique_ptr< uint8_t[]> buffer_
 file buffer More...
 
lfs1_file_config configuration_
 littlefs-v1 file configuration More...
 
lfs1_file_t file_
 littlefs-v1 file More...
 
Littlefs1FileSystemfileSystem_
 reference to owner file system More...
 
bool opened_
 true if file is opened, false otherwise More...
 

Friends

class Littlefs1FileSystem
 

Additional Inherited Members

- Public Types inherited from distortos::File
enum  Whence { Whence::beginning, Whence::current, Whence::end }
 seek() mode of operation More...
 

Detailed Description

Littlefs1File class is a littlefs-v1 file.

Constructor & Destructor Documentation

◆ ~Littlefs1File()

distortos::Littlefs1File::~Littlefs1File ( )
override

Littlefs1File's destructor.

Precondition
File is closed.

◆ Littlefs1File()

constexpr distortos::Littlefs1File::Littlefs1File ( Littlefs1FileSystem fileSystem)
inlineexplicitprivate

Littlefs1File's constructor.

Parameters
[in]fileSystemis a reference to owner file system

Member Function Documentation

◆ close()

int distortos::Littlefs1File::close ( )
overridevirtual

Closes file.

Similar to close()

Note
Even if error code is returned, the file must not be used.
Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Postcondition
File is closed.
Returns
0 on success, error code otherwise
  • converted error codes returned by lfs1_file_close();

Implements distortos::File.

Here is the call graph for this function:

◆ getPosition()

std::pair< int, off_t > distortos::Littlefs1File::getPosition ( )
overridevirtual

Returns current file offset.

Similar to ftello()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Returns
pair with return code (0 on success, error code otherwise) and current file offset, bytes; error codes:
  • converted error codes returned by lfs1_file_tell();

Implements distortos::File.

Here is the call graph for this function:

◆ getSize()

std::pair< int, off_t > distortos::Littlefs1File::getSize ( )
overridevirtual

Returns size of file.

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Returns
pair with return code (0 on success, error code otherwise) and size of file, bytes; error codes:
  • converted error codes returned by lfs1_file_size();

Implements distortos::File.

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

◆ getStatus()

int distortos::Littlefs1File::getStatus ( struct stat &  status)
overridevirtual

Returns status of file.

Similar to fstat()

st_mode and st_size fields are set in all cases. All other fields are zero-initialized.

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Parameters
[out]statusis a reference to stat struct into which status of file will be written
Returns
0 on success, error code otherwise:

Implements distortos::File.

Here is the call graph for this function:

◆ isATerminal()

std::pair< int, bool > distortos::Littlefs1File::isATerminal ( )
overridevirtual

Tells whether the file is a terminal.

Similar to isatty()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Returns
pair with return code (0 on success, error code otherwise) and bool telling whether the file is a terminal (true) or not (false)

Implements distortos::File.

◆ lock()

void distortos::Littlefs1File::lock ( )
overridevirtual

Locks the file 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 device is less than 65535.
Postcondition
Device is locked.

Implements distortos::File.

Here is the call graph for this function:

◆ open()

int distortos::Littlefs1File::open ( const char *  path,
int  flags 
)
private

Opens file.

Precondition
File is not opened.
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
0 on success, error code otherwise:
  • ENOMEM - unable to allocate memory for file;
  • converted error codes returned by lfs1_file_open();
Here is the caller graph for this function:

◆ read()

std::pair< int, size_t > distortos::Littlefs1File::read ( void *  buffer,
size_t  size 
)
overridevirtual

Reads data from file.

Similar to read()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
buffer is valid.
Parameters
[out]bufferis the buffer into which the data will be read, must be valid
[in]sizeis the size of buffer, bytes
Returns
pair with return code (0 on success, error code otherwise) and number of read bytes (valid even when error code is returned); error codes:
  • converted error codes returned by lfs1_file_read();

Implements distortos::File.

Here is the call graph for this function:

◆ rewind()

int distortos::Littlefs1File::rewind ( )
overridevirtual

Resets current file offset.

Similar to rewind()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_file_rewind();

Implements distortos::File.

Here is the call graph for this function:

◆ seek()

std::pair< int, off_t > distortos::Littlefs1File::seek ( Whence  whence,
off_t  offset 
)
overridevirtual

Moves file offset.

Similar to lseek()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Parameters
[in]whenceselects the mode of operation: Whence::beginning will set file offset to offset, Whence::current will set file offset to its current value plus offset, Whence::end will set file offset to the size of the file plus offset
[in]offsetis the value of offset, bytes
Returns
pair with return code (0 on success, error code otherwise) and current file offset, bytes; error codes:
  • converted error codes returned by lfs1_file_seek();

Implements distortos::File.

Here is the call graph for this function:

◆ synchronize()

int distortos::Littlefs1File::synchronize ( )
overridevirtual

Synchronizes state of a file, ensuring all cached writes are finished.

Similar to fsync()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
Returns
0 on success, error code otherwise:
  • converted error codes returned by lfs1_file_sync();

Implements distortos::File.

Here is the call graph for this function:

◆ unlock()

void distortos::Littlefs1File::unlock ( )
overridevirtual

Unlocks the file 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 device.

Implements distortos::File.

Here is the call graph for this function:

◆ write()

std::pair< int, size_t > distortos::Littlefs1File::write ( const void *  buffer,
size_t  size 
)
overridevirtual

Writes data to file.

Similar to write()

Warning
This function must not be called from interrupt context!
Precondition
File is opened.
buffer is valid.
Parameters
[in]bufferis the buffer with data that will be written, must be valid
[in]sizeis the size of buffer, bytes
Returns
pair with return code (0 on success, error code otherwise) and number of written bytes (valid even when error code is returned); error codes:
  • converted error codes returned by lfs1_file_write();

Implements distortos::File.

Here is the call graph for this function:

Member Data Documentation

◆ buffer_

std::unique_ptr<uint8_t[]> distortos::Littlefs1File::buffer_
private

file buffer

◆ configuration_

lfs1_file_config distortos::Littlefs1File::configuration_
private

littlefs-v1 file configuration

◆ file_

lfs1_file_t distortos::Littlefs1File::file_
private

littlefs-v1 file

◆ fileSystem_

Littlefs1FileSystem& distortos::Littlefs1File::fileSystem_
private

reference to owner file system

◆ opened_

bool distortos::Littlefs1File::opened_
private

true if file is opened, false otherwise


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