Skip to content

Commit

Permalink
Support mounting in /media for FHS compatibility
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinpitt committed Jan 13, 2015
1 parent 16db1d1 commit ae2a5ff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
#

Expand Down Expand Up @@ -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}
Expand Down
18 changes: 12 additions & 6 deletions src/udiskslinuxfilesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions src/udisksstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit ae2a5ff

Please sign in to comment.