IFS::FWFS::FileSystem Class Reference

Implementation of firmware filing system using IFS. More...

#include <FileSystem.h>

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

Public Member Functions

 FileSystem ()
 
 FileSystem (IObjectStore *store)
 
 ~FileSystem ()
 
int setVolume (uint8_t num, IObjectStore *store)
 Set object stores. More...
 
int mount () override
 Mount file system, performing any required initialisation. More...
 
int getinfo (Info &info) override
 get filing system information More...
 
int opendir (const char *path, DirHandle &dir) override
 open a directory for reading More...
 
int fopendir (const Stat *stat, DirHandle &dir) override
 open a directory for reading More...
 
int readdir (DirHandle dir, Stat &stat) override
 read a directory entry More...
 
int rewinddir (DirHandle dir) override
 Reset directory read position to start. More...
 
int closedir (DirHandle dir) override
 close a directory object More...
 
int mkdir (const char *path) override
 Create a directory. More...
 
int stat (const char *path, Stat *stat) override
 get file information More...
 
int fstat (FileHandle file, Stat *stat) override
 get file information More...
 
int fcontrol (FileHandle file, ControlCode code, void *buffer, size_t bufSize) override
 Low-level and non-standard file control operations. More...
 
int setacl (FileHandle file, const ACL &acl) override
 Set access control information for file. More...
 
int setattr (const char *path, FileAttributes attr)
 Set file attributes. More...
 
int settime (FileHandle file, time_t mtime) override
 Set modificatino tiem for file. More...
 
int setcompression (FileHandle file, const Compression &compression)
 Set file compression information. More...
 
FileHandle open (const char *path, OpenFlags flags) override
 open a file by name/path More...
 
FileHandle fopen (const Stat &stat, OpenFlags flags) override
 open a file from it's stat structure More...
 
int close (FileHandle file) override
 close an open file More...
 
int read (FileHandle file, void *data, size_t size) override
 read content from a file and advance cursor More...
 
int write (FileHandle file, const void *data, size_t size) override
 write content to a file at current position and advance cursor More...
 
int lseek (FileHandle file, int offset, SeekOrigin origin) override
 change file read/write position More...
 
int eof (FileHandle file) override
 determine if current file position is at end of file More...
 
int32_t tell (FileHandle file) override
 get current file position More...
 
int ftruncate (FileHandle file, size_t new_size) override
 Truncate (reduce) the size of an open file. More...
 
int flush (FileHandle file) override
 flush any buffered data to physical media More...
 
int rename (const char *oldpath, const char *newpath) override
 rename a file More...
 
int remove (const char *path) override
 remove (delete) a file by path More...
 
int fremove (FileHandle file) override
 remove (delete) a file by handle More...
 
int format () override
 format the filing system More...
 
int check () override
 Perform a file system consistency check. More...
 
int getFilePath (FileID fileid, NameBuffer &path)
 get the full path of a file from its ID More...
 
int getMd5Hash (FileHandle file, void *buffer, size_t bufSize)
 
- Public Member Functions inherited from IFS::IFileSystem
virtual ~IFileSystem ()
 Filing system implementations should dismount and cleanup here. More...
 
virtual String getErrorString (int err)
 get the text for a returned error code 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

Implementation of firmware filing system using IFS.

Constructor & Destructor Documentation

◆ FileSystem() [1/2]

IFS::FWFS::FileSystem::FileSystem ( )
inline

◆ FileSystem() [2/2]

IFS::FWFS::FileSystem::FileSystem ( IObjectStore store)
inline

◆ ~FileSystem()

IFS::FWFS::FileSystem::~FileSystem ( )
inline

Member Function Documentation

◆ check()

int IFS::FWFS::FileSystem::check ( )
inlineoverridevirtual

Perform a file system consistency check.

Return values
interror code
Note
if possible, issues should be resolved. Returns 0 if file system checked out OK. Otherwise there were issues: < 0 for unrecoverable errors,

0 for recoverable errors.

Reimplemented from IFS::IFileSystem.

◆ close()

int IFS::FWFS::FileSystem::close ( FileHandle  file)
overridevirtual

close an open file

Parameters
filehandle to open file
Return values
interror code

Implements IFS::IFileSystem.

◆ closedir()

int IFS::FWFS::FileSystem::closedir ( DirHandle  dir)
overridevirtual

close a directory object

