Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add original SD FAT info access methods #6092

Merged
merged 8 commits into from
May 19, 2019
4 changes: 4 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <memory>
#include <Arduino.h>

class SDClass;

namespace fs {

class File;
Expand Down Expand Up @@ -208,8 +210,10 @@ class FS

bool gc();

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

} // namespace fs
Expand Down
28 changes: 21 additions & 7 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,49 @@ class SDClass {
}

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

uint8_t fatType() {
return 0;//volume.fatType();
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
return sd->fatType();
}

size_t blocksPerCluster() {
return 0;//volume.blocksPerCluster();
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
return sd->blocksPerCluster();
}

size_t totalClusters() {
return 0;//volume.clusterCount();
sdfs::SDFSImpl* sd = static_cast<sdfs::SDFSImpl*>(SDFS.getImpl().get());
return sd->totalClusters();
}

size_t blockSize() {
return 512;
}

size_t totalBlocks() {
return 0;//(totalClusters() / blocksPerCluster());
return (totalClusters() / blocksPerCluster());
}

size_t clusterSize() {
return 0;//blocksPerCluster() * blockSize();
return blocksPerCluster() * blockSize();
}

size_t size() {
return 0;//(clusterSize() * totalClusters());
uint64_t sz = size64();
if (sz > (uint64_t)SIZE_MAX) {
Serial.printf_P(PSTR("WARNING: SD card size overflow (>= 4GB). Please update source to use size64(). Returning 0.\n"));
devyte marked this conversation as resolved.
Show resolved Hide resolved
return 0;
} else {
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
return sz;
}
}

uint64_t size64() {
return ((uint64_t)clusterSize() * (uint64_t)totalClusters());
}

private:
Expand Down
24 changes: 24 additions & 0 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ class SDFSImpl : public FSImpl

bool format() override;

// The following are not common FS interfaces, but are needed only to
// support the older SD.h exports
uint8_t type() {
return _fs.card()->type();
}
uint8_t fatType() {
return _fs.vol()->fatType();
}
size_t blocksPerCluster() {
return _fs.vol()->blocksPerCluster();
}
size_t totalClusters() {
return _fs.vol()->clusterCount();
}
size_t totalBlocks() {
return (totalClusters() / blocksPerCluster());
}
size_t clusterSize() {
return blocksPerCluster() * 512; // 512b block size
}
size_t size() {
return (clusterSize() * totalClusters());
}

protected:
friend class SDFileImpl;
friend class SDFSDirImpl;
Expand Down