@@ -43,21 +43,38 @@ bool SPIFFSImpl::exists(const char* path)
4343 return (f == true ) && !f.isDirectory ();
4444}
4545
46- SPIFFSFS::SPIFFSFS () : FS(FSImplPtr(new SPIFFSImpl()))
46+ SPIFFSFS::SPIFFSFS () : FS(FSImplPtr(new SPIFFSImpl())), partitionLabel_( NULL )
4747{
4848
4949}
5050
51- bool SPIFFSFS::begin ( bool formatOnFail, const char * basePath, uint8_t maxOpenFiles )
51+ SPIFFSFS::~SPIFFSFS ( )
5252{
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_)){
5471 log_w (" SPIFFS Already Mounted!" );
5572 return true ;
5673 }
5774
5875 esp_vfs_spiffs_conf_t conf = {
5976 .base_path = basePath,
60- .partition_label = NULL ,
77+ .partition_label = partitionLabel_ ,
6178 .max_files = maxOpenFiles,
6279 .format_if_mount_failed = false
6380 };
@@ -78,8 +95,8 @@ bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFi
7895
7996void SPIFFSFS::end ()
8097{
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_ );
83100 if (err){
84101 log_e (" Unmounting SPIFFS failed! Error: %d" , err);
85102 return ;
@@ -91,7 +108,7 @@ void SPIFFSFS::end()
91108bool SPIFFSFS::format ()
92109{
93110 disableCore0WDT ();
94- esp_err_t err = esp_spiffs_format (NULL );
111+ esp_err_t err = esp_spiffs_format (partitionLabel_ );
95112 enableCore0WDT ();
96113 if (err){
97114 log_e (" Formatting SPIFFS failed! Error: %d" , err);
@@ -103,7 +120,7 @@ bool SPIFFSFS::format()
103120size_t SPIFFSFS::totalBytes ()
104121{
105122 size_t total,used;
106- if (esp_spiffs_info (NULL , &total, &used)){
123+ if (esp_spiffs_info (partitionLabel_ , &total, &used)){
107124 return 0 ;
108125 }
109126 return total;
@@ -112,7 +129,7 @@ size_t SPIFFSFS::totalBytes()
112129size_t SPIFFSFS::usedBytes ()
113130{
114131 size_t total,used;
115- if (esp_spiffs_info (NULL , &total, &used)){
132+ if (esp_spiffs_info (partitionLabel_ , &total, &used)){
116133 return 0 ;
117134 }
118135 return used;
0 commit comments