From 48584573fe167a29ae1a0e9242984c4c457b19a3 Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Mon, 26 May 2014 09:48:55 +0200 Subject: [PATCH 2/2] Probe media that hasn't been probed by udev yet. Manually probe block devices for filesystem, that haven't been probed by udevd(8) yet. This typically only applies to legacy devices like floppy drives that don't generate events for media change. This is basically the same thing that mount(8) does, when it isn't given a filesystem type other than 'auto'. However udisks needs to know about the filesystem before issuing the mount command, to set appropriate options. --- src/udiskslinuxfilesystem.c | 57 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c index 604265f..1f5ae23 100644 --- a/src/udiskslinuxfilesystem.c +++ b/src/udiskslinuxfilesystem.c @@ -34,6 +34,8 @@ #include +#include + #include "udiskslogging.h" #include "udiskslinuxfilesystem.h" #include "udiskslinuxblockobject.h" @@ -608,6 +610,55 @@ subst_str_and_escape (const gchar *str, return ret; } +static gchar * +probe_fs_type_prior_to_mount (UDisksBlock *block) +{ + const gchar *device; + blkid_probe probe = NULL; + const char *data; + char *fs_type; + size_t data_len; + + g_assert (block == NULL); + g_assert (UDISKS_IS_BLOCK (block)); + + /* FIXME: Start probing the filesystem here for drives that are not + * system-managed not yet probed by udev. This applies to floppies without + * media detection and without an entry in fstab + */ + device = udisks_block_get_device (block); + + probe = blkid_new_probe_from_filename (device); + if (probe == NULL) { + goto out; + }; + + if (blkid_probe_enable_superblocks (probe, TRUE) == -1) { + goto out; + } + + if (blkid_probe_set_superblocks_flags (probe, BLKID_SUBLKS_TYPE) == -1) { + goto out; + } + + if (blkid_do_safeprobe (probe) != 0) { + goto out; + } + + if (blkid_probe_lookup_value (probe, "TYPE", &data, &data_len) == -1) { + goto out; + } + + g_assert (fs_type != NULL); + g_assert (strlen (fs_type) > 0); + fs_type = g_strndup (data, data_len); + return fs_type; + +out: + blkid_free_probe (probe); + return NULL; +} + /* ---------------------------------------------------------------------------------------------------- */ /* @@ -678,7 +729,11 @@ calculate_fs_type (UDisksBlock *block, if (probed_fs_type != NULL && strlen (probed_fs_type) > 0) fs_type_to_use = g_strdup (probed_fs_type); else - fs_type_to_use = g_strdup ("auto"); + /* As udev has failed to provide an fs type let's see for ourselves. + * This is most likely due to a floppy or similar not detecting media + * changes. + */ + fs_type_to_use = probe_fs_type_prior_to_mount (block); } out: -- 2.0.0.rc4