MCPcopy Create free account
hub / github.com/MarlinFirmware/Marlin / fatGet

Method fatGet

Marlin/src/sd/SdVolume.cpp:163–195  ·  view source on GitHub ↗

Fetch a FAT entry

Source from the content-addressed store, hash-verified

161
162// Fetch a FAT entry
163bool SdVolume::fatGet(const uint32_t cluster, uint32_t * const value) {
164 uint32_t lba;
165 if (cluster > (clusterCount_ + 1)) return false;
166 if (FAT12_SUPPORT && fatType_ == 12) {
167 uint16_t index = cluster;
168 index += index >> 1;
169 lba = fatStartBlock_ + (index >> 9);
170 if (!cacheRawBlock(lba, CACHE_FOR_READ)) return false;
171 index &= 0x1FF;
172 uint16_t tmp = cacheBuffer_.data[index];
173 index++;
174 if (index == 512) {
175 if (!cacheRawBlock(lba + 1, CACHE_FOR_READ)) return false;
176 index = 0;
177 }
178 tmp |= cacheBuffer_.data[index] << 8;
179 *value = cluster & 1 ? tmp >> 4 : tmp & 0xFFF;
180 return true;
181 }
182
183 if (fatType_ == 16)
184 lba = fatStartBlock_ + (cluster >> 8);
185 else if (fatType_ == 32)
186 lba = fatStartBlock_ + (cluster >> 7);
187 else
188 return false;
189
190 if (lba != cacheBlockNumber_ && !cacheRawBlock(lba, CACHE_FOR_READ))
191 return false;
192
193 *value = (fatType_ == 16) ? cacheBuffer_.fat16[cluster & 0xFF] : (cacheBuffer_.fat32[cluster & 0x7F] & FAT32MASK);
194 return true;
195}
196
197// Store a FAT entry
198bool SdVolume::fatPut(const uint32_t cluster, const uint32_t value) {

Callers 5

contiguousRangeMethod · 0.80
readMethod · 0.80
seekSetMethod · 0.80
truncateMethod · 0.80
writeMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected