The frndamental of gvfs monitor device change like below items:
1. summary first, launch a daemon /usr/libexec/gvfsd which emit "mount-changed" "mount-added"... to backend. backend example: /usr/libexec/gvfs-hal-volume-monitor to monitor hal, can get the "mount-changed" "mount-added"... singal, and try to mount device by tool of gnome-mount.
2. user insert a usb device
3. get notify by hal,also get the device properties
4. mount device as command of "gnome-mount -b -d [device-path]"
5. update the device properties, emit a singal "mount_changed" to GVolumeMonitor
6. why GVolumeMonitor class which belong "glib/gio" can be used like:
g_signal_connect (monitor, "mount-changed", G_CALLBACK (mount_changed), NULL);
we can find the monitor init source like:
GHalVolumeMonitor * monitor->mount_monitor = g_unix_mount_monitor_new (); g_signal_connect (monitor->mount_monitor, "mounts_changed", G_CALLBACK (mounts_changed), monitor); g_signal_connect (monitor->mount_monitor, "mountpoints_changed", G_CALLBACK (mountpoints_changed), monitor); g_signal_connect (monitor->pool, "device_added", G_CALLBACK (hal_changed), monitor); g_signal_connect (monitor->pool, "device_removed", G_CALLBACK (hal_changed), monitor);
Because GVolumeMonitor call the backend which monitor /etc/fstab /etc/mtab or /proc/mounts check the mount point of device and so on . when device mount/unmount these files will changed, then singal be wrapped and received by the GVolumeMonitor.
7.umount the device
8. monitor get notify by hal
9. use command of "gnome-mount -u -b -d [device]" to umount device
detail source see:
gvfs-1.2.3/monitor/*