FS: copy lfs_info and implement FS::Stat()

Implement the subset of the functionality to be usable to check if the
file exists or not and check the size of the file.
This commit is contained in:
Reinhold Gschweicher 2022-04-04 21:22:57 +02:00
parent d4e81ca177
commit 9f36b7886d
2 changed files with 34 additions and 1 deletions

View File

@ -163,6 +163,16 @@ int FS::DirDelete(const char* path) {
//return LFS_ERR_OK; //return LFS_ERR_OK;
} }
// check if file exists, if so write file-size into info object
int FS::Stat(const char* path, lfs_info* info) {
if (!std::filesystem::exists(path))
{
return LFS_ERR_NOENT; // No directory entry
}
info->size = std::filesystem::file_size(path);
return LFS_ERR_OK;
}
/* /*
----------- Interface between littlefs and SpiNorFlash ----------- ----------- Interface between littlefs and SpiNorFlash -----------

View File

@ -49,8 +49,31 @@ enum lfs_whence_flags {
LFS_SEEK_END = 2, // Seek relative to the end of the file LFS_SEEK_END = 2, // Seek relative to the end of the file
}; };
typedef uint32_t lfs_size_t;
typedef int32_t lfs_ssize_t; typedef int32_t lfs_ssize_t;
// Maximum name size in bytes, may be redefined to reduce the size of the
// info struct. Limited to <= 1022. Stored in superblock and must be
// respected by other littlefs drivers.
//#ifndef LFS_NAME_MAX
//#define LFS_NAME_MAX 255
//#endif
// File info structure
struct lfs_info {
// // Type of the file, either LFS_TYPE_REG or LFS_TYPE_DIR
// uint8_t type;
// Size of the file, only valid for REG files. Limited to 32-bits.
lfs_size_t size;
// // Name of the file stored as a null-terminated string. Limited to
// // LFS_NAME_MAX+1, which can be changed by redefining LFS_NAME_MAX to
// // reduce RAM. LFS_NAME_MAX is stored in superblock and must be
// // respected by other littlefs drivers.
// char name[LFS_NAME_MAX+1];
};
namespace Pinetime { namespace Pinetime {
namespace Controllers { namespace Controllers {
class FS { class FS {
@ -77,7 +100,7 @@ namespace Pinetime {
lfs_ssize_t GetFSSize(); lfs_ssize_t GetFSSize();
int Rename(const char* oldPath, const char* newPath); int Rename(const char* oldPath, const char* newPath);
//int Stat(const char* path, lfs_info* info); int Stat(const char* path, lfs_info* info);
void VerifyResource(); void VerifyResource();
static size_t getSize() { static size_t getSize() {