Fetch a FAT entry
| 161 | |
| 162 | // Fetch a FAT entry |
| 163 | bool 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 |
| 198 | bool SdVolume::fatPut(const uint32_t cluster, const uint32_t value) { |
no outgoing calls
no test coverage detected