SdFat
SdFat copied to clipboard
code freezes during recursion on malformed sdcard
Hi,
I've an problem with recursion on corrupted sdcard which results in freezing of mine SAMD. I presume issue is related to bad files/dirs names or general fat structure malforming.
Suggested solution:
- exclude malformed files/dirs access
- maybe creating some special file named "MALFORMED_CARD" which indicates problems in fat structure or method which returns indicator of such detection
sdfat: 2.1.2 ide: vscode + platformio board: MKR Zero sdfatconfig.h is default
Below code used on correctly structured sdcard works great:
void ls(char *path, uint16_t maxLevel)
{
SdBaseFile dir;
if (!dir.open(path, O_READ) || !dir.isDir())
{
DBG_SDCARD("--- bad_dir");
return;
}
dir.ls(&debugSerialPort, LS_R);
}
code is executed with:
SD.ls(&debugSerialPort, LS_R); //full recursion, on corrupted card it fails
I've prepared image with HDDRawCopy tool which can write/read images of files, link to raw image: https://github.com/Tarnak-public/filehosting_for_issues/blob/b5622e9fa7623ae8ed1ce3dbe7849688353938a2/sdfat/recursion_on_malformed_sdcard/SDcardMalformed.7z
It is not practical to detect a corrupt filesystem with the limited memory of a microprocessor like SAMD.
SdFat can detect some problems but corrupt FAT chains or corrupt directory trees can cause problems with ls.
Filesystem corruption can occur due to crashes or failure to close files open for write. Best to check and repair the SD on a PC with Linux or windows.