summaryrefslogtreecommitdiff
path: root/src/components/fs/FS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/fs/FS.cpp')
-rw-r--r--src/components/fs/FS.cpp105
1 files changed, 53 insertions, 52 deletions
diff --git a/src/components/fs/FS.cpp b/src/components/fs/FS.cpp
index 857e6bf9..8c98ae34 100644
--- a/src/components/fs/FS.cpp
+++ b/src/components/fs/FS.cpp
@@ -1,33 +1,32 @@
-#include "FS.h"
+#include "components/fs/FS.h"
#include <cstring>
#include <littlefs/lfs.h>
#include <lvgl/lvgl.h>
using namespace Pinetime::Controllers;
-FS::FS(Pinetime::Drivers::SpiNorFlash& driver) :
- flashDriver{ driver },
- lfsConfig{
- .context = this,
- .read = SectorRead,
- .prog = SectorProg,
- .erase = SectorErase,
- .sync = SectorSync,
-
- .read_size = 16,
- .prog_size = 8,
- .block_size = blockSize,
- .block_count = size / blockSize,
- .block_cycles = 1000u,
-
- .cache_size = 16,
- .lookahead_size = 16,
-
- .name_max = 50,
- .attr_max = 50,
- }
-{ }
-
+FS::FS(Pinetime::Drivers::SpiNorFlash& driver)
+ : flashDriver {driver},
+ lfsConfig {
+ .context = this,
+ .read = SectorRead,
+ .prog = SectorProg,
+ .erase = SectorErase,
+ .sync = SectorSync,
+
+ .read_size = 16,
+ .prog_size = 8,
+ .block_size = blockSize,
+ .block_count = size / blockSize,
+ .block_cycles = 1000u,
+
+ .cache_size = 16,
+ .lookahead_size = 16,
+
+ .name_max = 50,
+ .attr_max = 50,
+ } {
+}
void FS::Init() {
@@ -48,7 +47,6 @@ void FS::Init() {
VerifyResource();
LVGLFileSystemInit();
#endif
-
}
void FS::VerifyResource() {
@@ -56,7 +54,7 @@ void FS::VerifyResource() {
resourcesValid = true;
}
-int FS::FileOpen(lfs_file_t* file_p, const char* fileName, const int flags) {
+int FS::FileOpen(lfs_file_t* file_p, const char* fileName, const int flags) {
return lfs_file_open(&lfs, file_p, fileName, flags);
}
@@ -80,27 +78,31 @@ int FS::FileDelete(const char* fileName) {
return lfs_remove(&lfs, fileName);
}
+int FS::DirOpen(const char* path, lfs_dir_t* lfs_dir) {
+ return lfs_dir_open(&lfs, lfs_dir, path);
+}
+
+int FS::DirClose(lfs_dir_t* lfs_dir) {
+ return lfs_dir_close(&lfs, lfs_dir);
+}
+int FS::DirRead(lfs_dir_t* dir, lfs_info* info) {
+ return lfs_dir_read(&lfs, dir, info);
+}
+int FS::DirRewind(lfs_dir_t* dir) {
+ return lfs_dir_rewind(&lfs, dir);
+}
int FS::DirCreate(const char* path) {
return lfs_mkdir(&lfs, path);
}
-
-// Delete directory and all files inside
-int FS::DirDelete(const char* path) {
-
- lfs_dir_t lfs_dir;
- lfs_info entryInfo;
-
- int err;
- err = lfs_dir_open(&lfs, &lfs_dir, path);
- if (err) {
- return err;
- }
- while (lfs_dir_read(&lfs, &lfs_dir, &entryInfo)) {
- lfs_remove(&lfs, entryInfo.name);
- }
- lfs_dir_close(&lfs, &lfs_dir);
- return LFS_ERR_OK;
+int FS::Rename(const char* oldPath, const char* newPath){
+ return lfs_rename(&lfs,oldPath,newPath);
+}
+int FS::Stat(const char* path, lfs_info* info) {
+ return lfs_stat(&lfs, path, info);
+}
+lfs_ssize_t FS::GetFSSize() {
+ return lfs_fs_size(&lfs);
}
/*
@@ -141,17 +143,17 @@ int FS::SectorRead(const struct lfs_config* c, lfs_block_t block, lfs_off_t off,
namespace {
lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode) {
-
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
FS* filesys = static_cast<FS*>(drv->user_data);
- filesys->FileOpen(file, path, LFS_O_RDONLY);
-
- if (file->type == 0) {
- return LV_FS_RES_FS_ERR;
- }
- else {
- return LV_FS_RES_OK;
+ int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
+ if (res == 0) {
+ if (file->type == 0) {
+ return LV_FS_RES_FS_ERR;
+ } else {
+ return LV_FS_RES_OK;
+ }
}
+ return LV_FS_RES_NOT_EX;
}
lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
@@ -193,5 +195,4 @@ void FS::LVGLFileSystemInit() {
fs_drv.user_data = this;
lv_fs_drv_register(&fs_drv);
-
} \ No newline at end of file