From 96c17a856411a63a3160778e723e7d607a840191 Mon Sep 17 00:00:00 2001 From: David Riebenbauer Date: Tue, 27 May 2014 12:28:23 +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 | 62 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c index 604265f..ec6641a 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,57 @@ subst_str_and_escape (const gchar *str, return ret; } +static gchar * +probe_fs_type_prior_to_mount (UDisksBlock *block, + GError **error) +{ + const gchar *device; + blkid_probe probe = NULL; + char *fs_type = NULL; + const char *data; + size_t data_len; + + device = udisks_block_get_device (block); + + probe = blkid_new_probe_from_filename (device); + if (probe == NULL) { + g_set_error (error, + UDISKS_ERROR, + UDISKS_ERROR_FAILED, + "Failed to open device %s for filesystem probing.", + device); + goto out; + }; + + blkid_probe_enable_superblocks (probe, TRUE); + blkid_probe_set_superblocks_flags (probe, BLKID_SUBLKS_TYPE); + + if (blkid_do_safeprobe (probe) != 0) { + g_set_error (error, + UDISKS_ERROR, + UDISKS_ERROR_FAILED, + "Failed to recognize filesystem for device %s.", + device); + goto out; + } + + blkid_probe_lookup_value (probe, "TYPE", &data, &data_len); + if (data == NULL || data_len == 0) { + g_set_error (error, + UDISKS_ERROR, + UDISKS_ERROR_FAILED, + "Failed to recognize filesystem for device %s.", + device); + goto out; + } + + fs_type = g_strndup (data, data_len); + +out: + blkid_free_probe (probe); + return fs_type; +} + /* ---------------------------------------------------------------------------------------------------- */ /* @@ -678,7 +731,14 @@ 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 a 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, error); + if (fs_type_to_use == NULL) { + goto out; + } } out: -- 2.0.0.rc4