On Mon, 2022-12-26 at 21:26 +0100, Nicolas George wrote: > Tixy (12022-12-26): > > He didn't mention filesystems. > > > > The controller in the card would surely know what flash blocks contain > > data, so writing the whole card first would reserve those blocks as > > 'in-use' leaving just a relatively small amount of spare blocks which > > would be available for erasure and reuse the that repeated write. > > Unless the card is brand new, “what flash blocks contain data” is “all > of them”. The information whether a block is used or not used resides in > the filesystem data structures. >
The card could know what blocks of flash have been written to, it's the thing that has done the writing. Very simplistically, if the OS writes to sector N, card has to allocate a block of flash to contain the data for that sector. If OS writes to sector N again, card has to get an erased block of flash to write new sector data to, then it can erase the old block of flash which it now knows is unused. (Note blocks are much bigger than sectors, and the data structures and algorithms for keeping track of what's where will be proprietary 'magic'.) So, if like me, you have a 64GB card, with just a 4GB partition containing a filesystem, then the OS will never have written to sectors outside that partition and the controller on the card would never have had to allocated flash for them. Therefore it can know about 60GB of unused flash, plus whatever extra reserve the card was manufactured with. What SD cards actually do in reality though, I don't know. -- Tixy

