~ubuntu-multiseat/ubuntu/trusty/udisks2/full-logind-support

« back to all changes in this revision

Viewing changes to src/udiskslinuxdriveobject.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-06-13 17:01:30 UTC
  • mfrom: (1.1.1) (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20120613170130-9jggrd76bkv1vd0b
Tags: 1.98.0-1
* New upstream release.
* debian/control: Drop ntfsprogs Recommends. It is a transitional package
  for ntfs-3g now, which we already recommend.
* Add 00git_no_polkit_fallback.patch: Fix crash if polkit is not available.
  Patch backported from current upstream git head.
* Add debian/local/integration-test: Latest integration test suite from
  upstream git. 1.99 and later will ship that in the source tarball.
* Add debian/tests/control and debian/tests/upstream-system: DEP-8
  autopkgtest (adapted from udisks package).
* debian/control: Change suggestion of cryptsetup to cryptsetup-bin, as that
  is sufficient for udisks' needs.
* debian/copyright: Fix duplicate copyright line, thanks lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
665
665
static gchar *
666
666
check_for_vpd (GUdevDevice *device)
667
667
{
668
 
  gchar *ret;
 
668
  gchar *ret = NULL;
669
669
  const gchar *serial;
670
670
  const gchar *wwn;
 
671
  const gchar *path;
671
672
 
672
673
  g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
673
674
 
674
 
  ret = NULL;
675
 
 
676
 
  /* prefer WWN to serial */
 
675
  /* order of preference: WWN, serial, path */
677
676
  serial = g_udev_device_get_property (device, "ID_SERIAL");
678
677
  wwn = g_udev_device_get_property (device, "ID_WWN_WITH_EXTENSION");
 
678
  path = g_udev_device_get_property (device, "ID_PATH");
679
679
  if (wwn != NULL && strlen (wwn) > 0)
680
680
    {
681
681
      ret = g_strdup (wwn);
684
684
    {
685
685
      ret = g_strdup (serial);
686
686
    }
 
687
  else if (path != NULL && strlen (path) > 0)
 
688
    {
 
689
      ret = g_strdup (path);
 
690
    }
687
691
  return ret;
688
692
}
689
693
 
881
885
 out:
882
886
  return ret;
883
887
}
 
888
 
 
889
static gboolean
 
890
is_block_unlocked (GList *objects, const gchar *crypto_object_path)
 
891
{
 
892
  gboolean ret = FALSE;
 
893
  GList *l;
 
894
  for (l = objects; l != NULL; l = l->next)
 
895
    {
 
896
      UDisksObject *object = UDISKS_OBJECT (l->data);
 
897
      UDisksBlock *block;
 
898
      block = udisks_object_peek_block (object);
 
899
      if (block != NULL)
 
900
        {
 
901
          if (g_strcmp0 (udisks_block_get_crypto_backing_device (block), crypto_object_path) == 0)
 
902
            {
 
903
              ret = TRUE;
 
904
              goto out;
 
905
            }
 
906
        }
 
907
    }
 
908
 out:
 
909
  return ret;
 
910
}
 
911
 
 
912
/**
 
913
 * udisks_linux_drive_object_is_not_in_use:
 
914
 * @object: A #UDisksLinuxDriveObject.
 
915
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 
916
 * @error: A #GError or %NULL.
 
917
 *
 
918
 * Checks if the drive represented by @object is in use and sets
 
919
 * @error if so.
 
920
 *
 
921
 * Returns: %TRUE if @object is not is use, %FALSE if @error is set.
 
922
 */
 
923
gboolean
 
924
udisks_linux_drive_object_is_not_in_use (UDisksLinuxDriveObject   *object,
 
925
                                         GCancellable             *cancellable,
 
926
                                         GError                  **error)
 
927
{
 
928
  GDBusObjectManagerServer *object_manager;
 
929
  const gchar *drive_object_path;
 
930
  gboolean ret = TRUE;
 
931
  GList *objects = NULL;
 
932
  GList *l;
 
933
 
 
934
  g_return_val_if_fail (UDISKS_IS_LINUX_DRIVE_OBJECT (object), FALSE);
 
935
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
 
936
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
937
 
 
938
  drive_object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));
 
939
 
 
940
  object_manager = udisks_daemon_get_object_manager (object->daemon);
 
941
  objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (object_manager));
 
942
 
 
943
  /* Visit all block devices related to the drive... */
 
944
  for (l = objects; l != NULL; l = l->next)
 
945
    {
 
946
      GDBusObjectSkeleton *iter_object = G_DBUS_OBJECT_SKELETON (l->data);
 
947
      UDisksBlock *block;
 
948
      UDisksFilesystem *filesystem;
 
949
 
 
950
      if (!UDISKS_IS_LINUX_BLOCK_OBJECT (iter_object))
 
951
        continue;
 
952
 
 
953
      block = udisks_object_peek_block (UDISKS_OBJECT (iter_object));
 
954
      filesystem = udisks_object_peek_filesystem (UDISKS_OBJECT (iter_object));
 
955
 
 
956
      if (g_strcmp0 (udisks_block_get_drive (block), drive_object_path) != 0)
 
957
        continue;
 
958
 
 
959
      /* bail if block device is mounted */
 
960
      if (filesystem != NULL)
 
961
        {
 
962
          if (g_strv_length ((gchar **) udisks_filesystem_get_mount_points (filesystem)) > 0)
 
963
            {
 
964
              g_set_error (error,
 
965
                           UDISKS_ERROR,
 
966
                           UDISKS_ERROR_DEVICE_BUSY,
 
967
                           "Device %s is mounted",
 
968
                           udisks_block_get_preferred_device (block));
 
969
              ret = FALSE;
 
970
              goto out;
 
971
            }
 
972
        }
 
973
 
 
974
      /* bail if block device is unlocked (LUKS) */
 
975
      if (is_block_unlocked (objects, g_dbus_object_get_object_path (G_DBUS_OBJECT (iter_object))))
 
976
        {
 
977
          g_set_error (error,
 
978
                       UDISKS_ERROR,
 
979
                       UDISKS_ERROR_DEVICE_BUSY,
 
980
                       "Encrypted device %s is unlocked",
 
981
                       udisks_block_get_preferred_device (block));
 
982
          ret = FALSE;
 
983
          goto out;
 
984
        }
 
985
    }
 
986
 
 
987
 out:
 
988
  g_list_free_full (objects, g_object_unref);
 
989
  return ret;
 
990
}