Files
ESP8266lib/ext/sd/fat32/FreeClusterIterator.h
2021-02-21 21:04:11 +01:00

33 lines
542 B
C++

#pragma once
/**
* helper class to iterate all free clusters of the Filesystem.
* starts at cluster number 2 and then iterates over all subsequent clusters
* stopping at the free ones
*/
class FreeClusterIterator {
FS& fs;
ClusterNr cur;
public:
FreeClusterIterator(FS& fs) : fs(fs), cur(2) {
}
/** get the next free cluster that is available */
ClusterNr next() {
// TODO: end of filesystem reached
while(true) {
const ClusterNr tmp = fs.getNextCluster(cur);
if (tmp.isFree()) {return cur;}
++cur;
}
}
};