69 if (!cacheFlush())
return 0;
70 cacheBlockNumber_ = 0XFFFFFFFF;
119 bool dbgFat(uint32_t n, uint32_t* v) {
return fatGet(n, v);}
127 static bool const CACHE_FOR_READ =
false;
129 static bool const CACHE_FOR_WRITE =
true;
131 #if USE_MULTIPLE_CARDS
133 uint32_t cacheBlockNumber_;
136 uint32_t cacheMirrorBlock_;
139 static uint32_t cacheBlockNumber_;
141 static bool cacheDirty_;
142 static uint32_t cacheMirrorBlock_;
144 uint32_t allocSearchStart_;
145 uint8_t blocksPerCluster_;
146 uint32_t blocksPerFat_;
147 uint32_t clusterCount_;
148 uint8_t clusterSizeShift_;
149 uint32_t dataStartBlock_;
151 uint32_t fatStartBlock_;
153 uint16_t rootDirEntryCount_;
154 uint32_t rootDirStart_;
156 bool allocContiguous(uint32_t count, uint32_t*
curCluster);
157 uint8_t blockOfCluster(uint32_t position)
const {
158 return (position >> 9) & (blocksPerCluster_ - 1);}
159 uint32_t clusterStartBlock(uint32_t cluster)
const {
160 return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_);}
161 uint32_t blockNumber(uint32_t cluster, uint32_t position)
const {
162 return clusterStartBlock(cluster) + blockOfCluster(position);}
163 cache_t *cache() {
return &cacheBuffer_;}
164 uint32_t cacheBlockNumber() {
return cacheBlockNumber_;}
165 #if USE_MULTIPLE_CARDS
167 bool cacheRawBlock(uint32_t blockNumber,
bool dirty);
169 static bool cacheFlush();
170 static bool cacheRawBlock(uint32_t blockNumber,
bool dirty);
173 void cacheSetBlockNumber(uint32_t blockNumber,
bool dirty) {
175 cacheBlockNumber_ = blockNumber;
177 void cacheSetDirty() {cacheDirty_ |= CACHE_FOR_WRITE;}
178 bool chainSize(uint32_t beginCluster, uint32_t* size);
179 bool fatGet(uint32_t cluster, uint32_t* value);
180 bool fatPut(uint32_t cluster, uint32_t value);
181 bool fatPutEOC(uint32_t cluster) {
182 return fatPut(cluster, 0x0FFFFFFF);
184 bool freeChain(uint32_t cluster);
185 bool isEOC(uint32_t cluster)
const {
186 if (FAT12_SUPPORT && fatType_ == 12)
return cluster >=
FAT12EOC_MIN;
190 bool readBlock(uint32_t block, uint8_t* dst) {
192 bool writeBlock(uint32_t block,
const uint8_t* dst) {
197 #if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN)
210 return init(&dev, part);
Sd2Card class for V2 SD/SDHC cards.
configuration definitions
uint16_t const FAT16EOC_MIN
Definition: SdFatStructs.h:458
uint16_t const FAT12EOC_MIN
Definition: SdFatStructs.h:454
uint32_t const FAT32EOC_MIN
Definition: SdFatStructs.h:462
Raw access to SD and SDHC flash memory cards.
Definition: Sd2Card.h:148
bool readBlock(uint32_t block, uint8_t *dst)
Definition: Sd2Card.cpp:393
bool writeBlock(uint32_t blockNumber, const uint8_t *src)
Definition: Sd2Card.cpp:632
Base class for SdFile with Print and C++ streams.
Definition: SdBaseFile.h:182
uint32_t curCluster() const
Definition: SdBaseFile.h:210
SdBaseFile with Print.
Definition: SdFile.h:36
Access FAT16 and FAT32 volumes on SD and SDHC cards.
Definition: SdVolume.h:60
uint32_t rootDirStart() const
Definition: SdVolume.h:108
bool init(Sd2Card *dev)
Definition: SdVolume.h:83
uint8_t fatType() const
Definition: SdVolume.h:102
int32_t freeClusterCount()
Definition: SdVolume.cpp:280
uint8_t fatCount() const
Definition: SdVolume.h:98
SdVolume()
Definition: SdVolume.h:63
bool dbgFat(uint32_t n, uint32_t *v)
Definition: SdVolume.h:119
uint8_t blocksPerCluster() const
Definition: SdVolume.h:88
uint32_t rootDirEntryCount() const
Definition: SdVolume.h:105
uint32_t dataStartBlock() const
Definition: SdVolume.h:96
uint32_t blocksPerFat() const
Definition: SdVolume.h:90
uint8_t clusterSizeShift() const
Definition: SdVolume.h:94
bool init(Sd2Card &dev, uint8_t part)
Definition: SdVolume.h:209
uint32_t fatStartBlock() const
Definition: SdVolume.h:100
cache_t * cacheClear()
Definition: SdVolume.h:68
bool init(Sd2Card &dev)
Definition: SdVolume.h:203
uint32_t clusterCount() const
Definition: SdVolume.h:92
Sd2Card * sdCard()
Definition: SdVolume.h:112
FAT short directory entry.
Definition: SdFatStructs.h:496
Boot sector for a FAT32 volume.
Definition: SdFatStructs.h:262
FSINFO sector for a FAT32 volume.
Definition: SdFatStructs.h:420
Boot sector for a FAT12/FAT16 volume.
Definition: SdFatStructs.h:134
Master Boot Record.
Definition: SdFatStructs.h:111
Cache for an SD data block.
Definition: SdVolume.h:37
uint8_t data[512+1]
Definition: SdVolume.h:39
fat32_fsinfo_t fsinfo
Definition: SdVolume.h:53
uint32_t fat32[128]
Definition: SdVolume.h:43
mbr_t mbr
Definition: SdVolume.h:47
dir_t dir[16]
Definition: SdVolume.h:45
uint16_t fat16[256]
Definition: SdVolume.h:41
fat32_boot_t fbs32
Definition: SdVolume.h:51
fat_boot_t fbs
Definition: SdVolume.h:49