Skip to content

Commit 1838cd5

Browse files
Re-add original SD FAT info access methods
Fixes esp8266#6081 The SD rewrite blanked out some of the internal FAT info.. Restore the function calls and return proper values.
1 parent eea9999 commit 1838cd5

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

cores/esp8266/FS.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <memory>
2525
#include <Arduino.h>
2626

27+
class SDClass;
28+
2729
namespace fs {
2830

2931
class File;
@@ -208,8 +210,10 @@ class FS
208210

209211
bool gc();
210212

213+
friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits
211214
protected:
212215
FSImplPtr _impl;
216+
FSImplPtr getImpl() { return _impl; }
213217
};
214218

215219
} // namespace fs

libraries/SD/src/SD.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,39 @@ class SDClass {
8484
}
8585

8686
uint8_t type() {
87-
return 0;//card.type();
87+
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
88+
return sd->type();
8889
}
8990

9091
uint8_t fatType() {
91-
return 0;//volume.fatType();
92+
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
93+
return sd->fatType();
9294
}
9395

9496
size_t blocksPerCluster() {
95-
return 0;//volume.blocksPerCluster();
97+
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
98+
return sd->blocksPerCluster();
9699
}
97100

98101
size_t totalClusters() {
99-
return 0;//volume.clusterCount();
102+
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
103+
return sd->totalClusters();
100104
}
101105

102106
size_t blockSize() {
103107
return 512;
104108
}
105109

106110
size_t totalBlocks() {
107-
return 0;//(totalClusters() / blocksPerCluster());
111+
return (totalClusters() / blocksPerCluster());
108112
}
109113

110114
size_t clusterSize() {
111-
return 0;//blocksPerCluster() * blockSize();
115+
return blocksPerCluster() * blockSize();
112116
}
113117

114118
size_t size() {
115-
return 0;//(clusterSize() * totalClusters());
119+
return (clusterSize() * totalClusters());
116120
}
117121

118122
private:

libraries/SDFS/src/SDFS.h

+24
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ class SDFSImpl : public FSImpl
159159

160160
bool format() override;
161161

162+
// The following are not common FS interfaces, but are needed only to
163+
// support the older SD.h exports
164+
uint8_t type() {
165+
return _fs.card()->type();
166+
}
167+
uint8_t fatType() {
168+
return _fs.vol()->fatType();
169+
}
170+
size_t blocksPerCluster() {
171+
return _fs.vol()->blocksPerCluster();
172+
}
173+
size_t totalClusters() {
174+
return _fs.vol()->clusterCount();
175+
}
176+
size_t totalBlocks() {
177+
return (totalClusters() / blocksPerCluster());
178+
}
179+
size_t clusterSize() {
180+
return blocksPerCluster() * 512; // 512b block size
181+
}
182+
size_t size() {
183+
return (clusterSize() * totalClusters());
184+
}
185+
162186
protected:
163187
friend class SDFileImpl;
164188
friend class SDFSDirImpl;

0 commit comments

Comments
 (0)