How to detect sd card insert/removal in user space code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to detect sd card insert/removal in user space code

1,590 Views
Dhevan
Contributor IV

Hi,

      We are using imx8m mini evk board.

      SD card auto mounting is working fine.

      But we want user space code detect to detect sd card insertion and removal.

      Ubuntu i have tried netlink(libnl) suite https://www.infradead.org/~tgr/libnl/doc/core.html but not able to find proper apis.

      Please help us solve the issue.

Thanks & Regards,

       Vasu

0 Kudos
Reply
3 Replies

1,579 Views
b36401
NXP Employee
NXP Employee

I can suggest to grep /var/log/messages for messages related to SD card.
I mean something like this:
[ 542.576330] mmc1: card 59b4 removed
and this:
[ 570.761873] mmc1: new high speed SDHC card at address 59b4

0 Kudos
Reply

1,558 Views
Dhevan
Contributor IV

Hi @b36401,

     We want to detect user space c/c++ code.

     Do you have any suggestion detecting in user space c/c++ code ?

Thanks & Regards,

        Vasu

0 Kudos
Reply

1,549 Views
b36401
NXP Employee
NXP Employee

Another way (that may be more useful for C code) is to check if /dev/mmcblk1 appears.
I mean that the code may periodically check /dev/mmcblk1 filesystem entry for existing.

0 Kudos
Reply