Multiple mount events on mounting iPod
Question
I am working on an app which has to detect if a storage volume is mounted or unmounted. I am using GIO
for that. I listening for the mount-added
and mount-removed
signals. Everything works fine when I mount/unmount a pen drive. However, I am seeing an issue when mounting an iPod. I am getting two callbacks each on mount and unmount. I assumed one of the GMount
objects would be shadowed but g_mount_is_shadowed is returning false for both. How do I decide which one to process and which to ignore? I cannot process both. I have to detect the mount/unmount corresponding to the storage device and process only that.
int main()
{
g_type_init();
GVolumeMonitor* volume_monitor = g_volume_monitor_get();
g_signal_connect(G_OBJECT(volume_monitor), "mount-added", G_CALLBACK(mount_added), NULL);
g_signal_connect(G_OBJECT(volume_monitor), "mount-removed", G_CALLBACK(mount_removed), NULL);
GMainLoop* main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
...
}
Solution
I have figured it out. GIO
emits a mount-added
signal for each filesystem that is added. The iPod has two file systems - one for the OS and one for storing music. Hence the repeated callback. The same happens on unmount. This has nothing to do with shadowed mounts. Unfortunately, I still don't know how to distinguish between the two mounts. The only difference GIO
shows is that one of the GMount
objects does not have a GVolume
object associated with it. I don't know how to interpret that.