F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Os::FileSystemCommon< T > Class Template Reference

FileSystem class. More...

#include <Os/FileSystem.hpp>

Inheritance diagram for Os::FileSystemCommon< T >:
Os::FileSystemUserInterface

Public Member Functions

 ~FileSystemCommon ()
 Destructor. More...
 
FileSystemHandle * getHandle ()
 return the underlying FileSystem handle (implementation specific) More...
 
Status _removeDirectory (const char *path)
 Remove a directory at the specified path. More...
 
Status _removeFile (const char *path)
 Remove a file at the specified path. More...
 
Status _rename (const char *sourcePath, const char *destPath)
 Rename a file from source to destination. More...
 
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...
 
Status _getWorkingDirectory (char *path, FwSizeType bufferSize)
 Get the current working directory. More...
 
Status _changeWorkingDirectory (const char *path)
 Change the current working directory to the specified path. More...
 
Status _getPathType (const char *path, PathType &pathType)
 Get the type of the path (file, directory, etc.) 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, FwSizeType &size)
 Get the size of the file (in bytes) at the specified path. More...
 
static void init ()
 initialize singleton More...
 
static FileSystemCommon & getSingleton ()
 get a reference to singleton More...
 

Additional Inherited Members

- Public Types inherited from Os::FileSystemUserInterface
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, OTHER, NOT_EXIST }
 
- Static Public Attributes inherited from Os::FileSystemUserInterface
static constexpr FwSizeType FILE_SYSTEM_FILE_CHUNK_SIZE = FW_FILE_CHUNK_SIZE
 Size of file system chunk. More...
 

Detailed Description

template<typename T>
class Os::FileSystemCommon< T >

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 24 of file FileSystem.hpp.

Constructor & Destructor Documentation

◆ ~FileSystemCommon()

template<typename T >
Os::FileSystemCommon< T >::~FileSystemCommon ( )

Destructor.

Definition at line 321 of file FileSystem.hpp.

Member Function Documentation

◆ _changeWorkingDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_changeWorkingDirectory ( const char *  path)

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 361 of file FileSystem.hpp.

◆ _getFreeSpace()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_getFreeSpace ( const char *  path,
FwSizeType &  totalBytes,
FwSizeType &  freeBytes 
)

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 367 of file FileSystem.hpp.

◆ _getPathType()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_getPathType ( const char *  path,
PathType &  pathType 
)

Get the type of the path (file, directory, etc.)

It is invalid to pass nullptr as the path.

Parameters
pathThe path to check
pathTypeReference to store the path type
Returns
Status of the operation

Definition at line 348 of file FileSystem.hpp.

◆ _getWorkingDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_getWorkingDirectory ( char *  path,
FwSizeType  bufferSize 
)

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 354 of file FileSystem.hpp.

◆ _removeDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_removeDirectory ( const char *  path)

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 329 of file FileSystem.hpp.

◆ _removeFile()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_removeFile ( const char *  path)

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 335 of file FileSystem.hpp.

◆ _rename()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::_rename ( const char *  sourcePath,
const char *  destPath 
)

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 341 of file FileSystem.hpp.

◆ appendFile()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 498 of file FileSystem.hpp.

◆ changeWorkingDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 411 of file FileSystem.hpp.

◆ copyFile()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 472 of file FileSystem.hpp.

◆ createDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 427 of file FileSystem.hpp.

◆ exists()

template<typename T >
bool Os::FileSystemCommon< T >::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 467 of file FileSystem.hpp.

◆ getFileSize()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::getFileSize ( const char *  path,
FwSizeType &  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 552 of file FileSystem.hpp.

◆ getFreeSpace()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 416 of file FileSystem.hpp.

◆ getHandle()

template<typename T >
FileSystemHandle * Os::FileSystemCommon< T >::getHandle ( )

return the underlying FileSystem handle (implementation specific)

Returns
internal FileSystem handle representation

Definition at line 324 of file FileSystem.hpp.

◆ getPathType()

template<typename T >
FileSystemCommon< T >::PathType Os::FileSystemCommon< T >::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 456 of file FileSystem.hpp.

◆ getSingleton()

template<typename T >
FileSystemCommon< T > & Os::FileSystemCommon< T >::getSingleton ( )
static

get a reference to singleton

Returns
reference to singleton

Definition at line 381 of file FileSystem.hpp.

◆ getWorkingDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 406 of file FileSystem.hpp.

◆ init()

template<typename T >
void Os::FileSystemCommon< T >::init ( )
static

initialize singleton

Definition at line 375 of file FileSystem.hpp.

◆ moveFile()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 533 of file FileSystem.hpp.

◆ removeDirectory()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 391 of file FileSystem.hpp.

◆ removeFile()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 396 of file FileSystem.hpp.

◆ rename()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 401 of file FileSystem.hpp.

◆ touch()

template<typename T >
FileSystemCommon< T >::Status Os::FileSystemCommon< T >::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 443 of file FileSystem.hpp.


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