Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Os::FileSystem and Os::Directory #2871

Merged
merged 45 commits into from
Sep 27, 2024

Conversation

thomas-bc
Copy link
Collaborator

Related Issue(s) #2687
Has Unit Tests (y/n) y
Documentation Included (y/n) n

Change Description

Refactoring Os::FileSystem and Os::Directory to the new OSAL pattern

Rationale

See #2687

Future Work

Document the entire OSAL

@thomas-bc thomas-bc linked an issue Sep 13, 2024 that may be closed by this pull request
Os/Directory.cpp Fixed Show fixed Hide fixed
Os/Posix/Directory.cpp Fixed Show fixed Hide fixed
Os/test/ut/filesystem/RulesHeaders.hpp Fixed Show fixed Hide fixed
Os/test/ut/filesystem/RulesHeaders.hpp Fixed Show fixed Hide fixed
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Os/Directory.cpp Fixed Show fixed Hide fixed
}


Directory::Status Directory::readDirectory(Fw::String filenameArray[], const FwSizeType filenameArraySize, FwSizeType& filenameCount) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
bool isOpen(); //!< check if file descriptor is open or not.
Status rewind(); //!< rewind directory stream to the beginning
//! \brief default constructor
DirectoryInterface() = default;

Check notice

Code scanning / CodeQL

More than one statement per line Note

This line contains 2 statements; only one is allowed.
Os/FileSystem.cpp Fixed Show fixed Hide fixed
Os/FileSystem.cpp Fixed Show fixed Hide fixed
Os/Posix/Directory.cpp Fixed Show fixed Hide fixed
namespace Posix {
namespace Directory {

struct PosixDirectoryHandle : public DirectoryHandle {

Check notice

Code scanning / CodeQL

More than one statement per line Note

This line contains 2 statements; only one is allowed.
return status;
}

PosixFileSystem::Status PosixFileSystem::_getFreeSpace(const char* path, FwSizeType& totalBytes, FwSizeType& freeBytes) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@@ -48,6 +48,75 @@
return status;
}

FileSystem::Status errno_to_filesystem_status(PlatformIntType errno_input) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return status;
}

Directory::Status errno_to_directory_status(PlatformIntType errno_input) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@nasa nasa deleted a comment from Meganbrentshandacrain Sep 17, 2024
return fs_status;
} // end appendFile

FileSystem::Status FileSystem::moveFile(const char* source, const char* destination) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return status;
} // end handleFileError

FileSystem::Status FileSystem::handleDirectoryError(Directory::Status dirStatus) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
Os/FileSystem.cpp Fixed Show fixed Hide fixed
}


Directory::Status Directory::readDirectory(Fw::String filenameArray[], const FwSizeType filenameArraySize, FwSizeType& filenameCount) {

Check notice

Code scanning / CodeQL

No raw arrays in interfaces Note

Raw arrays should not be used in interfaces. A container class should be used instead.
Os/Directory.cpp Dismissed Show dismissed Hide dismissed
Os/Directory.cpp Dismissed Show dismissed Hide dismissed
FwSizeType count = 0;
char unusedBuffer[1]; // buffer must have size but is unused
Status readStatus = Status::OP_OK;
fileCount = 0;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter fileCount has not been checked.
Status readStatus = Status::OP_OK;
Status returnStatus = Status::OP_OK;
FwSizeType index;
filenameCount = 0;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter filenameCount has not been checked.
FileSystem::Status FileSystem::_getFreeSpace(const char* path, FwSizeType& totalBytes, FwSizeType& freeBytes) {
FW_ASSERT(&this->m_delegate == reinterpret_cast<FileSystemInterface*>(&this->m_handle_storage[0]));
FW_ASSERT(path != nullptr);
return this->m_delegate._getFreeSpace(path, totalBytes, freeBytes);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter totalBytes has not been checked.
total_blocks > (std::numeric_limits<FwSizeType>::max() / block_size)) {
return OVERFLOW_ERROR;
}
freeBytes = free_blocks * block_size;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter freeBytes has not been checked.
return OVERFLOW_ERROR;
}
freeBytes = free_blocks * block_size;
totalBytes = total_blocks * block_size;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter totalBytes has not been checked.
@@ -48,6 +48,86 @@
return status;
}

FileSystem::Status errno_to_filesystem_status(PlatformIntType errno_input) {
FileSystem::Status status = FileSystem::Status::OP_OK;
switch (errno_input) {

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter errno_input has not been checked.

Directory::Status errno_to_directory_status(PlatformIntType errno_input) {
Directory::Status status = Directory::Status::OP_OK;
switch (errno_input) {

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter errno_input has not been checked.
Svc/DpCatalog/DpCatalog.cpp Fixed Show fixed Hide fixed
Os/Directory.cpp Dismissed Show dismissed Hide dismissed
// Additional functions built on top of OS-specific operations
// ------------------------------------------------------------

FileSystem::Status FileSystem::createDirectory(const char* path, bool errorIfAlreadyExists) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return status;
}

FileSystem::Status FileSystem::touch(const char* path) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return status;
}

FileSystem::PathType FileSystem::getPathType(const char* path) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return FileSystem::getPathType(path) != PathType::NOT_EXIST;
} // end exists

FileSystem::Status FileSystem::copyFile(const char* sourcePath, const char* destPath) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
return status;
}

PosixDirectory::Status PosixDirectory::read(char* fileNameBuffer, FwSizeType bufSize) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
Os/Posix/DefaultDirectory.cpp Show resolved Hide resolved
Svc/FileManager/FileManager.cpp Show resolved Hide resolved
config/FpConfig.h Show resolved Hide resolved
@thomas-bc
Copy link
Collaborator Author

@LeStarch comments addressed and follow-up issues created.
I'm ready to merge this when you are!

@LeStarch LeStarch merged commit d6ebdff into nasa:devel Sep 27, 2024
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants