F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
|
FileSystem class. More...
#include <Os/FileSystem.hpp>
Public Member Functions | |
~FileSystem () final | |
Destructor. More... | |
FileSystemHandle * | getHandle () 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... | |
FileSystemInterface & | operator= (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 FileSystem & | getSingleton () |
get a reference to singleton More... | |
Static Public Member Functions inherited from Os::FileSystemInterface | |
static FileSystemInterface * | getDelegate (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... | |
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.
|
final |
Destructor.
Definition at line 14 of file FileSystem.cpp.
|
overridevirtual |
Change the current working directory to the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the new working directory |
Implements Os::FileSystemInterface.
Definition at line 50 of file FileSystem.cpp.
|
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.
path | The path on the filesystem to query |
totalBytes | Reference to store the total bytes on the filesystem |
freeBytes | Reference to store the free bytes on the filesystem |
Implements Os::FileSystemInterface.
Definition at line 56 of file FileSystem.cpp.
|
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.
path | Buffer to store the current working directory path |
bufferSize | Size of the buffer |
Implements Os::FileSystemInterface.
Definition at line 43 of file FileSystem.cpp.
|
overridevirtual |
Remove a directory at the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the directory to remove |
Implements Os::FileSystemInterface.
Definition at line 24 of file FileSystem.cpp.
|
overridevirtual |
Remove a file at the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the file to remove |
Implements Os::FileSystemInterface.
Definition at line 30 of file FileSystem.cpp.
|
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.
sourcePath | The path of the source file |
destPath | The path of the destination file |
Implements Os::FileSystemInterface.
Definition at line 36 of file FileSystem.cpp.
|
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.
sourcePath | The path of the source file |
destPath | The path of the destination file |
createMissingDest | If true, creates a new file if the destination doesn't exist |
Definition at line 178 of file FileSystem.cpp.
|
static |
Change the current working directory to the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the new working directory |
Definition at line 93 of file FileSystem.cpp.
|
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.
sourcePath | The path of the source file |
destPath | The path of the destination file |
Definition at line 153 of file FileSystem.cpp.
|
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.
path | The path where the new directory will be created |
errorIfAlreadyExists | If true, returns an error if the directory already exists |
Definition at line 106 of file FileSystem.cpp.
|
static |
Return true if the path exists, false otherwise.
It is invalid to pass nullptr
as the path.
path | The path to check for existence |
Definition at line 149 of file FileSystem.cpp.
|
static |
Get the size of the file (in bytes) at the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the file |
size | Reference to store the size of the file |
Definition at line 227 of file FileSystem.cpp.
|
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.
path | The path on the filesystem to query |
totalBytes | Reference to store the total bytes on the filesystem |
freeBytes | Reference to store the free bytes on the filesystem |
Definition at line 97 of file FileSystem.cpp.
|
overridevirtual |
return the underlying FileSystem handle (implementation specific)
Implements Os::FileSystemInterface.
Definition at line 19 of file FileSystem.cpp.
|
static |
Return the type of the path (file, directory, or doesn't exist)
It is invalid to pass nullptr
as the path.
path | The path to check for existence |
Definition at line 132 of file FileSystem.cpp.
|
static |
get a reference to singleton
Definition at line 67 of file FileSystem.cpp.
|
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.
path | Buffer to store the current working directory path |
bufferSize | Size of the buffer |
Definition at line 89 of file FileSystem.cpp.
|
static |
initialize singleton
Definition at line 62 of file FileSystem.cpp.
|
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.
sourcePath | The path of the source file |
destPath | The path of the destination file |
Definition at line 209 of file FileSystem.cpp.
|
static |
Remove a directory at the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the directory to remove |
Definition at line 77 of file FileSystem.cpp.
|
static |
Remove a file at the specified path.
It is invalid to pass nullptr
as the path.
path | The path of the file to remove |
Definition at line 81 of file FileSystem.cpp.
|
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.
sourcePath | The path of the source file |
destPath | The path of the destination file |
Definition at line 85 of file FileSystem.cpp.
|
static |
Touch a file at the specified path, creating it if it doesn't exist.
It is invalid to pass nullptr
as the path.
path | The path of the file to touch |
Definition at line 120 of file FileSystem.cpp.