Beispiel #1
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;
}
Beispiel #2
0
static void
update_extra_info(FormatDialog* dialog)
{
	gboolean show_info = FALSE;
	GtkLabel* info = dialog->extra_volume_info;

	/* Right now we only have one thing to display but it's possible that
	 * we might have more */

	/* Check to see if this has a mountpoint */
	do {
		char buf[512];
		GtkTreeIter iter;

		if(!gtk_combo_box_get_active_iter(dialog->volume_combo, &iter))
			break;

		const FormatVolume* vol = get_cached_device_from_treeiter(dialog, &iter);
		if(!vol || !vol->volume)
			break;

		const char* mountpoint = libhal_volume_get_mount_point(vol->volume);
		char* vol_name = get_friendly_volume_name(dialog->hal_context, vol->volume);
                
                if ( mountpoint == NULL ) {
                        const char *tmp;
                        tmp = libhal_volume_get_fstype(vol->volume);
                        
                        if ( tmp != NULL && strcmp (tmp, "swap") == 0 )
                                mountpoint = g_strdup(tmp);
                }
		
                /* FIXME: The \n is a hack to get the dialog box to not resize 
		 * horizontally so much */
		g_snprintf(buf, 512, _("<i>%s\n is currently mounted on/as '%s'</i>"), vol_name, mountpoint);
		g_free(vol_name);
		gtk_label_set_markup(info, buf);
		show_info |= TRUE;
	} while(0);

	if(show_info)
		gtk_widget_show_all(GTK_WIDGET(dialog->extra_volume_hbox));
	else
		gtk_widget_hide_all(GTK_WIDGET(dialog->extra_volume_hbox));
}
Beispiel #3
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);
}
Beispiel #4
0
GSList* 
build_volume_list(LibHalContext* ctx, 
		  enum FormatVolumeType type, 
		  GHashTable* icon_cache, 
		  int icon_width, int icon_height)
{
	const char* capability = "";
	char** device_udis;
	int i, device_udi_count = 0;
	GSList* device_list = NULL;
	DBusError error;

	switch(type) {
	case FORMATVOLUMETYPE_VOLUME:
		capability = "volume";
		break;
	case FORMATVOLUMETYPE_DRIVE:
		capability = "storage";
		break;
	}

	/* Pull the storage (or volume) list from HAL */
	dbus_error_init (&error); 
	if ( (device_udis = libhal_find_device_by_capability (ctx, capability, &device_udi_count, &error) ) == NULL) {
		LIBHAL_FREE_DBUS_ERROR (&error);
		goto out;
	}

	/* if we use libhal_device_get-property() instead of 
	 * libhal_volume_get_mount_mount_point() we have to setup DBusError and
	 * some other things, the problem is do we like to have (null) in the gui
	 * when libhal-storage cannot discover where a partition is mounted?
	 * if so we can remove the DBusError code and use the libhal-storage func
	 * to retrive the mount point.
	 * (or maybe we can check if is_partition == null and then don't strdup
	 * it.
	 * It returns null when a device is marked as swap or mounted via
	 * cryptdisk or even if it's not listed in /etc/fstab
	 */

	/* Now we use libhal-storage to get the info */
	FormatVolume* current;
	const char* icon_path;
	for(i=0; i < device_udi_count; i++) {
		current = g_new0(FormatVolume, 1);

		g_debug("udi: %s", device_udis[i]);
		current->udi = g_strdup(device_udis[i]);
		switch(type) {
		case FORMATVOLUMETYPE_VOLUME:
			current->volume = libhal_volume_from_udi(ctx, device_udis[i]);
			if(!current->volume) {
				g_free(current);
				continue;
			}

			/* FIXME: This tastes like wrong */
			current->icon = NULL;

			current->friendly_name = get_friendly_volume_info(ctx, current->volume);
			current->drive_udi = g_strdup(libhal_volume_get_storage_device_udi(current->volume));
			current->mountpoint = g_strdup(libhal_volume_get_mount_point(current->volume));
			break;

		case FORMATVOLUMETYPE_DRIVE:
			current->drive = libhal_drive_from_udi(ctx, device_udis[i]);
			if(!current->drive) {
				g_free(current);
				continue;
			}

			g_debug("Icon drive: %s; Icon volume: %s",
					libhal_drive_get_dedicated_icon_drive(current->drive),
					libhal_drive_get_dedicated_icon_volume(current->drive));
			icon_path = libhal_drive_get_dedicated_icon_drive(current->drive);
			current->icon = load_icon_from_cache(icon_path, icon_cache, icon_width, icon_height);

			current->friendly_name = get_friendly_drive_info(current->drive);

			break;
		}

		/* Do some last minute sanity checks */
		if(!current->friendly_name)	current->friendly_name = "";

		device_list = g_slist_prepend(device_list, current);
	}
	
	if(device_udis)
		libhal_free_string_array(device_udis);

out:
	return device_list;
}
Beispiel #5
0
gboolean
warn_user_of_impending_doom(FormatDialog* dialog, FormatVolume* target)
{
	GSList* mounted_list = NULL;

	/* Figure out if we're about to run over any live partitions first */
	if(target->volume) {
		if(libhal_volume_is_mounted(target->volume)) {
			mounted_list = g_slist_prepend(mounted_list, 
						       get_friendly_volume_name(dialog->hal_context, target->volume));
		}
	}
	else {
		mounted_list = get_volumes_mounted_on_drive(dialog->hal_context, target->drive);
	}

	gchar* message;
	gchar* name = (target->volume ? get_friendly_volume_name(dialog->hal_context, target->volume) : 
					get_friendly_drive_name(target->drive));
	/* Come up with the error message */
	if(!mounted_list) {
		message = g_strdup_printf(_("Formatting will irreversibly destroy all data on %s. "
					    "Are you sure you want to continue?"), name);
	}
	else {
		/* FIXME: There are a ton of malloc's here */
		int i; 	GSList* iter;
		gchar* tmp_list[65];

		/* TODO: It'd be cool if these were hyperlinks that opened nautilus at the mountpoint! */
		for(iter = mounted_list, i=0; iter != NULL && i < 64; iter = iter->next, i++) {
			FormatVolume* current = get_cached_device_from_udi(dialog, (char*)iter->data);
			g_debug("Mounted: %s", iter->data);
			if(!current) 	continue;

			gchar* mountpoint = libhal_volume_get_mount_point(current->volume);
			tmp_list[i] = g_strdup_printf( _("%s mounted at %s"), current->friendly_name, mountpoint);
		}
		tmp_list[i] = NULL;

		gchar* vol_list = g_strjoinv("\n", tmp_list);

		message = g_strdup_printf( _("Formatting will irreversibly destroy all data on %s, "
					     "including these volumes currently in use:"
					     "\n\n%s\n\n"
					     "Are you sure you want to continue?"), name, vol_list);

		/* Free our stuff */
		g_free(vol_list);
		for(int i=0; i < 64; i++) {
			if(!tmp_list[i]) break;
			g_free(tmp_list[i]);
		}
	}
	g_free(name);

	/* Show the dialog and get the response back */
	GtkWidget* messagebox;
	messagebox = gtk_message_dialog_new(GTK_WINDOW(dialog->toplevel), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, _("Formatting will erase data"));
	gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(messagebox), message);
	gtk_dialog_add_buttons(GTK_DIALOG(messagebox), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
			 _("Format device"), GTK_RESPONSE_OK, NULL);

	int id = gtk_dialog_run(GTK_DIALOG(messagebox));
	gtk_widget_destroy(messagebox);

	return (id == GTK_RESPONSE_OK);
}
static void
thunar_vfs_volume_hal_update (ThunarVfsVolumeHal *volume_hal,
                              LibHalContext      *context,
                              LibHalVolume       *hv,
                              LibHalDrive        *hd)
{
  gchar *desired_mount_point;
  gchar *mount_root;
  gchar *basename;
  gchar *filename;

  _thunar_vfs_return_if_fail (THUNAR_VFS_IS_VOLUME_HAL (volume_hal));
  _thunar_vfs_return_if_fail (hd != NULL);

  /* reset the volume status */
  volume_hal->status = 0;

  /* determine the new device file */
  g_free (volume_hal->device_file);
  volume_hal->device_file = g_strdup ((hv != NULL) ? libhal_volume_get_device_file (hv) : libhal_drive_get_device_file (hd));

  /* compute a usable display name for the volume/drive */
  g_free (volume_hal->device_label);
  volume_hal->device_label = (hv == NULL)
    ? exo_hal_drive_compute_display_name (context, hd)
    : exo_hal_volume_compute_display_name (context, hv, hd);
  if (G_UNLIKELY (volume_hal->device_label == NULL))
    {
      /* use the basename of the device file as label */
      volume_hal->device_label = g_path_get_basename (volume_hal->device_file);
    }

  /* compute a usable list of icon names for the volume/drive */
  g_list_foreach (volume_hal->icon_list, (GFunc) g_free, NULL);
  g_list_free (volume_hal->icon_list);
  volume_hal->icon_list = (hv == NULL)
    ? exo_hal_drive_compute_icon_list (context, hd)
    : exo_hal_volume_compute_icon_list (context, hv, hd);

  /* release the previous mount point (if any) */
  if (G_LIKELY (volume_hal->mount_point != NULL))
    {
      thunar_vfs_path_unref (volume_hal->mount_point);
      volume_hal->mount_point = NULL;
    }

  /* determine the type of the volume */
  switch (libhal_drive_get_type (hd))
    {
    case LIBHAL_DRIVE_TYPE_CDROM:
      /* check if we have a pure audio CD without any data track */
      if (libhal_volume_disc_has_audio (hv) && !libhal_volume_disc_has_data (hv))
        {
          /* special treatment for pure audio CDs */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_AUDIO_CD;
        }
      else
        {
          /* check which kind of CD-ROM/DVD we have */
          switch (libhal_volume_get_disc_type (hv))
            {
            case LIBHAL_VOLUME_DISC_TYPE_CDROM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDROM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_CDR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_CDRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDRW;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDROM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDROM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDRAM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDRAM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDRW;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDPLUSR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDPLUSRW;
              break;

            default:
              /* unsupported disc type */
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_UNKNOWN;
              break;
            }
        }
      break;

    case LIBHAL_DRIVE_TYPE_FLOPPY:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_FLOPPY;
      break;

    case LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_AUDIO_PLAYER;
      break;

    case LIBHAL_DRIVE_TYPE_SMART_MEDIA:
    case LIBHAL_DRIVE_TYPE_SD_MMC:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_MEMORY_CARD;
      break;

    default:
      /* check if the drive is connected to the USB bus */
      if (libhal_drive_get_bus (hd) == LIBHAL_DRIVE_BUS_USB)
        {
          /* we consider the drive to be an USB stick */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_USBSTICK;
        }
      else if (libhal_drive_uses_removable_media (hd)
            || libhal_drive_is_hotpluggable (hd))
        {
          /* fallback to generic removable disk */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_REMOVABLE_DISK;
        }
      else
        {
          /* fallback to harddisk drive */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_HARDDISK;
        }
      break;
    }

  /* either we have a volume, which means we have media, or
   * a drive, which means non-pollable then, so it's present
   */
  volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_PRESENT;
  
  /* figure out if the volume is mountable */
  if(hv != NULL && libhal_volume_get_fsusage (hv) == LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM)
    volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTABLE;

  /* check if the drive requires eject */
  volume_hal->requires_eject = libhal_drive_requires_eject (hd);

  /* check if the volume is currently mounted */
  if (hv != NULL && libhal_volume_is_mounted (hv))
    {
      /* try to determine the new mount point */
      volume_hal->mount_point = thunar_vfs_path_new (libhal_volume_get_mount_point (hv), NULL);

      /* we only mark the volume as mounted if we have a valid mount point */
      if (G_LIKELY (volume_hal->mount_point != NULL))
        volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;
    }
  else
    {
      /* we don't trust HAL, so let's see what the kernel says about the volume */
      volume_hal->mount_point = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);

      /* we must have been mounted successfully if we have a mount point */
      if (G_LIKELY (volume_hal->mount_point != NULL))
        volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;
    }

  /* check if we have to figure out the mount point ourself */
  if (G_UNLIKELY (volume_hal->mount_point == NULL))
    {
      /* ask HAL for the default mount root (falling back to /media otherwise) */
      mount_root = libhal_device_get_property_string (context, "/org/freedesktop/Hal/devices/computer", "storage.policy.default.mount_root", NULL);
      if (G_UNLIKELY (mount_root == NULL || !g_path_is_absolute (mount_root)))
        {
          /* fallback to /media (seems to be sane) */
          g_free (mount_root);
          mount_root = g_strdup ("/media");
        }

      /* lets see, maybe /etc/fstab knows where to mount */
      volume_hal->mount_point = thunar_vfs_volume_hal_find_fstab_mount_point (volume_hal);

      /* if we still don't have a mount point, ask HAL */
      if (G_UNLIKELY (volume_hal->mount_point == NULL))
        {
          /* determine the desired mount point and prepend the mount root */
          desired_mount_point = libhal_device_get_property_string (context, volume_hal->udi, "volume.policy.desired_mount_point", NULL);
          if (G_LIKELY (desired_mount_point != NULL && *desired_mount_point != '\0'))
            {
              filename = g_build_filename (mount_root, desired_mount_point, NULL);
              volume_hal->mount_point = thunar_vfs_path_new (filename, NULL);
              g_free (filename);
            }
          libhal_free_string (desired_mount_point);
        }

      /* ok, last fallback, just use <mount-root>/<device> */
      if (G_UNLIKELY (volume_hal->mount_point == NULL))
        {
          /* <mount-root>/<device> looks like a good idea */
          basename = g_path_get_basename (volume_hal->device_file);
          filename = g_build_filename (mount_root, basename, NULL);
          volume_hal->mount_point = thunar_vfs_path_new (filename, NULL);
          g_free (filename);
          g_free (basename);
        }

      /* release the mount root */
      g_free (mount_root);
    }

  /* if we get here, we must have a valid mount point */
  g_assert (volume_hal->mount_point != NULL);

  /* emit the "changed" signal */
  thunar_vfs_volume_changed (THUNAR_VFS_VOLUME (volume_hal));
}