Skip to content

Add partition label argument to SPIFFS #4443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions libraries/SPIFFS/src/SPIFFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,31 @@ bool SPIFFSImpl::exists(const char* path)
return (f == true) && !f.isDirectory();
}

SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl()))
SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl())), partitionLabel_(NULL)
{

}

bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles)
SPIFFSFS::~SPIFFSFS()
{
if(esp_spiffs_mounted(NULL)){
if (partitionLabel_){
free(partitionLabel_);
partitionLabel_ = NULL;
}
}

bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
{
partitionLabel_ = partitionLabel ? strdup(partitionLabel) : NULL;

if(esp_spiffs_mounted(partitionLabel_)){
log_w("SPIFFS Already Mounted!");
return true;
}

esp_vfs_spiffs_conf_t conf = {
.base_path = basePath,
.partition_label = NULL,
.partition_label = partitionLabel_,
.max_files = maxOpenFiles,
.format_if_mount_failed = false
};
Expand All @@ -78,8 +88,8 @@ bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFi

void SPIFFSFS::end()
{
if(esp_spiffs_mounted(NULL)){
esp_err_t err = esp_vfs_spiffs_unregister(NULL);
if(esp_spiffs_mounted(partitionLabel_)){
esp_err_t err = esp_vfs_spiffs_unregister(partitionLabel_);
if(err){
log_e("Unmounting SPIFFS failed! Error: %d", err);
return;
Expand All @@ -91,7 +101,7 @@ void SPIFFSFS::end()
bool SPIFFSFS::format()
{
disableCore0WDT();
esp_err_t err = esp_spiffs_format(NULL);
esp_err_t err = esp_spiffs_format(partitionLabel_);
enableCore0WDT();
if(err){
log_e("Formatting SPIFFS failed! Error: %d", err);
Expand All @@ -103,7 +113,7 @@ bool SPIFFSFS::format()
size_t SPIFFSFS::totalBytes()
{
size_t total,used;
if(esp_spiffs_info(NULL, &total, &used)){
if(esp_spiffs_info(partitionLabel_, &total, &used)){
return 0;
}
return total;
Expand All @@ -112,7 +122,7 @@ size_t SPIFFSFS::totalBytes()
size_t SPIFFSFS::usedBytes()
{
size_t total,used;
if(esp_spiffs_info(NULL, &total, &used)){
if(esp_spiffs_info(partitionLabel_, &total, &used)){
return 0;
}
return used;
Expand Down
6 changes: 5 additions & 1 deletion libraries/SPIFFS/src/SPIFFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ class SPIFFSFS : public FS
{
public:
SPIFFSFS();
bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10);
~SPIFFSFS();
bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10, const char * partitionLabel=NULL);
bool format();
size_t totalBytes();
size_t usedBytes();
void end();

private:
char * partitionLabel_;
};

}
Expand Down