From a00b2d7091032b3ec1de27944b87d845432ad8cc Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 5 Nov 2021 08:41:55 -0700 Subject: [PATCH] Update to SdFat 2.1.1 with UTF-8 support (#8355) --- libraries/ESP8266SdFat | 2 +- libraries/SD/src/SD.h | 17 +++------ libraries/SDFS/src/SDFS.cpp | 26 ++++++------- libraries/SDFS/src/SDFS.h | 74 ++++++++++++++++++------------------- tests/common.sh | 7 +--- tests/host/Makefile | 6 ++- 6 files changed, 63 insertions(+), 69 deletions(-) diff --git a/libraries/ESP8266SdFat b/libraries/ESP8266SdFat index 9472c8614..3a6b688b1 160000 --- a/libraries/ESP8266SdFat +++ b/libraries/ESP8266SdFat @@ -1 +1 @@ -Subproject commit 9472c8614033efdaa6064906e7065963581746af +Subproject commit 3a6b688b1b5112d149295813660ef9b2b7cc0ee5 diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index b563e2cd0..8101268a0 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -25,9 +25,9 @@ #include #undef FILE_READ -#define FILE_READ sdfat::O_READ +#define FILE_READ ((uint8_t)O_READ) #undef FILE_WRITE -#define FILE_WRITE (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT | sdfat::O_APPEND) +#define FILE_WRITE ((uint8_t)(O_READ | O_WRITE | O_CREAT | O_APPEND)) class SDClass { @@ -159,9 +159,9 @@ public: private: const char *getMode(uint8_t mode) { - bool read = (mode & sdfat::O_READ) ? true : false; - bool write = (mode & sdfat::O_WRITE) ? true : false; - bool append = (mode & sdfat::O_APPEND) ? true : false; + bool read = (mode & O_READ) ? true : false; + bool write = (mode & O_WRITE) ? true : false; + bool append = (mode & O_APPEND) ? true : false; if ( read & !write ) { return "r"; } else if ( !read & write & !append ) { return "w+"; } else if ( !read & write & append ) { return "a"; } @@ -183,10 +183,6 @@ private: }; -// Expose FatStructs.h helpers for MS-DOS date/time for use with dateTimeCallback -static inline uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day) { - return (year - 1980) << 9 | month << 5 | day; -} static inline uint16_t FAT_YEAR(uint16_t fatDate) { return 1980 + (fatDate >> 9); } @@ -196,9 +192,6 @@ static inline uint8_t FAT_MONTH(uint16_t fatDate) { static inline uint8_t FAT_DAY(uint16_t fatDate) { return fatDate & 0X1F; } -static inline uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second) { - return hour << 11 | minute << 5 | second >> 1; -} static inline uint8_t FAT_HOUR(uint16_t fatTime) { return fatTime >> 11; } diff --git a/libraries/SDFS/src/SDFS.cpp b/libraries/SDFS/src/SDFS.cpp index e7a891a08..5725a6ae0 100644 --- a/libraries/SDFS/src/SDFS.cpp +++ b/libraries/SDFS/src/SDFS.cpp @@ -64,13 +64,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces } free(pathStr); } - sdfat::File32 fd = _fs.open(path, flags); + File32 fd = _fs.open(path, flags); if (!fd) { DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d", &fd, path, openMode, accessMode); return FileImplPtr(); } - auto sharedFd = std::make_shared(fd); + auto sharedFd = std::make_shared(fd); return std::make_shared(this, sharedFd, path); } @@ -90,14 +90,14 @@ DirImplPtr SDFSImpl::openDir(const char* path) } // At this point we have a name of "/blah/blah/blah" or "blah" or "" // If that references a directory, just open it and we're done. - sdfat::File32 dirFile; + File32 dirFile; const char *filter = ""; if (!pathStr[0]) { // openDir("") === openDir("/") - dirFile = _fs.open("/", sdfat::O_RDONLY); + dirFile = _fs.open("/", O_RDONLY); filter = ""; } else if (_fs.exists(pathStr)) { - dirFile = _fs.open(pathStr, sdfat::O_RDONLY); + dirFile = _fs.open(pathStr, O_RDONLY); if (dirFile.isDir()) { // Easy peasy, path specifies an existing dir! filter = ""; @@ -107,12 +107,12 @@ DirImplPtr SDFSImpl::openDir(const char* path) char *ptr = strrchr(pathStr, '/'); if (!ptr) { // No slashes, open the root dir - dirFile = _fs.open("/", sdfat::O_RDONLY); + dirFile = _fs.open("/", O_RDONLY); filter = pathStr; } else { // We've got slashes, open the dir one up *ptr = 0; // Remove slash, truncare string - dirFile = _fs.open(pathStr, sdfat::O_RDONLY); + dirFile = _fs.open(pathStr, O_RDONLY); filter = ptr + 1; } } @@ -122,12 +122,12 @@ DirImplPtr SDFSImpl::openDir(const char* path) char *ptr = strrchr(pathStr, '/'); if (!ptr) { // No slashes, open the root dir - dirFile = _fs.open("/", sdfat::O_RDONLY); + dirFile = _fs.open("/", O_RDONLY); filter = pathStr; } else { // We've got slashes, open the dir one up *ptr = 0; // Remove slash, truncare string - dirFile = _fs.open(pathStr, sdfat::O_RDONLY); + dirFile = _fs.open(pathStr, O_RDONLY); filter = ptr + 1; } } @@ -135,7 +135,7 @@ DirImplPtr SDFSImpl::openDir(const char* path) DEBUGV("SDFSImpl::openDir: path=`%s`\n", path); return DirImplPtr(); } - auto sharedDir = std::make_shared(dirFile); + auto sharedDir = std::make_shared(dirFile); auto ret = std::make_shared(filter, this, sharedDir, pathStr); free(pathStr); return ret; @@ -145,12 +145,12 @@ bool SDFSImpl::format() { if (_mounted) { return false; } - sdfat::SdCardFactory cardFactory; - sdfat::SdCard* card = cardFactory.newCard(sdfat::SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings)); + SdCardFactory cardFactory; + SdCard* card = cardFactory.newCard(SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings)); if (!card || card->errorCode()) { return false; } - sdfat::FatFormatter fatFormatter; + FatFormatter fatFormatter; uint8_t *sectorBuffer = new uint8_t[512]; bool ret = fatFormatter.format(card, sectorBuffer, nullptr); delete[] sectorBuffer; diff --git a/libraries/SDFS/src/SDFS.h b/libraries/SDFS/src/SDFS.h index 542be537c..6e13cdf24 100644 --- a/libraries/SDFS/src/SDFS.h +++ b/libraries/SDFS/src/SDFS.h @@ -97,11 +97,11 @@ public: return false; } info.maxOpenFiles = 999; // TODO - not valid - info.blockSize = _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector(); + info.blockSize = _fs.vol()->bytesPerCluster(); info.pageSize = 0; // TODO ? info.maxPathLength = 255; // TODO ? info.totalBytes =_fs.vol()->clusterCount() * info.blockSize; - info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector()); + info.usedBytes = info.totalBytes - (_fs.vol()->freeClusterCount() * _fs.vol()->bytesPerCluster()); return true; } @@ -156,7 +156,7 @@ public: format(); _mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings); } - sdfat::FsDateTime::setCallback(dateTimeCB); + FsDateTime::setCallback(dateTimeCB); return _mounted; } @@ -185,7 +185,7 @@ public: return (totalClusters() / blocksPerCluster()); } size_t clusterSize() { - return blocksPerCluster() * _fs.vol()->bytesPerSector(); + return _fs.vol()->bytesPerCluster(); } size_t size() { return (clusterSize() * totalClusters()); @@ -229,8 +229,7 @@ protected: friend class SDFileImpl; friend class SDFSDirImpl; - sdfat::SdFat* getFs() - { + SdFat* getFs() { return &_fs; } @@ -238,24 +237,25 @@ protected: static uint8_t _getFlags(OpenMode openMode, AccessMode accessMode) { uint8_t mode = 0; if (openMode & OM_CREATE) { - mode |= sdfat::O_CREAT; + mode |= O_CREAT; } if (openMode & OM_APPEND) { - mode |= sdfat::O_AT_END; + mode |= O_AT_END; } if (openMode & OM_TRUNCATE) { - mode |= sdfat::O_TRUNC; + mode |= O_TRUNC; } - if (accessMode & AM_READ) { - mode |= sdfat::O_READ; - } - if (accessMode & AM_WRITE) { - mode |= sdfat::O_WRITE; + if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) { + mode |= O_RDWR; + } else if (accessMode & AM_READ) { + mode |= O_READ; + } else if (accessMode & AM_WRITE) { + mode |= O_WRITE; } return mode; } - sdfat::SdFat _fs; + SdFat _fs; SDFSConfig _cfg; bool _mounted; }; @@ -264,7 +264,7 @@ protected: class SDFSFileImpl : public FileImpl { public: - SDFSFileImpl(SDFSImpl *fs, std::shared_ptr fd, const char *name) + SDFSFileImpl(SDFSImpl *fs, std::shared_ptr fd, const char *name) : _fs(fs), _fd(fd), _opened(true) { _name = std::shared_ptr(new char[strlen(name) + 1], std::default_delete()); @@ -380,7 +380,7 @@ public: time_t getLastWrite() override { time_t ftime = 0; if (_opened && _fd) { - sdfat::DirFat_t tmp; + DirFat_t tmp; if (_fd.get()->dirEntry(&tmp)) { ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime); } @@ -391,7 +391,7 @@ public: time_t getCreationTime() override { time_t ftime = 0; if (_opened && _fd) { - sdfat::DirFat_t tmp; + DirFat_t tmp; if (_fd.get()->dirEntry(&tmp)) { ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime); } @@ -400,16 +400,16 @@ public: } protected: - SDFSImpl* _fs; - std::shared_ptr _fd; - std::shared_ptr _name; - bool _opened; + SDFSImpl* _fs; + std::shared_ptr _fd; + std::shared_ptr _name; + bool _opened; }; class SDFSDirImpl : public DirImpl { public: - SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr dir, const char *dirPath = nullptr) + SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr dir, const char *dirPath = nullptr) : _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr) { if (dirPath) { @@ -484,14 +484,14 @@ public: { const int n = _pattern.length(); do { - sdfat::File32 file; - file.openNext(_dir.get(), sdfat::O_READ); + File32 file; + file.openNext(_dir.get(), O_READ); if (file) { _valid = 1; _size = file.fileSize(); _isFile = file.isFile(); _isDirectory = file.isDir(); - sdfat::DirFat_t tmp; + DirFat_t tmp; if (file.dirEntry(&tmp)) { _time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime); _creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime); @@ -516,17 +516,17 @@ public: } protected: - String _pattern; - SDFSImpl* _fs; - std::shared_ptr _dir; - bool _valid; - char _lfn[64]; - time_t _time; - time_t _creation; - std::shared_ptr _dirPath; - uint32_t _size; - bool _isFile; - bool _isDirectory; + String _pattern; + SDFSImpl* _fs; + std::shared_ptr _dir; + bool _valid; + char _lfn[64]; + time_t _time; + time_t _creation; + std::shared_ptr _dirPath; + uint32_t _size; + bool _isFile; + bool _isDirectory; }; }; // namespace sdfs diff --git a/tests/common.sh b/tests/common.sh index a99ff6a9c..b6ce2fe61 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -9,16 +9,13 @@ function skip_ino() read -d '' skiplist << EOL || true /#attic/ /AvrAdcLogger/ -/BackwardCompatibility/ /examplesV1/ -/ExFatFormatter/ -/ExFatLogger/ -/ExFatUnicodeTest/ /RtcTimestampTest/ /SoftwareSpi/ -/STM32Test/ +/TeensyDmaAdcLogger/ /TeensyRtcTimestamp/ /TeensySdioDemo/ +/TeensySdioLogger/ /UserChipSelectFunction/ /UserSPIDriver/ EOL diff --git a/tests/host/Makefile b/tests/host/Makefile index 8cb9d8929..a2353a084 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -104,12 +104,16 @@ CORE_CPP_FILES := \ FatLib/FatFilePrint.cpp \ FatLib/FatFileSFN.cpp \ FatLib/FatFormatter.cpp \ + FatLib/FatName.cpp \ FatLib/FatVolume.cpp \ FatLib/FatPartition.cpp \ common/FmtNumber.cpp \ + common/FsCache.cpp \ common/FsStructs.cpp \ common/FsDateTime.cpp \ - common/PrintBasic.cpp \ + common/FsUtf.cpp \ + common/FsName.cpp \ + common/upcase.cpp \ ) \ $(abspath $(LIBRARIES_PATH)/SDFS/src/SDFS.cpp) \ $(abspath $(LIBRARIES_PATH)/SD/src/SD.cpp) \