home | list info | list archive | date index | thread index

[OCLUG-Tech] SD card set to read only

On our product there is a script on bootup that reads a config file on an
SD card that contains URL information required to download an executeable.
Once it has this information the script then calls wget to retrieve the
file. However, when the file can't be downloaded due to server or network
problems, the watchdog timer times out and reboots the device.

My understanding is that Linux sets flags on the SD card's filesystem when
accessed (or mounted?). Once the script that's accessing the SD card
completes, Linux changes these flags back to indicate a good filesystem
state. But if the watchdog fires within the script and the SD card is
re-accessed after it reboots, the SD card filesystem is improperly marked
and Linux will set the SD card file system to 'read only', thereby
rendering the CM incapable of being written to, which is a problem in our
application.

The SD filesystem is FAT. Here's what Linux says when re-accessing the
file on the SD card after a watchdog timeout:

 FAT: Filesystem error (dev mmcblk0p1)
 fat_free_clusters: deleting FAT entry beyond EOF
 File system has been set read-only

Is my accessment correct or is there another problem here? Note: the
access described above is a read access only. Later on the downloaded
executeable may have to write some data to the SD card.

My research on the net tells me that I can use the following command to
reset the SD card file system back to r/w:
mount -o rw,remount ....
but how can the script detect that the SD card filesystem has been set to
read only? The command 'stat -f' doesn't provide that kind of information
from what i can tell.

Or can I simply use the mount command all the time in the script
regardless of the state of the f/s?

Am I on the right track or is there a better way.

Hope my description is OK.

Regards,
/carl h.






replies