10 FileSystem::FileSystem() : m_handle_storage(), m_delegate(*FileSystemInterface::getDelegate(m_handle_storage)) {
11 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
15 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
16 m_delegate.~FileSystemInterface();
20 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
21 return this->m_delegate.getHandle();
25 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
27 return this->m_delegate._removeDirectory(path);
31 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
33 return this->m_delegate._removeFile(path);
37 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
40 return this->m_delegate._rename(sourcePath, destPath);
44 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
47 return this->m_delegate._getWorkingDirectory(path, bufferSize);
51 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
53 return this->m_delegate._changeWorkingDirectory(path);
57 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
59 return this->m_delegate._getFreeSpace(path, totalBytes, freeBytes);
110 errorIfAlreadyExists ? Directory::OpenMode::CREATE_EXCLUSIVE : Directory::OpenMode::CREATE_IF_MISSING;
114 return FileSystem::handleDirectoryError(dirStatus);
126 status = FileSystem::handleFileError(file_status);
137 return PathType::FILE;
143 return PathType::DIRECTORY;
145 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++) {
301 chunkSize =
FW_MIN(FILE_SYSTEM_FILE_CHUNK_SIZE, size - copiedSize);
302 file_status = source.read(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
304 return FileSystem::handleFileError(file_status);
306 file_status = destination.write(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
308 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
#define FW_MIN(a, b)
MIN macro.
void close() override
Close directory.
File doesn't exist (for read)
Status _removeFile(const char *path) override
Remove a file at the specified path.
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 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.