Julian Zhang
Julian Zhang

Reputation: 51

Android File System Mount/Unmount Notification

I'm developing a debugging program in Android. The debugging program is a native C++ process and is a part of the Android platform. I need to save log to the external SD card if there is one inserted into the Android device, and stop accessing it when it's unmounted.

Is there any notification mechanism of file system mount/unmount? I've checked the vold program and have not got any clue.

Upvotes: 1

Views: 1054

Answers (1)

alijandro
alijandro

Reputation: 12147

A mechanism called hotplug in the Linux kernel to handle it. In the userspace, you can use the netlink socket to do detect.

When the sdcard inserted or removed, you can get the action from netlink packet.

After receiving the action, to make sure the devices is mounted or unmounted, check the file /proc/mounts for a mounting point.

Refer here for the example of netlink event.

Upvotes: 1

Related Questions