chipKIT32/chipKIT32-MAX — Issue #161: FAT32 Fixes for SD lib (easy)
Author: JacobChrist
Created: 2011-12-12 19:58:17+00:00
State: open

The following changes are needed for Fat32 file systems:

hardware/pic32/libraries/SD/utility/SdFile.cpp

http://www.chipkit.org/forum/viewtopic.php?p=2702#p2702

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:
Code:
if (!vol->chainSize(firstCluster_, &fileSize_)) return false;

Modified code in the openRoot method is:
Code:
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.

-----------
http://www.chipkit.org/forum/viewtopic.php?p=2669#p2669

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;
}