Windows still caches SD Card after it is long gone!


At the moment I got a problem detecting if the SD Card is there and alive.
In our System we permanently install an SD Card and so we do not have a Card detect signal.
Also, a Card detect signal is irrelevant for the describes scenario.

In Case of an SD Card failing, we want to be able to detect, if it is still there and writable.

First, I just tried to detect a lost SD Card by checking if the folder “\SD Card” is still reachable. But if I remove the SD card from the SD Card Slot without toggling the Card Detect Signal, the SD Card is still shown in the Windows explorer.

Second, I tried to write a File using fstream to the SD Card, flush() the fstream and ask for the good() Bit.
This works, but only if I write enough data into the File to overcome the Windows cache (I guess?).
I can even write small files using the Notepad without it noticing, that there is no SD Card and also successfully open the Files again.

So, does anybody have an Idea, how I can detect if the SD Card died or get Windows to notice if it died?

Thank you in advance!


Dear @Sebastian

To verify whether a device has suddenly died requires physically accessing it. As you found the SD card driver uses read and write caches to improve the performance.
In the case of SD cards it might be even more complicated in a sense that the firmware inside the SD card itself does additional caching which could work fine even if the actual flash memory is not.

Some ideas how to achieve this:

  1. If you can control power of the SD card, power cycle it to clear at least the firmware caches
  2. Read a location of the SD card which you never accessed before since the last system power cycle - however, this is typically hard to control…
  3. Try to unmount and remount the SD card, calling Storage Manager functions.

Regards, Andy