8#include <sys/statvfs.h>
23 int mkStat = ::mkdir(path);
25 int mkStat = ::mkdir(path, S_IRWXU);
66 if (::rmdir(path) == -1) {
101 DIR* dirPtr =
nullptr;
102 struct dirent* direntData =
nullptr;
108 if ((dirPtr = ::opendir(path)) ==
nullptr) {
130 const U32 loopLimit = std::numeric_limits<U32>::max();
133 while (arrayIdx < maxNum && limitCount < loopLimit) {
136 if ((direntData = ::readdir(dirPtr)) !=
nullptr) {
138 if (direntData->d_type == DT_REG) {
143 fileArray[arrayIdx++] = str;
155 if (limitCount == loopLimit) {
159 if (::closedir(dirPtr) == -1) {
172 if (::unlink(path) == -1) {
205 if (::rename(originPath, destPath) == -1) {
249 switch (fileStatus) {
262 return fileSystemStatus;
274 struct stat local_info;
277 fileInfo = &local_info;
280 if (::stat(filePath, fileInfo) == -1) {
301 if (!S_ISREG(fileInfo->st_mode)) {
330 while (loopCounter < copyLoopLimit) {
332 file_status = source.
read(&fileBuffer, chunkSize,
false);
337 if (chunkSize == 0) {
342 file_status = destination.
write(fileBuffer, chunkSize,
true);
384 fs_status =
copyFileData(source, destination, fileSize);
386 (void)source.
close();
387 (void)destination.
close();
392Status appendFile(
const char* originPath,
const char* destPath,
bool createMissingDest) {
418 if (!createMissingDest) {
430 fs_status =
copyFileData(source, destination, fileSize);
432 (void)source.close();
433 (void)destination.close();
440 struct stat fileStatStruct;
445 size = fileStatStruct.st_size;
446 if (
static_cast<off_t
>(size) != fileStatStruct.st_size) {
457 if (::chdir(path) == -1) {
486 struct statvfs fsStat;
487 int ret = statvfs(path, &fsStat);
513 if (((block_size <= 0) || (
static_cast<unsigned long>(block_size) != fsStat.f_frsize)) ||
514 ((free_blocks <= 0) || (
static_cast<fsblkcnt_t
>(free_blocks) != fsStat.f_bfree)) ||
515 ((total_blocks <= 0) || (
static_cast<fsblkcnt_t
>(block_size) != fsStat.f_blocks))) {
519 if (free_blocks > (std::numeric_limits<FwSizeType>::max() / block_size) ||
520 total_blocks > (std::numeric_limits<FwSizeType>::max() / block_size)) {
523 freeBytes = free_blocks * block_size;
524 totalBytes = total_blocks * block_size;
531 DIR* dirPtr =
nullptr;
532 struct dirent* direntData =
nullptr;
534 const U32 loopLimit = std::numeric_limits<U32>::max();
537 if ((dirPtr = ::opendir(directory)) ==
nullptr) {
557 for (limitCount = 0; limitCount < loopLimit; limitCount++) {
558 if ((direntData = ::readdir(dirPtr)) !=
nullptr) {
560 if (direntData->d_type == DT_REG) {
572 if (limitCount == loopLimit) {
576 if (::closedir(dirPtr) == -1) {
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
#define FILE_SYSTEM_CHUNK_SIZE
PlatformSizeType FwSizeType
C++-compatible configuration header for fprime configuration.
@ DOESNT_EXIST
File doesn't exist (for read)
@ NO_PERMISSION
No permission to read/write file.
@ OP_OK
Operation was successful.
Status write(const void *buffer, NATIVE_INT_TYPE &size, bool waitForDone=true)
write size; will return amount written or errno
@ OPEN_APPEND
Open file for appending.
@ OPEN_WRITE
Open file for writing.
@ OPEN_READ
Open file for reading.
Status open(const char *fileName, Mode mode)
open file. Writing creates file if it doesn't exist
Status read(void *buffer, NATIVE_INT_TYPE &size, bool waitForFull=true)
waitForFull = true to wait for all bytes to be read
Status getFileCount(const char *directory, U32 &fileCount)
counts the number of files in the given directory
Status getFreeSpace(const char *path, FwSizeType &totalBytes, FwSizeType &freeBytes)
get FS free and total space in bytes on filesystem containing path
Status handleFileError(File::Status fileStatus)
Status createDirectory(const char *path)
create a new directory at location path
Status moveFile(const char *originPath, const char *destPath)
Status getFileSize(const char *path, FwSizeType &size)
append file origin to destination file. If boolean true, creates a brand new file if the destination ...
Status changeWorkingDirectory(const char *path)
move current directory to path
Status appendFile(const char *originPath, const char *destPath, bool createMissingDest)
copies a file from origin to destination
@ OP_OK
Operation was successful.
@ NOT_DIR
Path is not a directory.
@ ALREADY_EXISTS
File already exists.
@ NO_PERMISSION
No permission to write.
@ IS_DIR
Path is a directory.
@ INVALID_PATH
Path is too long, too many sym links, doesn't exist, ect.
@ FILE_LIMIT
Too many files or links.
@ OTHER_ERROR
other OS-specific error
@ NOT_EMPTY
directory is not empty
@ BUSY
Operand is in use by the system or by a process.
Status copyFile(const char *originPath, const char *destPath)
moves a file from origin to destination
Status removeDirectory(const char *path)
remove a directory at location path
Status readDirectory(const char *path, const U32 maxNum, Fw::String fileArray[])
Status removeFile(const char *path)
removes a file at location path
Status initAndCheckFileStats(const char *filePath, struct stat *fileInfo=nullptr)
Status copyFileData(File source, File destination, FwSizeType size)