Add a cluster to a directory file and zero the cluster. return with first block of cluster in the cache
| 62 | // Add a cluster to a directory file and zero the cluster. |
| 63 | // return with first block of cluster in the cache |
| 64 | bool SdBaseFile::addDirCluster() { |
| 65 | if (ENABLED(SDCARD_READONLY)) return false; |
| 66 | |
| 67 | uint32_t block; |
| 68 | // max folder size |
| 69 | if (fileSize_ / sizeof(dir_t) >= 0xFFFF) return false; |
| 70 | |
| 71 | if (!addCluster()) return false; |
| 72 | if (!vol_->cacheFlush()) return false; |
| 73 | |
| 74 | block = vol_->clusterStartBlock(curCluster_); |
| 75 | |
| 76 | // set cache to first block of cluster |
| 77 | vol_->cacheSetBlockNumber(block, true); |
| 78 | |
| 79 | // zero first block of cluster |
| 80 | memset(vol_->cacheBuffer_.data, 0, 512); |
| 81 | |
| 82 | // zero rest of cluster |
| 83 | for (uint8_t i = 1; i < vol_->blocksPerCluster_; i++) { |
| 84 | if (!vol_->writeBlock(block + i, vol_->cacheBuffer_.data)) return false; |
| 85 | } |
| 86 | // Increase directory file size by cluster size |
| 87 | fileSize_ += 512UL << vol_->clusterSizeShift_; |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | // cache a file's directory entry |
| 92 | // cache the current "dirBlock_" and return the entry at index "dirIndex_" |
no test coverage detected