10000 Update to SDFat 2.1.1 with UTF-8 support (#343) · solderparty/arduino-pico@29756de · GitHub
[go: up one dir, main page]

Skip to content

Commit 29756de

Browse files
Update to SDFat 2.1.1 with UTF-8 support (earlephilhower#343)
1 parent 1afbbab commit 29756de

File tree

5 files changed

+45
-53
lines changed

5 files changed

+45
-53
lines changed

libraries/SD/src/SD.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class SDClass {
135135
size_t size() {
136136
uint64_t sz = size64();
137137
#ifdef DEBUG_ESP_PORT
138-
if (sz > (uint64_t)SIZE_MAX) {
139-
DEBUG_ESP_PORT.printf_P(PSTR("WARNING: SD card size overflow (%lld>= 4GB). Please update source to use size64().\n"), sz);
138+
if (sz > std::numeric_limits<uint32_t>::max()) {
139+
DEBUG_ESP_PORT.printf_P(PSTR("WARNING: SD card size overflow (%lld >= 4GB). Please update source to use size64().\n"), (long long)sz);
140140
}
141141
#endif
142142
return (size_t)sz;
@@ -191,9 +191,6 @@ class SDClass {
191191

192192

193193
// Expose FatStructs.h helpers for MS-DOS date/time for use with dateTimeCallback
194-
static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) {
195-
return (year - 1980) << 9 | month << 5 | day;
196-
}
197194
static inline uint16_t FAT_YEAR(uint16_t fatDate) {
198195
return 1980 + (fatDate >> 9);
199196
}
@@ -203,9 +200,6 @@ static inline uint8_t FAT_MONTH(uint16_t fatDate) {
203200
static inline uint8_t FAT_DAY(uint16_t fatDate) {
204201
return fatDate & 0X1F;
205202
}
206-
static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) {
207-
return hour << 11 | minute << 5 | second >> 1;
208-
}
209203
static inline uint8_t FAT_HOUR(uint16_t fatTime) {
210204
return fatTime >> 11;
211205
}

libraries/SDFS/src/SDFS.cpp

Lines changed: 7 additions & 7 deletions
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,7 +90,7 @@ 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("/")
@@ -135,7 +135,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
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

Lines changed: 33 additions & 32 deletions
< 10000 td data-grid-cell-id="diff-69fe692df591869feeb4c1d38c8c917477db153713e136bab02e6b0a303df40e-156-156-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">156
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ class SDFSImpl : public FSImpl
9696
return false;
9797
}
9898
info.maxOpenFiles = 999; // TODO - not valid
99-
info.blockSize = _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector();
99+
info.blockSize = _fs.vol()->bytesPerCluster();
100100
info.pageSize = 0; // TODO ?
101101
info.maxPathLength = 255; // TODO ?
102102
info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
103-
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector());
103+
info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->bytesPerCluster());
104104
return true;
105105
}
106106

@@ -114,9 +114,9 @@ class SDFSImpl : public FSImpl
114114
info.maxOpenFiles = i.maxOpenFiles;
115115
info.maxPathLength = i.maxPathLength;
116116
#ifdef DEBUG_ESP_PORT
117-
if (i.totalBytes > (uint64_t)SIZE_MAX) {
117+
if (i.totalBytes > std::numeric_limits<uint32_t>::max()) {
118118
// This catches both total and used cases, since used must always be < total.
119-
DEBUG_ESP_PORT.printf_P(PSTR("WARNING: SD card size overflow (%lld>= 4GB). Please update source to use info64().\n"), i.totalBytes);
119+
DEBUG_ESP_PORT.printf_P(PSTR("WARNING: SD card size overflow (%lld >= 4GB). Please update source to use info64().\n"), (long long)i.totalBytes);
120120
}
121121
#endif
122122
info.totalBytes = (size_t)i.totalBytes;
@@ -155,7 +155,7 @@ class SDFSImpl : public FSImpl
155155
format();
156
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
157157
}
158-
sdfat::FsDateTime::setCallback(dateTimeCB);
158+
FsDateTime::setCallback(dateTimeCB);
159159
return _mounted;
160160
}
161161

