Post Reply 
[newRPL] Filesystem sanity checks after SD card reinsertion
09-19-2016, 01:02 AM
Post: #2
RE: [newRPL] File system sanity checks after SD card reinsertion
(09-18-2016 08:43 PM)matthiaspaul Wrote:  Split from the main newRPL thread at

(09-17-2016 06:55 PM)Claudio L. Wrote:  
  • Safe notification and exception when card is removed with open files
I like this a lot and have a suggestion how to further improve it:

At present there appears to be no protection if the user would reinsert a different card or change the contents of the card externally before reinserting it.
So, the system could store some signature identifying the card alongside the other card data. If the card gets removed before all data has been written out and the system detects that a card is inserted again, it would compare the card's signature with the internally stored one and write out the pending data only if the card was identified to be the same card as before. If, according to the signature,
it isn't the same card, the user is prompted to insert the correct card or discard the pending data.

It's done, but there's a weakness I haven't been able to resolve. Right now I'm using the card CID which is unique to each card to make sure the user inserts the right card. The exception warns the user and asks to reinsert the card immediately, so no data is lost. If the user doesn't care and inserts a different card, the system detects the card was changed and does a special shutdown of the file system that discards everything without writing it to the card. The new card will remain unmounted until first use.
In that regards the protection works as you intended.
What I can't prevent is the user from pulling the card with a dirty file system, carelessly disregard the request to reinsert the card, then use the card on a PC, which would make changes to the file system, and then reinsert the card on the 50g. The 50g would detect the same card is back and would keep the volume mounted, which risks corrupting the FAT if we had any pending writes to the FAT.
This case is quite rare, though, because the user has to pull the card within 3 seconds of the last write, but it could happen and I don't have a solution in place for it.

The last cluster and free space only work on FAT32, so that doesn't help. Also, moving a file to another directory may not allocate any clusters, keeping those counts the same. However, the altered directory may have open files on the 50g, which means there could be up to one sector of buffered data ready to overwrite whatever the PC did.

Any other way to achieve this?
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: [newRPL] File system sanity checks after SD card reinsertion - Claudio L. - 09-19-2016 01:02 AM

User(s) browsing this thread: 1 Guest(s)