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]));
14 FileSystem::~FileSystem() {
16 m_delegate.~FileSystemInterface();
21 return this->m_delegate.getHandle();
27 return this->m_delegate._removeDirectory(path);
33 return this->m_delegate._removeFile(path);
40 return this->m_delegate._rename(sourcePath, destPath);
47 return this->m_delegate._getWorkingDirectory(path, bufferSize);
53 return this->m_delegate._changeWorkingDirectory(path);
59 return this->m_delegate._getFreeSpace(path, totalBytes, freeBytes);
64 (void) FileSystem::getSingleton();
82 return FileSystem::getSingleton()._removeFile(path);
86 return FileSystem::getSingleton()._rename(sourcePath, destPath);
90 return FileSystem::getSingleton()._getWorkingDirectory(path, bufferSize);
94 return FileSystem::getSingleton()._changeWorkingDirectory(path);
98 return FileSystem::getSingleton()._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;
149 bool FileSystem::exists(
const char* path) {
150 return FileSystem::getPathType(path) != PathType::NOT_EXIST;
160 return FileSystem::handleFileError(fileStatus);
164 return FileSystem::handleFileError(fileStatus);
173 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
178 FileSystem::Status FileSystem::appendFile(
const char* sourcePath,
const char* destPath,
bool createMissingDest) {
183 if (not createMissingDest and not FileSystem::exists(destPath)) {
184 return Status::DOESNT_EXIST;
189 return FileSystem::handleFileError(fileStatus);
193 return FileSystem::handleFileError(fileStatus);
199 fs_status = FileSystem::getFileSize(sourcePath, sourceFileSize);
204 fs_status = FileSystem::copyFileData(source, destination, sourceFileSize);
213 status = FileSystem::rename(source, destination);
216 if (status == Status::EXDEV_ERROR) {
217 status = FileSystem::copyFile(source, destination);
221 status = FileSystem::removeFile(source);
231 return FileSystem::handleFileError(status);
233 status = file.
size(size);
235 return FileSystem::handleFileError(status);
248 switch (fileStatus) {
252 case File::NO_PERMISSION:
253 status = FileSystem::NO_PERMISSION;
255 case File::DOESNT_EXIST:
256 status = FileSystem::DOESNT_EXIST;
268 case Directory::DOESNT_EXIST:
269 status = FileSystem::DOESNT_EXIST;
271 case Directory::NO_PERMISSION:
272 status = FileSystem::NO_PERMISSION;
274 case Directory::ALREADY_EXISTS:
275 status = FileSystem::ALREADY_EXISTS;
277 case Directory::NOT_SUPPORTED:
278 status = FileSystem::NOT_SUPPORTED;
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);
#define FW_MIN(a, b)
MIN macro.
uint8_t U8
8-bit unsigned integer
PlatformSignedSizeType FwSignedSizeType
PlatformSizeType FwSizeType
Status open(const char *path, OpenMode mode) override
Open or create a directory.
void close() override
Close directory.
Status size(FwSignedSizeType &size_result) override
get size of currently open file
void close() override
close the file, if not opened then do nothing
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
@ OP_OK
Operation was successful.
@ OPEN_WRITE
Open file for writing.
@ OPEN_READ
Open file for reading.
@ OPEN_APPEND
Open file for appending.
Status _removeDirectory(const char *path) override
Remove a directory at the specified path.
Status
Generic OK/ERROR status.
@ OP_OK
Operation succeeded.
@ OTHER_ERROR
A catch-all for other errors. Have to look in implementation-specific code.
@ NO_SPACE
No space left on the device for writing.
void init()
Initialize the OS Abstraction Layer (OSAL)