Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

71%
+3 −0
Q&A What happens when a microSD card is hot-unplugged?

There is no provision in FatFS or the fat32 filesystem in general regarding hot-unplug, so this behaviour depends wholly on the implementation layer for your hardware. As an example, in my use cas...

posted 6mo ago by DSI‭  ·  edited 6mo ago by DSI‭

Answer
#2: Post edited by user avatar DSI‭ · 2024-04-29T01:19:59Z (6 months ago)
  • There is no provision in FatFS or the fat32 filesystem in general regarding hot-unplug, so this behaviour depends wholly on the implementation layer for your hardware.
  • As an example, in my use case I have tested the behaviour of my system when I remove the memory card without calling f_close() on open files. I found that there is a 0-sized file that was created when I called f_open(), and when I used filesystem repair tool in Disks on Linux, it created "orphaned" files it found - the data in them was usable up to the removal of the card. You will need to implement card detect interrupt that would flush all filesystem IO and close all opened files if you want to handle it robustly.
  • There is no provision in FatFS or the fat32 filesystem in general regarding hot-unplug, so this behaviour depends wholly on the implementation layer for your hardware.
  • As an example, in my use case I have tested the behaviour of my system when I remove the memory card without calling f_close() on open files. I found that there is a 0-sized file that was created when I called f_open(), and when I used filesystem repair tool in Disks on Linux, it created "orphaned" files it found - the data in them was usable up to the removal of the card. If your card socket supports it (ie the card detect triggers before pin contact is lost), you will need to implement card detect interrupt that would flush all filesystem IO and close all opened files if you want to handle it robustly. Alternatively, you will need to buffer data in RAM and write it in f_open -> f_write -> f_sync -> f_close sequence every time. Depending on implementation, it can take a while to do those (a hundred ms is not uncommon).
#1: Initial revision by user avatar DSI‭ · 2024-04-29T01:13:38Z (6 months ago)
There is no provision in FatFS or the fat32 filesystem in general regarding hot-unplug, so this behaviour depends wholly on the implementation layer for your hardware.

As an example, in my use case I have tested the behaviour of my system when I remove the memory card without calling f_close() on open files. I found that there is a 0-sized file that was created when I called f_open(), and when I used filesystem repair tool in Disks on Linux, it created "orphaned" files it found - the data in them was usable up to the removal of the card. You will need to implement card detect interrupt that would flush all filesystem IO and close all opened files if you want to handle it robustly.