static void unmount_childs (LibHalContext *ctx, const char *udi) { DBusError error; int num_volumes; char **volumes; dbus_error_init (&error); /* need to force unmount all partitions */ if ((volumes = libhal_manager_find_device_string_match ( ctx, "block.storage_device", udi, &num_volumes, &error)) != NULL) { dbus_error_free (&error); int i; for (i = 0; i < num_volumes; i++) { char *vol_udi; vol_udi = volumes[i]; if (libhal_device_get_property_bool (ctx, vol_udi, "block.is_volume", &error)) { dbus_error_free (&error); if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) { dbus_error_free (&error); HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi)); force_unmount (ctx, vol_udi); } } } libhal_free_string_array (volumes); } my_dbus_error_free (&error); }
static dbus_bool_t unmount_cleartext_devices (LibHalContext *ctx, const char *udi) { DBusError error; char **clear_devices; int num_clear_devices; dbus_bool_t ret; ret = FALSE; /* check if the volume we back is mounted.. if it is.. unmount it */ dbus_error_init (&error); clear_devices = libhal_manager_find_device_string_match (ctx, "volume.crypto_luks.clear.backing_volume", udi, &num_clear_devices, &error); if (clear_devices != NULL && num_clear_devices > 0) { int i; ret = TRUE; for (i = 0; i < num_clear_devices; i++) { char *clear_udi; clear_udi = clear_devices[i]; LIBHAL_FREE_DBUS_ERROR (&error); if (libhal_device_get_property_bool (ctx, clear_udi, "volume.is_mounted", &error)) { HAL_DEBUG (("Forcing unmount of child '%s' (crypto)", clear_udi)); force_unmount (ctx, clear_udi); } } libhal_free_string_array (clear_devices); } LIBHAL_FREE_DBUS_ERROR (&error); return ret; }
static void unmount_childs (LibHalContext *ctx, const char *udi) { int num_volumes; char **volumes; DBusError error; /* need to force unmount all partitions */ dbus_error_init (&error); if ((volumes = libhal_manager_find_device_string_match (ctx, "block.storage_device", udi, &num_volumes, &error)) != NULL) { int i; for (i = 0; i < num_volumes; i++) { char *vol_udi; vol_udi = volumes[i]; LIBHAL_FREE_DBUS_ERROR (&error); if (libhal_device_get_property_bool (ctx, vol_udi, "block.is_volume", &error)) { dbus_bool_t is_crypto; /* unmount all cleartext devices associated with us */ is_crypto = unmount_cleartext_devices (ctx, vol_udi); LIBHAL_FREE_DBUS_ERROR (&error); if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) { HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi)); force_unmount (ctx, vol_udi); } /* teardown crypto */ if (is_crypto) { DBusMessage *msg = NULL; DBusMessage *reply = NULL; /* tear down mapping */ HAL_DEBUG (("Teardown crypto for '%s'", vol_udi)); msg = dbus_message_new_method_call ("org.freedesktop.Hal", vol_udi, "org.freedesktop.Hal.Device.Volume.Crypto", "Teardown"); if (msg == NULL) { HAL_ERROR (("Could not create dbus message for %s", vol_udi)); goto teardown_failed; } LIBHAL_FREE_DBUS_ERROR (&error); if (!(reply = dbus_connection_send_with_reply_and_block ( libhal_ctx_get_dbus_connection (ctx), msg, -1, &error)) || dbus_error_is_set (&error)) { HAL_DEBUG (("Teardown failed for %s: %s : %s\n", udi, error.name, error.message)); dbus_error_free (&error); } teardown_failed: if (msg != NULL) dbus_message_unref (msg); if (reply != NULL) dbus_message_unref (reply); } } } libhal_free_string_array (volumes); } LIBHAL_FREE_DBUS_ERROR (&error); }