From: David Zeuthen Date: Mon, 5 Dec 2011 18:16:54 +0000 (-0500) Subject: Add Block.OpenForRestore() method X-Git-Tag: upstream/2.1.2~381 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1191adb4e4276c407b68b3a19768c8c06b74cb13;p=platform%2Fupstream%2Fudisks2.git Add Block.OpenForRestore() method Signed-off-by: David Zeuthen --- diff --git a/data/org.freedesktop.UDisks2.xml b/data/org.freedesktop.UDisks2.xml index 5d53416..bc26fcd 100644 --- a/data/org.freedesktop.UDisks2.xml +++ b/data/org.freedesktop.UDisks2.xml @@ -840,6 +840,21 @@ + + + + + + + diff --git a/src/udiskslinuxblock.c b/src/udiskslinuxblock.c index 86067bd..eeb4a4d 100644 --- a/src/udiskslinuxblock.c +++ b/src/udiskslinuxblock.c @@ -2131,6 +2131,55 @@ handle_open_for_backup (UDisksBlock *block, /* ---------------------------------------------------------------------------------------------------- */ +static gboolean +handle_open_for_restore (UDisksBlock *block, + GDBusMethodInvocation *invocation, + GUnixFDList *fd_list, + GVariant *options) +{ + UDisksObject *object; + UDisksDaemon *daemon; + const gchar *action_id; + const gchar *device; + GUnixFDList *out_fd_list = NULL; + gint fd; + + object = UDISKS_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (block))); + daemon = udisks_linux_block_object_get_daemon (UDISKS_LINUX_BLOCK_OBJECT (object)); + + action_id = "org.freedesktop.udisks2.open-device"; + if (udisks_block_get_hint_system (block)) + action_id = "org.freedesktop.udisks2.open-device-system"; + + if (!udisks_daemon_util_check_authorization_sync (daemon, + object, + action_id, + options, + N_("Authentication is required to open $(udisks2.device) for restore"), + invocation)) + goto out; + + + device = udisks_block_get_device (UDISKS_BLOCK (block)); + + fd = open (device, O_WRONLY | O_SYNC | O_CLOEXEC | O_EXCL); + if (fd == -1) + { + g_dbus_method_invocation_return_error (invocation, UDISKS_ERROR, UDISKS_ERROR_FAILED, + "Error opening %s: %m", device); + goto out; + } + + out_fd_list = g_unix_fd_list_new_from_array (&fd, 1); + udisks_block_complete_open_for_backup (block, invocation, out_fd_list, g_variant_new_handle (0)); + + out: + g_clear_object (&out_fd_list); + return TRUE; /* returning true means that we handled the method invocation */ +} + +/* ---------------------------------------------------------------------------------------------------- */ + static void block_iface_init (UDisksBlockIface *iface) { @@ -2140,4 +2189,5 @@ block_iface_init (UDisksBlockIface *iface) iface->handle_update_configuration_item = handle_update_configuration_item; iface->handle_format = handle_format; iface->handle_open_for_backup = handle_open_for_backup; + iface->handle_open_for_restore = handle_open_for_restore; }