Skip to content

Commit a00b2d7

Browse files
Update to SdFat 2.1.1 with UTF-8 support (#8355)
1 parent 7d971fa commit a00b2d7

File tree

6 files changed

+63
-69
lines changed

6 files changed

+63
-69
lines changed

libraries/ESP8266SdFat

Submodule ESP8266SdFat updated 860 files

libraries/SD/src/SD.h

+5-12
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#include <SDFS.h>
2626

2727
#undef FILE_READ
28-
#define FILE_READ sdfat::O_READ
28+
#define FILE_READ ((uint8_t)O_READ)
2929
#undef FILE_WRITE
30-
#define FILE_WRITE (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT | sdfat::O_APPEND)
30+
#define FILE_WRITE ((uint8_t)(O_READ | O_WRITE | O_CREAT | O_APPEND))
3131

3232

3333
class SDClass {
@@ -159,9 +159,9 @@ class SDClass {
159159

160160
private:
161161
const char *getMode(uint8_t mode) {
162-
bool read = (mode & sdfat::O_READ) ? true : false;
163-
bool write = (mode & sdfat::O_WRITE) ? true : false;
164-
bool append = (mode & sdfat::O_APPEND) ? true : false;
162+
bool read = (mode & O_READ) ? true : false;
163+
bool write = (mode & O_WRITE) ? true : false;
164+
bool append = (mode & O_APPEND) ? true : false;
165165
if ( read & !write ) { return "r"; }
166166
else if ( !read & write & !append ) { return "w+"; }
167167
else if ( !read & write & append ) { return "a"; }
@@ -183,10 +183,6 @@ class SDClass {
183183
};
184184

185185

186-
// Expose FatStructs.h helpers for MS-DOS date/time for use with dateTimeCallback
187-
static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) {
188-
return (year - 1980) << 9 | month << 5 | day;
189-
}
190186
static inline uint16_t FAT_YEAR(uint16_t fatDate) {
191187
return 1980 + (fatDate >> 9);
192188
}
@@ -196,9 +192,6 @@ static inline uint8_t FAT_MONTH(uint16_t fatDate) {
196192
static inline uint8_t FAT_DAY(uint16_t fatDate) {
197193
return fatDate & 0X1F;
198194
}
199-
static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) {
200-
return hour << 11 | minute << 5 | second >> 1;
201-
}
202195
static inline uint8_t FAT_HOUR(uint16_t fatTime) {
203196
return fatTime >> 11;
204197
}

libraries/SDFS/src/SDFS.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
6464
}
6565
free(pathStr);
6666
}
67-
sdfat::File32 fd = _fs.open(path, flags);
67+
File32 fd = _fs.open(path, flags);
6868
if (!fd) {
6969
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
7070
&fd, path, openMode, accessMode);
7171
return FileImplPtr();
7272
}
73-
auto sharedFd = std::make_shared<sdfat::File32>(fd);
73+
auto sharedFd = std::make_shared<File32>(fd);
7474
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
7575
}
7676

