AnsweredAssumed Answered

FatFS erase and defrag NOR flash

Question asked by rshipman on Jul 23, 2020
Latest reply on Jul 23, 2020 by Mark Butcher



I'm using FatFS for a filing system on a nor flash device (e.g. RT1020-EVK) and I have a some questions:


1. Defragmentation:


I had a quick look at the source and it looks like files can be fragmented, because the file object sets up a fragment chain, or something like that. In fact that seems to be the way FAT works - linked lists of clusters.

I just want to ask if my understanding is correct:
a. Files can be fragmented without any problems.
b. No defragmentation is required to fit large files in, because it is all sector based and there is a chain for each file maintaining which sectors are occupied by it. So the file does not need to be contiguous etc.


2. Erasing Sectors:


At the moment when FatFS asks me to write a sector, I always erase it first (just to get things working). However if the sector has already been erased, this seems unnecessary. Does FatFS provide a way to handle this? Or do I need to maintain a map (of sectors that need erasing) or something and handle this myself?


Thanks and kind regards,