|
@@ -12,7 +12,7 @@
|
|
|
// See the License for the specific language governing permissions and
|
|
|
// limitations under the License.
|
|
|
|
|
|
-static constexpr const char LFS_NAME[] = "spiffs";
|
|
|
+
|
|
|
|
|
|
#include "vfs_api.h"
|
|
|
|
|
@@ -27,21 +27,56 @@ extern "C" {
|
|
|
|
|
|
using namespace fs;
|
|
|
|
|
|
-LITTLEFSFS::LITTLEFSFS() : FS(FSImplPtr(new VFSImpl()))
|
|
|
+class LITTLEFSImpl : public VFSImpl
|
|
|
{
|
|
|
+public:
|
|
|
+ LITTLEFSImpl();
|
|
|
+ virtual ~LITTLEFSImpl() { }
|
|
|
+ virtual bool exists(const char* path);
|
|
|
+};
|
|
|
|
|
|
+LITTLEFSImpl::LITTLEFSImpl()
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+bool LITTLEFSImpl::exists(const char* path)
|
|
|
+{
|
|
|
+ File f = open(path, "r");
|
|
|
+ return (f == true);
|
|
|
}
|
|
|
|
|
|
-bool LITTLEFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles)
|
|
|
+LITTLEFSFS::LITTLEFSFS() : FS(FSImplPtr(new LITTLEFSImpl())), partitionLabel_(NULL)
|
|
|
{
|
|
|
- if(esp_littlefs_mounted(LFS_NAME)){
|
|
|
+}
|
|
|
+
|
|
|
+LITTLEFSFS::~LITTLEFSFS()
|
|
|
+{
|
|
|
+ if (partitionLabel_){
|
|
|
+ free(partitionLabel_);
|
|
|
+ partitionLabel_ = NULL;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool LITTLEFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
|
|
|
+{
|
|
|
+
|
|
|
+ if (partitionLabel_){
|
|
|
+ free(partitionLabel_);
|
|
|
+ partitionLabel_ = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (partitionLabel){
|
|
|
+ partitionLabel_ = strdup(partitionLabel);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(esp_littlefs_mounted(partitionLabel_)){
|
|
|
log_w("LITTLEFS Already Mounted!");
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
esp_vfs_littlefs_conf_t conf = {
|
|
|
.base_path = basePath,
|
|
|
- .partition_label = LFS_NAME,
|
|
|
+ .partition_label = partitionLabel_,
|
|
|
.format_if_mount_failed = false
|
|
|
};
|
|
|
|
|
@@ -61,8 +96,8 @@ bool LITTLEFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpen
|
|
|
|
|
|
void LITTLEFSFS::end()
|
|
|
{
|
|
|
- if(esp_littlefs_mounted(LFS_NAME)){
|
|
|
- esp_err_t err = esp_vfs_littlefs_unregister(LFS_NAME);
|
|
|
+ if(esp_littlefs_mounted(partitionLabel_)){
|
|
|
+ esp_err_t err = esp_vfs_littlefs_unregister(partitionLabel_);
|
|
|
if(err){
|
|
|
log_e("Unmounting LITTLEFS failed! Error: %d", err);
|
|
|
return;
|
|
@@ -74,7 +109,7 @@ void LITTLEFSFS::end()
|
|
|
bool LITTLEFSFS::format()
|
|
|
{
|
|
|
disableCore0WDT();
|
|
|
- esp_err_t err = esp_littlefs_format(LFS_NAME);
|
|
|
+ esp_err_t err = esp_littlefs_format(partitionLabel_);
|
|
|
enableCore0WDT();
|
|
|
if(err){
|
|
|
log_e("Formatting LITTLEFS failed! Error: %d", err);
|
|
@@ -86,7 +121,7 @@ bool LITTLEFSFS::format()
|
|
|
size_t LITTLEFSFS::totalBytes()
|
|
|
{
|
|
|
size_t total,used;
|
|
|
- if(esp_littlefs_info(LFS_NAME, &total, &used)){
|
|
|
+ if(esp_littlefs_info(partitionLabel_, &total, &used)){
|
|
|
return 0;
|
|
|
}
|
|
|
return total;
|
|
@@ -95,7 +130,7 @@ size_t LITTLEFSFS::totalBytes()
|
|
|
size_t LITTLEFSFS::usedBytes()
|
|
|
{
|
|
|
size_t total,used;
|
|
|
- if(esp_littlefs_info(LFS_NAME, &total, &used)){
|
|
|
+ if(esp_littlefs_info(partitionLabel_, &total, &used)){
|
|
|
return 0;
|
|
|
}
|
|
|
return used;
|