Installable File System base class. More...

#include <FileSystem.h>

Inheritance diagram for IFS::FileSystem:
[legend]
Collaboration diagram for IFS::FileSystem:
[legend]

Public Member Functions

int opendir (const String &path, DirHandle &dir)
 open a directory for reading More...
 
int mkdir (const String &path)
 
int makedirs (const char *path)
 Create a directory and any intermediate directories if they do not already exist. More...
 
int makedirs (const String &path)
 
int stat (const String &path, Stat *s)
 
int stat (const String &path, Stat &s)
 
int fstat (FileHandle file, Stat &stat)
 
FileHandle open (const String &path, OpenFlags flags)
 
int ftruncate (FileHandle file)
 
int truncate (const char *fileName, size_t newSize)
 Truncate a file to a specific size. More...
 
int truncate (const String &fileName, size_t newSize)
 
String getContent (const String &fileName)
 Read content of a file. More...
 
Read content of a file
Parameters
fileNameName of file to read from
bufferPointer to a character buffer in to which to read the file content
bufSizeQuantity of bytes to read from file
Return values
size_tQuantity of bytes read from file or zero on failure

After calling this function the content of the file is placed in to a c-string Ensure there is sufficient space in the buffer for file content plus extra trailing null, i.e. at least bufSize + 1 Always check the return value!

Returns 0 if the file could not be read

size_t getContent (const char *fileName, char *buffer, size_t bufSize)
 
size_t getContent (const String &fileName, char *buffer, size_t bufSize)
 
Create or replace file with defined content
Parameters
fileNameName of file to create or replace
contentPointer to c-string containing content to populate file with
Return values
intNumber of bytes transferred or error code
Parameters
length(optional) number of characters to write

This function creates a new file or replaces an existing file and populates the file with the content of a c-string buffer.

int setContent (const char *fileName, const void *content, size_t length)
 
int setContent (const char *fileName, const char *content)
 
int setContent (const String &fileName, const char *content)
 
int setContent (const String &fileName, const void *content, size_t length)
 
int setContent (const String &fileName, const String &content)
 
- Public Member Functions inherited from IFS::IFileSystem
virtual ~IFileSystem ()
 Filing system implementations should dismount and cleanup here. More...
 
virtual int mount ()=0
 Mount file system, performing any required initialisation. More...
 
virtual int getinfo (Info &info)=0
 get filing system information More...
 
virtual int setProfiler (IProfiler *profiler)
 Set profiler instance to enable debugging and performance assessment. More...
 
virtual String getErrorString (int err)
 get the text for a returned error code More...
 
virtual int setVolume (uint8_t index, IFileSystem *fileSystem)
 Set volume for mountpoint. More...
 
virtual int opendir (const char *path, DirHandle &dir)=0
 open a directory for reading More...
 
virtual int readdir (DirHandle dir, Stat &stat)=0
 read a directory entry More...
 
virtual int rewinddir (DirHandle dir)=0
 Reset directory read position to start. More...
 
virtual int closedir (DirHandle dir)=0
 close a directory object More...
 
virtual int mkdir (const char *path)=0
 Create a directory. More...
 
virtual int stat (const char *path, Stat *stat)=0
 get file information More...
 
virtual int fstat (FileHandle file, Stat *stat)=0
 get file information More...
 
virtual int fcontrol (FileHandle file, ControlCode code, void *buffer, size_t bufSize)
 Low-level and non-standard file control operations. More...
 
virtual FileHandle open (const char *path, OpenFlags flags)=0
 open a file by path More...
 
virtual int close (FileHandle file)=0
 close an open file More...
 
virtual int read (FileHandle file, void *data, size_t size)=0
 read content from a file and advance cursor More...
 
virtual int write (FileHandle file, const void *data, size_t size)=0
 write content to a file at current position and advance cursor More...
 
virtual int lseek (FileHandle file, int offset, SeekOrigin origin)=0
 change file read/write position More...
 
virtual int eof (FileHandle file)=0
 determine if current file position is at end of file More...
 
virtual int32_t tell (FileHandle file)=0
 get current file position More...
 
virtual int ftruncate (FileHandle file, size_t new_size)=0
 Truncate (reduce) the size of an open file. More...
 
