FAT32 Fixes for SD lib (easy) #161

JacobChrist opened this Issue Dec 12, 2011 · 1 comment


None yet

2 participants


The following changes are needed for Fat32 file systems:



ound a part of the FAT32 bug. It's in the same SDFile.cpp, openRoot method, where in calling vol->chainSize(firstCluster_, &fileSize_), fileSize_'s address is not correct. Tried this and works to open a FAT32 card , it says it creates a new file, but I didn't check the card. So I don't know if there is another bug remained or not.

Initial code in the openRoot method is:
if (!vol->chainSize(firstCluster_, &fileSize_)) return false;

Modified code in the openRoot method is:
uint32_t *pfileSize_ = new uint32_t();
*pfileSize_ = fileSize_;
if (!vol->chainSize(firstCluster_, pfileSize_))
Serial.println("Error opening FAT32 filesystem"); return false;
Serial.println("Success opening filesystem");
fileSize_ = *pfileSize_;
delete pfileSize_;
pfileSize_ = NULL;

The Serial.println's are just for debugging.


uint8_t SdFile::addCluster() {
uint32_t *curClusterP_ = new uint32_t();
*curClusterP_ = curCluster_;
if (!vol_->allocContiguous(1, curClusterP_)) return false;
curCluster_ = *curClusterP_;
delete curClusterP_;
curClusterP_ = NULL;
// if first cluster of file link to directory entry
if (firstCluster_ == 0) {
firstCluster_ = curCluster_;
flags_ |= F_FILE_DIR_DIRTY;
return true;


Thanks for this information. I have someone working on trying to track down the problems with SD right now. I'll have her look at this right away.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment