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);
111 Directory::OpenMode mode = errorIfAlreadyExists ? Directory::OpenMode::CREATE_EXCLUSIVE : Directory::OpenMode::CREATE_IF_MISSING;
115 return FileSystem::handleDirectoryError(dirStatus);
127 status = FileSystem::handleFileError(file_status);
138 return PathType::FILE;
144 return PathType::DIRECTORY;
146 return PathType::NOT_EXIST;
160 return FileSystem::handleFileError(fileStatus);
164 return FileSystem::handleFileError(fileStatus);
173 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
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);
248 switch (fileStatus) {
287 static_assert(FILE_SYSTEM_FILE_CHUNK_SIZE != 0,
"FILE_SYSTEM_FILE_CHUNK_SIZE must be >0");
288 U8 fileBuffer[FILE_SYSTEM_FILE_CHUNK_SIZE];
295 for (copiedSize = 0; copiedSize < size; copiedSize += chunkSize) {
298 chunkSize =
FW_MIN(FILE_SYSTEM_FILE_CHUNK_SIZE, size - copiedSize);
299 file_status = source.read(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
301 return FileSystem::handleFileError(file_status);
303 file_status = destination.write(fileBuffer, chunkSize, Os::File::WaitType::WAIT);
305 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.
Status size(FwSignedSizeType &size_result) override
get size of currently open file
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.
PlatformSizeType FwSizeType
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 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.
PlatformSignedSizeType FwSignedSizeType
static Status copyFile(const char *sourcePath, const char *destPath)
Copy a file from the source path to the destination path.
static Status getFileSize(const char *path, FwSignedSizeType &size)
Get the size of the file (in bytes) at the specified 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.