[Xfce4-commits] <exo:master> Read mount options from a rc file (bug #2891).

Nick Schermer noreply at xfce.org
Sat Oct 17 13:06:01 CEST 2009


Updating branch refs/heads/master
         to 94acf3844546d235dc310ab9303917fe96efeec3 (commit)
       from b9217ffd03affdd7dac64ec601f3c401d192f0c6 (commit)

commit 94acf3844546d235dc310ab9303917fe96efeec3
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Oct 17 13:02:33 2009 +0200

    Read mount options from a rc file (bug #2891).
    
    All the hardcoded mount options are now read from a rc file so
    they can be easily changed by the distro or user.

 exo-mount/Makefile.am     |    4 ++
 exo-mount/README          |    2 +
 exo-mount/exo-mount-hal.c |  133 ++++++++++++++++++++++++++++++---------------
 exo-mount/mount.rc        |   54 ++++++++++++++++++
 4 files changed, 149 insertions(+), 44 deletions(-)

diff --git a/exo-mount/Makefile.am b/exo-mount/Makefile.am
index a44a46e..f035efe 100644
--- a/exo-mount/Makefile.am
+++ b/exo-mount/Makefile.am
@@ -10,6 +10,9 @@ INCLUDES = 								\
 	-DPATH_MOUNT=\"$(PATH_MOUNT)\"					\
 	-DPATH_UMOUNT=\"$(PATH_UMOUNT)\"
 
+defaultsdir = $(sysconfdir)/xdg/xfce4
+defaults_DATA = mount.rc
+
 bin_PROGRAMS =								\
 	exo-mount
 
@@ -52,6 +55,7 @@ install-data-local:
 	-( cd $(DESTDIR)$(bindir) ; ln -sf exo-mount exo-unmount )
 
 EXTRA_DIST =								\
+	$(defaults_DATA)					\
 	README
 
 # vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/exo-mount/README b/exo-mount/README
index 30b0553..2fd9724 100644
--- a/exo-mount/README
+++ b/exo-mount/README
@@ -9,3 +9,5 @@ highly recommended. See the output of
 
 for available command line options.
 
+For the mount options used by HAL, see the mount.rc file installed by exo in the
+$prefix/etc/xdg/xfce4 directory.
diff --git a/exo-mount/exo-mount-hal.c b/exo-mount/exo-mount-hal.c
index 852062e..a398d2e 100644
--- a/exo-mount/exo-mount-hal.c
+++ b/exo-mount/exo-mount-hal.c
@@ -694,8 +694,14 @@ exo_mount_hal_device_mount (ExoMountHalDevice *device,
   gchar       *fstype;
   const gchar *fs;
   gchar       *s;
-  gint         m, n = 0;
+  guint        m, n;
   const gchar *charset;
+  XfceRc      *rc;
+  gchar       *key;
+  gchar       *option;
+  GSList      *lp, *fsoptions = NULL;
+  gsize        len;
+  const gchar *value;
 
   g_return_val_if_fail (device != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -710,60 +716,98 @@ exo_mount_hal_device_mount (ExoMountHalDevice *device,
   else
     fs = device->fstype;
 
+  /* open the config file and look for the filesystem group */
+  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4" G_DIR_SEPARATOR_S "mount.rc", FALSE);
+  if (G_LIKELY (rc != NULL))
+    {
+      if (xfce_rc_has_group (rc, fs))
+        {
+          /* set the filesystem group */
+          xfce_rc_set_group (rc, fs);
+        }
+      else
+        {
+          /* config is not usable */
+          xfce_rc_close (rc);
+          rc = NULL;
+        }
+    }
+
   /* check if we know any valid mount options */
   if (G_LIKELY (device->fsoptions != NULL))
     {
       /* process all valid mount options */
       for (m = 0; device->fsoptions[m] != NULL; ++m)
         {
-          /* this is currently mostly Linux specific noise */
-          if (strcmp (device->fsoptions[m], "uid=") == 0
-              && (strcmp (fs, "vfat") == 0
-               || strcmp (fs, "iso9660") == 0
-               || strcmp (fs, "udf") == 0
-               || strcmp (fs, "ntfs") == 0
-               || strcmp (fs, "ntfs-3g") == 0
-               || device->volume == NULL))
-            {
-              options[n++] = g_strdup_printf ("uid=%u", (guint) getuid ());
-            }
-          else if (strcmp (device->fsoptions[m], "shortname=") == 0
-                && strcmp (fs, "vfat") == 0)
-            {
-              options[n++] = g_strdup_printf ("shortname=winnt");
-            }
-          else if (strcmp (device->fsoptions[m], "sync") == 0
-                && device->volume == NULL)
+          option = NULL;
+
+          if (strcmp (device->fsoptions[m], "sync") == 0)
             {
               /* non-pollable drive... */
-              options[n++] = g_strdup ("sync");
-            }
-          else if (strcmp (device->fsoptions[m], "longnames") == 0
-                && strcmp (fs, "vfat") == 0)
-            {
-              /* however this one is FreeBSD specific */
-              options[n++] = g_strdup ("longnames");
-            }
-          else if (strcmp (device->fsoptions[m], "umask=") == 0
-                   && strcmp (fs, "ntfs-3g") == 0)
-            {
-              /* we need to pass umask=0077 to ntfs-g3 or else it gets 0777 perms */
-              options[n++] = g_strdup ("umask=0077");
+              option = g_strdup ("sync");
             }
-          else if (strcmp (device->fsoptions[m], "iocharset=") == 0)
+          else if (rc != NULL)
             {
-              /* get the charset from a variable set by the user or glib */
-              charset = g_getenv ("EXO_MOUNT_IOCHARSET");
-              if (G_LIKELY (charset == NULL))
-                if (g_get_charset (&charset))
-                  charset = "utf8";
-
-              if (G_LIKELY (charset != NULL && *charset != '\0'))
-                options[n++] = g_strdup_printf ("iocharset=%s", charset);
+              /* option with value or enabled/disabled */
+              if (g_str_has_suffix (device->fsoptions[m], "="))
+                {
+                  len = strlen (device->fsoptions[m]) - 1;
+                  key = g_strndup (device->fsoptions[m], len);
+                  value = xfce_rc_read_entry_untranslated (rc, key, NULL);
+
+                  if (value != NULL)
+                    {
+                      /* substitute the <auto> options */
+                      if (strcmp (value, "<auto>") == 0)
+                        {
+                          if (strcmp (key, "uid") == 0)
+                            {
+                              option = g_strdup_printf ("uid=%u", (guint) getuid ());
+                            }
+                          else if (strcmp (key, "gid") == 0)
+                            {
+                              option = g_strdup_printf ("gid=%u", (guint) getgid ());
+                            }
+                          else if (strcmp (key, "iocharset") == 0)
+                            {
+                              charset = g_getenv ("EXO_MOUNT_IOCHARSET");
+                              if (charset == NULL
+                                  && g_get_charset (&charset))
+                                charset = "utf8";
+                              option = g_strdup_printf ("iocharset=%s", charset);
+                            }
+                        }
+                      else
+                        {
+                          /* use the value from the rc file */
+                          option = g_strdup_printf ("%s=%s", key, value);
+                        }
+                    }
+
+                  g_free (key);
+                }
+              else if (xfce_rc_has_entry (rc, device->fsoptions[m]))
+                {
+                  if (xfce_rc_read_bool_entry (rc, device->fsoptions[m], FALSE))
+                    option = g_strdup (device->fsoptions[m]);
+                }
             }
+
+          /* add the option */
+          if (option != NULL)
+            fsoptions = g_slist_prepend (fsoptions, option);
         }
     }
 
+  if (rc != NULL)
+    xfce_rc_close (rc);
+
+  /* create the filesystem options (+2 for possible "ro" and null terminate) */
+  options = g_new0 (gchar *, g_slist_length (fsoptions) + 2);
+  for (n = 0, lp = fsoptions; lp != NULL; lp = lp->next, ++n)
+    options[n] = lp->data;
+  g_slist_free (fsoptions);
+
   /* try to determine a usable mount point */
   if (G_LIKELY (device->volume != NULL))
     {
@@ -777,9 +821,10 @@ exo_mount_hal_device_mount (ExoMountHalDevice *device,
     }
 
   /* make sure that the mount point is usable (i.e. does not contain G_DIR_SEPARATOR's) */
-  mount_point = !exo_str_is_empty (mount_point)
-              ? exo_str_replace (mount_point, G_DIR_SEPARATOR_S, "_")
-              : g_strdup ("");
+  if (!exo_str_is_empty (mount_point))
+    mount_point = exo_str_replace (mount_point, G_DIR_SEPARATOR_S, "_");
+  else
+    mount_point = g_strdup ("");
 
   /* let HAL guess the fstype, unless we have an alternative preferred fstype */
   if (G_UNLIKELY (device->altfstype != NULL))
diff --git a/exo-mount/mount.rc b/exo-mount/mount.rc
new file mode 100644
index 0000000..723b841
--- /dev/null
+++ b/exo-mount/mount.rc
@@ -0,0 +1,54 @@
+#
+# ABOUT
+# =====
+# This file contains the mount option configuration when exo-mount is used with the HAL
+# back end (which is highly recommended). If mounting using exo is somehow not working
+# for you, you can copy this file to your $XDG_CONFIG_HOME/xfce4 directory and modify it.
+#
+# The options for each filesystem are not used when they are not in the list of
+# valid mount options provided by HAL. You can find those values using lshal and
+# search for the volume.mount.valid_options property.
+#
+#
+# EXAMPLE
+# =======
+# For example your usb device contains the vfat file system and lshal shows the
+# following valid mount options for the device:
+#
+#   volume.mount.valid_options = {'ro', 'sync', 'dirsync', 'noatime', 'nodiratime',
+#                                 'noexec', 'quiet', 'remount', 'exec', 'uid=',
+#                                 'gid=', 'umask=', 'utf8'} (string list)
+#
+# All the values that end with a = character are options that contain a value,
+# the other options are booleans that can be enabled by for example putting
+# utf8=true in the group.
+#
+#
+# SUBSTITUTIONS
+# =============
+# Some options can be substituted by exo-mount when you set the value to <auto>:
+#   uid      : The real user ID
+#   gid      : The real group ID
+#   iocharset: To the EXO_MOUNT_IOCHARSET or LC_CTYPE environment variable.
+#
+
+[vfat]
+uid=<auto>
+shortname=winnt
+# FreeBSD specific option
+longnames=true
+
+[iso9660]
+uid=<auto>
+
+[udf]
+uid=<auto>
+iocharset=<auto>
+
+[ntfs]
+uid=<auto>
+
+[ntfs-3g]
+uid=<auto>
+# Make sure the device does not get 0777 permissions
+umask=0077



More information about the Xfce4-commits mailing list