File tree 3 files changed +49
-7
lines changed
3 files changed +49
-7
lines changed Original file line number Diff line number Diff line change 24
24
#include < memory>
25
25
#include < Arduino.h>
26
26
27
+ class SDClass ;
28
+
27
29
namespace fs {
28
30
29
31
class File ;
@@ -208,8 +210,10 @@ class FS
208
210
209
211
bool gc ();
210
212
213
+ friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits
211
214
protected:
212
215
FSImplPtr _impl;
216
+ FSImplPtr getImpl () { return _impl; }
213
217
};
214
218
215
219
} // namespace fs
Original file line number Diff line number Diff line change @@ -84,35 +84,49 @@ class SDClass {
84
84
}
85
85
86
86
uint8_t type () {
87
- return 0 ;// card.type();
87
+ sdfs::SDFSImpl* sd = static_cast <sdfs::SDFSImpl*>(SDFS.getImpl ().get ());
88
+ return sd->type ();
88
89
}
89
90
90
91
uint8_t fatType () {
91
- return 0 ;// volume.fatType();
92
+ sdfs::SDFSImpl* sd = static_cast <sdfs::SDFSImpl*>(SDFS.getImpl ().get ());
93
+ return sd->fatType ();
92
94
}
93
95
94
96
size_t blocksPerCluster () {
95
- return 0 ;// volume.blocksPerCluster();
97
+ sdfs::SDFSImpl* sd = static_cast <sdfs::SDFSImpl*>(SDFS.getImpl ().get ());
98
+ return sd->blocksPerCluster ();
96
99
}
97
100
98
101
size_t totalClusters () {
99
- return 0 ;// volume.clusterCount();
102
+ sdfs::SDFSImpl* sd = static_cast <sdfs::SDFSImpl*>(SDFS.getImpl ().get ());
103
+ return sd->totalClusters ();
100
104
}
101
105
102
106
size_t blockSize () {
103
107
return 512 ;
104
108
}
105
109
106
110
size_t totalBlocks () {
107
- return 0 ; // (totalClusters() / blocksPerCluster());
111
+ return (totalClusters () / blocksPerCluster ());
108
112
}
109
113
110
114
size_t clusterSize () {
111
- return 0 ; // blocksPerCluster() * blockSize();
115
+ return blocksPerCluster () * blockSize ();
112
116
}
113
117
114
118
size_t size () {
115
- return 0 ;// (clusterSize() * totalClusters());
119
+ uint64_t sz = size64 ();
120
+ #ifdef DEBUG_ESP_PORT
121
+ if (sz > (uint64_t )SIZE_MAX) {
122
+ DEBUG_ESP_PORT.printf_P (PSTR (" WARNING: SD card size overflow (%lld>= 4GB). Please update source to use size64().\n " ), sz);
123
+ }
124
+ #endif
125
+ return (size_t )sz;
126
+ }
127
+
128
+ uint64_t size64 () {
129
+ return ((uint64_t )clusterSize () * (uint64_t )totalClusters ());
116
130
}
117
131
118
132
private:
Original file line number Diff line number Diff line change @@ -159,6 +159,30 @@ class SDFSImpl : public FSImpl
159
159
160
160
bool format () override ;
161
161
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
+
162
186
protected:
163
187
friend class SDFileImpl ;
164
188
friend class SDFSDirImpl ;
You can’t perform that action at this time.
0 commit comments