mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Update to SdFat 2.1.1 with UTF-8 support (#8355)
This commit is contained in:
committed by
GitHub
parent
7d971fa45b
commit
a00b2d7091
@ -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);
|
||||
}
|
||||
|
||||
@ -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<sdfat::File32>(dirFile);
|
||||
auto sharedDir = std::make_shared<File32>(dirFile);
|
||||
auto ret = std::make_shared<SDFSDirImpl>(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;
|
||||
|
@ -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<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[]>());
|
||||
@ -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<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) {
|
||||
@ -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<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
|
||||
|
Reference in New Issue
Block a user