@@ -90,14 +90,14 @@ DirImplPtr SDFSImpl::openDir(const char* path)
9090
}
9191
// At this point we have a name of "/blah/blah/blah" or "blah" or ""
9292
// If that references a directory, just open it and we're done.
93-
sdfat::File32 dirFile;
93+
File32 dirFile;
9494
const char *filter = "";
9595
if (!pathStr[0]) {
9696
// openDir("") === openDir("/")
97-
dirFile = _fs.open("/", sdfat::O_RDONLY);
97+
dirFile = _fs.open("/", O_RDONLY);
9898
filter = "";
9999
} else if (_fs.exists(pathStr)) {
100-
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
100+
dirFile = _fs.open(pathStr, O_RDONLY);
101101
if (dirFile.isDir()) {
102102
// Easy peasy, path specifies an existing dir!
103103
filter = "";
@@ -107,12 +107,12 @@ DirImplPtr SDFSImpl::openDir(const char* path)
107107
char *ptr = strrchr(pathStr, '/');
108108
if (!ptr) {
109109
// No slashes, open the root dir
110-
dirFile = _fs.open("/", sdfat::O_RDONLY);
110+
dirFile = _fs.open("/", O_RDONLY);
111111
filter = pathStr;
112112
} else {
113113
// We've got slashes, open the dir one up
114114
*ptr = 0; // Remove slash, truncare string
115-
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
115+
dirFile = _fs.open(pathStr, O_RDONLY);
116116
filter = ptr + 1;
117117
}
118118
}
@@ -122,20 +122,20 @@ DirImplPtr SDFSImpl::openDir(const char* path)
122122
char *ptr = strrchr(pathStr, '/');
123123
if (!ptr) {
124124
// No slashes, open the root dir
125-
dirFile = _fs.open("/", sdfat::O_RDONLY);
125+
dirFile = _fs.open("/", O_RDONLY);
126126
filter = pathStr;
127127
} else {
128128
// We've got slashes, open the dir one up
129129
*ptr = 0; // Remove slash, truncare string
130-
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
130+
dirFile = _fs.open(pathStr, O_RDONLY);
131131
filter = ptr + 1;
132132
}
133133
}
134134
if (!dirFile) {
135135
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
136136
return DirImplPtr();
137137
}
138-
auto sharedDir = std::make_shared<sdfat::File32>(dirFile);
138+
auto sharedDir = std::make_shared<File32>(dirFile);
139139
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
140140
free(pathStr);
141141
return ret;
@@ -145,12 +145,12 @@ bool SDFSImpl::format() {
145145
if (_mounted) {
146146
return false;
147147
}
148-
sdfat::SdCardFactory cardFactory;
149-
sdfat::SdCard* card = cardFactory.newCard(sdfat::SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
148+
SdCardFactory cardFactory;
149+
SdCard* card = cardFactory.newCard(SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
150150
if (!card || card->errorCode()) {
151151
return false;
152152
}
153-
sdfat::FatFormatter fatFormatter;
153+
FatFormatter fatFormatter;
154154
uint8_t *sectorBuffer = new uint8_t[512];
155155
bool ret = fatFormatter.format(card, sectorBuffer, nullptr);
156156
delete[] sectorBuffer;

libraries/SDFS/src/SDFS.h

+37-37
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ class SDFSImpl : public FSImpl
9797
return false;
9898
}
9999
info.maxOpenFiles = 999; // TODO - not valid
100-
info.blockSize = _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector();
100+
info.blockSize = _fs.vol()->bytesPerCluster();
101101
info.pageSize = 0; // TODO ?
102102
info.maxPathLength = 255; // TODO ?
103103
info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
104-
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector());
104+
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->bytesPerCluster());
105105
return true;
106106
}
107107

@@ -156,7 +156,7 @@ class SDFSImpl : public FSImpl
156156
format();
157157
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
158158
}
159-
sdfat::FsDateTime::setCallback(dateTimeCB);
159+
FsDateTime::setCallback(dateTimeCB);
160160
return _mounted;
161161
}
162162

@@ -185,7 +185,7 @@ class SDFSImpl : public FSImpl
185185
return (totalClusters() / blocksPerCluster());
186186
}
187187
size_t clusterSize() {
188-
return blocksPerCluster() * _fs.vol()->bytesPerSector();
188+
return _fs.vol()->bytesPerCluster();
189189
}
190190
size_t size() {
191191
return (clusterSize() * totalClusters());
@@ -229,33 +229,33 @@ class SDFSImpl : public FSImpl
229229
friend class SDFileImpl;
230230
friend class SDFSDirImpl;
231231

232-
sdfat::SdFat* getFs()
233-
{
232+
SdFat* getFs() {
234233
return &_fs;
235234
}
236235

237236

238237
static uint8_t _getFlags(OpenMode openMode, AccessMode accessMode) {
239238
uint8_t mode = 0;
240239
if (openMode & OM_CREATE) {
241-
mode |= sdfat::O_CREAT;
240+
mode |= O_CREAT;
242241
}
243242
if (openMode & OM_APPEND) {
244-
mode |= sdfat::O_AT_END;
243+
mode |= O_AT_END;
245244
}
246245
if (openMode & OM_TRUNCATE) {
247-
mode |= sdfat::O_TRUNC;
248-
}
249-
if (accessMode & AM_READ) {
250-
mode |= sdfat::O_READ;
246+
mode |= O_TRUNC;
251247
}
252-
if (accessMode & AM_WRITE) {
253-
mode |= sdfat::O_WRITE;
248+
if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) {
249+
mode |= O_RDWR;
250+
} else if (accessMode & AM_READ) {
251+
mode |= O_READ;
252+
} else if (accessMode & AM_WRITE) {
253+
mode |= O_WRITE;
254254
}
255255
return mode;
256256
}
257257

258-
sdfat::SdFat _fs;
258+
SdFat _fs;
259259
SDFSConfig _cfg;
260260
bool _mounted;
261261
};
@@ -264,7 +264,7 @@ class SDFSImpl : public FSImpl
264264
class SDFSFileImpl : public FileImpl
265265
{
266266
public:
267-
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File32> fd, const char *name)
267+
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
268268
: _fs(fs), _fd(fd), _opened(true)
269269
{
270270
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
@@ -380,7 +380,7 @@ class SDFSFileImpl : public FileImpl
380380
time_t getLastWrite() override {
381381
time_t ftime = 0;
382382
if (_opened && _fd) {
383-
sdfat::DirFat_t tmp;
383+
DirFat_t tmp;
384384
if (_fd.get()->dirEntry(&tmp)) {
385385
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
386386
}
@@ -391,7 +391,7 @@ class SDFSFileImpl : public FileImpl
391391
time_t getCreationTime() override {
392392
time_t ftime = 0;
393393
if (_opened && _fd) {
394-
sdfat::DirFat_t tmp;
394+
DirFat_t tmp;
395395
if (_fd.get()->dirEntry(&tmp)) {
396396
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
397397
}
@@ -400,16 +400,16 @@ class SDFSFileImpl : public FileImpl
400400
}
401401

402402
protected:
403-
SDFSImpl* _fs;
404-
std::shared_ptr<sdfat::File32> _fd;
405-
std::shared_ptr<char> _name;
406-
bool _opened;
403+
SDFSImpl* _fs;
404+
std::shared_ptr<File32> _fd;
405+
std::shared_ptr<char> _name;
406+
bool _opened;
407407
};
408408

409409
class SDFSDirImpl : public DirImpl
410410
{
411411
public:
412-
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File32> dir, const char *dirPath = nullptr)
412+
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<File32> dir, const char *dirPath = nullptr)
413413
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
414414
{
415415
if (dirPath) {
@@ -484,14 +484,14 @@ class SDFSDirImpl : public DirImpl
484484
{
485485
const int n = _pattern.length();
486486
do {
487-
sdfat::File32 file;
488-
file.openNext(_dir.get(), sdfat::O_READ);
487+
File32 file;
488+
file.openNext(_dir.get(), O_READ);
489489
if (file) {
490490
_valid = 1;
491491
_size = file.fileSize();
492492
_isFile = file.isFile();
493493
_isDirectory = file.isDir();
494-
sdfat::DirFat_t tmp;
494+
DirFat_t tmp;
495495
if (file.dirEntry(&tmp)) {
496496
_time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
497497
_creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
@@ -516,17 +516,17 @@ class SDFSDirImpl : public DirImpl
516516
}
517517

518518
protected:
519-
String _pattern;
520-
SDFSImpl* _fs;
521-
std::shared_ptr<sdfat::File32> _dir;
522-
bool _valid;
523-
char _lfn[64];
524-
time_t _time;
525-
time_t _creation;
526-
std::shared_ptr<char> _dirPath;
527-
uint32_t _size;
528-
bool _isFile;
529-
bool _isDirectory;
519+
String _pattern;
520+
SDFSImpl* _fs;
521+
std::shared_ptr<File32> _dir;
522+
bool _valid;
523+
char _lfn[64];
524+
time_t _time;
525+
time_t _creation;
526+
std::shared_ptr<char> _dirPath;
527+
uint32_t _size;
528+
bool _isFile;
529+
bool _isDirectory;
530530
};
531531

532532
}; // namespace sdfs

tests/common.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ function skip_ino()
99
read -d '' skiplist << EOL || true
1010
/#attic/
1111
/AvrAdcLogger/
12-
/BackwardCompatibility/
1312
/examplesV1/
14-
/ExFatFormatter/
15-
/ExFatLogger/
16-
/ExFatUnicodeTest/
1713
/RtcTimestampTest/
1814
/SoftwareSpi/
19-
/STM32Test/
15+
/TeensyDmaAdcLogger/
2016
/TeensyRtcTimestamp/
2117
/TeensySdioDemo/
18+
/TeensySdioLogger/
2219
/UserChipSelectFunction/
2320
/UserSPIDriver/
2421
EOL

tests/host/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,16 @@ CORE_CPP_FILES := \
104104
FatLib/FatFilePrint.cpp \
105105
FatLib/FatFileSFN.cpp \
106106
FatLib/FatFormatter.cpp \
107+
FatLib/FatName.cpp \
107108
FatLib/FatVolume.cpp \
108109
FatLib/FatPartition.cpp \
109110
common/FmtNumber.cpp \
111+
common/FsCache.cpp \
110112
common/FsStructs.cpp \
111113
common/FsDateTime.cpp \
112-
common/PrintBasic.cpp \
114+
common/FsUtf.cpp \
115+
common/FsName.cpp \
116+
common/upcase.cpp \
113117
) \
114118
$(abspath $(LIBRARIES_PATH)/SDFS/src/SDFS.cpp) \
115119
$(abspath $(LIBRARIES_PATH)/SD/src/SD.cpp) \

0 commit comments

Comments
 (0)