summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2015-01-13 15:34:52 +0100
committerMartin Pitt <martin.pitt@ubuntu.com>2015-01-13 15:34:52 +0100
commitae2a5ff1e49ae924605502ace170eb831e9c38e4 (patch)
tree88b71705d17615ea7f42e54ec7f6ed38cef32a52
parent16db1d1ba60cbc76397f193c95db5fda4546f099 (diff)
Support mounting in /media for FHS compatibility
Add --enable-fhs-media configure option to mount in /media instead of /run/media, for FHS compliance and backwards compatibility. Usually /media is not a tmpfs, so make the "mounted-fs" state file persistant in this case. https://bugs.freedesktop.org/show_bug.cgi?id=51709 http://bugs.debian.org/680403 https://launchpad.net/bugs/1020759
-rw-r--r--configure.ac13
-rw-r--r--src/udiskslinuxfilesystem.c18
-rw-r--r--src/udisksstate.c17
3 files changed, 40 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index af209dd..0c28a30 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,6 +115,18 @@ AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no)
GOBJECT_INTROSPECTION_CHECK([0.6.2])
+# Behavior
+#
+
+AC_ARG_ENABLE(fhs-media,
+ [AS_HELP_STRING([--enable-fhs-media],
+ [Mount devices in /media instead of /run/media [default=no]])],
+ fhs_media=yes,
+ fhs_media=no)
+if test "x$fhs_media" = "xyes"; then
+ AC_DEFINE([HAVE_FHS_MEDIA], 1, [Define to 1 to use /media for mounting])
+fi
+
# Libraries
#
@@ -229,6 +241,7 @@ echo "
udevdir: ${udevdir}
systemdsystemunitdir: ${systemdsystemunitdir}
using libsystemd-login: ${have_libsystemd_login}
+ use /media for mounting: ${fhs_media}
compiler: ${CC}
cflags: ${CFLAGS}
diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c
index b5fa27f..b7d71ae 100644
--- a/src/udiskslinuxfilesystem.c
+++ b/src/udiskslinuxfilesystem.c
@@ -79,6 +79,12 @@ static void filesystem_iface_init (UDisksFilesystemIface *iface);
G_DEFINE_TYPE_WITH_CODE (UDisksLinuxFilesystem, udisks_linux_filesystem, UDISKS_TYPE_FILESYSTEM_SKELETON,
G_IMPLEMENT_INTERFACE (UDISKS_TYPE_FILESYSTEM, filesystem_iface_init));
+#ifdef HAVE_FHS_MEDIA
+# define MOUNT_BASE "/media"
+#else
+# define MOUNT_BASE "/run/media"
+#endif
+
/* ---------------------------------------------------------------------------------------------------- */
static void
@@ -892,23 +898,23 @@ calculate_mount_point (UDisksDaemon *daemon,
}
/* If we know the user-name and it doesn't have any '/' character in
- * it, mount in /run/media/$USER
+ * it, mount in MOUNT_BASE/$USER
*/
if (!fs_shared && (user_name != NULL && strstr (user_name, "/") == NULL))
{
- mount_dir = g_strdup_printf ("/run/media/%s", user_name);
+ mount_dir = g_strdup_printf (MOUNT_BASE "/%s", user_name);
if (!g_file_test (mount_dir, G_FILE_TEST_EXISTS))
{
- /* First ensure that /run/media exists */
- if (g_mkdir ("/run/media", 0755) != 0 && errno != EEXIST)
+ /* First ensure that MOUNT_BASE exists */
+ if (g_mkdir (MOUNT_BASE, 0755) != 0 && errno != EEXIST)
{
g_set_error (error,
UDISKS_ERROR,
UDISKS_ERROR_FAILED,
- "Error creating directory /run/media: %m");
+ "Error creating directory " MOUNT_BASE ": %m");
goto out;
}
- /* Then create the per-user /run/media/$USER */
+ /* Then create the per-user MOUNT_BASE/$USER */
if (g_mkdir (mount_dir, 0700) != 0 && errno != EEXIST)
{
g_set_error (error,
diff --git a/src/udisksstate.c b/src/udisksstate.c
index 4dfe393..ee40b8a 100644
--- a/src/udisksstate.c
+++ b/src/udisksstate.c
@@ -2235,7 +2235,14 @@ udisks_state_get (UDisksState *state,
* - could also mmap the file
*/
- path = g_strdup_printf ("/run/udisks2/%s", key);
+#ifdef HAVE_FHS_MEDIA
+ /* /media usually isn't on a tmpfs, so we need to make this persistant */
+ if (strcmp (key, "mounted-fs") == 0)
+ path = g_strdup_printf (PACKAGE_LOCALSTATE_DIR "/lib/udisks2/%s", key);
+ else
+#endif
+ path = g_strdup_printf ("/run/udisks2/%s", key);
+
/* see if it's already in the cache */
ret = g_hash_table_lookup (state->cache, path);
@@ -2301,7 +2308,13 @@ udisks_state_set (UDisksState *state,
data = g_malloc (size);
g_variant_store (normalized, data);
- path = g_strdup_printf ("/run/udisks2/%s", key);
+#ifdef HAVE_FHS_MEDIA
+ /* /media usually isn't on a tmpfs, so we need to make this persistant */
+ if (strcmp (key, "mounted-fs") == 0)
+ path = g_strdup_printf (PACKAGE_LOCALSTATE_DIR "/lib/udisks2/%s", key);
+ else
+#endif
+ path = g_strdup_printf ("/run/udisks2/%s", key);
g_hash_table_insert (state->cache, g_strdup (path), g_variant_ref (value));