distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::FileSystem Class Referenceabstract

#include "distortos/FileSystem/FileSystem.hpp"

Inheritance diagram for distortos::FileSystem:
[legend]

Public Member Functions

virtual ~FileSystem ()=default
 FileSystem's destructor. More...
 
virtual int format ()=0
 Formats associated device with the file system. More...
 
virtual int getFileStatus (const char *path, struct stat &status)=0
 Returns status of file. More...
 
virtual int getStatus (struct statvfs &status)=0
 Returns status of file system. More...
 
virtual void lock ()=0
 Locks the file system for exclusive use by current thread. More...
 
virtual int makeDirectory (const char *path, mode_t mode)=0
 Makes a directory. More...
 
virtual int mount ()=0
 Mounts file system on associated device. More...
 
virtual std::pair< int, std::unique_ptr< Directory > > openDirectory (const char *path)=0
 Opens directory. More...
 
virtual std::pair< int, std::unique_ptr< File > > openFile (const char *path, int flags)=0
 Opens file. More...
 
virtual int remove (const char *path)=0
 Removes file or directory. More...
 
virtual int rename (const char *path, const char *newPath)=0
 Renames file or directory. More...
 
virtual void unlock ()=0
 Unlocks the file system which was previously locked by current thread. More...
 
virtual int unmount ()=0
 Unmounts file system from associated device. More...
 
 FileSystem (const FileSystem &)=delete
 
FileSystemoperator= (const FileSystem &)=delete
 

Detailed Description

FileSystem class is an interface for a file system.

Constructor & Destructor Documentation

◆ ~FileSystem()

virtual distortos::FileSystem::~FileSystem ( )
virtualdefault

FileSystem's destructor.

Precondition
File system is unmounted.

Member Function Documentation

◆ format()

virtual int distortos::FileSystem::format ( )
pure virtual

Formats associated device with the file system.

Precondition
File system is unmounted.
Returns
0 on success, error code otherwise

Implemented in distortos::Littlefs1FileSystem.

◆ getFileStatus()

virtual int distortos::FileSystem::getFileStatus ( const char *  path,
struct stat &  status 
)
pure virtual

Returns status of file.

Similar to stat()

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:
  • ENAMETOOLONG - length of component of path and/or length of path are longer than allowed maximum;
  • ENOENT - no such file or directory;
  • ENOTDIR - component of path names an existing file where directory was expected;

Implemented in distortos::Littlefs1FileSystem.

◆ getStatus()

virtual int distortos::FileSystem::getStatus ( struct statvfs status)
pure virtual

Returns status of file system.

Similar to statvfs()

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

Implemented in distortos::Littlefs1FileSystem.

◆ lock()

virtual void distortos::FileSystem::lock ( )
pure virtual

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.

Implemented in distortos::Littlefs1FileSystem.

◆ makeDirectory()

virtual int distortos::FileSystem::makeDirectory ( const char *  path,
mode_t  mode 
)
pure virtual

Makes a directory.

Similar to mkdir()

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:
  • EEXIST - named file exists;
  • ENAMETOOLONG - length of component of path and/or length of path are longer than allowed maximum;
  • ENOENT - prefix component of path does not name an existing directory;
  • ENOSPC - no space left on the device containing the file system;
  • ENOTDIR - component of path names an existing file where directory was expected;
  • EROFS - read-only file system;

Implemented in distortos::Littlefs1FileSystem.

◆ mount()

virtual int distortos::FileSystem::mount ( )
pure virtual

Mounts file system on associated device.

Precondition
File system is unmounted.
Returns
0 on success, error code otherwise:
  • EILSEQ - device does not contain valid file system;
  • ENOMEM - unable to allocate memory for file system;

Implemented in distortos::Littlefs1FileSystem.

◆ openDirectory()

virtual std::pair<int, std::unique_ptr<Directory> > distortos::FileSystem::openDirectory ( const char *  path)
pure virtual

Opens directory.

Similar to opendir()

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:
  • ENAMETOOLONG - length of component of path and/or length of path are longer than allowed maximum;
  • ENOENT - path does not name an existing directory;
  • ENOMEM - unable to allocate memory for directory;
  • ENOTDIR - component of path names an existing file where directory was expected;

Implemented in distortos::Littlefs1FileSystem.

◆ openFile()

virtual std::pair<int, std::unique_ptr<File> > distortos::FileSystem::openFile ( const char *  path,
int  flags 
)
pure virtual

Opens file.

Similar to open()

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:
  • EEXIST - O_CREAT and O_EXCL are set, and file named by path exists;
  • EISDIR - file named by path is a directory;
  • ENAMETOOLONG - length of component of path and/or length of path are longer than allowed maximum;
  • ENOENT - O_CREAT is not set and path does not name an existing file or O_CREAT is set and prefix component of path does not name an existing directory;
  • ENOMEM - unable to allocate memory for file;
  • ENOSPC - O_CREAT is set, file named by path does not exist and no space is left on the device containing the file system; *
  • ENOTDIR - component of path names an existing file where directory was expected;
  • EROFS - either O_WRONLY, O_RDWR, O_CREAT (and file named by path does not exist), or O_TRUNC are set and file system is read-only;

Implemented in distortos::Littlefs1FileSystem.

◆ remove()

virtual int distortos::FileSystem::remove ( const char *  path)
pure virtual

Removes file or directory.

Similar to remove()

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:
  • ENAMETOOLONG - length of component of path and/or length of path are longer than allowed maximum;
  • ENOENT - path does not name an existing file or directory;
  • ENOTDIR - component of path names an existing file where directory was expected;
  • ENOTEMPTY - path names a directory which is not empty;
  • EROFS - read-only file system;

Implemented in distortos::Littlefs1FileSystem.

◆ rename()

virtual int distortos::FileSystem::rename ( const char *  path,
const char *  newPath 
)
pure virtual

Renames file or directory.

Similar to rename()

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:
  • EEXIST - file or directory named by newPath exists;
  • EISDIR - newPath points to a directory while path points to a file;
  • ENAMETOOLONG - length of component of path and/or length of path and/or length of component of newPath and/or length of newPath are longer than allowed maximum;
  • ENOENT - path does not name an existing file or directory or prefix component of newPath does not name an existing directory;
  • ENOSPC - no space left on the device containing the file system;
  • ENOTDIR - component of path and/or newPath name an existing file where directory was expected;
  • EROFS - read-only file system;

Implemented in distortos::Littlefs1FileSystem.

◆ unlock()

virtual void distortos::FileSystem::unlock ( )
pure virtual

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.

Implemented in distortos::Littlefs1FileSystem.

◆ unmount()

virtual int distortos::FileSystem::unmount ( )
pure virtual

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).
Precondition
File system is mounted.
Postcondition
File system is unmounted.
Returns
0 on success, error code otherwise

Implemented in distortos::Littlefs1FileSystem.


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