From ae2a5ff1e49ae924605502ace170eb831e9c38e4 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 13 Jan 2015 15:34:52 +0100 Subject: [PATCH] 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 --- configure.ac | 13 +++++++++++++ src/udiskslinuxfilesystem.c | 18 ++++++++++++------ src/udisksstate.c | 17 +++++++++++++++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index af209ddb8a..0c28a30290 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 b5fa27fe72..b7d71ae9e6 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 4dfe393fbe..ee40b8ad18 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));