virtual int flush (FileHandle file)=0
 flush any buffered data to physical media More...
 
virtual int fsetxattr (FileHandle file, AttributeTag tag, const void *data, size_t size)=0
 Set an extended attribute on an open file. More...
 
virtual int fgetxattr (FileHandle file, AttributeTag tag, void *buffer, size_t size)=0
 Get an extended attribute from an open file. More...
 
virtual int fenumxattr (FileHandle file, AttributeEnumCallback callback, void *buffer, size_t bufsize)=0
 Enumerate attributes. More...
 
virtual int setxattr (const char *path, AttributeTag tag, const void *data, size_t size)=0
 Set an extended attribute for a file given its path. More...
 
virtual int getxattr (const char *path, AttributeTag tag, void *buffer, size_t size)=0
 Get an attribute from a file given its path. More...
 
virtual int rename (const char *oldpath, const char *newpath)=0
 rename a file More...
 
virtual int remove (const char *path)=0
 remove (delete) a file by path More...
 
virtual int fremove (FileHandle file)=0
 remove (delete) a file by handle More...
 
virtual int format ()=0
 format the filing system More...
 
virtual int check ()
 Perform a file system consistency check. More...
 

Static Public Member Functions

static constexpr FileSystemcast (IFileSystem &fs)
 
static constexpr FileSystemcast (IFileSystem *fs)
 

rename a file

Parameters
oldpath
newpath
Return values
interror code
using ReadContentCallback = Delegate< int(const char *buffer, size_t size)>
 Callback for readContent method. More...
 
int rename (const String &oldpath, const String &newpath)
 
int remove (const String &path)
 remove (delete) a file by path More...
 
int setAttribute (FileHandle file, AttributeTag tag, const void *data, size_t size)
 
int setAttribute (const char *file, AttributeTag tag, const void *data, size_t size)
 
int setAttribute (const String &file, AttributeTag tag, const void *data, size_t size)
 
template<typename T >
int setAttribute (const T &file, AttributeTag tag, const String &data)
 
int getAttribute (FileHandle file, AttributeTag tag, void *buffer, size_t size)
 
int getAttribute (const char *file, AttributeTag tag, void *buffer, size_t size)
 
int getAttribute (const String &file, AttributeTag tag, void *buffer, size_t size)
 
template<typename T >
int getAttribute (const T &file, AttributeTag tag, String &value)
 
template<typename T >
String getAttribute (const T &file, AttributeTag tag)
 
template<typename T >
int removeAttribute (const T &file, AttributeTag tag)
 
template<typename T , typename... ParamTypes>
int setUserAttribute (const T &file, uint8_t tagValue, ParamTypes... params)
 
template<typename T , typename... ParamTypes>
int getUserAttribute (const T &file, uint8_t tagValue, ParamTypes... params)
 
template<typename T >
String getUserAttribute (const T &file, uint8_t tagValue)
 
template<typename T >
bool removeUserAttribute (const T &file, uint8_t tagValue)
 
template<typename T >
int setacl (const T &file, const ACL &acl)
 Set access control information for file. More...
 
template<typename T >
int setattr (const T &file, FileAttributes attr)
 Set file attributes. More...
 
template<typename T >
int settime (const T &file, time_t mtime)
 Set modification time for file. More...
 
template<typename T >
int setcompression (const T &file, const Compression &compression)
 Set file compression information. More...
 
uint32_t getSize (FileHandle file)
 Get size of file. More...
 
uint32_t getSize (const char *fileName)
 Get size of file. More...
 
uint32_t getSize (const String &fileName)
 
int readContent (FileHandle file, size_t size, ReadContentCallback callback)
 Read from current file position and invoke callback for each block read. More...
 
int readContent (FileHandle file, ReadContentCallback callback)
 Read from current file position to end of file and invoke callback for each block read. More...
 
int readContent (const String &filename, ReadContentCallback callback)
 Read entire file content in blocks, invoking callback after every read. More...
 

Additional Inherited Members

- Public Types inherited from IFS::IFileSystem
enum  Type { Type::XX, Type::MAX }
 
enum  Attribute { Attribute::XX, Attribute::MAX }
 
using Attributes = BitSet< uint8_t, Attribute, size_t(Attribute::MAX)>
 

