Skip to content

Instantly share code, notes, and snippets.

@mcspr

mcspr/fslib.diff Secret

Created November 4, 2021 23:20
Show Gist options
  • Save mcspr/7b87fbcc1df71937be474ff3c0b97e9a to your computer and use it in GitHub Desktop.
Save mcspr/7b87fbcc1df71937be474ff3c0b97e9a to your computer and use it in GitHub Desktop.
diff --git a/libraries/SDFS/src/SDFS.cpp b/libraries/SDFS/src/SDFS.cpp
index 5725a6ae..c0416331 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);
}
- File32 fd = _fs.open(path, flags);
+ FsFile 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<File32>(fd);
+ auto sharedFd = std::make_shared<FsFile>(fd);
return std::make_shared<SDFSFileImpl>(this, sharedFd, path);
}
@@ -90,7 +90,7 @@ 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.
- File32 dirFile;
+ FsFile dirFile;
const char *filter = "";
if (!pathStr[0]) {
// openDir("") === openDir("/")
@@ -135,7 +135,7 @@ DirImplPtr SDFSImpl::openDir(const char* path)
DEBUGV("SDFSImpl::openDir: path=`%s`\n", path);
return DirImplPtr();
}
- auto sharedDir = std::make_shared<File32>(dirFile);
+ auto sharedDir = std::make_shared<FsFile>(dirFile);
auto ret = std::make_shared<SDFSDirImpl>(filter, this, sharedDir, pathStr);
free(pathStr);
return ret;
diff --git a/libraries/SDFS/src/SDFS.h b/libraries/SDFS/src/SDFS.h
index 6e13cdf2..77d6fb2c 100644
--- a/libraries/SDFS/src/SDFS.h
+++ b/libraries/SDFS/src/SDFS.h
@@ -229,7 +229,7 @@ protected:
friend class SDFileImpl;
friend class SDFSDirImpl;
- SdFat* getFs() {
+ SdFs* getFs() {
return &_fs;
}
@@ -255,7 +255,7 @@ protected:
return mode;
}
- SdFat _fs;
+ SdFs _fs;
SDFSConfig _cfg;
bool _mounted;
};
@@ -264,7 +264,7 @@ protected:
class SDFSFileImpl : public FileImpl
{
public:
- SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
+ SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<FsFile> fd, const char *name)
: _fs(fs), _fd(fd), _opened(true)
{
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
@@ -279,7 +279,7 @@ public:
int availableForWrite() override
{
- return _opened ? _fd->availableSpaceForWrite() : 0;
+ return _opened ? _fd->availableForWrite() : 0;
}
size_t write(const uint8_t *buf, size_t size) override
@@ -380,10 +380,10 @@ public:
time_t getLastWrite() override {
time_t ftime = 0;
if (_opened && _fd) {
- DirFat_t tmp;
- if (_fd.get()->dirEntry(&tmp)) {
- ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.modifyDate, *(uint16_t*)tmp.modifyTime);
- }
+ uint16_t pdate;
+ uint16_t ptime;
+ _fd->getModifyDateTime(&pdate, &ptime);
+ ftime = SDFSImpl::FatToTimeT(pdate, ptime);
}
return ftime;
}
@@ -391,17 +391,17 @@ public:
time_t getCreationTime() override {
time_t ftime = 0;
if (_opened && _fd) {
- DirFat_t tmp;
- if (_fd.get()->dirEntry(&tmp)) {
- ftime = SDFSImpl::FatToTimeT(*(uint16_t*)tmp.createDate, *(uint16_t*)tmp.createTime);
- }
+ uint16_t pdate;
+ uint16_t ptime;
+ _fd->getCreateDateTime(&pdate, &ptime);
+ ftime = SDFSImpl::FatToTimeT(pdate, ptime);
}
return ftime;
}
protected:
SDFSImpl* _fs;
- std::shared_ptr<File32> _fd;
+ std::shared_ptr<FsFile> _fd;
std::shared_ptr<char> _name;
bool _opened;
};
@@ -409,7 +409,7 @@ protected:
class SDFSDirImpl : public DirImpl
{
public:
- SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<File32> dir, const char *dirPath = nullptr)
+ SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<FsFile> dir, const char *dirPath = nullptr)
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false), _dirPath(nullptr)
{
if (dirPath) {
@@ -484,21 +484,23 @@ public:
{
const int n = _pattern.length();
do {
- File32 file;
+ FsFile file;
file.openNext(_dir.get(), O_READ);
if (file) {
_valid = 1;
_size = file.fileSize();
_isFile = file.isFile();
_isDirectory = file.isDir();
- 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);
- } else {
- _time = 0;
- _creation = 0;
- }
+
+ uint16_t pdate;
+ uint16_t ptime;
+
+ file.getModifyDateTime(&pdate, &ptime);
+ _time = SDFSImpl::FatToTimeT(pdate, ptime);
+
+ file.getCreateDateTime(&pdate, &ptime);
+ _creation = SDFSImpl::FatToTimeT(pdate, ptime);
+
file.getName(_lfn, sizeof(_lfn));
file.close();
} else {
@@ -518,7 +520,7 @@ public:
protected:
String _pattern;
SDFSImpl* _fs;
- std::shared_ptr<File32> _dir;
+ std::shared_ptr<FsFile> _dir;
bool _valid;
char _lfn[64];
time_t _time;
~\.\p\f\l\SDFS>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy