F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Os::FileSystem Class Referencefinal

FileSystem class. More...

#include <Os/FileSystem.hpp>

Inheritance diagram for Os::FileSystem:
Os::FileSystemInterface

Public Member Functions

 ~FileSystem () final
 Destructor. More...
 
FileSystemHandlegetHandle () override
 return the underlying FileSystem handle (implementation specific) More...
 
Status _removeDirectory (const char *path) override
 Remove a directory at the specified path. More...
 
Status _removeFile (const char *path) override
 Remove a file at the specified path. More...
 
Status _rename (const char *sourcePath, const char *destPath) override
 Rename a file from source to destination. More...
 
Status _getFreeSpace (const char *path, FwSizeType &totalBytes, FwSizeType &freeBytes) override
 Get filesystem free and total space in bytes on the filesystem containing the specified path. More...
 
Status _getWorkingDirectory (char *path, FwSizeType bufferSize) override
 Get the current working directory. More...
 
Status _changeWorkingDirectory (const char *path) override
 Change the current working directory to the specified path. More...
 
- Public Member Functions inherited from Os::FileSystemInterface
 FileSystemInterface ()=default
 default constructor More...
 
virtual ~FileSystemInterface ()=default
 default virtual destructor More...
 
 FileSystemInterface (const FileSystemInterface &other)=delete
 copy constructor is forbidden More...
 
FileSystemInterfaceoperator= (const FileSystemInterface &other)=delete
 assignment operator is forbidden More...
 

Static Public Member Functions

static Status removeDirectory (const char *path)
 Remove a directory at the specified path. More...
 
static Status removeFile (const char *path)
 Remove a file at the specified path. More...
 
static Status rename (const char *sourcePath, const char *destPath)
 Rename a file from source to destination. More...
 
static Status getFreeSpace (const char *path, FwSizeType &totalBytes, FwSizeType &freeBytes)
 Get filesystem free and total space in bytes on the filesystem containing the specified path. More...
 
static Status getWorkingDirectory (char *path, FwSizeType bufferSize)
 Get the current working directory. More...
 
static Status changeWorkingDirectory (const char *path)
 Change the current working directory to the specified path. More...
 
static bool exists (const char *path)
 Return true if the path exists, false otherwise. More...
 