Parameters
dirdirectory to close
Return values
interror code

Implements IFS::IFileSystem.

◆ eof()

int IFS::FWFS::FileSystem::eof ( FileHandle  file)
overridevirtual

determine if current file position is at end of file

Parameters
filehandle to open file
Return values
int0 - not EOF, > 0 - at EOF, < 0 - error

Implements IFS::IFileSystem.

◆ fcontrol()

int IFS::FWFS::FileSystem::fcontrol ( FileHandle  file,
ControlCode  code,
void *  buffer,
size_t  bufSize 
)
overridevirtual

Low-level and non-standard file control operations.

Parameters
file
codeFCNTL_XXX code
bufferInput/Output buffer
bufSizeSize of buffer
Return values
interror code or, on success, data size

To simplify usage the same buffer is used for both input and output. Only the size of the buffer is provided. If a specific FCNTL code requires more information then it will be contained within the provided data.

Reimplemented from IFS::IFileSystem.

◆ flush()

int IFS::FWFS::FileSystem::flush ( FileHandle  file)
inlineoverridevirtual

flush any buffered data to physical media

Parameters
filehandle to open file
Return values
interror code

Implements IFS::IFileSystem.

◆ fopen()

FileHandle IFS::FWFS::FileSystem::fopen ( const Stat stat,
OpenFlags  flags 
)
overridevirtual

open a file from it's stat structure

Parameters
statobtained from readdir()
flagsopens for opening file
Return values
FileHandlefile handle or error code

Implements IFS::IFileSystem.

◆ fopendir()

int IFS::FWFS::FileSystem::fopendir ( const Stat stat,
DirHandle dir 
)
overridevirtual

open a directory for reading

Parameters
statidentifies directory to open. nullptr is interpreted as root directory
dirreturns a pointer to the directory object
Return values
interror code

Reimplemented from IFS::IFileSystem.

◆ format()

int IFS::FWFS::FileSystem::format ( )
inlineoverridevirtual

format the filing system

Return values
interror code
Note
this does a default format, returning file system to a fresh state The filing system implementation may define more specialised methods which can be called directly.

Implements IFS::IFileSystem.

◆ fremove()

int IFS::FWFS::FileSystem::fremove ( FileHandle  file)
inlineoverridevirtual

remove (delete) a file by handle

Parameters
filehandle to open file
Return values
interror code

Implements IFS::IFileSystem.

◆ fstat()

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

get file information

Parameters
filehandle to open file
statstructure to return information in, may be null
Return values
interror code

Implements IFS::IFileSystem.

◆ ftruncate()

int IFS::FWFS::FileSystem::ftruncate ( FileHandle  file,
size_t  new_size 
)
inlineoverridevirtual

Truncate (reduce) the size of an open file.

Parameters
fileOpen file handle, must have Write access
newSize
Return values
intError code
Note
In POSIX ftruncate() can also make the file bigger, however SPIFFS can only reduce the file size and will return an error if newSize > fileSize

Implements IFS::IFileSystem.

◆ getFilePath()

int IFS::FWFS::FileSystem::getFilePath ( FileID  fileid,
NameBuffer path 
)

get the full path of a file from its ID

Parameters
fileid
path
Return values
interror code

◆ getinfo()

int IFS::FWFS::FileSystem::getinfo ( Info info)
overridevirtual

get filing system information

Parameters
infostructure to read information into
Return values
interror code

Implements IFS::IFileSystem.

◆ getMd5Hash()

int IFS::FWFS::FileSystem::getMd5Hash ( FileHandle  file,
void *  buffer,
size_t  bufSize 
)

◆ lseek()

int IFS::FWFS::FileSystem::lseek ( FileHandle  file,
int  offset,
SeekOrigin  origin 
)
overridevirtual

change file read/write position

Parameters
filehandle to open file
offsetposition relative to origin
originwhere to seek from (start/end or current position)
Return values
intcurrent position or error code

Implements IFS::IFileSystem.

◆ mkdir()

int IFS::FWFS::FileSystem::mkdir ( const char *  path)
inlineoverridevirtual

Create a directory.

Parameters
pathPath to directory
Return values
interror code

Only the final directory in the path is guaranteed to be created. Usually, this call will fail if intermediate directories are not present. Use makedirs() for this purpose.

Implements IFS::IFileSystem.

◆ mount()

int IFS::FWFS::FileSystem::mount ( )
overridevirtual

