Programmatically detecting the SD card

Home Forums MultiConnect OCG Programmatically detecting the SD card

Tagged: ,

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2574
    Brian
    Participant

    I am trying to find a reliable way to detect when an SD card is present. When I try to write to the SD card and it’s not inserted, it doesn’t cause any errors, which is odd.

    Right now, I have to check the available space in the mounted location. Is there a more elegant way to determine whether or not there is an SD card inserted?

    #3180
    Jesse Gilles
    Blocked

    It doesn’t cause any errors when you write to /media/card because it is just a regular directory until a device is mounted at that location (which happens automatically when you insert the SD card).

    You can see this behavior just by unmounting the filesystem (umount /media/card) and then inspecting the /media/card directory. If you create files in that directory when the SD card isn’t mounted, they will stay there and be visible whenever the card isn’t mounted.

    You could read the file /proc/mounts which shows the currently mounted filesystems.

    #3181
    Brian
    Participant

    If the SD card is inserted on boot, there is no change in the file when the card is removed.

    I’m not sure how to detect the SD card in this case.

    #3182
    Jesse Gilles
    Blocked

    When I have my SD inserted in my CDP on boot, the /media/card mount shows up in /proc/mounts. If I remove the card, it disappears from /proc/mounts pretty quickly.

    Yours doesn’t do this?

    #3183
    Brian
    Participant

    I figured out why my CDP is behaving differently. I had a file open on the SD card, so it wasn’t unmounting properly on removal.

    There might not be a good way to detect a removal if the card is currently in use. Under normal use, this shouldn’t ever happen though, so maybe isn’t not worth worrying about.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.