static PathType getPathType (const char *path)
 Return the type of the path (file, directory, or doesn't exist) More...
 
static Status touch (const char *path)
 Touch a file at the specified path, creating it if it doesn't exist. More...
 
static Status createDirectory (const char *path, bool errorIfAlreadyExists=false)
 Create a new directory at the specified path. More...
 
static Status appendFile (const char *sourcePath, const char *destPath, bool createMissingDest=false)
 Append the source file to the destination file. More...
 
static Status copyFile (const char *sourcePath, const char *destPath)
 Copy a file from the source path to the destination path. More...
 
static Status moveFile (const char *sourcePath, const char *destPath)
 Move a file from sourcePath to destPath. More...
 
static Status getFileSize (const char *path, FwSignedSizeType &size)
 Get the size of the file (in bytes) at the specified path. More...
 
static void init ()
 initialize singleton More...
 
static FileSystemgetSingleton ()
 get a reference to singleton More...
 
- Static Public Member Functions inherited from Os::FileSystemInterface
static FileSystemInterfacegetDelegate (FileSystemHandleStorage &aligned_new_memory)
 provide a pointer to a FileSystem delegate object More...
 

Additional Inherited Members

- Public Types inherited from Os::FileSystemInterface
enum  Status {
  OP_OK , ALREADY_EXISTS , NO_SPACE , NO_PERMISSION ,
  NOT_DIR , IS_DIR , NOT_EMPTY , INVALID_PATH ,
  DOESNT_EXIST , FILE_LIMIT , BUSY , NO_MORE_FILES ,
  BUFFER_TOO_SMALL , EXDEV_ERROR , OVERFLOW_ERROR , NOT_SUPPORTED ,
  OTHER_ERROR
}
 
enum  PathType { FILE , DIRECTORY , NOT_EXIST }
 
- Static Public Attributes inherited from Os::FileSystemInterface
static constexpr FwSignedSizeType FILE_SYSTEM_FILE_CHUNK_SIZE = FW_FILE_CHUNK_SIZE
 Size of file system chunk. More...
 

Detailed Description

FileSystem class.

This class provides a common interface for file system operations. This class uses the singleton pattern and should be accessed through its static functions, for example using Os::FileSystem::removeFile(path).

Definition at line 117 of file FileSystem.hpp.

Constructor & Destructor Documentation

◆ ~FileSystem()

Os::FileSystem::~FileSystem ( )
final

Destructor.

Definition at line 14 of file FileSystem.cpp.

Member Function Documentation

◆ _changeWorkingDirectory()

FileSystem::Status Os::FileSystem::_changeWorkingDirectory ( const char *  path)
overridevirtual

Change the current working directory to the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the new working directory
Returns
Status of the operation

Implements Os::FileSystemInterface.

Definition at line 50 of file FileSystem.cpp.

◆ _getFreeSpace()

FileSystem::Status Os::FileSystem::_getFreeSpace ( const char *  path,
FwSizeType totalBytes,
FwSizeType freeBytes 
)
overridevirtual

Get filesystem free and total space in bytes on the filesystem containing the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path on the filesystem to query
totalBytesReference to store the total bytes on the filesystem
freeBytesReference to store the free bytes on the filesystem
Returns
Status of the operation

Implements Os::FileSystemInterface.

Definition at line 56 of file FileSystem.cpp.

◆ _getWorkingDirectory()

FileSystem::Status Os::FileSystem::_getWorkingDirectory ( char *  path,
FwSizeType  bufferSize 
)
overridevirtual

Get the current working directory.

Writes the current working directory path to the provided buffer of size bufferSize. If the buffer is too small to hold the full path, the function will return BUFFER_TOO_SMALL.

It is invalid to pass nullptr as the path. It is invalid to pass a bufferSize of 0.

Parameters
pathBuffer to store the current working directory path
bufferSizeSize of the buffer
Returns
Status of the operation

Implements Os::FileSystemInterface.

Definition at line 43 of file FileSystem.cpp.

◆ _removeDirectory()

FileSystem::Status Os::FileSystem::_removeDirectory ( const char *  path)
overridevirtual

Remove a directory at the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the directory to remove
Returns
Status of the operation

Implements Os::FileSystemInterface.

Definition at line 24 of file FileSystem.cpp.

◆ _removeFile()

FileSystem::Status Os::FileSystem::_removeFile ( const char *  path)
overridevirtual

Remove a file at the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the file to remove
Returns
Status of the operation

Implements Os::FileSystemInterface.

Definition at line 30 of file FileSystem.cpp.

◆ _rename()

FileSystem::Status Os::FileSystem::_rename ( const char *  sourcePath,
const char *  destPath 
)
overridevirtual

Rename a file from source to destination.

If the rename fails due to a cross-device operation, this function should return EXDEV_ERROR and moveFile can be used instead to force a copy-and-remove.

It is invalid to pass nullptr as sourcePath or destPath.

Parameters
sourcePathThe path of the source file
destPathThe path of the destination file
Returns
Status of the operation

Implements Os::FileSystemInterface.

Definition at line 36 of file FileSystem.cpp.

◆ appendFile()

FileSystem::Status Os::FileSystem::appendFile ( const char *  sourcePath,
const char *  destPath,
bool  createMissingDest = false 
)
static

Append the source file to the destination file.

This function opens both files, and iteratively reads the source by chunks and writes chunks to the destination. If the destination file does not exist and createMissingDest is true, a new file is created.

It is invalid to pass nullptr as either the source or destination path.

Parameters
sourcePathThe path of the source file
destPathThe path of the destination file
createMissingDestIf true, creates a new file if the destination doesn't exist
Returns
Status of the operation

Definition at line 178 of file FileSystem.cpp.

◆ changeWorkingDirectory()

FileSystem::Status Os::FileSystem::changeWorkingDirectory ( const char *  path)
static

Change the current working directory to the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the new working directory
Returns
Status of the operation

Definition at line 93 of file FileSystem.cpp.

◆ copyFile()

FileSystem::Status Os::FileSystem::copyFile ( const char *  sourcePath,
const char *  destPath 
)
static

Copy a file from the source path to the destination path.

This function opens both files, and iteratively reads the source by chunks and writes chunks to the destination.

It is invalid to pass nullptr as either the source or destination path.

Parameters
sourcePathThe path of the source file
destPathThe path of the destination file
Returns
Status of the operation

Definition at line 153 of file FileSystem.cpp.

◆ createDirectory()

FileSystem::Status Os::FileSystem::createDirectory ( const char *  path,
bool  errorIfAlreadyExists = false 
)
static

Create a new directory at the specified path.

The optional errorIfAlreadyExists (default=false) parameter can be set to true to return an error status if the directory already exists.

It is invalid to pass nullptr as the path.

Parameters
pathThe path where the new directory will be created
errorIfAlreadyExistsIf true, returns an error if the directory already exists
Returns
Status of the operation

Definition at line 106 of file FileSystem.cpp.

◆ exists()

bool Os::FileSystem::exists ( const char *  path)
static

Return true if the path exists, false otherwise.

It is invalid to pass nullptr as the path.

Parameters
pathThe path to check for existence
Returns
True if the path exists, false otherwise

Definition at line 149 of file FileSystem.cpp.

◆ getFileSize()

FileSystem::Status Os::FileSystem::getFileSize ( const char *  path,
FwSignedSizeType size 
)
static

Get the size of the file (in bytes) at the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the file
sizeReference to store the size of the file
Returns
Status of the operation

Definition at line 227 of file FileSystem.cpp.

◆ getFreeSpace()

FileSystem::Status Os::FileSystem::getFreeSpace ( const char *  path,
FwSizeType totalBytes,
FwSizeType freeBytes 
)
static

Get filesystem free and total space in bytes on the filesystem containing the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path on the filesystem to query
totalBytesReference to store the total bytes on the filesystem
freeBytesReference to store the free bytes on the filesystem
Returns
Status of the operation

Definition at line 97 of file FileSystem.cpp.

◆ getHandle()

FileSystemHandle * Os::FileSystem::getHandle ( )
overridevirtual

return the underlying FileSystem handle (implementation specific)

Returns
internal FileSystem handle representation

Implements Os::FileSystemInterface.

Definition at line 19 of file FileSystem.cpp.

◆ getPathType()

FileSystem::PathType Os::FileSystem::getPathType ( const char *  path)
static

Return the type of the path (file, directory, or doesn't exist)

It is invalid to pass nullptr as the path.

Parameters
pathThe path to check for existence
Returns
PathType enum representing the type of the path (FILE, DIRECTORY, NOT_EXIST)

Definition at line 132 of file FileSystem.cpp.

◆ getSingleton()

FileSystem & Os::FileSystem::getSingleton ( )
static

get a reference to singleton

Returns
reference to singleton

Definition at line 67 of file FileSystem.cpp.

◆ getWorkingDirectory()

FileSystem::Status Os::FileSystem::getWorkingDirectory ( char *  path,
FwSizeType  bufferSize 
)
static

Get the current working directory.

Writes the current working directory path to the provided buffer of size bufferSize. If the buffer is too small to hold the full path, the function will return BUFFER_TOO_SMALL.

It is invalid to pass nullptr as the path. It is invalid to pass a bufferSize of 0.

Parameters
pathBuffer to store the current working directory path
bufferSizeSize of the buffer
Returns
Status of the operation

Definition at line 89 of file FileSystem.cpp.

◆ init()

void Os::FileSystem::init ( )
static

initialize singleton

Definition at line 62 of file FileSystem.cpp.

◆ moveFile()

FileSystem::Status Os::FileSystem::moveFile ( const char *  sourcePath,
const char *  destPath 
)
static

Move a file from sourcePath to destPath.

This is done by first trying to rename, and if renaming fails, copy it and then remove the original

It is invalid to pass nullptr as either the source or destination path.

Parameters
sourcePathThe path of the source file
destPathThe path of the destination file
Returns
Status of the operation

Definition at line 209 of file FileSystem.cpp.

◆ removeDirectory()

FileSystem::Status Os::FileSystem::removeDirectory ( const char *  path)
static

Remove a directory at the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the directory to remove
Returns
Status of the operation

Definition at line 77 of file FileSystem.cpp.

◆ removeFile()

FileSystem::Status Os::FileSystem::removeFile ( const char *  path)
static

Remove a file at the specified path.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the file to remove
Returns
Status of the operation

Definition at line 81 of file FileSystem.cpp.

◆ rename()

FileSystem::Status Os::FileSystem::rename ( const char *  sourcePath,
const char *  destPath 
)
static

Rename a file from source to destination.

If the rename fails due to a cross-device operation, this function should return EXDEV_ERROR and moveFile can be used instead to force a copy-and-remove.

It is invalid to pass nullptr as sourcePath or destPath.

Parameters
sourcePathThe path of the source file
destPathThe path of the destination file
Returns
Status of the operation

Definition at line 85 of file FileSystem.cpp.

◆ touch()

FileSystem::Status Os::FileSystem::touch ( const char *  path)
static

Touch a file at the specified path, creating it if it doesn't exist.

It is invalid to pass nullptr as the path.

Parameters
pathThe path of the file to touch
Returns
Status of the operation

Definition at line 120 of file FileSystem.cpp.


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