12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- static constexpr const char LFS_NAME[] = " spiffs " ;
15
+
16
16
17
17
#include " vfs_api.h"
18
18
19
19
extern " C" {
20
20
#include < sys/unistd.h>
21
21
#include < sys/stat.h>
22
22
#include < dirent.h>
23
- #undef B110
24
- #undef B1000000
25
- #include " esp_littlefs.h"
23
+ #include " esp_littlefs.h"
26
24
}
27
25
28
26
#include " LITTLEFS.h"
29
27
30
28
using namespace fs ;
31
29
32
- LITTLEFSFS::LITTLEFSFS () : FS(FSImplPtr( new VFSImpl()))
30
+ class LITTLEFSImpl : public VFSImpl
33
31
{
32
+ public:
33
+ LITTLEFSImpl ();
34
+ virtual ~LITTLEFSImpl () { }
35
+ virtual bool exists (const char * path);
36
+ };
34
37
38
+ LITTLEFSImpl::LITTLEFSImpl ()
39
+ {
40
+ }
41
+
42
+ bool LITTLEFSImpl::exists (const char * path)
43
+ {
44
+ File f = open (path, " r" );
45
+ return (f == true );
35
46
}
36
47
37
- bool LITTLEFSFS::begin ( bool formatOnFail, const char * basePath, uint8_t maxOpenFilesUnused )
48
+ LITTLEFSFS::LITTLEFSFS () : FS(FSImplPtr( new LITTLEFSImpl())), partitionLabel_( NULL )
38
49
{
39
- if (esp_littlefs_mounted (LFS_NAME)){
50
+ }
51
+
52
+ LITTLEFSFS::~LITTLEFSFS ()
53
+ {
54
+ if (partitionLabel_){
55
+ free (partitionLabel_);
56
+ partitionLabel_ = NULL ;
57
+ }
58
+ }
59
+
60
+ bool LITTLEFSFS::begin (bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
61
+ {
62
+
63
+ if (partitionLabel_){
64
+ free (partitionLabel_);
65
+ partitionLabel_ = NULL ;
66
+ }
67
+
68
+ if (partitionLabel){
69
+ partitionLabel_ = strdup (partitionLabel);
70
+ }
71
+
72
+ if (esp_littlefs_mounted (partitionLabel_)){
40
73
log_w (" LITTLEFS Already Mounted!" );
41
74
return true ;
42
75
}
43
76
44
77
esp_vfs_littlefs_conf_t conf = {
45
78
.base_path = basePath,
46
- .partition_label = LFS_NAME ,
79
+ .partition_label = partitionLabel_ ,
47
80
.format_if_mount_failed = false
48
81
};
49
82
@@ -63,8 +96,8 @@ bool LITTLEFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpen
63
96
64
97
void LITTLEFSFS::end ()
65
98
{
66
- if (esp_littlefs_mounted (LFS_NAME )){
67
- esp_err_t err = esp_vfs_littlefs_unregister (LFS_NAME );
99
+ if (esp_littlefs_mounted (partitionLabel_ )){
100
+ esp_err_t err = esp_vfs_littlefs_unregister (partitionLabel_ );
68
101
if (err){
69
102
log_e (" Unmounting LITTLEFS failed! Error: %d" , err);
70
103
return ;
@@ -76,7 +109,7 @@ void LITTLEFSFS::end()
76
109
bool LITTLEFSFS::format ()
77
110
{
78
111
disableCore0WDT ();
79
- esp_err_t err = esp_littlefs_format (LFS_NAME );
112
+ esp_err_t err = esp_littlefs_format (partitionLabel_ );
80
113
enableCore0WDT ();
81
114
if (err){
82
115
log_e (" Formatting LITTLEFS failed! Error: %d" , err);
@@ -88,7 +121,7 @@ bool LITTLEFSFS::format()
88
121
size_t LITTLEFSFS::totalBytes ()
89
122
{
90
123
size_t total,used;
91
- if (esp_littlefs_info (LFS_NAME , &total, &used)){
124
+ if (esp_littlefs_info (partitionLabel_ , &total, &used)){
92
125
return 0 ;
93
126
}
94
127
return total;
@@ -97,7 +130,7 @@ size_t LITTLEFSFS::totalBytes()
97
130
size_t LITTLEFSFS::usedBytes ()
98
131
{
99
132
size_t total,used;
100
- if (esp_littlefs_info (LFS_NAME , &total, &used)){
133
+ if (esp_littlefs_info (partitionLabel_ , &total, &used)){
101
134
return 0 ;
102
135
}
103
136
return used;
0 commit comments