From 189af262abaa6610f5a7c90bc427e8685d5ebc55 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Tue, 15 Nov 2011 15:13:31 -0500 Subject: [PATCH] Wipe device before formatting it It's better to not trust various mkfs tools etc. to get it right. Signed-off-by: David Zeuthen --- src/udiskslinuxblock.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/udiskslinuxblock.c b/src/udiskslinuxblock.c index c446840..5b85e63 100644 --- a/src/udiskslinuxblock.c +++ b/src/udiskslinuxblock.c @@ -1756,10 +1756,6 @@ handle_format (UDisksBlock *block, goto out; } - wait_data = g_new0 (FormatWaitData, 1); - wait_data->object = object; - wait_data->type = type; - /* TODO: Consider just accepting any @type and just running "mkfs -t ". * There are some obvious security implications by doing this, though */ @@ -1785,6 +1781,42 @@ handle_format (UDisksBlock *block, g_variant_lookup (options, "take-ownership", "b", &take_ownership); g_variant_lookup (options, "encrypt.passphrase", "s", &encrypt_passphrase); + /* First wipe the device */ + wait_data = g_new0 (FormatWaitData, 1); + wait_data->object = object; + if (!udisks_daemon_launch_spawned_job_sync (daemon, + NULL, /* cancellable */ + 0, /* uid_t run_as_uid */ + 0, /* uid_t run_as_euid */ + &status, + &error_message, + NULL, /* input_string */ + "wipefs -a %s", + udisks_block_get_device (block))) + { + g_dbus_method_invocation_return_error (invocation, + UDISKS_ERROR, + UDISKS_ERROR_FAILED, + "Error wiping device: %s", + error_message); + g_free (error_message); + goto out; + } + if (udisks_daemon_wait_for_object_sync (daemon, + wait_for_filesystem, + wait_data, + NULL, + 30, + &error) == NULL) + { + g_prefix_error (&error, "Error synchronizing after initial wipe: "); + g_dbus_method_invocation_take_error (invocation, error); + goto out; + } + + /* And now create the desired filesystem */ + wait_data->type = type; + if (encrypt_passphrase != NULL) { /* Create it */ @@ -1921,12 +1953,10 @@ handle_format (UDisksBlock *block, g_free (error_message); goto out; } - /* The mkfs program may not generate all the uevents we need - so explicitly * trigger an event here */ udisks_linux_block_object_trigger_uevent (UDISKS_LINUX_BLOCK_OBJECT (object_to_mkfs)); - if (udisks_daemon_wait_for_object_sync (daemon, wait_for_filesystem, wait_data, @@ -1935,7 +1965,7 @@ handle_format (UDisksBlock *block, &error) == NULL) { g_prefix_error (&error, - "Error waiting for FileSystem interface after creating `%s' fs/content: ", + "Error synchronizing after formatting with type `%s': ", type); g_dbus_method_invocation_take_error (invocation, error); goto out; -- 2.7.4