Esempio n. 1
0
static gboolean
cleanup_block_walker (UDisksClient *client,
                      UDisksBlock *block,
                      gboolean is_leaf,
                      gpointer user_data,
                      GError **error)
{
  StorageProvider *provider = user_data;
  UDisksObject *object = UDISKS_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (block)));
  UDisksEncrypted *enc = udisks_object_peek_encrypted (object);

  if (enc)
    {
      UDisksBlock *cleartext = udisks_client_get_cleartext_block (client, block);
      if (cleartext)
        {
          /* The crypto backing device is unlocked and the cleartext
             device has been cleaned up.  Lock the backing device so
             that we can format or wipe it later.
          */
          if (enc && !udisks_encrypted_call_lock_sync (enc,
                                                       g_variant_new ("a{sv}", NULL),
                                                       NULL,
                                                       error))
            return FALSE;
        }
      else
        {
          /* The crypto backing device is locked and the cleartext
             device has not been cleaned up (since it doesn't exist).
             Remove its remembered configs.
          */
          GList *remembered_configs = storage_provider_get_and_forget_remembered_configs
              (provider, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
          for (GList *l = remembered_configs; l; l = l->next)
            {
              GVariant *config = l->data;
              storage_remove_config (provider, block, config);
            }
          g_list_free_full (remembered_configs, (GDestroyNotify)g_variant_unref);
        }
    }

  storage_remove_config (provider, block, udisks_block_get_configuration (block));

  return TRUE;
}
Esempio n. 2
0
static gboolean
walk_block (UDisksClient *client,
            UDisksBlock *block,
            BlockWalker *walker,
            gpointer user_data,
            GError **error)
{
  gboolean is_leaf = TRUE;

  UDisksObject *object = (UDisksObject *)g_dbus_interface_get_object (G_DBUS_INTERFACE(block));
  if (object != NULL)
    {
      // Recurse for all primary and extended partitions if this is a
      // partition table, or for all logical partitions if this is a
      // extended partition.

      UDisksPartitionTable *table;
      gboolean is_container;

      UDisksPartition *partition = udisks_object_peek_partition (object);
      if (partition && udisks_partition_get_is_container (partition))
        {
          table = udisks_client_get_partition_table (client, partition);
          is_container = TRUE;
        }
      else
        {
          table = udisks_object_peek_partition_table (object);
          is_container = FALSE;
        }

      if (table)
        {
          GList *ps, *l;
          ps = udisks_client_get_partitions (client, table);
          for (l = ps; l != NULL; l = l->next)
            {
              UDisksPartition *p = UDISKS_PARTITION (l->data);
              UDisksObject *o = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (p));
              UDisksBlock *b = o ? udisks_object_peek_block (o) : NULL;
              if (b && !is_container == !udisks_partition_get_is_contained (p))
                {
                  is_leaf = FALSE;
                  if (!walk_block (client, b, walker, user_data, error))
                    {
                      g_list_free_full (ps, g_object_unref);
                      return FALSE;
                    }
                }
            }
          g_list_free_full (ps, g_object_unref);
        }
    }

  gs_unref_object UDisksBlock *cleartext = udisks_client_get_cleartext_block (client, block);
  if (cleartext)
    {
      is_leaf = FALSE;
      if (!walk_block (client, cleartext, walker, user_data, error))
        return FALSE;
    }

  return walker (client, block, is_leaf, user_data, error);
}
Esempio n. 3
0
static gboolean
set_fstab_config (UDisksBlock *block,
                  const gchar *mount_point,
                  const gchar *mount_options,
                  GError **error)
{
  if (mount_point && *mount_point)
    {
      gs_unref_object UDisksClient *client = udisks_client_new_sync (NULL, error);
      if (client == NULL)
        return FALSE;

      UDisksBlock *cleartext = udisks_client_get_cleartext_block (client, block);
      if (cleartext)
        return set_fstab_config (cleartext, mount_point, mount_options, error);

      GVariantBuilder item;
      g_variant_builder_init (&item, G_VARIANT_TYPE("a{sv}"));

      gs_free gchar *fsname = NULL;
      const gchar *uuid = udisks_block_get_id_uuid (block);
      if (uuid && *uuid)
        fsname = g_strdup_printf ("UUID=%s", uuid);
      else
        {
          // XXX - find a more stable name among the symlinks.
          fsname = udisks_block_dup_device (block);
        }
      g_variant_builder_add (&item, "{sv}", "fsname", g_variant_new_bytestring (fsname));

      gs_free gchar *dir = g_filename_from_utf8 (mount_point, -1, NULL, NULL, error);
      if (dir == NULL)
        return FALSE;
      g_variant_builder_add (&item, "{sv}", "dir", g_variant_new_bytestring (dir));

      if (mount_options && *mount_options)
        {
          gs_free gchar *opts = g_locale_from_utf8 (mount_options, -1, NULL, NULL, error);
          if (opts == NULL)
            return FALSE;
          g_variant_builder_add (&item, "{sv}", "opts", g_variant_new_bytestring (opts));
        }
      else
        g_variant_builder_add (&item, "{sv}", "opts", g_variant_new_bytestring ("defaults"));

      g_variant_builder_add (&item, "{sv}", "type", g_variant_new_bytestring ("auto"));
      g_variant_builder_add (&item, "{sv}", "freq", g_variant_new_int32 (0));
      g_variant_builder_add (&item, "{sv}", "passno", g_variant_new_int32 (0));

      if (!udisks_block_call_add_configuration_item_sync (block,
                                                          g_variant_new ("(sa{sv})",
                                                                         "fstab",
                                                                         &item),
                                                          g_variant_new ("a{sv}", NULL),
                                                          NULL,
                                                          error))
        return FALSE;
    }

  return TRUE;
}