Пример #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;
}
Пример #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));
}
Пример #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
int
main (int argc, char *argv[])
{
	char *udi;
	char *device;
	const char *drive_udi;
	LibHalDrive *drive;
	LibHalVolume *volume;
	DBusError error;
	LibHalContext *hal_ctx = NULL;
	DBusConnection *system_bus = NULL;
#ifdef HAVE_POLKIT
	LibPolKitContext *pol_ctx = NULL;
#endif
	char *invoked_by_uid;
	char *invoked_by_syscon_name;

	device = getenv ("HAL_PROP_BLOCK_DEVICE");
	if (device == NULL)
		usage ();

	udi = getenv ("HAL_PROP_INFO_UDI");
	if (udi == NULL)
		usage ();

	invoked_by_uid = getenv ("HAL_METHOD_INVOKED_BY_UID");

	invoked_by_syscon_name = getenv ("HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME");

	dbus_error_init (&error);
	if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) {
		printf ("Cannot connect to hald\n");
		LIBHAL_FREE_DBUS_ERROR (&error);
		usage ();
	}

	dbus_error_init (&error);
	system_bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
	if (system_bus == NULL) {
		printf ("Cannot connect to the system bus\n");
		LIBHAL_FREE_DBUS_ERROR (&error);
		usage ();
	}
#ifdef HAVE_POLKIT
	pol_ctx = libpolkit_new_context (system_bus);
	if (pol_ctx == NULL) {
		printf ("Cannot get libpolkit context\n");
		unknown_zpool_error ("Cannot get libpolkit context");
	}
#endif

	/* should be a volume */
	if ((volume = libhal_volume_from_udi (hal_ctx, udi)) == NULL) {
		unknown_zpool_error ("Invalid volume");
	}
	if ((drive_udi = libhal_volume_get_storage_device_udi (volume)) == NULL ) {
		unknown_zpool_error ("Cannot get drive udi");
	}
	if ((drive = libhal_drive_from_udi (hal_ctx, drive_udi)) == NULL) {
		unknown_zpool_error ("Cannot get drive from udi");
	}
	if ((libhal_volume_get_fstype (volume) == NULL) ||
	    (strcmp (libhal_volume_get_fstype (volume), "zfs") != 0)) {
		unknown_zpool_error ("Not a zpool");
	}
	if ((libhal_volume_get_label (volume) == NULL) ||
	    (strlen (libhal_volume_get_label (volume)) == 0)) {
		unknown_zpool_error ("Invalid zpool name");
	}

        handle_zpool (hal_ctx,
#ifdef HAVE_POLKIT
		      pol_ctx,
#endif
                      ZPOOL_SUBCMD,
                      libhal_volume_get_label (volume),
		      device,
                      invoked_by_uid,
                      invoked_by_syscon_name,
		      system_bus);

	return 0;
}
Пример #5
0
/* Callback function, called when a new device has been inserted. */
static void
device_added(LibHalContext *context, const char *did)
{
    const char *dudi, *fstype;
    char *dev, *mountp, *mountable, *label, *locked_reason;
    LibHalVolume *volume;
    LibHalDrive *drive;
    struct device_t *device;

    if (libhal_device_property_exists(context, did, "info.locked",
                                      (DBusError *)NULL)
            && libhal_device_get_property_bool(context, did, "info.locked",
                                               (DBusError *)NULL)) {
        if (debug_mode_flag) {
            locked_reason = libhal_device_get_property_string(
                                context, did, "info.locked.reason",
                                (DBusError *)NULL);
            if (locked_reason) {
                if (debug_mode_flag)
                    printf("%s%d: %s\n", __FILE__, __LINE__, locked_reason);
                libhal_free_string(locked_reason);
            }
        }
        return;
    }

    if (!libhal_device_query_capability(context, did, "volume",
                                        (DBusError *)NULL))
        return;
    label = libhal_device_get_property_string(context, did, "volume.label",
                                              (DBusError *)NULL);
    if (!(mountable = libhal_device_get_property_string(
                          context, did, "volume.fsusage", (DBusError *)NULL))
            || strcmp(mountable, "filesystem"))
        goto out;
    if (!(volume = libhal_volume_from_udi(context, did)))
        goto out;
    if (!(dudi = libhal_volume_get_storage_device_udi(volume)))
        goto out;
    if (!(drive = libhal_drive_from_udi(context, dudi)))
        goto out;
    if (!libhal_drive_is_hotpluggable(drive)
            && !libhal_drive_uses_removable_media(drive))
        goto out;
    if (!(fstype = libhal_volume_get_fstype(volume)))
        goto out;
    if (!(dev = libhal_device_get_property_string(context, did, "block.device",
                                                  (DBusError *)NULL)))
        goto out;
    mountp = get_mount_point(dev, label);
    if (!mountp)
        goto out;
    device = get_device(mountp, did, dev, label, fstype, volume, drive);
    if(!is_mounted(device)) {
        free_device(device);
        goto out;
    }
    if (!device)
        goto out;
    consider_fstab(device);

    device->hook = malloc(2*sizeof(char*)); 
    if(!file_exists(HOOK_PATH)) {
        device->hook[0] = get_hook(device, "mount");
        device->hook[1] = get_hook(device, "umount");
    }
    else {
        device->hook[0] = NULL;
        device->hook[1] = NULL;
    }

    if (file_exists(device->mountp) < 0)
        mkdir(device->mountp, 0750);
    do_mount(device) < 0 ? free_device(device) : add_to_device_list(device);

    if (device) {
        if (!add_fstab_entry(device))
            device->should_remove_entry = 1;
        if (debug_mode_flag)
            debug_dump_device(device);
    }

    if (device->hook[0]) run_hook(0, device);

out:
    if (mountable)
        libhal_free_string(mountable);
    if (label)
        libhal_free_string(label);
}