Skip to content
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

Update to SdFat 2.1.1 with UTF-8 support #8355

Merged
merged 8 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/ESP8266SdFat
Submodule ESP8266SdFat updated 860 files
17 changes: 5 additions & 12 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <SDFS.h>

#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 {
Expand Down Expand Up @@ -159,9 +159,9 @@ class SDClass {

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"; }
Expand All @@ -183,10 +183,6 @@ class SDClass {
};


// 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);
}
Expand All @@ -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;
}
Expand Down
26 changes: 13 additions & 13 deletions libraries/SDFS/src/SDFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sdfat::File32>(fd);
auto sharedFd = std::make_shared<File32>(fd);
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
}

Expand All @@ -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 = "";
Expand All @@ -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;
}
}
Expand All @@ -122,20 +122,20 @@ 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;
}
}
if (!dirFile) {
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
return DirImplPtr();
}
auto sharedDir = std::make_shared<sdfat::File32>(dirFile);
auto sharedDir = std::make_shared<File32>(dirFile);
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
free(pathStr);
return ret;
Expand All @@ -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;
Expand Down
74 changes: 37 additions & 37 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ class SDFSImpl : public FSImpl
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;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ class SDFSImpl : public FSImpl
format();
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
}
sdfat::FsDateTime::setCallback(dateTimeCB);
FsDateTime::setCallback(dateTimeCB);
return _mounted;
}

Expand Down Expand Up @@ -185,7 +185,7 @@ class SDFSImpl : public FSImpl
return (totalClusters() / blocksPerCluster());
}
size_t clusterSize() {
return blocksPerCluster() * _fs.vol()->bytesPerSector();
return _fs.vol()->bytesPerCluster();
}
size_t size() {
return (clusterSize() * totalClusters());
Expand Down Expand Up @@ -229,33 +229,33 @@ class SDFSImpl : public FSImpl
friend class SDFileImpl;
friend class SDFSDirImpl;

sdfat::SdFat* getFs()
{
SdFat* getFs() {
return &_fs;
}


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;
}
if (accessMode & AM_READ) {
mode |= sdfat::O_READ;
mode |= O_TRUNC;
}
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;
};
Expand All @@ -264,7 +264,7 @@ class SDFSImpl : public FSImpl
class SDFSFileImpl : public FileImpl
{
public:
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<sdfat::File32> fd, const char *name)
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
: _fs(fs), _fd(fd), _opened(true)
{
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
Expand Down Expand Up @@ -380,7 +380,7 @@ class SDFSFileImpl : public FileImpl
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);
}
Expand All @@ -391,7 +391,7 @@ class SDFSFileImpl : public FileImpl
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);
}
Expand All @@ -400,16 +400,16 @@ class SDFSFileImpl : public FileImpl
}

protected:
SDFSImpl* _fs;
std::shared_ptr<sdfat::File32> _fd;
std::shared_ptr<char> _name;
bool _opened;
SDFSImpl* _fs;
std::shared_ptr<File32> _fd;
std::shared_ptr<char> _name;
bool _opened;
};

class SDFSDirImpl : public DirImpl
{
public:
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat::File32> dir, const char *dirPath = nullptr)
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<File32> dir, const char *dirPath = nullptr)
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
{
if (dirPath) {
Expand Down Expand Up @@ -484,14 +484,14 @@ class SDFSDirImpl : public DirImpl
{
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);
Expand All @@ -516,17 +516,17 @@ class SDFSDirImpl : public DirImpl
}

protected:
String _pattern;
SDFSImpl* _fs;
std::shared_ptr<sdfat::File32> _dir;
bool _valid;
char _lfn[64];
time_t _time;
time_t _creation;
std::shared_ptr<char> _dirPath;
uint32_t _size;
bool _isFile;
bool _isDirectory;
String _pattern;
SDFSImpl* _fs;
std::shared_ptr<File32> _dir;
bool _valid;
char _lfn[64];
time_t _time;
time_t _creation;
std::shared_ptr<char> _dirPath;
uint32_t _size;
bool _isFile;
bool _isDirectory;
};

}; // namespace sdfs
Expand Down
7 changes: 2 additions & 5 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down