summaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2009-12-08 13:54:27 -0500
committerDavid Zeuthen <davidz@redhat.com>2009-12-08 13:54:27 -0500
commit9d815258f5d0e11a36e2b73adc7e6e7129329ca2 (patch)
tree5b67fa4d9caf922d44ef027167937526a754759a /monitor
parentc1994adbc67be47838d2a20bf1c6420d521cf5d7 (diff)
downloadgvfs-9d815258f5d0e11a36e2b73adc7e6e7129329ca2.tar.gz
[gdu] Prefer using dev_t to device file when comparing devices
This works around new behavior in mount(8) where it decides to put /dev/mapper/<blah> in /etc/mtab instead of the /dev/dm-0 device that the user actually requested. Of course /dev/mapper/<blah> currently does not exist in the udev database because of device-mapper brokenness so without this fix things can never work if using a sufficiently new mount(8) command. Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r--monitor/gdu/ggdudrive.c12
-rw-r--r--monitor/gdu/ggdudrive.h4
-rw-r--r--monitor/gdu/ggduvolume.c49
-rw-r--r--monitor/gdu/ggduvolume.h2
-rw-r--r--monitor/gdu/ggduvolumemonitor.c49
-rw-r--r--monitor/gdu/ggduvolumemonitor.h5
6 files changed, 109 insertions, 12 deletions
diff --git a/monitor/gdu/ggdudrive.c b/monitor/gdu/ggdudrive.c
index 309e18ce..72126a0a 100644
--- a/monitor/gdu/ggdudrive.c
+++ b/monitor/gdu/ggdudrive.c
@@ -46,6 +46,7 @@ struct _GGduDrive {
GIcon *icon;
gchar *name;
gchar *device_file;
+ dev_t dev;
gboolean is_media_removable;
gboolean has_media;
gboolean can_eject;
@@ -128,6 +129,7 @@ update_drive (GGduDrive *drive)
GIcon *old_icon;
gchar *old_name;
gchar *old_device_file;
+ dev_t old_dev;
gboolean old_is_media_removable;
gboolean old_has_media;
gboolean old_can_eject;
@@ -151,6 +153,7 @@ update_drive (GGduDrive *drive)
old_name = g_strdup (drive->name);
old_device_file = g_strdup (drive->device_file);
+ old_dev = drive->dev;
old_icon = drive->icon != NULL ? g_object_ref (drive->icon) : NULL;
/* in with the new */
@@ -170,6 +173,7 @@ update_drive (GGduDrive *drive)
if (device == NULL)
{
g_free (drive->device_file);
+ drive->dev = 0;
drive->device_file = NULL;
drive->is_media_removable = TRUE;
drive->has_media = TRUE;
@@ -179,6 +183,7 @@ update_drive (GGduDrive *drive)
else
{
g_free (drive->device_file);
+ drive->dev = gdu_device_get_dev (device);
drive->device_file = g_strdup (gdu_device_get_device_file (device));
drive->is_media_removable = gdu_device_is_removable (device);
drive->has_media = gdu_device_is_media_available (device);
@@ -265,6 +270,7 @@ update_drive (GGduDrive *drive)
(old_can_poll_for_media == drive->can_poll_for_media) &&
(g_strcmp0 (old_name, drive->name) == 0) &&
(g_strcmp0 (old_device_file, drive->device_file) == 0) &&
+ (old_dev == drive->dev) &&
g_icon_equal (old_icon, drive->icon)
);
@@ -1200,10 +1206,10 @@ g_gdu_drive_drive_iface_init (GDriveIface *iface)
}
gboolean
-g_gdu_drive_has_device_file (GGduDrive *drive,
- const gchar *device_file)
+g_gdu_drive_has_dev (GGduDrive *drive,
+ dev_t dev)
{
- return g_strcmp0 (drive->device_file, device_file) == 0;
+ return drive->dev == dev;
}
gboolean
diff --git a/monitor/gdu/ggdudrive.h b/monitor/gdu/ggdudrive.h
index e182c292..e1aab7dc 100644
--- a/monitor/gdu/ggdudrive.h
+++ b/monitor/gdu/ggdudrive.h
@@ -52,8 +52,8 @@ void g_gdu_drive_set_volume (GGduDrive *drive,
void g_gdu_drive_unset_volume (GGduDrive *drive,
GGduVolume *volume);
void g_gdu_drive_disconnected (GGduDrive *drive);
-gboolean g_gdu_drive_has_device_file (GGduDrive *drive,
- const gchar *device_file);
+gboolean g_gdu_drive_has_dev (GGduDrive *drive,
+ dev_t dev);
time_t g_gdu_drive_get_time_of_last_media_insertion (GGduDrive *drive);
gboolean g_gdu_drive_has_presentable (GGduDrive *drive,
diff --git a/monitor/gdu/ggduvolume.c b/monitor/gdu/ggduvolume.c
index be324c98..6e2fcd3b 100644
--- a/monitor/gdu/ggduvolume.c
+++ b/monitor/gdu/ggduvolume.c
@@ -77,6 +77,7 @@ struct _GGduVolume
GFile *activation_root;
gchar *name;
gchar *device_file;
+ dev_t dev;
gchar *uuid;
gboolean can_mount;
gboolean should_automount;
@@ -179,6 +180,7 @@ update_volume (GGduVolume *volume)
gboolean old_should_automount;
gchar *old_name;
gchar *old_device_file;
+ dev_t old_dev;
GIcon *old_icon;
gboolean keep_cleartext_volume;
@@ -187,6 +189,7 @@ update_volume (GGduVolume *volume)
old_should_automount = volume->should_automount;
old_name = g_strdup (volume->name);
old_device_file = g_strdup (volume->device_file);
+ old_dev = volume->dev;
old_icon = volume->icon != NULL ? g_object_ref (volume->icon) : NULL;
/* ---------------------------------------------------------------------------------------------------- */
@@ -194,11 +197,14 @@ update_volume (GGduVolume *volume)
/* if the volume is a fstab mount point, get the data from there */
if (volume->unix_mount_point != NULL)
{
+ struct stat_buf;
+
volume->can_mount = TRUE;
volume->should_automount = FALSE;
g_free (volume->device_file);
volume->device_file = g_strdup (g_unix_mount_point_get_device_path (volume->unix_mount_point));
+ volume->dev = 0;
if (volume->icon != NULL)
g_object_unref (volume->icon);
@@ -289,9 +295,15 @@ update_volume (GGduVolume *volume)
g_free (volume->device_file);
if (luks_cleartext_volume_device != NULL)
- volume->device_file = g_strdup (gdu_device_get_device_file (luks_cleartext_volume_device));
+ {
+ volume->device_file = g_strdup (gdu_device_get_device_file (luks_cleartext_volume_device));
+ volume->dev = gdu_device_get_dev (luks_cleartext_volume_device);
+ }
else
- volume->device_file = NULL;
+ {
+ volume->device_file = NULL;
+ volume->dev = 0;
+ }
volume->can_mount = TRUE;
@@ -327,9 +339,15 @@ update_volume (GGduVolume *volume)
g_free (volume->device_file);
if (device != NULL)
- volume->device_file = g_strdup (gdu_device_get_device_file (device));
+ {
+ volume->device_file = g_strdup (gdu_device_get_device_file (device));
+ volume->dev = gdu_device_get_dev (device);
+ }
else
- volume->device_file = NULL;
+ {
+ volume->device_file = NULL;
+ volume->dev = 0;
+ }
volume->can_mount = TRUE;
@@ -369,6 +387,7 @@ update_volume (GGduVolume *volume)
(old_should_automount == volume->should_automount) &&
(g_strcmp0 (old_name, volume->name) == 0) &&
(g_strcmp0 (old_device_file, volume->device_file) == 0) &&
+ (old_dev == volume->dev) &&
g_icon_equal (old_icon, volume->icon)
);
@@ -1676,6 +1695,28 @@ g_gdu_volume_volume_iface_init (GVolumeIface *iface)
}
gboolean
+g_gdu_volume_has_dev (GGduVolume *volume,
+ dev_t dev)
+{
+ dev_t _dev;
+
+ _dev = volume->dev;
+
+ if (volume->cleartext_gdu_volume != NULL)
+ {
+ GduDevice *luks_cleartext_volume_device;
+ luks_cleartext_volume_device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->cleartext_gdu_volume));
+ if (luks_cleartext_volume_device != NULL)
+ {
+ _dev = gdu_device_get_dev (luks_cleartext_volume_device);
+ g_object_unref (luks_cleartext_volume_device);
+ }
+ }
+
+ return _dev == dev;
+}
+
+gboolean
g_gdu_volume_has_device_file (GGduVolume *volume,
const gchar *device_file)
{
diff --git a/monitor/gdu/ggduvolume.h b/monitor/gdu/ggduvolume.h
index a230d280..007484aa 100644
--- a/monitor/gdu/ggduvolume.h
+++ b/monitor/gdu/ggduvolume.h
@@ -71,6 +71,8 @@ gboolean g_gdu_volume_has_uuid (GGduVolume *volume,
const char *uuid);
gboolean g_gdu_volume_has_device_file (GGduVolume *volume,
const gchar *device_file);
+gboolean g_gdu_volume_has_dev (GGduVolume *volume,
+ dev_t dev);
GduPresentable *g_gdu_volume_get_presentable (GGduVolume *volume);
diff --git a/monitor/gdu/ggduvolumemonitor.c b/monitor/gdu/ggduvolumemonitor.c
index c5b58a00..bcf23f13 100644
--- a/monitor/gdu/ggduvolumemonitor.c
+++ b/monitor/gdu/ggduvolumemonitor.c
@@ -1061,16 +1061,37 @@ find_disc_volume_for_device_file (GGduVolumeMonitor *monitor,
const gchar *device_file)
{
GList *l;
+ GGduVolume *ret;
+ struct stat stat_buf;
+
+ ret = NULL;
+
+ if (stat (device_file, &stat_buf) == 0)
+ {
+ for (l = monitor->disc_volumes; l != NULL; l = l->next)
+ {
+ GGduVolume *volume = G_GDU_VOLUME (l->data);
+ if (g_gdu_volume_has_dev (volume, stat_buf.st_rdev))
+ {
+ ret = volume;
+ goto out;
+ }
+ }
+ }
for (l = monitor->disc_volumes; l != NULL; l = l->next)
{
GGduVolume *volume = G_GDU_VOLUME (l->data);
if (g_gdu_volume_has_device_file (volume, device_file))
- return volume;
+ {
+ ret = volume;
+ goto out;
+ }
}
- return NULL;
+ out:
+ return ret;
}
static GGduVolume *
@@ -1079,8 +1100,23 @@ find_volume_for_device_file (GGduVolumeMonitor *monitor,
{
GList *l;
GGduVolume *ret;
+ struct stat stat_buf;
ret = NULL;
+
+ if (stat (device_file, &stat_buf) == 0)
+ {
+ for (l = monitor->volumes; l != NULL; l = l->next)
+ {
+ GGduVolume *volume = G_GDU_VOLUME (l->data);
+ if (g_gdu_volume_has_dev (volume, stat_buf.st_rdev))
+ {
+ ret = volume;
+ goto out;
+ }
+ }
+ }
+
for (l = monitor->volumes; l != NULL; l = l->next)
{
GGduVolume *volume = G_GDU_VOLUME (l->data);
@@ -1113,12 +1149,19 @@ find_drive_by_device_file (GGduVolumeMonitor *monitor,
const gchar *device_file)
{
GList *l;
+ struct stat stat_buf;
+
+ if (stat (device_file, &stat_buf) != 0)
+ {
+ g_warning ("%s:%s: Error statting %s: %m", G_STRLOC, G_STRFUNC, device_file);
+ return NULL;
+ }
for (l = monitor->drives; l != NULL; l = l->next)
{
GGduDrive *drive = G_GDU_DRIVE (l->data);
- if (g_gdu_drive_has_device_file (drive, device_file))
+ if (g_gdu_drive_has_dev (drive, stat_buf.st_rdev))
return drive;
}
diff --git a/monitor/gdu/ggduvolumemonitor.h b/monitor/gdu/ggduvolumemonitor.h
index b91ceb9c..2b6383a9 100644
--- a/monitor/gdu/ggduvolumemonitor.h
+++ b/monitor/gdu/ggduvolumemonitor.h
@@ -28,6 +28,11 @@
#include <gio/gio.h>
#include <gio/gunixmounts.h>
+/* for dev_t */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include <gdu/gdu.h>
G_BEGIN_DECLS