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]));
17 m_delegate.~FileSystemInterface();
21 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
22 return this->m_delegate.getHandle();
26 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
28 return this->m_delegate._removeDirectory(path);
32 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
34 return this->m_delegate._removeFile(path);
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]));
47 return this->m_delegate._getPathType(path, pathType);
51 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
54 return this->m_delegate._getWorkingDirectory(path, bufferSize);
58 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
60 return this->m_delegate._changeWorkingDirectory(path);
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);
141 Status status = getSingleton()._getPathType(path, pathType);
143 return PathType::NOT_EXIST;
159 return FileSystem::handleFileError(fileStatus);
163 return FileSystem::handleFileError(fileStatus);
172 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
183 return Status::DOESNT_EXIST;
188 return FileSystem::handleFileError(fileStatus);
192 return FileSystem::handleFileError(fileStatus);
203 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
215 if (status == Status::EXDEV_ERROR) {
230 return FileSystem::handleFileError(status);
232 status = file.
size(size);
234 return FileSystem::handleFileError(status);
246 switch (fileStatus) {
285 static_assert(FILE_SYSTEM_FILE_CHUNK_SIZE != 0,
"FILE_SYSTEM_FILE_CHUNK_SIZE must be >0");
286 U8 fileBuffer[FILE_SYSTEM_FILE_CHUNK_SIZE];
290 FwSizeType chunkSize = FILE_SYSTEM_FILE_CHUNK_SIZE;
294 (size > (std::numeric_limits<FwSizeType>::max() / 2)) ? std::numeric_limits<FwSizeType>::max() : size * 2;
298 for (copiedSize = 0; (copiedSize < size) && (i < maximum); copiedSize += chunkSize, i++) {
302 chunkSize =
std::min(static_cast<FwSizeType>(FILE_SYSTEM_FILE_CHUNK_SIZE), size - copiedSize);
303 file_status = source.read(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
305 return FileSystem::handleFileError(file_status);
307 file_status = destination.write(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
309 return FileSystem::handleFileError(file_status);
FileSystemHandle * getHandle() override
return the underlying FileSystem handle (implementation specific)
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.
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
static void init()
initialize singleton
Status _rename(const char *sourcePath, const char *destPath) override
Rename 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
static Status getFileSize(const char *path, FwSizeType &size)
Get the size of the file (in bytes) at the specified path.
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.
Operation was successful.
Operation is not supported by the current implementation.
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.
Operation was successful.
Directory already exists.
~FileSystem() final
Destructor.
Operation is not supported by the current implementation.
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.
static Status touch(const char *path)
Touch a file at the specified path, creating it if it doesn't exist.