Detailed Description

Installable File System base class.

Adds additional methods to ease use over base IFileSystem.

Member Typedef Documentation

◆ ReadContentCallback

using IFS::FileSystem::ReadContentCallback = Delegate<int(const char* buffer, size_t size)>

Callback for readContent method.

Parameters
buffer
size
Return values
intReturn number of bytes consumed, < size to stop If < 0 then this is returned as error code to readContent call.

Member Function Documentation

◆ cast() [1/2]

static constexpr FileSystem& IFS::FileSystem::cast ( IFileSystem fs)
inlinestatic

◆ cast() [2/2]

static constexpr FileSystem* IFS::FileSystem::cast ( IFileSystem fs)
inlinestatic

◆ fstat()

int IFS::FileSystem::fstat ( FileHandle  file,
Stat stat 
)
inline

◆ ftruncate()

int IFS::FileSystem::ftruncate ( FileHandle  file)
inline

◆ getAttribute() [1/5]

int IFS::FileSystem::getAttribute ( FileHandle  file,
AttributeTag  tag,
void *  buffer,
size_t  size 
)
inline

◆ getAttribute() [2/5]

int IFS::FileSystem::getAttribute ( const char *  file,
AttributeTag  tag,
void *  buffer,
size_t  size 
)
inline

◆ getAttribute() [3/5]

int IFS::FileSystem::getAttribute ( const String file,
AttributeTag  tag,
void *  buffer,
size_t  size 
)
inline

◆ getAttribute() [4/5]

template<typename T >
int IFS::FileSystem::getAttribute ( const T &  file,
AttributeTag  tag,
String value 
)
inline

◆ getAttribute() [5/5]

template<typename T >
String IFS::FileSystem::getAttribute ( const T &  file,
AttributeTag  tag 
)
inline

◆ getContent() [1/3]

size_t IFS::FileSystem::getContent ( const char *  fileName,
char *  buffer,
size_t  bufSize 
)

◆ getContent() [2/3]

size_t IFS::FileSystem::getContent ( const String fileName,
char *  buffer,
size_t  bufSize 
)
inline

◆ getContent() [3/3]

String IFS::FileSystem::getContent ( const String fileName)

Read content of a file.

Parameters
fileNameName of file to read from
Return values
StringString variable in to which to read the file content
Note
After calling this function the content of the file is placed in to a string. The result will be an invalid String (equates to false) if the file could not be read. If the file exists, but is empty, the result will be an empty string "".

◆ getSize() [1/3]

uint32_t IFS::FileSystem::getSize ( FileHandle  file)

Get size of file.

Parameters
fileFile handle
Return values
uint32_tSize of file in bytes, 0 on error

◆ getSize() [2/3]

uint32_t IFS::FileSystem::getSize ( const char *  fileName)

Get size of file.

Parameters
fileNameName of file
Return values
uint32_tSize of file in bytes, 0 on error

◆ getSize() [3/3]

uint32_t IFS::FileSystem::getSize ( const String fileName)
inline

◆ getUserAttribute() [1/2]

template<typename T , typename... ParamTypes>
int IFS::FileSystem::getUserAttribute ( const T &  file,
uint8_t  tagValue,
ParamTypes...  params 
)
inline

◆ getUserAttribute() [2/2]

template<typename T >
String IFS::FileSystem::getUserAttribute ( const T &  file,
uint8_t  tagValue 
)
inline

◆ makedirs() [1/2]

int IFS::FileSystem::makedirs ( const char *  path)

Create a directory and any intermediate directories if they do not already exist.

Parameters
pathPath to directory. If no trailing '/' is present the final element is considered a filename.
Return values
interror code

◆ makedirs() [2/2]

int IFS::FileSystem::makedirs ( const String path)
inline

◆ mkdir()

int IFS::FileSystem::mkdir ( const String path)
inline

◆ open()

FileHandle IFS::FileSystem::open ( const String path,
OpenFlags  flags 
)
inline

◆ opendir()

int IFS::FileSystem::opendir ( const String path,
DirHandle dir 
)
inline

open a directory for reading

◆ readContent() [1/3]

int IFS::FileSystem::readContent ( FileHandle  file,
size_t  size,
ReadContentCallback  callback 
)

