diff options
author | David Zeuthen <davidz@redhat.com> | 2011-10-06 16:36:51 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2011-10-06 16:36:51 -0400 |
commit | 62ebe3061f5693ad24a22d7e2230ea9bb9945305 (patch) | |
tree | de2a64c390c2a2abeff1e1ee6d574aeb73b14def | |
parent | 89784d4493a9d482ec3fd6559a5fa4c30958180d (diff) | |
download | gvfs-62ebe3061f5693ad24a22d7e2230ea9bb9945305.tar.gz |
udisks2: handle when a mount is added before its containing volume
Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r-- | monitor/udisks2/gvfsudisks2mount.c | 11 | ||||
-rw-r--r-- | monitor/udisks2/gvfsudisks2mount.h | 1 | ||||
-rw-r--r-- | monitor/udisks2/gvfsudisks2volumemonitor.c | 61 |
3 files changed, 59 insertions, 14 deletions
diff --git a/monitor/udisks2/gvfsudisks2mount.c b/monitor/udisks2/gvfsudisks2mount.c index 4835dcdc..1745134b 100644 --- a/monitor/udisks2/gvfsudisks2mount.c +++ b/monitor/udisks2/gvfsudisks2mount.c @@ -405,6 +405,7 @@ gvfs_udisks2_mount_set_volume (GVfsUDisks2Mount *mount, /* this is for piggy backing on the name and icon of the associated volume */ g_signal_connect (mount->volume, "changed", G_CALLBACK (on_volume_changed), mount); } + update_mount (mount); emit_changed (mount); } } @@ -470,7 +471,7 @@ gvfs_udisks2_mount_get_drive (GMount *_mount) } static GVolume * -gvfs_udisks2_mount_get_volume (GMount *_mount) +gvfs_udisks2_mount_get_volume_ (GMount *_mount) { GVfsUDisks2Mount *mount = GVFS_UDISKS2_MOUNT (_mount); GVolume *volume = NULL; @@ -1225,7 +1226,7 @@ gvfs_udisks2_mount_mount_iface_init (GMountIface *iface) iface->get_icon = gvfs_udisks2_mount_get_icon; iface->get_uuid = gvfs_udisks2_mount_get_uuid; iface->get_drive = gvfs_udisks2_mount_get_drive; - iface->get_volume = gvfs_udisks2_mount_get_volume; + iface->get_volume = gvfs_udisks2_mount_get_volume_; iface->can_unmount = gvfs_udisks2_mount_can_unmount; iface->can_eject = gvfs_udisks2_mount_can_eject; iface->unmount = gvfs_udisks2_mount_unmount; @@ -1247,3 +1248,9 @@ gvfs_udisks2_mount_has_volume (GVfsUDisks2Mount *mount, { return mount->volume == volume; } + +GVfsUDisks2Volume * +gvfs_udisks2_mount_get_volume (GVfsUDisks2Mount *mount) +{ + return mount->volume; +} diff --git a/monitor/udisks2/gvfsudisks2mount.h b/monitor/udisks2/gvfsudisks2mount.h index 13c96569..6b476673 100644 --- a/monitor/udisks2/gvfsudisks2mount.h +++ b/monitor/udisks2/gvfsudisks2mount.h @@ -51,6 +51,7 @@ void gvfs_udisks2_mount_unset_volume (GVfsUDisks2Mount *m GVfsUDisks2Volume *volume); gboolean gvfs_udisks2_mount_has_volume (GVfsUDisks2Mount *mount, GVfsUDisks2Volume *volume); +GVfsUDisks2Volume *gvfs_udisks2_mount_get_volume (GVfsUDisks2Mount *mount); const gchar *gvfs_udisks2_mount_get_mount_path (GVfsUDisks2Mount *mount); GUnixMountEntry *gvfs_udisks2_mount_get_mount_entry (GVfsUDisks2Mount *mount); diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.c b/monitor/udisks2/gvfsudisks2volumemonitor.c index 08798385..be5e4473 100644 --- a/monitor/udisks2/gvfsudisks2volumemonitor.c +++ b/monitor/udisks2/gvfsudisks2volumemonitor.c @@ -418,11 +418,14 @@ diff_sorted_lists (GList *list1, GList *list2, GCompareFunc compare, GList **added, - GList **removed) + GList **removed, + GList **unchanged) { int order; *added = *removed = NULL; + if (unchanged != NULL) + *unchanged = NULL; while (list1 != NULL && list2 != NULL) @@ -440,6 +443,8 @@ diff_sorted_lists (GList *list1, } else { /* same item */ + if (unchanged != NULL) + *unchanged = g_list_prepend (*unchanged, list1->data); list1 = list1->next; list2 = list2->next; } @@ -929,7 +934,10 @@ find_volume_for_device (GVfsUDisks2VolumeMonitor *monitor, goto out; if (stat (device, &statbuf) != 0) - goto out; + { + g_debug ("error statting %s: %m", device); + goto out; + } for (l = monitor->volumes; l != NULL; l = l->next) { @@ -1017,7 +1025,7 @@ update_drives (GVfsUDisks2VolumeMonitor *monitor, new_udisks_drives = g_list_sort (new_udisks_drives, (GCompareFunc) udisks_drive_compare); diff_sorted_lists (cur_udisks_drives, new_udisks_drives, (GCompareFunc) udisks_drive_compare, - &added, &removed); + &added, &removed, NULL); for (l = removed; l != NULL; l = l->next) { @@ -1098,7 +1106,7 @@ update_volumes (GVfsUDisks2VolumeMonitor *monitor, new_block_volumes = g_list_sort (new_block_volumes, (GCompareFunc) block_compare); diff_sorted_lists (cur_block_volumes, new_block_volumes, (GCompareFunc) block_compare, - &added, &removed); + &added, &removed, NULL); for (l = removed; l != NULL; l = l->next) { @@ -1252,7 +1260,7 @@ update_fstab_volumes (GVfsUDisks2VolumeMonitor *monitor, new_mount_points = g_list_sort (new_mount_points, (GCompareFunc) g_unix_mount_point_compare); diff_sorted_lists (cur_mount_points, new_mount_points, (GCompareFunc) g_unix_mount_point_compare, - &added, &removed); + &added, &removed, NULL); for (l = removed; l != NULL; l = l->next) { @@ -1313,7 +1321,7 @@ update_mounts (GVfsUDisks2VolumeMonitor *monitor, { GList *cur_mounts; GList *new_mounts; - GList *removed, *added; + GList *removed, *added, *unchanged; GList *l, *ll; GVfsUDisks2Mount *mount; GVfsUDisks2Volume *volume; @@ -1348,7 +1356,7 @@ update_mounts (GVfsUDisks2VolumeMonitor *monitor, new_mounts = g_list_sort (new_mounts, (GCompareFunc) g_unix_mount_compare); diff_sorted_lists (cur_mounts, new_mounts, (GCompareFunc) g_unix_mount_compare, - &added, &removed); + &added, &removed, &unchanged); for (l = removed; l != NULL; l = l->next) { @@ -1367,10 +1375,7 @@ update_mounts (GVfsUDisks2VolumeMonitor *monitor, for (l = added; l != NULL; l = l->next) { GUnixMountEntry *mount_entry = l->data; - const gchar *device_file; - - device_file = g_unix_mount_get_device_path (mount_entry); - volume = find_volume_for_device (monitor, device_file); + volume = find_volume_for_device (monitor, g_unix_mount_get_device_path (mount_entry)); if (volume == NULL) volume = find_fstab_volume_for_mount_entry (monitor, mount_entry); mount = gvfs_udisks2_mount_new (monitor, mount_entry, volume); /* adopts mount_entry */ @@ -1384,8 +1389,39 @@ update_mounts (GVfsUDisks2VolumeMonitor *monitor, } } + /* Handle the case where the volume containing the mount appears *after* + * the mount. + * + * This can happen when unlocking+mounting a LUKS device and the two + * operations are *right* after each other. In that case we get the + * event from GUnixMountMonitor (which monitors /proc/mounts) before + * the event from udisks. + */ + for (l = unchanged; l != NULL; l = l->next) + { + GUnixMountEntry *mount_entry = l->data; + mount = find_mount_by_mount_path (monitor, g_unix_mount_get_mount_path (mount_entry)); + if (mount == NULL) + { + g_warning ("No mount object for path %s", g_unix_mount_get_mount_path (mount_entry)); + continue; + } + if (gvfs_udisks2_mount_get_volume (mount) == NULL) + { + volume = find_volume_for_device (monitor, g_unix_mount_get_device_path (mount_entry)); + if (volume == NULL) + volume = find_fstab_volume_for_mount_entry (monitor, mount_entry); + if (volume != NULL) + { + g_debug ("late setting volume for %s", g_unix_mount_get_mount_path (mount_entry)); + gvfs_udisks2_mount_set_volume (mount, volume); + } + } + } + g_list_free (added); g_list_free (removed); + g_list_free (unchanged); g_list_foreach (new_mounts, (GFunc) g_unix_mount_free, NULL); g_list_free (new_mounts); @@ -1449,7 +1485,8 @@ update_discs (GVfsUDisks2VolumeMonitor *monitor, cur_disc_drives = g_list_sort (cur_disc_drives, (GCompareFunc) udisks_drive_compare); new_disc_drives = g_list_sort (new_disc_drives, (GCompareFunc) udisks_drive_compare); - diff_sorted_lists (cur_disc_drives, new_disc_drives, (GCompareFunc) udisks_drive_compare, &added, &removed); + diff_sorted_lists (cur_disc_drives, new_disc_drives, (GCompareFunc) udisks_drive_compare, + &added, &removed, NULL); for (l = removed; l != NULL; l = l->next) { |