Skip to content

Commit 21e3188

Browse files
committed
WIP commit for implementation of SD and FS performance increases on the ESP32 platfor
1 parent 82ef749 commit 21e3188

File tree

10 files changed

+675
-312
lines changed

10 files changed

+675
-312
lines changed

libraries/FS.slow/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=FS
2+
version=1.0
3+
author=Hristo Gochkov, Ivan Grokhtkov
4+
maintainer=Hristo Gochkov <hristo@espressif.com>
5+
sentence=ESP32 File System
6+
paragraph=
7+
category=Data Storage
8+
url=
9+
architectures=esp32

libraries/FS.slow/src/FS.cpp

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
/*
2+
FS.cpp - file system wrapper
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "FS.h"
22+
#include "FSImpl.h"
23+
24+
using namespace fs;
25+
26+
size_t File::write(uint8_t c)
27+
{
28+
if (!_p) {
29+
return 0;
30+
}
31+
32+
return _p->write(&c, 1);
33+
}
34+
35+
time_t File::getLastWrite()
36+
{
37+
if (!_p) {
38+
return 0;
39+
}
40+
41+
return _p->getLastWrite();
42+
}
43+
44+
size_t File::write(const uint8_t *buf, size_t size)
45+
{
46+
if (!_p) {
47+
return 0;
48+
}
49+
50+
return _p->write(buf, size);
51+
}
52+
53+
int File::available()
54+
{
55+
if (!_p) {
56+
return false;
57+
}
58+
59+
return _p->size() - _p->position();
60+
}
61+
62+
int File::read()
63+
{
64+
if (!_p) {
65+
return -1;
66+
}
67+
68+
uint8_t result;
69+
if (_p->read(&result, 1) != 1) {
70+
return -1;
71+
}
72+
73+
return result;
74+
}
75+
76+
size_t File::read(uint8_t* buf, size_t size)
77+
{
78+
if (!_p) {
79+
return -1;
80+
}
81+
82+
return _p->read(buf, size);
83+
}
84+
85+
int File::peek()
86+
{
87+
if (!_p) {
88+
return -1;
89+
}
90+
91+
size_t curPos = _p->position();
92+
int result = read();
93+
seek(curPos, SeekSet);
94+
return result;
95+
}
96+
97+
void File::flush()
98+
{
99+
if (!_p) {
100+
return;
101+
}
102+
103+
_p->flush();
104+
}
105+
106+
bool File::seek(uint32_t pos, SeekMode mode)
107+
{
108+
if (!_p) {
109+
return false;
110+
}
111+
112+
return _p->seek(pos, mode);
113+
}
114+
115+
size_t File::position() const
116+
{
117+
if (!_p) {
118+
return 0;
119+
}
120+
121+
return _p->position();
122+
}
123+
124+
size_t File::size() const
125+
{
126+
if (!_p) {
127+
return 0;
128+
}
129+
130+
return _p->size();
131+
}
132+
133+
void File::close()
134+
{
135+
if (_p) {
136+
_p->close();
137+
_p = nullptr;
138+
}
139+
}
140+
141+
File::operator bool() const
142+
{
143+
return !!_p;
144+
}
145+
146+
const char* File::name() const
147+
{
148+
if (!_p) {
149+
return nullptr;
150+
}
151+
152+
return _p->name();
153+
}
154+
155+
//to implement
156+
boolean File::isDirectory(void)
157+
{
158+
if (!_p) {
159+
return false;
160+
}
161+
return _p->isDirectory();
162+
}
163+
164+
File File::openNextFile(const char* mode)
165+
{
166+
if (!_p) {
167+
return File();
168+
}
169+
return _p->openNextFile(mode);
170+
}
171+
172+
void File::rewindDirectory(void)
173+
{
174+
if (!_p) {
175+
return;
176+
}
177+
_p->rewindDirectory();
178+
}
179+
180+
File FS::open(const String& path, const char* mode)
181+
{
182+
return open(path.c_str(), mode);
183+
}
184+
185+
File FS::open(const char* path, const char* mode)
186+
{
187+
if (!_impl) {
188+
return File();
189+
}
190+
191+
return File(_impl->open(path, mode));
192+
}
193+
194+
bool FS::exists(const char* path)
195+
{
196+
if (!_impl) {
197+
return false;
198+
}
199+
return _impl->exists(path);
200+
}
201+
202+
bool FS::exists(const String& path)
203+
{
204+
return exists(path.c_str());
205+
}
206+
207+
bool FS::remove(const char* path)
208+
{
209+
if (!_impl) {
210+
return false;
211+
}
212+
return _impl->remove(path);
213+
}
214+
215+
bool FS::remove(const String& path)
216+
{
217+
return remove(path.c_str());
218+
}
219+
220+
bool FS::rename(const char* pathFrom, const char* pathTo)
221+
{
222+
if (!_impl) {
223+
return false;
224+
}
225+
return _impl->rename(pathFrom, pathTo);
226+
}
227+
228+
bool FS::rename(const String& pathFrom, const String& pathTo)
229+
{
230+
return rename(pathFrom.c_str(), pathTo.c_str());
231+
}
232+
233+
234+
bool FS::mkdir(const char *path)
235+
{
236+
if (!_impl) {
237+
return false;
238+
}
239+
return _impl->mkdir(path);
240+
}
241+
242+
bool FS::mkdir(const String &path)
243+
{
244+
return mkdir(path.c_str());
245+
}
246+
247+
bool FS::rmdir(const char *path)
248+
{
249+
if (!_impl) {
250+
return false;
251+
}
252+
return _impl->rmdir(path);
253+
}
254+
255+
bool FS::rmdir(const String &path)
256+
{
257+
return rmdir(path.c_str());
258+
}
259+
260+
261+
void FSImpl::mountpoint(const char * mp)
262+
{
263+
_mountpoint = mp;
264+
}
265+
266+
const char * FSImpl::mountpoint()
267+
{
268+
return _mountpoint;
269+
}

0 commit comments

Comments
 (0)