-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Fix #2750 #2763
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
Fix #2750 #2763
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,26 @@ | ||
| // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "vfs_api.h" | ||
|
|
||
| extern "C" { | ||
| #include <sys/unistd.h> | ||
| #include <sys/stat.h> | ||
| #include <dirent.h> | ||
| #include "esp_spiffs.h" | ||
| } | ||
|
|
||
| #include "SPIFFS.h" | ||
|
|
||
| using namespace fs; | ||
|
|
||
| SPIFFSFS::SPIFFSFS(FSImplPtr impl) | ||
| : FS(impl) | ||
| {} | ||
| SPIFFSImpl::SPIFFSImpl() | ||
| { | ||
| } | ||
|
|
||
| bool SPIFFSImpl::exists(const char* path) { | ||
|
||
| File f = open(path, "r"); | ||
| return (f == true) && !f.isDirectory(); | ||
| } | ||
|
|
||
| SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl())) { | ||
|
|
||
| } | ||
|
|
||
| bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles) | ||
| { | ||
|
|
@@ -68,8 +62,7 @@ void SPIFFSFS::end() | |
| } | ||
| } | ||
|
|
||
| bool SPIFFSFS::format() | ||
| { | ||
| bool SPIFFSFS::format() { | ||
| disableCore0WDT(); | ||
| esp_err_t err = esp_spiffs_format(NULL); | ||
| enableCore0WDT(); | ||
|
|
@@ -80,34 +73,21 @@ bool SPIFFSFS::format() | |
| return true; | ||
| } | ||
|
|
||
| size_t SPIFFSFS::totalBytes() | ||
| { | ||
| size_t SPIFFSFS::totalBytes() { | ||
| size_t total,used; | ||
| if(esp_spiffs_info(NULL, &total, &used)){ | ||
| return 0; | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| size_t SPIFFSFS::usedBytes() | ||
| { | ||
| size_t SPIFFSFS::usedBytes() { | ||
| size_t total,used; | ||
| if(esp_spiffs_info(NULL, &total, &used)){ | ||
| return 0; | ||
| } | ||
| return used; | ||
| } | ||
|
|
||
| bool SPIFFSFS::exists(const char* path) | ||
| { | ||
| File f = open(path, "r"); | ||
| return (f == true) && !f.isDirectory(); | ||
| } | ||
|
|
||
| bool SPIFFSFS::exists(const String& path) | ||
| { | ||
| return exists(path.c_str()); | ||
| } | ||
|
|
||
| SPIFFSFS SPIFFS; | ||
|
|
||
| SPIFFSFS SPIFFS = SPIFFSFS(FSImplPtr(new VFSImpl())); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,33 @@ | ||
| // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not remove the headers! |
||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #ifndef _SPIFFS_H_ | ||
| #define _SPIFFS_H_ | ||
| #pragma once | ||
|
||
|
|
||
| #include "FS.h" | ||
| #include "FSImpl.h" | ||
|
||
| #include "vfs_api.h" | ||
|
||
|
|
||
| namespace fs | ||
| { | ||
|
|
||
| class SPIFFSImpl : public VFSImpl | ||
| { | ||
| public: | ||
| SPIFFSImpl(); | ||
|
||
| virtual ~SPIFFSImpl() { } | ||
| virtual bool exists(const char* path); | ||
| }; | ||
|
|
||
| class SPIFFSFS : public FS | ||
| { | ||
| public: | ||
| SPIFFSFS(FSImplPtr impl); | ||
| SPIFFSFS(); | ||
| bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10); | ||
| bool format(); | ||
| size_t totalBytes(); | ||
| size_t usedBytes(); | ||
| void end(); | ||
| bool exists(const char* path); | ||
| bool exists(const String& path); | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| extern fs::SPIFFSFS SPIFFS; | ||
|
|
||
| #endif /* _SPIFFS_H_ */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not remove the headers!