From da7cf8535ca488808c56c13a5a0b37a96f61e45e Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Wed, 4 Nov 2015 10:04:55 +0100 Subject: [PATCH 1/3] Extend DBUS interface by MountOptions property Additionally monitor mount options instead of mount points only and add MountOptions property to the DBUS interface. --- data/org.freedesktop.UDisks2.xml | 6 ++++++ src/udiskslinuxfilesystem.c | 11 ++++++++++- src/udisksmount.c | 26 ++++++++++++++++++++++++++ src/udisksmount.h | 13 +++++++------ src/udisksmountmonitor.c | 14 ++++++++++---- src/udisksprivate.h | 1 + 6 files changed, 60 insertions(+), 11 deletions(-) diff --git a/data/org.freedesktop.UDisks2.xml b/data/org.freedesktop.UDisks2.xml index bd72795..bc77e8a 100644 --- a/data/org.freedesktop.UDisks2.xml +++ b/data/org.freedesktop.UDisks2.xml @@ -1510,6 +1510,12 @@ --> + + + -type mount. + * + * It is a programming error to call this on any other type of #UDisksMount. + * + * Returns: A string owned by @mount. Do not free. + */ +const gchar * +udisks_mount_get_mount_options (UDisksMount *mount) +{ + g_return_val_if_fail (UDISKS_IS_MOUNT (mount), NULL); + g_return_val_if_fail (mount->type == UDISKS_MOUNT_TYPE_FILESYSTEM, NULL); + return mount->mount_options; +} + +/** * udisks_mount_get_dev: * @mount: A #UDisksMount. * @@ -160,6 +182,10 @@ udisks_mount_compare (UDisksMount *mount, goto out; ret = other_mount->type - mount->type; + if (ret != 0) + goto out; + + ret = g_strcmp0 (mount->mount_options, other_mount->mount_options); out: return ret; diff --git a/src/udisksmount.h b/src/udisksmount.h index 0beaf32..308c956 100644 --- a/src/udisksmount.h +++ b/src/udisksmount.h @@ -29,12 +29,13 @@ G_BEGIN_DECLS #define UDISKS_MOUNT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UDISKS_TYPE_MOUNT, UDisksMount)) #define UDISKS_IS_MOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UDISKS_TYPE_MOUNT)) -GType udisks_mount_get_type (void) G_GNUC_CONST; -UDisksMountType udisks_mount_get_mount_type (UDisksMount *mount); -const gchar *udisks_mount_get_mount_path (UDisksMount *mount); -dev_t udisks_mount_get_dev (UDisksMount *mount); -gint udisks_mount_compare (UDisksMount *mount, - UDisksMount *other_mount); +GType udisks_mount_get_type (void) G_GNUC_CONST; +UDisksMountType udisks_mount_get_mount_type (UDisksMount *mount); +const gchar *udisks_mount_get_mount_path (UDisksMount *mount); +const gchar *udisks_mount_get_mount_options (UDisksMount *mount); +dev_t udisks_mount_get_dev (UDisksMount *mount); +gint udisks_mount_compare (UDisksMount *mount, + UDisksMount *other_mount); G_END_DECLS diff --git a/src/udisksmountmonitor.c b/src/udisksmountmonitor.c index 891d118..a6e783d 100644 --- a/src/udisksmountmonitor.c +++ b/src/udisksmountmonitor.c @@ -423,26 +423,30 @@ udisks_mount_monitor_get_mountinfo (UDisksMountMonitor *monitor, guint major, minor; gchar encoded_root[PATH_MAX + 1]; gchar encoded_mount_point[PATH_MAX + 1]; + gchar encoded_mount_options[PATH_MAX + 1]; gchar *mount_point; + gchar *mount_options; dev_t dev; if (strlen (lines[n]) == 0) continue; if (sscanf (lines[n], - "%u %u %u:%u " PATH_MAX_FMT " " PATH_MAX_FMT, + "%u %u %u:%u " PATH_MAX_FMT " " PATH_MAX_FMT " " PATH_MAX_FMT, &mount_id, &parent_id, &major, &minor, encoded_root, - encoded_mount_point) != 6) + encoded_mount_point, + encoded_mount_options) != 7) { udisks_warning ("Error parsing line '%s'", lines[n]); continue; } encoded_root[sizeof encoded_root - 1] = '\0'; encoded_mount_point[sizeof encoded_mount_point - 1] = '\0'; + encoded_mount_options[sizeof encoded_mount_options - 1] = '\0'; /* Temporary work-around for btrfs, see * @@ -500,16 +504,18 @@ udisks_mount_monitor_get_mountinfo (UDisksMountMonitor *monitor, } mount_point = g_strcompress (encoded_mount_point); + mount_options = g_strcompress (encoded_mount_options); /* TODO: we can probably use a hash table or something if this turns out to be slow */ if (!have_mount (monitor, dev, mount_point)) { UDisksMount *mount; - mount = _udisks_mount_new (dev, mount_point, UDISKS_MOUNT_TYPE_FILESYSTEM); + mount = _udisks_mount_new (dev, mount_point, mount_options, UDISKS_MOUNT_TYPE_FILESYSTEM); monitor->mounts = g_list_prepend (monitor->mounts, mount); } g_free (mount_point); + g_free (mount_options); } ret = TRUE; @@ -584,7 +590,7 @@ udisks_mount_monitor_get_swaps (UDisksMountMonitor *monitor, if (!have_mount (monitor, dev, NULL)) { UDisksMount *mount; - mount = _udisks_mount_new (dev, NULL, UDISKS_MOUNT_TYPE_SWAP); + mount = _udisks_mount_new (dev, NULL, NULL, UDISKS_MOUNT_TYPE_SWAP); monitor->mounts = g_list_prepend (monitor->mounts, mount); } } diff --git a/src/udisksprivate.h b/src/udisksprivate.h index 5dfd77e..a61002c 100644 --- a/src/udisksprivate.h +++ b/src/udisksprivate.h @@ -28,6 +28,7 @@ G_BEGIN_DECLS UDisksMount *_udisks_mount_new (dev_t dev, const gchar *mount_path, + const gchar *mount_options, UDisksMountType type); UDisksFstabEntry *_udisks_fstab_entry_new (const struct mntent *mntent); -- 2.4.0