[glib] gio: Add g_unix_mount_get_options



commit d0821da5244fd08c756a5f84ec0d3063c72d1ac6
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Apr 26 10:36:36 2018 +0200

    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
    <withnall endlessm com>.)
    
    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 c74b0cfaf..f2db27e66 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;
 };
@@ -412,6 +413,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;
@@ -420,6 +422,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 =
@@ -498,6 +501,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);
@@ -592,6 +596,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,
@@ -705,6 +710,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);
@@ -771,6 +777,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);
@@ -846,6 +853,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);
@@ -1989,6 +1997,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);
 }
 
@@ -2013,6 +2022,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;
 
@@ -2096,6 +2106,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;
@@ -2151,6 +2165,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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]