Esempio n. 1
0
static GDBusInterface *
get_udisk_iface (UDisksObject *object)
{
  UDisksBlock *block = udisks_object_peek_block (object);
  if (block)
    {
      /* don't include unused loop or nbd devices */
      if (udisks_block_get_size (block) == 0 &&
          (g_str_has_prefix (udisks_block_get_device (block), "/dev/loop") ||
           g_str_has_prefix (udisks_block_get_device (block), "/dev/nbd")))
        return NULL;

      return G_DBUS_INTERFACE (block);
    }

  UDisksDrive *drive = udisks_object_peek_drive (object);
  if (drive)
    {
      return G_DBUS_INTERFACE (drive);
    }

  UDisksMDRaid *mdraid = udisks_object_peek_mdraid (object);
  if (mdraid)
    {
      return G_DBUS_INTERFACE (mdraid);
    }

  return NULL;
}
Esempio n. 2
0
static gboolean
block_is_unused_walker (UDisksClient *client,
                        UDisksBlock *block,
                        gboolean is_leaf,
                        gpointer user_data,
                        GError **error)
{
  const gchar *device_file;
  int fd;

  if (is_leaf)
    {
      device_file = udisks_block_get_device (block);
      fd = open (device_file, O_RDONLY | O_EXCL);
      if (fd < 0)
        {
          g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                       "Error opening device %s: %m",
                       device_file);
          return FALSE;
        }
      close (fd);
    }

  return TRUE;
}
Esempio n. 3
0
static void
on_examine_action_clicked (NotifyNotification  *notification,
                           const gchar         *action,
                           gpointer             user_data)
{
  GduSdMonitor *monitor = GDU_SD_MONITOR (user_data);
  const gchar *device_file = NULL;
  gchar *command_line = NULL;
  GAppInfo *app_info = NULL;
  GError *error = NULL;

  if (g_strcmp0 (action, "examine-smart") == 0)
    {
      if (monitor->ata_smart_problems != NULL)
        {
          UDisksObject *object = UDISKS_OBJECT (monitor->ata_smart_problems->data);
          if (object != NULL)
            {
              UDisksDrive *drive = udisks_object_peek_drive (object);
              if (drive != NULL)
                {
                  UDisksBlock *block = udisks_client_get_block_for_drive (monitor->client,
                                                                          drive,
                                                                          TRUE); /* get_physical */
                  if (block != NULL)
                    {
                      device_file = udisks_block_get_device (block);
                      g_object_ref (block);
                    }
                }
            }
        }
    }
  else
    {
      g_assert_not_reached ();
    }

  if (device_file != NULL)
    command_line = g_strdup_printf ("gnome-disks --block-device %s", device_file);
  else
    command_line = g_strdup_printf ("gnome-disks");


  app_info = g_app_info_create_from_commandline (command_line,
                                                 NULL, /* application name */
                                                 G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
                                                 NULL);
  if (!g_app_info_launch (app_info, NULL, NULL, &error))
    {
      g_warning ("Error launching gnome-disks: %s (%s, %d)",
                 error->message, g_quark_to_string (error->domain), error->code);
      g_clear_error (&error);
    }
  g_clear_object (&app_info);
  g_free (command_line);
}
Esempio n. 4
0
static gboolean
write_unattended_config (gchar  **backup,
                         GError **error)
{
  GFile *image_file = NULL;
  GFile *image_dir = NULL;
  g_autoptr(GFile) unattended_ini_file = NULL;
  g_autofree gchar *unattended_ini = NULL;
  const gchar *locale = setlocale (LC_ALL, NULL);
  g_autofree gchar *image = NULL;
  UDisksBlock *block = NULL;
  g_autofree gchar *vendor = NULL;
  g_autofree gchar *product = NULL;
  const GError *existing_error = gis_store_get_error ();

  /* Refuse to write a new unattended.ini if installation failed, reminding the
   * user of the error.
   */
  if (existing_error != NULL)
    {
      g_propagate_error (error, g_error_copy (existing_error));
      return FALSE;
    }

  image_file = G_FILE (gis_store_get_object (GIS_STORE_IMAGE));
  image = g_file_get_basename (image_file);
  image_dir = G_FILE (gis_store_get_object (GIS_STORE_IMAGE_DIR));
  unattended_ini_file = g_file_get_child (image_dir, "unattended.ini");
  unattended_ini = g_file_get_path (unattended_ini_file);
  block = UDISKS_BLOCK (gis_store_get_object (GIS_STORE_BLOCK_DEVICE));

  if (!gis_dmi_read_vendor_product (&vendor, &product, error))
    return FALSE;

  return gis_unattended_config_write (unattended_ini, locale, image,
                                      udisks_block_get_device (block), vendor,
                                      product, backup, error);
}
Esempio n. 5
0
const gchar *
storage_block_get_device (StorageBlock *self)
{
  g_return_val_if_fail (STORAGE_IS_BLOCK (self), NULL);
  return udisks_block_get_device (self->real_block);
}
Esempio n. 6
0
/**
 * udisks_daemon_util_setup_by_user:
 * @daemon: A #UDisksDaemon.
 * @object: The #GDBusObject that the call is on or %NULL.
 * @user: The user in question.
 *
 * Checks whether the device represented by @object (if any) has been
 * setup by @user.
 *
 * Returns: %TRUE if @object has been set-up by @user, %FALSE if not.
 */
gboolean
udisks_daemon_util_setup_by_user (UDisksDaemon *daemon,
                                  UDisksObject *object,
                                  uid_t         user)
{
  gboolean ret;
  UDisksBlock *block = NULL;
  UDisksPartition *partition = NULL;
  UDisksState *state;
  uid_t setup_by_user;
  UDisksObject *crypto_object;

  ret = FALSE;

  state = udisks_daemon_get_state (daemon);
  block = udisks_object_get_block (object);
  if (block == NULL)
    goto out;
  partition = udisks_object_get_partition (object);

  /* loop devices */
  if (udisks_state_has_loop (state, udisks_block_get_device (block), &setup_by_user))
    {
      if (setup_by_user == user)
        {
          ret = TRUE;
          goto out;
        }
    }

  /* partition of a loop device */
  if (partition != NULL)
    {
      UDisksObject *partition_object = NULL;
      partition_object = udisks_daemon_find_object (daemon, udisks_partition_get_table (partition));
      if (partition_object != NULL)
        {
          if (udisks_daemon_util_setup_by_user (daemon, partition_object, user))
            {
              ret = TRUE;
              g_object_unref (partition_object);
              goto out;
            }
          g_object_unref (partition_object);
        }
    }

  /* LUKS devices */
  crypto_object = udisks_daemon_find_object (daemon, udisks_block_get_crypto_backing_device (block));
  if (crypto_object != NULL)
    {
      UDisksBlock *crypto_block;
      crypto_block = udisks_object_peek_block (crypto_object);
      if (udisks_state_find_unlocked_luks (state,
                                           udisks_block_get_device_number (crypto_block),
                                           &setup_by_user))
        {
          if (setup_by_user == user)
            {
              ret = TRUE;
              g_object_unref (crypto_object);
              goto out;
            }
        }
      g_object_unref (crypto_object);
    }

  /* MDRaid devices */
  if (g_strcmp0 (udisks_block_get_mdraid (block), "/") != 0)
    {
      uid_t started_by_user;
      if (udisks_state_has_mdraid (state, udisks_block_get_device_number (block), &started_by_user))
        {
          if (started_by_user == user)
            {
              ret = TRUE;
              goto out;
            }
        }
    }

 out:
  g_clear_object (&partition);
  g_clear_object (&block);
  return ret;
}