@@ -96,11 +96,11 @@ class SDFSImpl : public FSImpl
96
96
return false ;
97
97
}
98
98
info.maxOpenFiles = 999 ; // TODO - not valid
99
- info.blockSize = _fs.vol ()->sectorsPerCluster () * _fs. vol ()-> bytesPerSector ();
99
+ info.blockSize = _fs.vol ()->bytesPerCluster ();
100
100
info.pageSize = 0 ; // TODO ?
101
101
info.maxPathLength = 255 ; // TODO ?
102
102
info.totalBytes =_fs.vol ()->clusterCount () * info.blockSize ;
103
- info.usedBytes = info.totalBytes - (_fs.vol ()->freeClusterCount () * _fs.vol ()->sectorsPerCluster () * _fs. vol ()-> bytesPerSector ());
103
+ info.usedBytes = info.totalBytes - (_fs.vol ()->freeClusterCount () * _fs.vol ()->bytesPerCluster ());
104
104
return true ;
105
105
}
106
106
@@ -114,9 +114,9 @@ class SDFSImpl : public FSImpl
114
114
info.maxOpenFiles = i.maxOpenFiles ;
115
115
info.maxPathLength = i.maxPathLength ;
116
116
#ifdef DEBUG_ESP_PORT
117
- if (i.totalBytes > ( uint64_t )SIZE_MAX ) {
117
+ if (i.totalBytes > std::numeric_limits< uint32_t >:: max () ) {
118
118
// This catches both total and used cases, since used must always be < total.
119
- DEBUG_ESP_PORT.printf_P (PSTR (" WARNING: SD card size overflow (%lld>= 4GB). Please update source to use info64().\n " ), i.totalBytes );
119
+ DEBUG_ESP_PORT.printf_P (PSTR (" WARNING: SD card size overflow (%lld >= 4GB). Please update source to use info64().\n " ), ( long long ) i.totalBytes );
120
120
}
121
121
#endif
122
122
info.totalBytes = (size_t )i.totalBytes ;
@@ -155,7 +155,7 @@ class SDFSImpl : public FSImpl
155
155
format ();
<
10000
td data-grid-cell-id="diff-69fe692df591869feeb4c1d38c8c917477db153713e136bab02e6b0a303df40e-156-156-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">156
156
_mounted = _fs.begin (_cfg._csPin , _cfg._spiSettings );
157
157
}
158
- sdfat:: FsDateTime::setCallback (dateTimeCB);
158
+ FsDateTime::setCallback (dateTimeCB);
159
159
return _mounted;
160
160
}
161
161
@@ -184,7 +184,7 @@ class SDFSImpl : public FSImpl
184
184
return (totalClusters () / blocksPerCluster ());
185
185
}
186
186
size_t clusterSize () {
187
- return blocksPerCluster () * _fs.vol ()->bytesPerSector ();
187
+ return _fs.vol ()->bytesPerCluster ();
188
188
}
189
189
size_t size () {
190
190
return (clusterSize () * totalClusters ());
@@ -228,7 +228,7 @@ class SDFSImpl : public FSImpl
228
228
friend class SDFileImpl ;
229
229
friend class SDFSDirImpl ;
230
230
231
- sdfat:: SdFat* getFs ()
231
+ SdFat* getFs ()
232
232
{
233
233
return &_fs;
234
234
}
@@ -245,16 +245,17 @@ class SDFSImpl : public FSImpl
245
245
if (openMode & OM_TRUNCATE) {
246
246
mode |= O_TRUNC;
247
247
}
248
- if (accessMode & AM_READ) {
248
+ if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) {
249
+ mode |= O_RDWR;
250
+ } else if (accessMode & AM_READ) {
249
251
mode |= O_READ;
250
- }
251
- if (accessMode & AM_WRITE) {
252
+ } else if (accessMode & AM_WRITE) {
252
253
mode |= O_WRITE;
253
254
}
254
255
return mode;
255
256
}
256
257
257
- sdfat:: SdFat _fs;
258
+ SdFat _fs;
258
259
SDFSConfig _cfg;
259
260
bool _mounted;
260
261
};
@@ -263,7 +264,7 @@ class SDFSImpl : public FSImpl
263
264
class SDFSFileImpl : public FileImpl
264
265
{
265
266
public:
266
- SDFSFileImpl (SDFSImpl *fs, std::shared_ptr<sdfat:: File32> fd, const char *name)
267
+ SDFSFileImpl (SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
267
268
: _fs(fs), _fd(fd), _opened(true )
268
269
{
269
270
_name = std::shared_ptr<char >(new char [strlen (name) + 1 ], std::default_delete<char []>());
@@ -379,7 +380,7 @@ class SDFSFileImpl : public FileImpl
379
380
time_t getLastWrite () override {
380
381
time_t ftime = 0 ;
381
382
if (_opened && _fd) {
382
- sdfat:: DirFat_t tmp;
383
+ DirFat_t tmp;
383
384
if (_fd.get ()->dirEntry (&tmp)) {
384
385
ftime = SDFSImpl::FatToTimeT (*(uint16_t *)tmp.modifyDate , *(uint16_t *)tmp.modifyTime );
385
386
}
@@ -390,7 +391,7 @@ class SDFSFileImpl : public FileImpl
390
391
time_t getCreationTime () override {
391
392
time_t ftime = 0 ;
392
393
if (_opened && _fd) {
393
- sdfat:: DirFat_t tmp;
394
+ DirFat_t tmp;
394
395
if (_fd.get ()->dirEntry (&tmp)) {
395
396
ftime = SDFSImpl::FatToTimeT (*(uint16_t *)tmp.createDate , *(uint16_t *)tmp.createTime );
396
397
}
@@ -399,16 +400,16 @@ class SDFSFileImpl : public FileImpl
399
400
}
400
401
401
402
protected:
402
- SDFSImpl* _fs;
403
- std::shared_ptr<sdfat:: File32> _fd;
404
- std::shared_ptr<char > _name;
405
- bool _opened;
403
+ SDFSImpl* _fs;
404
+ std::shared_ptr<File32> _fd;
405
+ std::shared_ptr<char > _name;
406
+ bool _opened;
406
407
};
407
408
408
409
class SDFSDirImpl : public DirImpl
409
410
{
410
411
public:
411
- SDFSDirImpl (const String& pattern, SDFSImpl* fs, std::shared_ptr<sdfat:: File32> dir, const char *dirPath = nullptr )
412
+ SDFSDirImpl (const String& pattern, SDFSImpl* fs, std::shared_ptr<File32> dir, const char *dirPath = nullptr )
412
413
: _pattern(pattern), _fs(fs), _dir(dir), _valid(false ), _dirPath(nullptr )
413
414
{
414
415
if (dirPath) {
@@ -483,14 +484,14 @@ class SDFSDirImpl : public DirImpl
483
484
{
484
485
const int n = _pattern.length ();
485
486
do {
486
- sdfat:: File32 file;
487
+ File32 file;
487
488
file.openNext (_dir.get (), O_READ);
488
489
if (file) {
489
490
_valid = 1 ;
490
491
_size = file.fileSize ();
491
492
_isFile = file.isFile ();
492
493
_isDirectory = file.isDir ();
493
- sdfat:: DirFat_t tmp;
494
+ DirFat_t tmp;
494
495
if (file.dirEntry (&tmp)) {
495
496
_time = SDFSImpl::FatToTimeT (*(uint16_t *)tmp.modifyDate , *(uint16_t *)tmp.modifyTime );
496
497
_creation = SDFSImpl::FatToTimeT (*(uint16_t *)tmp.createDate , *(uint16_t *)tmp.createTime );
@@ -515,17 +516,17 @@ class SDFSDirImpl : public DirImpl
515
516
}
516
517
517
518
protected:
518
- String _pattern;
519
- SDFSImpl* _fs;
520
- std::shared_ptr<sdfat:: File32> _dir;
521
- bool _valid;
522
- char _lfn[64 ];
523
- time_t _time;
524
- time_t _creation;
525
- std::shared_ptr<char > _dirPath;
526
- uint32_t _size;
527
- bool _isFile;
528
- bool _isDirectory;
519
+ String _pattern;
520
+ SDFSImpl* _fs;
521
+ std::shared_ptr<File32> _dir;
522
+ bool _valid;
523
+ char _lfn[64 ];
524
+ time_t _time;
525
+ time_t _creation;
526
+ std::shared_ptr<char > _dirPath;
527
+ uint32_t _size;
528
+ bool _isFile;
529
+ bool _isDirectory;
529
530
};
530
531
531
532
}; // namespace sdfs
0 commit comments