@@ -184,7 +184,7 @@ class SDFSImpl : public FSImpl
184184
return (totalClusters() / blocksPerCluster());
185185
}
186186
size_t clusterSize() {
187-
return blocksPerCluster() * _fs.vol()->bytesPerSector();
187+
return _fs.vol()->bytesPerCluster();
188188
}
189189
size_t size() {
190190
return (clusterSize() * totalClusters());
@@ -228,7 +228,7 @@ class SDFSImpl : public FSImpl
228228
friend class SDFileImpl;
229229
friend class SDFSDirImpl;
230230

231-
sdfat::SdFat* getFs()
231+
SdFat* getFs()
232232
{
233233
return &_fs;
234234
}
@@ -245,16 +245,17 @@ class SDFSImpl : public FSImpl
245245
if (openMode & OM_TRUNCATE) {
246246
mode |= O_TRUNC;
247247
}
248-
if (accessMode & AM_READ) {
248+
if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) {
249+
mode |= O_RDWR;
250+
} else if (accessMode & AM_READ) {
249251
mode |= O_READ;
250-
}
251-
if (accessMode & AM_WRITE) {
252+
} else if (accessMode & AM_WRITE) {
252253
mode |= O_WRITE;
253254
}
254255
return mode;
255256
}
256257

257-
sdfat::SdFat _fs;
258+
SdFat _fs;
258259
SDFSConfig _cfg;
259260
bool _mounted;
260261
};
@@ -263,7 +264,7 @@ class SDFSImpl : public FSImpl
263264
class SDFSFileImpl : public FileImpl
264265
{
265266
public:
266-
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File32> fd, const char *name)
267+
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
267268
: _fs(fs), _fd(fd), _opened(true)
268269
{
269270
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
@@ -379,7 +380,7 @@ class SDFSFileImpl : public FileImpl
379380
time_t getLastWrite() override {
380381
time_t ftime = 0;
381382
if (_opened && _fd) {
382-
sdfat::DirFat_t tmp;
383+
DirFat_t tmp;
383384
if (_fd.get()->dirEntry(&tmp)) {
384385
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
385386
}
@@ -390,7 +391,7 @@ class SDFSFileImpl : public FileImpl
390391
time_t getCreationTime() override {
391392
time_t ftime = 0;
392393
if (_opened && _fd) {
393-
sdfat::DirFat_t tmp;
394+
DirFat_t tmp;
394395
if (_fd.get()->dirEntry(&tmp)) {
395396
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
396397
}
@@ -399,16 +400,16 @@ class SDFSFileImpl : public FileImpl
399400
}
400401

401402
protected:
402-
SDFSImpl* _fs;
403-
std::shared_ptr<sdfat::File32> _fd;
404-
std::shared_ptr<char> _name;
405-
bool _opened;
403+
SDFSImpl* _fs;
404+
std::shared_ptr<File32> _fd;
405+
std::shared_ptr<char> _name;
406+
bool _opened;
406407
};
407408

408409
class SDFSDirImpl : public DirImpl
409410
{
410411
public:
411-
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)
412413
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
413414
{
414415
if (dirPath) {
@@ -483,14 +484,14 @@ class SDFSDirImpl : public DirImpl
483484
{
484485
const int n = _pattern.length();
485486
do {
486-
sdfat::File32 file;
487+
File32 file;
487488
file.openNext(_dir.get(), O_READ);
488489
if (file) {
489490
_valid = 1;
490491
_size = file.fileSize();
491492
_isFile = file.isFile();
492493
_isDirectory = file.isDir();
493-
sdfat::DirFat_t tmp;
494+
DirFat_t tmp;
494495
if (file.dirEntry(&tmp)) {
495496
_time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
496497
_creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
@@ -515,17 +516,17 @@ class SDFSDirImpl : public DirImpl
515516
}
516517

517518
protected:
518-
String _pattern;
519-
SDFSImpl* _fs;
520-
std::shared_ptr<sdfat::File32> _dir;
521-
bool _valid;
522-
char _lfn[64];
523-
time_t _time;
524-
time_t _creation;
525-
std::shared_ptr<char> _dirPath;
526-
uint32_t _size;
527-
bool _isFile;
528-
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;
529530
};
530531

531532
}; // namespace sdfs

libraries/SdFat

Submodule SdFat updated 860 files

tests/common.sh

Lines changed: 2 additions & 5 deletions
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
/Adafruit_TinyUSB_Arduino/

0 commit comments

Comments
 (0)
0