示例#1
0
GSList* 
get_volumes_mounted_on_drive(LibHalContext* ctx, LibHalDrive* drive)
{
	/* FIXME: This sucks - HAL doesn't report mounted volumes correctly */

	GSList* volume_list = NULL;
	int num_vols = 0;

	char** vol_udis = libhal_drive_find_all_volumes(ctx, drive, &num_vols);
	if(num_vols <= 0 || vol_udis == NULL)
		goto out;

	int i=0;
	for(i=0; i < num_vols; i++) {
		LibHalVolume* current;
		if(!vol_udis[i]) 	break;
		current = libhal_volume_from_udi(ctx, vol_udis[i]);
		if(!current) 	continue;

		if(libhal_volume_is_mounted(current)) 
			volume_list = g_slist_prepend(volume_list, g_strdup(vol_udis[i]));
		libhal_volume_free(current);
	}
	libhal_free_string_array(vol_udis);

out:
	return volume_list;
}
示例#2
0
// Helper function. creates a CStorageDevice from a HAL udi
bool CHALManager::DeviceFromVolumeUdi(const char *udi, CStorageDevice *device)
{
  if (g_HalManager.m_Context == NULL)
    return false;

  LibHalVolume *tempVolume;
  LibHalDrive  *tempDrive;
  bool Created = false;

  tempVolume = libhal_volume_from_udi(g_HalManager.m_Context, udi);
  if (tempVolume)
  {
    const char *DriveUdi = libhal_volume_get_storage_device_udi(tempVolume);
    tempDrive = libhal_drive_from_udi(g_HalManager.m_Context, DriveUdi);

    if (tempDrive)
    {
      char * FriendlyName   = libhal_device_get_property_string(g_HalManager.m_Context, udi, "info.product", NULL);
      device->FriendlyName  = FriendlyName;
      libhal_free_string(FriendlyName);
      char *block = libhal_device_get_property_string(g_HalManager.m_Context, udi, "block.device", NULL);
      device->DevID         = block;
      libhal_free_string(block);

      device->HotPlugged  = (bool)libhal_drive_is_hotpluggable(tempDrive);
      device->Type        = libhal_drive_get_type(tempDrive);
      device->Mounted     = (bool)libhal_volume_is_mounted(tempVolume);
      device->MountPoint  = libhal_volume_get_mount_point(tempVolume);
      if (device->Mounted)
        URIUtils::AddSlashAtEnd(device->MountPoint);
      device->Label       = libhal_volume_get_label(tempVolume);
      device->UUID        = libhal_volume_get_uuid(tempVolume);
      device->FileSystem  = libhal_volume_get_fstype(tempVolume);
      device->HalIgnore   = libhal_device_get_property_bool(g_HalManager.m_Context, udi, "volume.ignore", NULL);
      ApproveDevice(device);

      libhal_drive_free(tempDrive);
      Created = true;
    }
    else
      CLog::Log(LOGERROR, "HAL: Couldn't create a Drive even if we had a volume - %s", udi);

    libhal_volume_free(tempVolume);
  }

  return Created;
}
示例#3
0
static int pusb_volume_mount(t_pusb_options *opts, LibHalVolume **volume,
		LibHalContext *ctx)
{
	char		command[1024];
	char		tempname[32];
	const char	*devname;
	const char	*udi;
	const char	*fs;

	snprintf(tempname, sizeof(tempname), "pam_usb%d", getpid());
	if (!(devname = libhal_volume_get_device_file(*volume)))
	{
		log_error("Unable to retrieve device filename\n");
		return (0);
	}
	fs = libhal_volume_get_fstype(*volume);
	log_debug("Attempting to mount device %s with label %s\n",
			devname, tempname);
	if (!fs)
		snprintf(command, sizeof(command), "pmount -A -s %s %s",
				devname, tempname);
	else
		snprintf(command, sizeof(command), "pmount -A -s -t %s %s %s",
				fs, devname, tempname);
	log_debug("Executing \"%s\"\n", command);
	if (system(command) != 0)
	{
		log_error("Mount failed\n");
		return (0);
	}
	udi = libhal_volume_get_udi(*volume);
	if (!udi)
	{
		log_error("Unable to retrieve volume UDI\n");
		return (0);
	}
	udi = strdup(udi);
	libhal_volume_free(*volume);
	*volume = libhal_volume_from_udi(ctx, udi);
	free((char *)udi);
	log_debug("Mount succeeded.\n");
	return (1);
}
示例#4
0
LibHalVolume *pusb_volume_get(t_pusb_options *opts, LibHalContext *ctx)
{
	LibHalVolume	*volume;

	if (!(volume = pusb_volume_probe(opts, ctx)))
		return (NULL);
	log_debug("Found volume %s\n", opts->device.volume_uuid);
	if (libhal_volume_is_mounted(volume))
	{
		log_debug("Volume is already mounted.\n");
		return (volume);
	}
	if (!pusb_volume_mount(opts, &volume, ctx))
	{
		libhal_volume_free(volume);
		return (NULL);
	}
	return (volume);
}
示例#5
0
void pusb_volume_destroy(LibHalVolume *volume)
{
	const char	*mntpoint;

	mntpoint = libhal_volume_get_mount_point(volume);
	if (mntpoint && strstr(mntpoint, "pam_usb"))
	{
		char	command[1024];

		log_debug("Attempting to umount %s\n",
				mntpoint);
		snprintf(command, sizeof(command), "pumount %s", mntpoint);
		log_debug("Executing \"%s\"\n", command);
		if (!system(command))
			log_debug("Umount succeeded.\n");
		else
			log_error("Unable to umount %s\n", mntpoint);
	}
	libhal_volume_free(volume);
}
示例#6
0
void 
format_volume_free(FormatVolume* fvol)
{
	g_assert(fvol != NULL);

	if(fvol->volume)
		libhal_volume_free(fvol->volume);
	if(fvol->drive)
		libhal_drive_free(fvol->drive);
	if(fvol->icon)
		g_object_unref(fvol->icon);
	if(fvol->friendly_name)
		g_free(fvol->friendly_name);
	if(fvol->udi)
		g_free(fvol->udi);
	if(fvol->drive_udi)
		g_free(fvol->drive_udi);
	if(fvol->mountpoint)
		g_free(fvol->mountpoint);
		
	g_free(fvol);
}
示例#7
0
static LibHalVolume	*pusb_volume_probe(t_pusb_options *opts,
		LibHalContext *ctx)
{
	LibHalVolume	*volume = NULL;
	int				maxtries = 0;
	int				i;

	if (!*(opts->device.volume_uuid))
	{
		log_debug("No UUID configured for device\n");
		return (NULL);
	}
	log_debug("Searching for volume with uuid %s\n", opts->device.volume_uuid);
	maxtries = ((opts->probe_timeout * 1000000) / 250000);
	for (i = 0; i < maxtries; ++i)
	{
		char	*udi = NULL;

		if (i == 1)
			log_info("Probing volume (this could take a while)...\n");
		udi = pusb_hal_find_item(ctx,
				"volume.uuid", opts->device.volume_uuid,
				NULL);
		if (!udi)
		{
			usleep(250000);
			continue;
		}
		volume = libhal_volume_from_udi(ctx, udi);
		libhal_free_string(udi);
		if (!libhal_volume_should_ignore(volume))
			return (volume);
		libhal_volume_free(volume);
		usleep(250000);
	}
	return (NULL);
}
static void
thunar_vfs_volume_manager_hal_device_added (LibHalContext *context,
                                            const gchar   *udi)
{
  ThunarVfsVolumeManagerHal *manager_hal = libhal_ctx_get_user_data (context);
  ThunarVfsVolumeHal        *volume_hal;
  LibHalVolume              *hv;
  LibHalDrive               *hd;
  const gchar               *drive_udi;

  _thunar_vfs_return_if_fail (THUNAR_VFS_IS_VOLUME_MANAGER_HAL (manager_hal));
  _thunar_vfs_return_if_fail (manager_hal->context == context);

  /* check if we have a volume here */
  hv = libhal_volume_from_udi (context, udi);

  /* HAL might want us to ignore this volume for some reason */
  if (G_UNLIKELY (hv != NULL && libhal_volume_should_ignore (hv)))
    {
      libhal_volume_free (hv);
      return;
    }

  /* emit the "device-added" signal (to support thunar-volman) */
  g_signal_emit_by_name (G_OBJECT (manager_hal), "device-added", udi);

  if (G_LIKELY (hv != NULL))
    {
      /* check if we have a mountable file system here */
      if (libhal_volume_get_fsusage (hv) == LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM)
        {
          /* determine the UDI of the drive to which this volume belongs */
          drive_udi = libhal_volume_get_storage_device_udi (hv);
          if (G_LIKELY (drive_udi != NULL))
            {
              /* determine the drive for the volume */
              hd = libhal_drive_from_udi (context, drive_udi);
              if (G_LIKELY (hd != NULL))
                {
                  /* check if we already have a volume object for the UDI */
                  volume_hal = thunar_vfs_volume_manager_hal_get_volume_by_udi (manager_hal, udi);
                  if (G_LIKELY (volume_hal == NULL))
                    {
                      /* otherwise, we allocate a new volume object */
                      volume_hal = g_object_new (THUNAR_VFS_TYPE_VOLUME_HAL, NULL);
                      volume_hal->udi = g_strdup (udi);
                    }

                  /* update the volume object with the new data from the HAL volume/drive */
                  thunar_vfs_volume_hal_update (volume_hal, context, hv, hd);

                  /* add the volume object to our list if we allocated a new one */
                  if (g_list_find (THUNAR_VFS_VOLUME_MANAGER (manager_hal)->volumes, volume_hal) == NULL)
                    {
                      /* add the volume to the volume manager */
                      thunar_vfs_volume_manager_add (THUNAR_VFS_VOLUME_MANAGER (manager_hal), THUNAR_VFS_VOLUME (volume_hal));

                      /* release the reference on the volume */
                      g_object_unref (G_OBJECT (volume_hal));
                    }

                  /* release the HAL drive */
                  libhal_drive_free (hd);
                }
            }
        }

      /* release the HAL volume */
      libhal_volume_free (hv);
    }
  else
    {
      /* but maybe we have a floppy disk drive here */
      hd = libhal_drive_from_udi (context, udi);
      if (G_UNLIKELY (hd == NULL))
        return;

      /* check if we have a floppy disk drive */
      if (G_LIKELY (libhal_drive_get_type (hd) == LIBHAL_DRIVE_TYPE_FLOPPY))
        {
          /* check if we already have a volume object for the UDI */
          volume_hal = thunar_vfs_volume_manager_hal_get_volume_by_udi (manager_hal, udi);
          if (G_LIKELY (volume_hal == NULL))
            {
              /* otherwise, we allocate a new volume object */
              volume_hal = g_object_new (THUNAR_VFS_TYPE_VOLUME_HAL, NULL);
              volume_hal->udi = g_strdup (udi);
            }

          /* update the volume object with the new data from the HAL volume/drive */
          thunar_vfs_volume_hal_update (volume_hal, context, NULL, hd);

          /* add the volume object to our list if we allocated a new one */
          if (g_list_find (THUNAR_VFS_VOLUME_MANAGER (manager_hal)->volumes, volume_hal) == NULL)
            {
              /* add the volume to the volume manager */
              thunar_vfs_volume_manager_add (THUNAR_VFS_VOLUME_MANAGER (manager_hal), THUNAR_VFS_VOLUME (volume_hal));

              /* release the reference on the volume */
              g_object_unref (G_OBJECT (volume_hal));
            }
        }

      /* release the HAL drive */
      libhal_drive_free (hd);
    }
}
static void
thunar_vfs_volume_manager_hal_update_volume_by_udi (ThunarVfsVolumeManagerHal *manager_hal,
                                                    const gchar               *udi)
{
  ThunarVfsVolumeHal *volume_hal;
  LibHalVolume       *hv = NULL;
  LibHalDrive        *hd = NULL;
  const gchar        *drive_udi;

  /* check if we have a volume for the UDI */
  volume_hal = thunar_vfs_volume_manager_hal_get_volume_by_udi (manager_hal, udi);
  if (G_UNLIKELY (volume_hal == NULL))
    return;

  /* check if we have a volume here */
  hv = libhal_volume_from_udi (manager_hal->context, udi);
  if (G_UNLIKELY (hv == NULL))
    {
      /* check if we have a drive here */
      hd = libhal_drive_from_udi (manager_hal->context, udi);
      if (G_UNLIKELY (hd == NULL))
        {
          /* the device is no longer a drive or volume, so drop it */
          thunar_vfs_volume_manager_hal_device_removed (manager_hal->context, udi);
          return;
        }

      /* update the drive with the new HAL drive/volume */
      thunar_vfs_volume_hal_update (volume_hal, manager_hal->context, NULL, hd);

      /* release the drive */
      libhal_drive_free (hd);
    }
  else
    {
      /* determine the UDI of the drive to which this volume belongs */
      drive_udi = libhal_volume_get_storage_device_udi (hv);
      if (G_LIKELY (drive_udi != NULL))
        {
          /* determine the drive for the volume */
          hd = libhal_drive_from_udi (manager_hal->context, drive_udi);
        }

      /* check if we have the drive for the volume */
      if (G_LIKELY (hd != NULL))
        {
          /* update the volume with the new HAL drive/volume */
          thunar_vfs_volume_hal_update (volume_hal, manager_hal->context, hv, hd);

          /* release the drive */
          libhal_drive_free (hd);
        }
      else
        {
          /* unable to determine the drive, volume gone? */
          thunar_vfs_volume_manager_hal_device_removed (manager_hal->context, udi);
        }

      /* release the volume */
      libhal_volume_free (hv);
    }
}