简体   繁体   English

挂载iPod时发生多次挂载事件

[英]Multiple mount events on mounting iPod

I am working on an app which has to detect if a storage volume is mounted or unmounted. 我正在开发一个必须检测存储卷是否已挂载的应用程序。 I am using GIO for that. 我正在为此使用GIO I listening for the mount-added and mount-removed signals. 我在听mount-addedmount-removed信号。 Everything works fine when I mount/unmount a pen drive. 当我安装/卸载笔式驱动器时,一切正常。 However, I am seeing an issue when mounting an iPod. 但是,安装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. 我假设的一个GMount对象将被阴影 ,但g_mount_is_shadowed将返回两个错误。 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);
    ...
}

I have figured it out. 我已经知道了。 GIO emits a mount-added signal for each filesystem that is added. GIO会为每个添加的文件系统发出mount-added信号。 The iPod has two file systems - one for the OS and one for storing music. iPod有两个文件系统-一个用于操作系统,另一个用于存储音乐。 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. GIO显示的唯一区别是,其中一个GMount对象没有与之关联的GVolume对象。 I don't know how to interpret that. 我不知道该怎么解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM