From e746031ac3eee56e26e8a47c59dd59b270292f9a Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 26 Apr 2018 10:36:36 +0200 Subject: [PATCH] gio: Add g_unix_mount_get_options GVfsUDisks2VolumeMonitor handles x-gvfs-hide/x-gvfs-show mount options used to overwrite our heuristics whether the mount should be shown, or hidden. Unfortunately, it works currently only for mounts with corresponding fstab entries, because the options are read over g_unix_mount_point_get_options. Let's introduce g_unix_mount_get_options to allow reading of the options for all sort of mounts (e.g. created over pam_mount, or manually mounted). (Minor fixes to the documentation by Philip Withnall .) https://bugzilla.gnome.org/show_bug.cgi?id=668132 --- docs/reference/gio/gio-sections.txt | 1 + gio/gunixmounts.c | 37 +++++++++++++++++++++++++++++ gio/gunixmounts.h | 2 ++ 3 files changed, 40 insertions(+) diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index 2eb7efc74..0a35f9541 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -1546,6 +1546,7 @@ g_unix_mount_copy g_unix_mount_get_mount_path g_unix_mount_get_device_path g_unix_mount_get_fs_type +g_unix_mount_get_options g_unix_mount_is_readonly g_unix_mount_is_system_internal g_unix_mount_guess_icon diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index 4d19217ca..e0dc51847 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -126,6 +126,7 @@ struct _GUnixMountEntry { char *mount_path; char *device_path; char *filesystem_type; + char *options; gboolean is_read_only; gboolean is_system_internal; }; @@ -408,6 +409,7 @@ static GUnixMountEntry * create_unix_mount_entry (const char *device_path, const char *mount_path, const char *filesystem_type, + const char *options, gboolean is_read_only) { GUnixMountEntry *mount_entry = NULL; @@ -416,6 +418,7 @@ create_unix_mount_entry (const char *device_path, mount_entry->device_path = g_strdup (device_path); mount_entry->mount_path = g_strdup (mount_path); mount_entry->filesystem_type = g_strdup (filesystem_type); + mount_entry->options = g_strdup (options); mount_entry->is_read_only = is_read_only; mount_entry->is_system_internal = @@ -494,6 +497,7 @@ _g_get_unix_mounts (void) mount_entry = create_unix_mount_entry (device_path, mnt_fs_get_target (fs), mnt_fs_get_fstype (fs), + mnt_fs_get_options (fs), is_read_only); return_list = g_list_prepend (return_list, mount_entry); @@ -588,6 +592,7 @@ _g_get_unix_mounts (void) mount_entry = create_unix_mount_entry (device_path, mntent->mnt_dir, mntent->mnt_type, + mntent->mnt_opts, is_read_only); g_hash_table_insert (mounts_hash, @@ -701,6 +706,7 @@ _g_get_unix_mounts (void) mount_entry = create_unix_mount_entry (mntent.mnt_special, mntent.mnt_mountp, mntent.mnt_fstype, + mntent.mnt_opts, is_read_only); return_list = g_list_prepend (return_list, mount_entry); @@ -767,6 +773,7 @@ _g_get_unix_mounts (void) mount_entry = create_unix_mount_entry (vmt2dataptr (vmount_info, VMT_OBJECT), vmt2dataptr (vmount_info, VMT_STUB), fs_info == NULL ? "unknown" : fs_info->vfsent_name, + NULL, is_read_only); return_list = g_list_prepend (return_list, mount_entry); @@ -842,6 +849,7 @@ _g_get_unix_mounts (void) mount_entry = create_unix_mount_entry (mntent[i].f_mntfromname, mntent[i].f_mntonname, mntent[i].f_fstypename, + NULL, is_read_only); return_list = g_list_prepend (return_list, mount_entry); @@ -1985,6 +1993,7 @@ g_unix_mount_free (GUnixMountEntry *mount_entry) g_free (mount_entry->mount_path); g_free (mount_entry->device_path); g_free (mount_entry->filesystem_type); + g_free (mount_entry->options); g_free (mount_entry); } @@ -2009,6 +2018,7 @@ g_unix_mount_copy (GUnixMountEntry *mount_entry) copy->mount_path = g_strdup (mount_entry->mount_path); copy->device_path = g_strdup (mount_entry->device_path); copy->filesystem_type = g_strdup (mount_entry->filesystem_type); + copy->options = g_strdup (mount_entry->options); copy->is_read_only = mount_entry->is_read_only; copy->is_system_internal = mount_entry->is_system_internal; @@ -2092,6 +2102,10 @@ g_unix_mount_compare (GUnixMountEntry *mount1, if (res != 0) return res; + res = g_strcmp0 (mount1->options, mount2->options); + if (res != 0) + return res; + res = mount1->is_read_only - mount2->is_read_only; if (res != 0) return res; @@ -2147,6 +2161,29 @@ g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry) return mount_entry->filesystem_type; } +/** + * g_unix_mount_get_options: + * @mount_entry: a #GUnixMountEntry. + * + * Gets a comma-separated list of mount options for the unix mount. For example, + * `rw,relatime,seclabel,data=ordered`. + * + * This is similar to g_unix_mount_point_get_options(), but it takes + * a #GUnixMountEntry as an argument. + * + * Returns: (nullable): a string containing the options, or %NULL if not + * available. + * + * Since: 2.58 + */ +const gchar * +g_unix_mount_get_options (GUnixMountEntry *mount_entry) +{ + g_return_val_if_fail (mount_entry != NULL, NULL); + + return mount_entry->options; +} + /** * g_unix_mount_is_readonly: * @mount_entry: a #GUnixMount. diff --git a/gio/gunixmounts.h b/gio/gunixmounts.h index 04d6b0726..a392d497f 100644 --- a/gio/gunixmounts.h +++ b/gio/gunixmounts.h @@ -81,6 +81,8 @@ GLIB_AVAILABLE_IN_ALL const char * g_unix_mount_get_device_path (GUnixMountEntry *mount_entry); GLIB_AVAILABLE_IN_ALL const char * g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry); +GLIB_AVAILABLE_IN_2_58 +const char * g_unix_mount_get_options (GUnixMountEntry *mount_entry); GLIB_AVAILABLE_IN_ALL gboolean g_unix_mount_is_readonly (GUnixMountEntry *mount_entry); GLIB_AVAILABLE_IN_ALL