Read from current file position and invoke callback for each block read.

Parameters
file
sizeMaximum number of bytes to read
callback
Return values
intNumber of bytes processed, or error code

◆ readContent() [2/3]

int IFS::FileSystem::readContent ( FileHandle  file,
ReadContentCallback  callback 
)

Read from current file position to end of file and invoke callback for each block read.

Parameters
file
callback
Return values
intNumber of bytes processed, or error code

◆ readContent() [3/3]

int IFS::FileSystem::readContent ( const String filename,
ReadContentCallback  callback 
)

Read entire file content in blocks, invoking callback after every read.

Parameters
filename
callback
Return values
intNumber of bytes processed, or error code

◆ remove()

int IFS::FileSystem::remove ( const String path)
inline

remove (delete) a file by path

Parameters
path
Return values
interror code

◆ removeAttribute()

template<typename T >
int IFS::FileSystem::removeAttribute ( const T &  file,
AttributeTag  tag 
)
inline

◆ removeUserAttribute()

template<typename T >
bool IFS::FileSystem::removeUserAttribute ( const T &  file,
uint8_t  tagValue 
)
inline

◆ rename()

int IFS::FileSystem::rename ( const String oldpath,
const String newpath 
)
inline

◆ setacl()

template<typename T >
int IFS::FileSystem::setacl ( const T &  file,
const ACL acl 
)
inline

Set access control information for file.

Parameters
filehandle or path to file
acl
Return values
interror code

◆ setattr()

template<typename T >
int IFS::FileSystem::setattr ( const T &  file,
FileAttributes  attr 
)
inline

Set file attributes.

Parameters
filehandle or path to file
attr
Return values
interror code

◆ setAttribute() [1/4]

int IFS::FileSystem::setAttribute ( FileHandle  file,
AttributeTag  tag,
const void *  data,
size_t  size 
)
inline

◆ setAttribute() [2/4]

int IFS::FileSystem::setAttribute ( const char *  file,
AttributeTag  tag,
const void *  data,
size_t  size 
)
inline

◆ setAttribute() [3/4]

int IFS::FileSystem::setAttribute ( const String file,
AttributeTag  tag,
const void *  data,
size_t  size 
)
inline

◆ setAttribute() [4/4]

template<typename T >
int IFS::FileSystem::setAttribute ( const T &  file,
AttributeTag  tag,
const String data 
)
inline

◆ setcompression()

template<typename T >
int IFS::FileSystem::setcompression ( const T &  file,
const Compression &  compression 
)
inline

Set file compression information.

Parameters
file
compression
Return values
interror code

◆ setContent() [1/5]

int IFS::FileSystem::setContent ( const char *  fileName,
const void *  content,
size_t  length 
)

◆ setContent() [2/5]

int IFS::FileSystem::setContent ( const char *  fileName,
const char *  content 
)
inline

◆ setContent() [3/5]

int IFS::FileSystem::setContent ( const String fileName,
const char *  content 
)
inline

◆ setContent() [4/5]

int IFS::FileSystem::setContent ( const String fileName,
const void *  content,
size_t  length 
)
inline

◆ setContent() [5/5]

int IFS::FileSystem::setContent ( const String fileName,
const String content 
)
inline

◆ settime()

template<typename T >
int IFS::FileSystem::settime ( const T &  file,
time_t  mtime 
)
inline

Set modification time for file.

Parameters
filehandle or path to file
Return values
interror code
Note
any subsequent writes to file will reset this to current time

◆ setUserAttribute()

template<typename T , typename... ParamTypes>
int IFS::FileSystem::setUserAttribute ( const T &  file,
uint8_t  tagValue,
ParamTypes...  params 
)
inline

◆ stat() [1/2]

int IFS::FileSystem::stat ( const String path,
Stat s 
)
inline

◆ stat() [2/2]

int IFS::FileSystem::stat ( const String path,
Stat s 
)
inline

◆ truncate() [1/2]

int IFS::FileSystem::truncate ( const char *  fileName,
size_t  newSize 
)

Truncate a file to a specific size.

Parameters
fileNameFile to truncate
Return values
intnew file size, or error code

◆ truncate() [2/2]

int IFS::FileSystem::truncate ( const String fileName,
size_t  newSize 
)
inline

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