@@ -43,21 +43,38 @@ bool SPIFFSImpl::exists(const char* path)
43
43
return (f == true ) && !f.isDirectory ();
44
44
}
45
45
46
- SPIFFSFS::SPIFFSFS () : FS(FSImplPtr(new SPIFFSImpl()))
46
+ SPIFFSFS::SPIFFSFS () : FS(FSImplPtr(new SPIFFSImpl())), partitionLabel_( NULL )
47
47
{
48
48
49
49
}
50
50
51
- bool SPIFFSFS::begin ( bool formatOnFail, const char * basePath, uint8_t maxOpenFiles )
51
+ SPIFFSFS::~SPIFFSFS ( )
52
52
{
53
- if (esp_spiffs_mounted (NULL )){
53
+ if (partitionLabel_){
54
+ free (partitionLabel_);
55
+ partitionLabel_ = NULL ;
56
+ }
57
+ }
58
+
59
+ bool SPIFFSFS::begin (bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
60
+ {
61
+ if (partitionLabel_){
62
+ free (partitionLabel_);
63
+ partitionLabel_ = NULL ;
64
+ }
65
+
66
+ if (partitionLabel){
67
+ partitionLabel_ = strdup (partitionLabel);
68
+ }
69
+
70
+ if (esp_spiffs_mounted (partitionLabel_)){
54
71
log_w (" SPIFFS Already Mounted!" );
55
72
return true ;
56
73
}
57
74
58
75
esp_vfs_spiffs_conf_t conf = {
59
76
.base_path = basePath,
60
- .partition_label = NULL ,
77
+ .partition_label = partitionLabel_ ,
61
78
.max_files = maxOpenFiles,
62
79
.format_if_mount_failed = false
63
80
};
@@ -78,8 +95,8 @@ bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFi
78
95
79
96
void SPIFFSFS::end ()
80
97
{
81
- if (esp_spiffs_mounted (NULL )){
82
- esp_err_t err = esp_vfs_spiffs_unregister (NULL );
98
+ if (esp_spiffs_mounted (partitionLabel_ )){
99
+ esp_err_t err = esp_vfs_spiffs_unregister (partitionLabel_ );
83
100
if (err){
84
101
log_e (" Unmounting SPIFFS failed! Error: %d" , err);
85
102
return ;
@@ -91,7 +108,7 @@ void SPIFFSFS::end()
91
108
bool SPIFFSFS::format ()
92
109
{
93
110
disableCore0WDT ();
94
- esp_err_t err = esp_spiffs_format (NULL );
111
+ esp_err_t err = esp_spiffs_format (partitionLabel_ );
95
112
enableCore0WDT ();
96
113
if (err){
97
114
log_e (" Formatting SPIFFS failed! Error: %d" , err);
@@ -103,7 +120,7 @@ bool SPIFFSFS::format()
103
120
size_t SPIFFSFS::totalBytes ()
104
121
{
105
122
size_t total,used;
106
- if (esp_spiffs_info (NULL , &total, &used)){
123
+ if (esp_spiffs_info (partitionLabel_ , &total, &used)){
107
124
return 0 ;
108
125
}
109
126
return total;
@@ -112,7 +129,7 @@ size_t SPIFFSFS::totalBytes()
112
129
size_t SPIFFSFS::usedBytes ()
113
130
{
114
131
size_t total,used;
115
- if (esp_spiffs_info (NULL , &total, &used)){
132
+ if (esp_spiffs_info (partitionLabel_ , &total, &used)){
116
133
return 0 ;
117
134
}
118
135
return used;
0 commit comments