mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Update to SdFat 2.1.1 with UTF-8 support (#8355)
This commit is contained in:
parent
7d971fa45b
commit
a00b2d7091
@ -1 +1 @@
|
|||||||
Subproject commit 9472c8614033efdaa6064906e7065963581746af
|
Subproject commit 3a6b688b1b5112d149295813660ef9b2b7cc0ee5
|
@ -25,9 +25,9 @@
|
|||||||
#include <SDFS.h>
|
#include <SDFS.h>
|
||||||
|
|
||||||
#undef FILE_READ
|
#undef FILE_READ
|
||||||
#define FILE_READ sdfat::O_READ
|
#define FILE_READ ((uint8_t)O_READ)
|
||||||
#undef FILE_WRITE
|
#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 {
|
class SDClass {
|
||||||
@ -159,9 +159,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const char *getMode(uint8_t mode) {
|
const char *getMode(uint8_t mode) {
|
||||||
bool read = (mode & sdfat::O_READ) ? true : false;
|
bool read = (mode & O_READ) ? true : false;
|
||||||
bool write = (mode & sdfat::O_WRITE) ? true : false;
|
bool write = (mode & O_WRITE) ? true : false;
|
||||||
bool append = (mode & sdfat::O_APPEND) ? true : false;
|
bool append = (mode & O_APPEND) ? true : false;
|
||||||
if ( read & !write ) { return "r"; }
|
if ( read & !write ) { return "r"; }
|
||||||
else if ( !read & write & !append ) { return "w+"; }
|
else if ( !read & write & !append ) { return "w+"; }
|
||||||
else if ( !read & write & append ) { return "a"; }
|
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) {
|
static inline uint16_t FAT_YEAR(uint16_t fatDate) {
|
||||||
return 1980 + (fatDate >> 9);
|
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) {
|
static inline uint8_t FAT_DAY(uint16_t fatDate) {
|
||||||
return fatDate & 0X1F;
|
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) {
|
static inline uint8_t FAT_HOUR(uint16_t fatTime) {
|
||||||
return fatTime >> 11;
|
return fatTime >> 11;
|
||||||
}
|
}
|
||||||
|
@ -64,13 +64,13 @@ FileImplPtr SDFSImpl::open(const char* path, OpenMode openMode, AccessMode acces
|
|||||||
}
|
}
|
||||||
free(pathStr);
|
free(pathStr);
|
||||||
}
|
}
|
||||||
sdfat::File32 fd = _fs.open(path, flags);
|
File32 fd = _fs.open(path, flags);
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
|
DEBUGV("SDFSImpl::openFile: fd=%p path=`%s` openMode=%d accessMode=%d",
|
||||||
&fd, path, openMode, accessMode);
|
&fd, path, openMode, accessMode);
|
||||||
return FileImplPtr();
|
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);
|
return std::make_shared<SDFSFileImpl>(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 ""
|
// 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.
|
// If that references a directory, just open it and we're done.
|
||||||
sdfat::File32 dirFile;
|
File32 dirFile;
|
||||||
const char *filter = "";
|
const char *filter = "";
|
||||||
if (!pathStr[0]) {
|
if (!pathStr[0]) {
|
||||||
// openDir("") === openDir("/")
|
// openDir("") === openDir("/")
|
||||||
dirFile = _fs.open("/", sdfat::O_RDONLY);
|
dirFile = _fs.open("/", O_RDONLY);
|
||||||
filter = "";
|
filter = "";
|
||||||
} else if (_fs.exists(pathStr)) {
|
} else if (_fs.exists(pathStr)) {
|
||||||
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
|
dirFile = _fs.open(pathStr, O_RDONLY);
|
||||||
if (dirFile.isDir()) {
|
if (dirFile.isDir()) {
|
||||||
// Easy peasy, path specifies an existing dir!
|
// Easy peasy, path specifies an existing dir!
|
||||||
filter = "";
|
filter = "";
|
||||||
@ -107,12 +107,12 @@ DirImplPtr SDFSImpl::openDir(const char* path)
|
|||||||
char *ptr = strrchr(pathStr, '/');
|
char *ptr = strrchr(pathStr, '/');
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
// No slashes, open the root dir
|
// No slashes, open the root dir
|
||||||
dirFile = _fs.open("/", sdfat::O_RDONLY);
|
dirFile = _fs.open("/", O_RDONLY);
|
||||||
filter = pathStr;
|
filter = pathStr;
|
||||||
} else {
|
} else {
|
||||||
// We've got slashes, open the dir one up
|
// We've got slashes, open the dir one up
|
||||||
*ptr = 0; // Remove slash, truncare string
|
*ptr = 0; // Remove slash, truncare string
|
||||||
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
|
dirFile = _fs.open(pathStr, O_RDONLY);
|
||||||
filter = ptr + 1;
|
filter = ptr + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,12 +122,12 @@ DirImplPtr SDFSImpl::openDir(const char* path)
|
|||||||
char *ptr = strrchr(pathStr, '/');
|
char *ptr = strrchr(pathStr, '/');
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
// No slashes, open the root dir
|
// No slashes, open the root dir
|
||||||
dirFile = _fs.open("/", sdfat::O_RDONLY);
|
dirFile = _fs.open("/", O_RDONLY);
|
||||||
filter = pathStr;
|
filter = pathStr;
|
||||||
} else {
|
} else {
|
||||||
// We've got slashes, open the dir one up
|
// We've got slashes, open the dir one up
|
||||||
*ptr = 0; // Remove slash, truncare string
|
*ptr = 0; // Remove slash, truncare string
|
||||||
dirFile = _fs.open(pathStr, sdfat::O_RDONLY);
|
dirFile = _fs.open(pathStr, O_RDONLY);
|
||||||
filter = ptr + 1;
|
filter = ptr + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
|
|||||||
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
|
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
|
||||||
return DirImplPtr();
|
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);
|
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
|
||||||
free(pathStr);
|
free(pathStr);
|
||||||
return ret;
|
return ret;
|
||||||
@ -145,12 +145,12 @@ bool SDFSImpl::format() {
|
|||||||
if (_mounted) {
|
if (_mounted) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sdfat::SdCardFactory cardFactory;
|
SdCardFactory cardFactory;
|
||||||
sdfat::SdCard* card = cardFactory.newCard(sdfat::SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
|
SdCard* card = cardFactory.newCard(SdSpiConfig(_cfg._csPin, DEDICATED_SPI, _cfg._spiSettings));
|
||||||
if (!card || card->errorCode()) {
|
if (!card || card->errorCode()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sdfat::FatFormatter fatFormatter;
|
FatFormatter fatFormatter;
|
||||||
uint8_t *sectorBuffer = new uint8_t[512];
|
uint8_t *sectorBuffer = new uint8_t[512];
|
||||||
bool ret = fatFormatter.format(card, sectorBuffer, nullptr);
|
bool ret = fatFormatter.format(card, sectorBuffer, nullptr);
|
||||||
delete[] sectorBuffer;
|
delete[] sectorBuffer;
|
||||||
|
@ -97,11 +97,11 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
info.maxOpenFiles = 999; // TODO - not valid
|
info.maxOpenFiles = 999; // TODO - not valid
|
||||||
info.blockSize = _fs.vol()->sectorsPerCluster() * _fs.vol()->bytesPerSector();
|
info.blockSize = _fs.vol()->bytesPerCluster();
|
||||||
info.pageSize = 0; // TODO ?
|
info.pageSize = 0; // TODO ?
|
||||||
info.maxPathLength = 255; // TODO ?
|
info.maxPathLength = 255; // TODO ?
|
||||||
info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public:
|
|||||||
format();
|
format();
|
||||||
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
|
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
|
||||||
}
|
}
|
||||||
sdfat::FsDateTime::setCallback(dateTimeCB);
|
FsDateTime::setCallback(dateTimeCB);
|
||||||
return _mounted;
|
return _mounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ public:
|
|||||||
return (totalClusters() / blocksPerCluster());
|
return (totalClusters() / blocksPerCluster());
|
||||||
}
|
}
|
||||||
size_t clusterSize() {
|
size_t clusterSize() {
|
||||||
return blocksPerCluster() * _fs.vol()->bytesPerSector();
|
return _fs.vol()->bytesPerCluster();
|
||||||
}
|
}
|
||||||
size_t size() {
|
size_t size() {
|
||||||
return (clusterSize() * totalClusters());
|
return (clusterSize() * totalClusters());
|
||||||
@ -229,8 +229,7 @@ protected:
|
|||||||
friend class SDFileImpl;
|
friend class SDFileImpl;
|
||||||
friend class SDFSDirImpl;
|
friend class SDFSDirImpl;
|
||||||
|
|
||||||
sdfat::SdFat* getFs()
|
SdFat* getFs() {
|
||||||
{
|
|
||||||
return &_fs;
|
return &_fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,24 +237,25 @@ protected:
|
|||||||
static uint8_t _getFlags(OpenMode openMode, AccessMode accessMode) {
|
static uint8_t _getFlags(OpenMode openMode, AccessMode accessMode) {
|
||||||
uint8_t mode = 0;
|
uint8_t mode = 0;
|
||||||
if (openMode & OM_CREATE) {
|
if (openMode & OM_CREATE) {
|
||||||
mode |= sdfat::O_CREAT;
|
mode |= O_CREAT;
|
||||||
}
|
}
|
||||||
if (openMode & OM_APPEND) {
|
if (openMode & OM_APPEND) {
|
||||||
mode |= sdfat::O_AT_END;
|
mode |= O_AT_END;
|
||||||
}
|
}
|
||||||
if (openMode & OM_TRUNCATE) {
|
if (openMode & OM_TRUNCATE) {
|
||||||
mode |= sdfat::O_TRUNC;
|
mode |= O_TRUNC;
|
||||||
}
|
}
|
||||||
if (accessMode & AM_READ) {
|
if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) {
|
||||||
mode |= sdfat::O_READ;
|
mode |= O_RDWR;
|
||||||
}
|
} else if (accessMode & AM_READ) {
|
||||||
if (accessMode & AM_WRITE) {
|
mode |= O_READ;
|
||||||
mode |= sdfat::O_WRITE;
|
} else if (accessMode & AM_WRITE) {
|
||||||
|
mode |= O_WRITE;
|
||||||
}
|
}
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdfat::SdFat _fs;
|
SdFat _fs;
|
||||||
SDFSConfig _cfg;
|
SDFSConfig _cfg;
|
||||||
bool _mounted;
|
bool _mounted;
|
||||||
};
|
};
|
||||||
@ -264,7 +264,7 @@ protected:
|
|||||||
class SDFSFileImpl : public FileImpl
|
class SDFSFileImpl : public FileImpl
|
||||||
{
|
{
|
||||||
public:
|
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)
|
: _fs(fs), _fd(fd), _opened(true)
|
||||||
{
|
{
|
||||||
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
|
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
|
||||||
@ -380,7 +380,7 @@ public:
|
|||||||
time_t getLastWrite() override {
|
time_t getLastWrite() override {
|
||||||
time_t ftime = 0;
|
time_t ftime = 0;
|
||||||
if (_opened && _fd) {
|
if (_opened && _fd) {
|
||||||
sdfat::DirFat_t tmp;
|
DirFat_t tmp;
|
||||||
if (_fd.get()->dirEntry(&tmp)) {
|
if (_fd.get()->dirEntry(&tmp)) {
|
||||||
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
|
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
|
||||||
}
|
}
|
||||||
@ -391,7 +391,7 @@ public:
|
|||||||
time_t getCreationTime() override {
|
time_t getCreationTime() override {
|
||||||
time_t ftime = 0;
|
time_t ftime = 0;
|
||||||
if (_opened && _fd) {
|
if (_opened && _fd) {
|
||||||
sdfat::DirFat_t tmp;
|
DirFat_t tmp;
|
||||||
if (_fd.get()->dirEntry(&tmp)) {
|
if (_fd.get()->dirEntry(&tmp)) {
|
||||||
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
|
ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
SDFSImpl* _fs;
|
SDFSImpl* _fs;
|
||||||
std::shared_ptr<sdfat::File32> _fd;
|
std::shared_ptr<File32> _fd;
|
||||||
std::shared_ptr<char> _name;
|
std::shared_ptr<char> _name;
|
||||||
bool _opened;
|
bool _opened;
|
||||||
};
|
};
|
||||||
@ -409,7 +409,7 @@ protected:
|
|||||||
class SDFSDirImpl : public DirImpl
|
class SDFSDirImpl : public DirImpl
|
||||||
{
|
{
|
||||||
public:
|
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)
|
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
|
||||||
{
|
{
|
||||||
if (dirPath) {
|
if (dirPath) {
|
||||||
@ -484,14 +484,14 @@ public:
|
|||||||
{
|
{
|
||||||
const int n = _pattern.length();
|
const int n = _pattern.length();
|
||||||
do {
|
do {
|
||||||
sdfat::File32 file;
|
File32 file;
|
||||||
file.openNext(_dir.get(), sdfat::O_READ);
|
file.openNext(_dir.get(), O_READ);
|
||||||
if (file) {
|
if (file) {
|
||||||
_valid = 1;
|
_valid = 1;
|
||||||
_size = file.fileSize();
|
_size = file.fileSize();
|
||||||
_isFile = file.isFile();
|
_isFile = file.isFile();
|
||||||
_isDirectory = file.isDir();
|
_isDirectory = file.isDir();
|
||||||
sdfat::DirFat_t tmp;
|
DirFat_t tmp;
|
||||||
if (file.dirEntry(&tmp)) {
|
if (file.dirEntry(&tmp)) {
|
||||||
_time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
|
_time = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
|
||||||
_creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
|
_creation = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
|
||||||
@ -518,7 +518,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
String _pattern;
|
String _pattern;
|
||||||
SDFSImpl* _fs;
|
SDFSImpl* _fs;
|
||||||
std::shared_ptr<sdfat::File32> _dir;
|
std::shared_ptr<File32> _dir;
|
||||||
bool _valid;
|
bool _valid;
|
||||||
char _lfn[64];
|
char _lfn[64];
|
||||||
time_t _time;
|
time_t _time;
|
||||||
|
@ -9,16 +9,13 @@ function skip_ino()
|
|||||||
read -d '' skiplist << EOL || true
|
read -d '' skiplist << EOL || true
|
||||||
/#attic/
|
/#attic/
|
||||||
/AvrAdcLogger/
|
/AvrAdcLogger/
|
||||||
/BackwardCompatibility/
|
|
||||||
/examplesV1/
|
/examplesV1/
|
||||||
/ExFatFormatter/
|
|
||||||
/ExFatLogger/
|
|
||||||
/ExFatUnicodeTest/
|
|
||||||
/RtcTimestampTest/
|
/RtcTimestampTest/
|
||||||
/SoftwareSpi/
|
/SoftwareSpi/
|
||||||
/STM32Test/
|
/TeensyDmaAdcLogger/
|
||||||
/TeensyRtcTimestamp/
|
/TeensyRtcTimestamp/
|
||||||
/TeensySdioDemo/
|
/TeensySdioDemo/
|
||||||
|
/TeensySdioLogger/
|
||||||
/UserChipSelectFunction/
|
/UserChipSelectFunction/
|
||||||
/UserSPIDriver/
|
/UserSPIDriver/
|
||||||
EOL
|
EOL
|
||||||
|
@ -104,12 +104,16 @@ CORE_CPP_FILES := \
|
|||||||
FatLib/FatFilePrint.cpp \
|
FatLib/FatFilePrint.cpp \
|
||||||
FatLib/FatFileSFN.cpp \
|
FatLib/FatFileSFN.cpp \
|
||||||
FatLib/FatFormatter.cpp \
|
FatLib/FatFormatter.cpp \
|
||||||
|
FatLib/FatName.cpp \
|
||||||
FatLib/FatVolume.cpp \
|
FatLib/FatVolume.cpp \
|
||||||
FatLib/FatPartition.cpp \
|
FatLib/FatPartition.cpp \
|
||||||
common/FmtNumber.cpp \
|
common/FmtNumber.cpp \
|
||||||
|
common/FsCache.cpp \
|
||||||
common/FsStructs.cpp \
|
common/FsStructs.cpp \
|
||||||
common/FsDateTime.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)/SDFS/src/SDFS.cpp) \
|
||||||
$(abspath $(LIBRARIES_PATH)/SD/src/SD.cpp) \
|
$(abspath $(LIBRARIES_PATH)/SD/src/SD.cpp) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user