Mount file system, performing any required initialisation.

Return values
errorcode

Implements IFS::IFileSystem.

◆ open()

FileHandle IFS::FWFS::FileSystem::open ( const char *  path,
OpenFlags  flags 
)
overridevirtual

open a file by name/path

Parameters
pathfull path to file
flagsopens for opening file
Return values
FileHandlefile handle or error code

Implements IFS::IFileSystem.

◆ opendir()

int IFS::FWFS::FileSystem::opendir ( const char *  path,
DirHandle dir 
)
overridevirtual

open a directory for reading

Parameters
pathpath to directory. nullptr is interpreted as root directory
dirreturns a pointer to the directory object
Return values
interror code

Implements IFS::IFileSystem.

◆ read()

int IFS::FWFS::FileSystem::read ( FileHandle  file,
void *  data,
size_t  size 
)
overridevirtual

read content from a file and advance cursor

Parameters
filehandle to open file
databuffer to write into
sizesize of file buffer, maximum number of bytes to read
Return values
intnumber of bytes read or error code

Implements IFS::IFileSystem.

◆ readdir()

int IFS::FWFS::FileSystem::readdir ( DirHandle  dir,
Stat stat 
)
overridevirtual

read a directory entry

Parameters
dir
stat
Return values
interror code
Note
File system allocates entries structure as it usually needs to track other information. It releases memory when closedir() is called.

Implements IFS::IFileSystem.

◆ remove()

int IFS::FWFS::FileSystem::remove ( const char *  path)
inlineoverridevirtual

remove (delete) a file by path

Parameters
path
Return values
interror code

Implements IFS::IFileSystem.

◆ rename()

int IFS::FWFS::FileSystem::rename ( const char *  oldpath,
const char *  newpath 
)
inlineoverridevirtual

rename a file

Parameters
oldpath
newpath
Return values
interror code

Implements IFS::IFileSystem.

◆ rewinddir()

int IFS::FWFS::FileSystem::rewinddir ( DirHandle  dir)
overridevirtual

Reset directory read position to start.

Parameters
dir
Return values
interror code

Implements IFS::IFileSystem.

◆ setacl()

int IFS::FWFS::FileSystem::setacl ( FileHandle  file,
const ACL acl 
)
inlineoverridevirtual

Set access control information for file.

Parameters
filehandle to open file
acl
Return values
interror code

Implements IFS::IFileSystem.

◆ setattr()

int IFS::FWFS::FileSystem::setattr ( const char *  path,
FileAttributes  attr 
)
inlinevirtual

Set file attributes.

Parameters
pathFull path to file
attr
Return values
interror code

Implements IFS::IFileSystem.

◆ setcompression()

int IFS::FWFS::FileSystem::setcompression ( FileHandle  file,
const Compression compression 
)
inlinevirtual

Set file compression information.

Parameters
file
compression
Return values
interror code

Implements IFS::IFileSystem.

◆ settime()

int IFS::FWFS::FileSystem::settime ( FileHandle  file,
time_t  mtime 
)
inlineoverridevirtual

Set modificatino tiem for file.

Parameters
filehandle to open file, must have write access
Return values
interror code
Note
any subsequent writes to file will reset this to current time

Implements IFS::IFileSystem.

◆ setVolume()

int IFS::FWFS::FileSystem::setVolume ( uint8_t  num,
IObjectStore store 
)

Set object stores.

Parameters
numwhich store to set
storethe object store object
Return values
interror code

◆ stat()

int IFS::FWFS::FileSystem::stat ( const char *  path,
Stat stat 
)
overridevirtual

get file information

Parameters
pathname or path of file
sstructure to return information in, may be null to do a simple file existence check
Return values
interror code

Implements IFS::IFileSystem.

◆ tell()

int32_t IFS::FWFS::FileSystem::tell ( FileHandle  file)
overridevirtual

get current file position

Parameters
filehandle to open file
Return values
int32_tcurrent position relative to start of file, or error code

Implements IFS::IFileSystem.

◆ write()

int IFS::FWFS::FileSystem::write ( FileHandle  file,
const void *  data,
size_t  size 
)
inlineoverridevirtual

write content to a file at current position and advance cursor

Parameters
filehandle to open file
databuffer to read from
sizenumber of bytes to write
Return values
intnumber of bytes written or error code

Implements IFS::IFileSystem.


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