11 FileSystem::FileSystem() : m_handle_storage(), m_delegate(*FileSystemInterface::getDelegate(m_handle_storage)) {
12 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
16 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
21 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
26 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
32 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
38 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
41 return this->m_delegate.
_rename(sourcePath, destPath);
45 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
51 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
58 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
64 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
66 return this->m_delegate.
_getFreeSpace(path, totalBytes, freeBytes);
117 errorIfAlreadyExists ? Directory::OpenMode::CREATE_EXCLUSIVE : Directory::OpenMode::CREATE_IF_MISSING;
121 return FileSystem::handleDirectoryError(dirStatus);
133 status = FileSystem::handleFileError(file_status);
143 return PathType::NOT_EXIST;
159 return FileSystem::handleFileError(fileStatus);
163 return FileSystem::handleFileError(fileStatus);
172 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
183 if (not createMissingDest and not destExists) {
184 return Status::DOESNT_EXIST;
189 return FileSystem::handleFileError(fileStatus);
193 return FileSystem::handleFileError(fileStatus);
204 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
216 if (status == Status::EXDEV_ERROR) {
231 return FileSystem::handleFileError(status);
233 status = file.
size(size);
235 return FileSystem::handleFileError(status);
247 switch (fileStatus) {
295 (size > (std::numeric_limits<FwSizeType>::max() / 2)) ? std::numeric_limits<FwSizeType>::max() : size * 2;
299 for (copiedSize = 0; (copiedSize < size) && (i < maximum); copiedSize += chunkSize, i++) {
304 file_status = source.read(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
306 return FileSystem::handleFileError(file_status);
308 file_status = destination.write(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
310 return FileSystem::handleFileError(file_status);
FileSystemHandle * getHandle() override
return the underlying FileSystem handle (implementation specific)
virtual Status _getFreeSpace(const char *path, FwSizeType &totalBytes, FwSizeType &freeBytes)=0
Get filesystem free and total space in bytes on the filesystem containing the specified path...
static Status rename(const char *sourcePath, const char *destPath)
Rename a file from source to destination.
PlatformSizeType FwSizeType
static Status moveFile(const char *sourcePath, const char *destPath)
Move a file from sourcePath to destPath.
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...
Status _getWorkingDirectory(char *path, FwSizeType bufferSize) override
Get the current working directory.
static Status removeDirectory(const char *path)
Remove a directory at the specified path.
static Status appendFile(const char *sourcePath, const char *destPath, bool createMissingDest=false)
Append the source file to the destination file.
Status size(FwSizeType &size_result) override
get size of currently open file
No permission to read/write file.
Directory doesn't exist.
static bool exists(const char *path)
Return true if the path exists, false otherwise.
virtual ~FileSystemInterface()=default
default virtual destructor
static void init()
initialize singleton
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
Status _rename(const char *sourcePath, const char *destPath) override
Rename a file from source to destination.
virtual Status _rename(const char *sourcePath, const char *destPath)=0
Rename (or move) a file from source to destination.
No permission to read directory.
static FileSystem & getSingleton()
get a reference to singleton
void close() override
Close directory.
File doesn't exist (for read)
Status _removeFile(const char *path) override
Remove a file at the specified path.
Status _getPathType(const char *path, PathType &pathType) override
Get the type of the path (file, directory, etc.)
void close() override
close the file, if not opened then do nothing
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...
Status _removeDirectory(const char *path) override
Remove a directory at the specified path.
static Status getWorkingDirectory(char *path, FwSizeType bufferSize)
Get the current working directory.
uint8_t U8
8-bit unsigned integer
virtual Status _getPathType(const char *path, PathType &pathType)=0
Get the type of the path (file, directory, etc.)
static Status getFileSize(const char *path, FwSizeType &size)
Get the size of the file (in bytes) at the specified path.
virtual Status _getWorkingDirectory(char *path, FwSizeType bufferSize)=0
Get the current working directory.
static Status createDirectory(const char *path, bool errorIfAlreadyExists=false)
Create a new directory at the specified path.
static U32 min(const U32 a, const U32 b)
static PathType getPathType(const char *path)
Return the type of the path (file, directory, or doesn't exist)
Operation was successful.
static constexpr FwSizeType FILE_SYSTEM_FILE_CHUNK_SIZE
Size of file system chunk.
Operation was successful.
Operation is not supported by the current implementation.
virtual FileSystemHandle * getHandle()=0
return the underlying FileSystem handle (implementation specific)
Status open(const char *path, OpenMode mode) override
Open or create a directory.
static Status copyFile(const char *sourcePath, const char *destPath)
Copy a file from the source path to the destination path.
virtual Status _removeFile(const char *path)=0
Remove a file at the specified path.
Operation was successful.
Directory already exists.
~FileSystem() final
Destructor.
Operation is not supported by the current implementation.
virtual Status _removeDirectory(const char *path)=0
Remove a directory at the specified path.
static Status changeWorkingDirectory(const char *path)
Change the current working directory to the specified path.
Status _changeWorkingDirectory(const char *path) override
Change the current working directory to the specified path.
static Status removeFile(const char *path)
Remove a file at the specified path.
virtual Status _changeWorkingDirectory(const char *path)=0
Change the current working directory to the specified path.
static Status touch(const char *path)
Touch a file at the specified path, creating it if it doesn't exist.