static void
update_block (StoragedLinuxBlockObject       *block_object,
              StoragedLinuxVolumeGroupObject *group_object,
              GHashTable                     *new_lvs,
              GHashTable                     *new_pvs)
{
    StoragedBlock *block;
    GVariant *pv_info;

    block = storaged_object_peek_block (STORAGED_OBJECT (block_object));
    if (block == NULL)
        return;

    // XXX - move this elsewhere?
    {
        StoragedLinuxDevice *device;
        StoragedLinuxLogicalVolumeObject *lv_object;
        const gchar *block_vg_name;
        const gchar *block_lv_name;

        device = storaged_linux_block_object_get_device (block_object);
        if (device)
        {
            block_vg_name = g_udev_device_get_property (device->udev_device, "DM_VG_NAME");
            block_lv_name = g_udev_device_get_property (device->udev_device, "DM_LV_NAME");

            if (g_strcmp0 (block_vg_name, storaged_linux_volume_group_object_get_name (group_object)) == 0
                    && (lv_object = g_hash_table_lookup (new_lvs, block_lv_name)))
            {
                block_object_update_lvm_iface (block_object, g_dbus_object_get_object_path (G_DBUS_OBJECT (lv_object)));
            }
        }
    }

    pv_info = g_hash_table_lookup (new_pvs, storaged_block_get_device (block));
    if (!pv_info)
    {
        const gchar *const *symlinks;
        int i;
        symlinks = storaged_block_get_symlinks (block);
        for (i = 0; symlinks[i]; i++)
        {
            pv_info = g_hash_table_lookup (new_pvs, symlinks[i]);
            if (pv_info)
                break;
        }
    }

    if (pv_info)
    {
        storaged_linux_block_object_update_lvm_pv (block_object, group_object, pv_info);
    }
    else
    {
        StoragedPhysicalVolume *pv = storaged_object_peek_physical_volume (STORAGED_OBJECT (block_object));
        if (pv && g_strcmp0 (storaged_physical_volume_get_volume_group (pv),
                             g_dbus_object_get_object_path (G_DBUS_OBJECT (group_object))) == 0)
            storaged_linux_block_object_update_lvm_pv (block_object, NULL, NULL);
    }
}
Esempio n. 2
0
static void
handle_block_uevent_for_mdraid (UDisksLinuxProvider *provider,
                                const gchar         *action,
                                UDisksLinuxDevice   *device)
{
  const gchar *uuid;
  const gchar *member_uuid;

  /* For nested RAID levels, a device can be both a member of one
   * array and the RAID device for another. Therefore we need to
   * consider both UUIDs.
   *
   * For removal, we also need to consider the case where there is no
   * UUID.
   */
  uuid = g_udev_device_get_property (device->udev_device, "UDISKS_MD_UUID");
  member_uuid = g_udev_device_get_property (device->udev_device, "UDISKS_MD_MEMBER_UUID");

  if (uuid != NULL)
    handle_block_uevent_for_mdraid_with_uuid (provider, action, device, uuid, FALSE);

  if (member_uuid != NULL)
    handle_block_uevent_for_mdraid_with_uuid (provider, action, device, member_uuid, TRUE);

  if (uuid == NULL && member_uuid == NULL)
    handle_block_uevent_for_mdraid_with_uuid (provider, action, device, NULL, FALSE);
}
Esempio n. 3
0
/**
 * cd_sensor_client_add:
 **/
static gboolean
cd_sensor_client_add (CdSensorClient *sensor_client,
		      GUdevDevice *device)
{
	CdSensor *sensor = NULL;
	const gchar *device_file;
	const gchar *tmp;
	gboolean ret = FALSE;
	GError *error = NULL;

	/* interesting device? */
	tmp = g_udev_device_get_property (device, "COLORD_SENSOR_KIND");
	if (tmp == NULL)
		goto out;
	tmp = g_udev_device_get_property (device, "COLORD_IGNORE");
	if (tmp != NULL)
		goto out;

	/* actual device? */
	device_file = g_udev_device_get_device_file (device);
	if (device_file == NULL)
		goto out;

	/* get data */
	g_debug ("adding color management device: %s [%s]",
		 g_udev_device_get_sysfs_path (device),
		 device_file);
	sensor = cd_sensor_new ();
	ret = cd_sensor_set_from_device (sensor, device, &error);
	if (!ret) {
		g_warning ("CdSensorClient: failed to set CM sensor: %s",
			   error->message);
		g_error_free (error);
		goto out;
	}

	/* set the index */
	cd_sensor_set_index (sensor, sensor_client->priv->idx);

	/* load the sensor */
	ret = cd_sensor_load (sensor, &error);
	if (!ret) {
		/* not fatal, non-native devices are still useable */
		g_debug ("CdSensorClient: failed to load native sensor: %s",
			 error->message);
		g_clear_error (&error);
	}

	/* signal the addition */
	g_debug ("emit: added");
	g_signal_emit (sensor_client, signals[SIGNAL_SENSOR_ADDED], 0, sensor);
	sensor_client->priv->idx++;

	/* keep track so we can remove with the same device */
	g_ptr_array_add (sensor_client->priv->array_sensors, g_object_ref (sensor));
out:
	if (sensor != NULL)
		g_object_unref (sensor);
	return ret;
}
static gchar *
check_for_vpd (GUdevDevice *device)
{
    gchar *ret = NULL;
    const gchar *serial;
    const gchar *wwn;
    const gchar *path;

    g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);

    /* order of preference: WWN_serial, WWN, serial, path */
    serial = g_udev_device_get_property (device, "ID_SERIAL");
    wwn = g_udev_device_get_property (device, "ID_WWN_WITH_EXTENSION");
    path = g_udev_device_get_property (device, "ID_PATH");
    if (wwn != NULL && strlen (wwn) > 0 && !is_wwn_black_listed (wwn))
    {
        if (serial != NULL && strlen (serial) > 0)
            ret = g_strdup_printf ("%s_%s", wwn, serial);
        else
            ret = g_strdup (wwn);
    }
    else if (serial != NULL && strlen (serial) > 0)
    {
        ret = g_strdup (serial);
    }
    else if (path != NULL && strlen (path) > 0)
    {
        ret = g_strdup (path);
    }
    return ret;
}
Esempio n. 5
0
static gboolean
input_accel_open (GUdevDevice        *device,
		  ReadingsUpdateFunc  callback_func,
		  gpointer            user_data)
{
	const gchar * const subsystems[] = { "input", NULL };
	const char *mount_matrix;

	drv_data = g_new0 (DrvData, 1);
	drv_data->dev = g_object_ref (device);
	drv_data->parent = g_udev_device_get_parent (drv_data->dev);
	drv_data->dev_path = g_udev_device_get_device_file (device);
	drv_data->name = g_udev_device_get_property (device, "NAME");
	drv_data->client = g_udev_client_new (subsystems);

	mount_matrix = g_udev_device_get_property (device, "ACCEL_MOUNT_MATRIX");
	if (!parse_mount_matrix (mount_matrix, &drv_data->mount_matrix)) {
		g_warning ("Invalid mount-matrix ('%s'), falling back to identity",
			   mount_matrix);
		parse_mount_matrix (NULL, &drv_data->mount_matrix);
	}

	drv_data->callback_func = callback_func;
	drv_data->user_data = user_data;

	g_signal_connect (drv_data->client, "uevent",
			  G_CALLBACK (uevent_received), NULL);

	g_idle_add (first_values, NULL);

	return TRUE;
}
Esempio n. 6
0
char *
g_vfs_get_volume_name (GUdevDevice *device, const char *device_id)
{
  const char *gphoto_name;
  const char *product = NULL;
  const char *vendor;
  const char *model;

  /* our preference: device_id > ID_MEDIA_PLAYER_{VENDOR,PRODUCT} > product >
   * ID_{VENDOR,MODEL} */

  gphoto_name = g_udev_device_get_property (device, device_id);
  if (gphoto_name != NULL && strcmp (gphoto_name, "1") != 0)
    return g_strdup (gphoto_name);

  vendor = g_udev_device_get_property (device, "ID_MEDIA_PLAYER_VENDOR");
  if (vendor == NULL)
    vendor = g_udev_device_get_property (device, "ID_VENDOR_ENC");
  model = g_udev_device_get_property (device, "ID_MEDIA_PLAYER_MODEL");
  if (model == NULL) {
    model = g_udev_device_get_property (device, "ID_MODEL_ENC");
    product = g_udev_device_get_sysfs_attr (device, "product");
  }

  if (product != NULL && strlen (product) > 0)
    return g_strdup (udev_decode_string (product));
  else if (vendor == NULL)
    {
      if (model != NULL)
        return g_strdup (udev_decode_string (model));
    }
  else
    {
      if (model != NULL)
        {
          /* we can't call udev_decode_string() twice in one g_strdup_printf(),
           * it returns a static buffer */
          gchar *temp = g_strconcat (vendor, " ", model, NULL);
          gchar *name = g_strdup (udev_decode_string (temp));
          g_free (temp);
          return name;
        }
      else
        {
          if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER"))
            {
              /* Translators: %s is the device vendor */
              return g_strdup_printf (_("%s Audio Player"), udev_decode_string (vendor));
            }
          else
            {
              /* Translators: %s is the device vendor */
              return g_strdup_printf (_("%s Camera"), udev_decode_string (vendor));
            }
        }
    }

  return g_strdup (_("Camera"));
}
gboolean
mm_plugin_base_get_device_ids (MMPluginBase *self,
                               const char *subsys,
                               const char *name,
                               guint16 *vendor,
                               guint16 *product)
{
    MMPluginBasePrivate *priv;
    GUdevDevice *device = NULL;
    const char *vid, *pid;
    gboolean success = FALSE;

    g_return_val_if_fail (self != NULL, FALSE);
    g_return_val_if_fail (MM_IS_PLUGIN_BASE (self), FALSE);
    g_return_val_if_fail (subsys != NULL, FALSE);
    g_return_val_if_fail (name != NULL, FALSE);
    if (vendor)
        g_return_val_if_fail (*vendor == 0, FALSE);
    if (product)
        g_return_val_if_fail (*product == 0, FALSE);

    priv = MM_PLUGIN_BASE_GET_PRIVATE (self);

    device = g_udev_client_query_by_subsystem_and_name (priv->client, subsys, name);
    if (!device)
        goto out;

    vid = g_udev_device_get_property (device, "ID_VENDOR_ID");
    if (!vid || (strlen (vid) != 4))
        goto out;

    if (vendor) {
        *vendor = (guint16) (hex2byte (vid + 2) & 0xFF);
        *vendor |= (guint16) ((hex2byte (vid) & 0xFF) << 8);
    }

    pid = g_udev_device_get_property (device, "ID_MODEL_ID");
    if (!pid || (strlen (pid) != 4)) {
        *vendor = 0;
        goto out;
    }

    if (product) {
        *product = (guint16) (hex2byte (pid + 2) & 0xFF);
        *product |= (guint16) ((hex2byte (pid) & 0xFF) << 8);
    }

    success = TRUE;

out:
    if (device)
        g_object_unref (device);
    return success;
}
Esempio n. 8
0
void
storage_volume_group_update_block (StorageVolumeGroup *self,
                                   StorageBlock *block)
{

  GUdevDevice *device;
  StorageLogicalVolume *volume;
  const gchar *block_vg_name;
  const gchar *block_lv_name;
  GVariant *pv_info;

  device = storage_block_get_udev (block);
  if (device)
    {
      block_vg_name = g_udev_device_get_property (device, "DM_VG_NAME");
      block_lv_name = g_udev_device_get_property (device, "DM_LV_NAME");

      if (g_strcmp0 (block_vg_name, storage_volume_group_get_name (self)) == 0)
        {
          volume = g_hash_table_lookup (self->logical_volumes, block_lv_name);
          storage_block_update_lv (block, volume);
        }
      g_object_unref (device);
    }

  pv_info = g_hash_table_lookup (self->physical_volumes, storage_block_get_device (block));
  if (!pv_info)
    {
      const gchar *const *symlinks;
      int i;
      symlinks = storage_block_get_symlinks (block);
      for (i = 0; symlinks[i]; i++)
        {
          pv_info = g_hash_table_lookup (self->physical_volumes, symlinks[i]);
          if (pv_info)
            break;
        }
    }

  if (pv_info)
    {
      storage_block_update_pv (block, self, pv_info);
    }
  else
    {
      LvmPhysicalVolumeBlock *pv = storage_block_get_physical_volume_block (block);
      if (pv && g_strcmp0 (lvm_physical_volume_block_get_volume_group (pv),
                           storage_volume_group_get_object_path (self)) == 0)
        storage_block_update_pv (block, NULL, NULL);
    }
}
static void
empathy_camera_device_monitor_removed (EmpathyCameraDeviceMonitor *monitor,
                                      GUdevDevice               *udevice)
{
  g_signal_emit (monitor, monitor_signals[REMOVED], 0,
                 g_udev_device_get_property (udevice, "DEVPATH"));
}
Esempio n. 10
0
static void
impl_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
	RBAndroidSourcePrivate *priv = GET_PRIVATE (object);

	switch (prop_id) {
	case PROP_IGNORE_ENTRY_TYPE:
		g_value_set_object (value, priv->ignore_type);
		break;
	case PROP_ERROR_ENTRY_TYPE:
		g_value_set_object (value, priv->error_type);
		break;
	case PROP_DEVICE_INFO:
		g_value_set_object (value, priv->device_info);
		break;
	case PROP_MOUNT:
		g_value_set_object (value, priv->mount);
		break;
	case PROP_GUDEV_DEVICE:
		g_value_set_object (value, priv->gudev_device);
		break;
	case PROP_DEVICE_SERIAL:
		g_value_set_string (value, g_udev_device_get_property (priv->gudev_device, "ID_SERIAL"));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Esempio n. 11
0
static char *
get_decoded_property (GUdevDevice *device, const char *property)
{
	const char *orig, *p;
	char *unescaped, *n;
	guint len;

	p = orig = g_udev_device_get_property (device, property);
	if (!orig)
		return NULL;

	len = strlen (orig);
	n = unescaped = g_malloc0 (len + 1);
	while (*p) {
		if ((len >= 4) && (*p == '\\') && (*(p+1) == 'x')) {
			*n++ = (char) hex2byte (p + 2);
			p += 4;
			len -= 4;
		} else {
			*n++ = *p++;
			len--;
		}
	}

	return unescaped;
}
static gboolean
iio_buffer_light_open (GUdevDevice        *device,
                       ReadingsUpdateFunc  callback_func,
                       gpointer            user_data)
{
	char *trigger_name;

	drv_data = g_new0 (DrvData, 1);

	/* Get the trigger name, and build the channels from that */
	trigger_name = get_trigger_name (device);
	if (!trigger_name) {
		g_clear_pointer (&drv_data, g_free);
		return FALSE;
	}
	drv_data->buffer_data = buffer_drv_data_new (device, trigger_name);
	g_free (trigger_name);

	if (!drv_data->buffer_data) {
		g_clear_pointer (&drv_data, g_free);
		return FALSE;
	}

	drv_data->dev = g_object_ref (device);
	drv_data->dev_path = g_udev_device_get_device_file (device);
	drv_data->name = g_udev_device_get_property (device, "NAME");
	if (!drv_data->name)
		drv_data->name = g_udev_device_get_name (device);

	drv_data->callback_func = callback_func;
	drv_data->user_data = user_data;

	return TRUE;
}
Esempio n. 13
0
static Killswitch *
killswitch_new (GUdevDevice *device, RfKillType rtype)
{
	Killswitch *ks;
	GUdevDevice *parent = NULL, *grandparent = NULL;
	const char *driver, *subsys, *parent_subsys = NULL;

	ks = g_malloc0 (sizeof (Killswitch));
	ks->name = g_strdup (g_udev_device_get_name (device));
	ks->seqnum = g_udev_device_get_seqnum (device);
	ks->path = g_strdup (g_udev_device_get_sysfs_path (device));
	ks->rtype = rtype;

	driver = g_udev_device_get_property (device, "DRIVER");
	subsys = g_udev_device_get_subsystem (device);

	/* Check parent for various attributes */
	parent = g_udev_device_get_parent (device);
	if (parent) {
		parent_subsys = g_udev_device_get_subsystem (parent);
		if (!driver)
			driver = g_udev_device_get_property (parent, "DRIVER");
		if (!driver) {
			/* Sigh; try the grandparent */
			grandparent = g_udev_device_get_parent (parent);
			if (grandparent)
				driver = g_udev_device_get_property (grandparent, "DRIVER");
		}
	}

	if (!driver)
		driver = "(unknown)";
	ks->driver = g_strdup (driver);

	if (   g_strcmp0 (subsys, "platform") == 0
	    || g_strcmp0 (parent_subsys, "platform") == 0
	    || g_strcmp0 (subsys, "acpi") == 0
	    || g_strcmp0 (parent_subsys, "acpi") == 0)
		ks->platform = TRUE;

	if (grandparent)
		g_object_unref (grandparent);
	if (parent)
		g_object_unref (parent);
	return ks;
}
Esempio n. 14
0
static gboolean
hwmon_light_discover (GUdevDevice *device)
{
	if (g_strcmp0 (g_udev_device_get_property (device, "IIO_SENSOR_PROXY_TYPE"), "hwmon-als") != 0)
		return FALSE;

	g_debug ("Found HWMon light at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Esempio n. 15
0
static void device_dump_config(GUdevDevice * device)
{
	gchar *device_name, *name;
	device_name = g_strdup_printf("/dev/%s", g_udev_device_get_name(device));

	if (device_is_serial(device)) {
		name = g_strdup_printf(_("Phone on serial port %s"), g_udev_device_get_number(device));
	} else if (device_is_usb_serial(device)) {
		name = g_strdup_printf(_("Phone on USB serial port %s %s"), g_udev_device_get_property(device, "ID_VENDOR"), g_udev_device_get_property(device, "ID_MODEL"));
	} else if (device_is_acm(device)) {
		name = g_strdup_printf("%s %s", g_udev_device_get_property(device, "ID_VENDOR"), g_udev_device_get_property(device, "ID_MODEL"));
	} else {
		name = NULL;
	}
	print_config(device_name, name, "at");
	g_free(device_name);
	g_free(name);
}
static gboolean
iio_buffer_light_discover (GUdevDevice *device)
{
	if (g_strcmp0 (g_udev_device_get_property (device, "IIO_SENSOR_PROXY_TYPE"), "iio-buffer-als") != 0)
		return FALSE;

	g_debug ("Found IIO buffer ALS at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Esempio n. 17
0
char *
g_vfs_get_volume_icon (GUdevDevice *device)
{
  if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER_ICON_NAME"))
    return g_strdup (g_udev_device_get_property (device, "ID_MEDIA_PLAYER_ICON_NAME"));
  else if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER"))
    return g_strdup ("phone");
  else
    return g_strdup ("camera-photo");
}
Esempio n. 18
0
char *
g_vfs_get_volume_symbolic_icon (GUdevDevice *device)
{
  if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER_ICON_NAME"))
    return g_strconcat (g_udev_device_get_property (device, "ID_MEDIA_PLAYER_ICON_NAME"), "-symbolic", NULL);
  else if (g_udev_device_has_property (device, "ID_MEDIA_PLAYER"))
    return g_strdup ("phone-symbolic");
  else
    return g_strdup ("camera-photo-symbolic");
}
/**
 * rb_removable_media_manager_device_is_android:
 * @manager: the #RBRemovableMediaManager
 * @device: the #GUdevDevice to query
 *
 * Determines whether the specified device looks like an Android device.
 *
 * Return value: %TRUE if the device appears to be Android-based
 */
gboolean
rb_removable_media_manager_device_is_android (RBRemovableMediaManager *manager, GObject *device)
{
#if defined(HAVE_GUDEV)
	gboolean match;
	const char *model;
	const char *vendor;
	int i;

	const char *androids[] = {
		"Android",
		"Nexus"
	};
	const char *android_vendors[] = {
		"motorola",
		"OnePlus"
	};

	match = FALSE;

	model = g_udev_device_get_property (G_UDEV_DEVICE (device), "ID_MODEL");
	if (model != NULL) {
		for (i = 0; i < G_N_ELEMENTS (androids); i++) {
			if (strstr (model, androids[i]))
				match = TRUE;
		}
	}

	vendor = g_udev_device_get_property (G_UDEV_DEVICE (device), "ID_VENDOR");
	if (vendor != NULL) {
		for (i = 0; i < G_N_ELEMENTS (android_vendors); i++) {
			if (strstr (vendor, android_vendors[i]))
				match = TRUE;
		}
	}

	return match;
#else
	return FALSE;
#endif
}
Esempio n. 20
0
static int
get_property_as_int (GUdevDevice *device, const char *property, int base)
{
	const char *strvalue;

	strvalue = g_udev_device_get_property (device, property);
	if (strvalue == NULL) {
		return 0;
	}

	return strtol (strvalue, NULL, base);
}
Esempio n. 21
0
/**
 * cd_plugin_get_scanner_id_for_udev_device:
 **/
static gchar *
cd_plugin_get_scanner_id_for_udev_device (GUdevDevice *udev_device)
{
	GString *string;
	const gchar *tmp;

	/* get id */
	string = g_string_new ("sysfs");
	tmp = g_udev_device_get_property (udev_device, "ID_VENDOR");
	if (tmp != NULL)
		g_string_append_printf (string, "-%s", tmp);
	tmp = g_udev_device_get_property (udev_device, "ID_MODEL");
	if (tmp != NULL)
		g_string_append_printf (string, "-%s", tmp);

	/* fallback */
	if (string->len == 5) {
		tmp = g_udev_device_get_device_file (udev_device);
		g_string_append_printf (string, "-%s", tmp);
	}

	return g_string_free (string, FALSE);
}
static gboolean
partition_table_check (StoragedObject *object)
{
    StoragedLinuxBlockObject *block_object = STORAGED_LINUX_BLOCK_OBJECT (object);
    gboolean ret = FALSE;

    /* only consider whole disks, never partitions */
    if (g_strcmp0 (g_udev_device_get_devtype (block_object->device->udev_device), "disk") != 0)
        goto out;

    /* if blkid(8) already identified the device as a partition table, it's all good */
    if (g_udev_device_has_property (block_object->device->udev_device, "ID_PART_TABLE_TYPE"))
    {
        /* however, if blkid(8) also think that we're a filesystem... then don't
         * mark us as a partition table ... except if we are partitioned by the
         * kernel
         *
         * (see filesystem_check() for the similar case where we don't pretend
         * to be a filesystem)
         */
        if (g_strcmp0 (g_udev_device_get_property (block_object->device->udev_device, "ID_FS_USAGE"), "filesystem") == 0)
        {
            if (!disk_is_partitioned_by_kernel (block_object->device->udev_device))
            {
                goto out;
            }
        }
        ret = TRUE;
        goto out;
    }

    /* Note that blkid(8) might not detect all partition table
     * formats that the kernel knows about.... so we need to
     * double check...
     *
     * Fortunately, note that the kernel guarantees that all children
     * block devices that are partitions are created before the uevent
     * for the parent block device.... so if the parent block device has
     * children... then it must be partitioned by the kernel, hence it
     * must contain a partition table.
     */
    if (disk_is_partitioned_by_kernel (block_object->device->udev_device))
    {
        ret = TRUE;
        goto out;
    }

out:
    return ret;
}
static gboolean
btrfs_block_check (StoragedObject *object)
{
  const gchar *fs_type = NULL;
  StoragedLinuxDevice *device = NULL;

  g_return_val_if_fail (STORAGED_IS_LINUX_BLOCK_OBJECT (object), FALSE);

  /* Check filesystem type from udev property. */
  device = storaged_linux_block_object_get_device (STORAGED_LINUX_BLOCK_OBJECT (object));
  fs_type = g_udev_device_get_property (device->udev_device, "ID_FS_TYPE");

  return g_strcmp0 (fs_type, "btrfs") == 0;
}
/**
 * storaged_linux_partition_table_update:
 * @table: A #StoragedLinuxPartitionTable.
 * @object: The enclosing #StoragedLinuxBlockObject instance.
 *
 * Updates the interface.
 */
void
storaged_linux_partition_table_update (StoragedLinuxPartitionTable  *table,
                                       StoragedLinuxBlockObject     *object)
{
  const gchar *type = NULL;
  StoragedLinuxDevice *device = NULL;;

  device = storaged_linux_block_object_get_device (object);
  if (device != NULL)
    type = g_udev_device_get_property (device->udev_device, "ID_PART_TABLE_TYPE");

  storaged_partition_table_set_type_ (STORAGED_PARTITION_TABLE (table), type);

  g_clear_object (&device);
}
Esempio n. 25
0
static gboolean
fake_compass_discover (GUdevDevice *device)
{
	if (g_getenv ("FAKE_COMPASS") == NULL)
		return FALSE;

	if (g_strcmp0 (g_udev_device_get_subsystem (device), "input") != 0)
		return FALSE;

	/* "Lid switch" is a random input device to latch onto */
	if (g_strcmp0 (g_udev_device_get_property (device, "NAME"), "\"Lid Switch\"") != 0)
		return FALSE;

	g_debug ("Found fake compass at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Esempio n. 26
0
static gboolean
input_accel_discover (GUdevDevice *device)
{
	const char *path;

	if (g_strcmp0 (g_udev_device_get_property (device, "IIO_SENSOR_PROXY_TYPE"), "input-accel") != 0)
		return FALSE;

	path = g_udev_device_get_device_file (device);
	if (!path)
		return FALSE;
	if (strstr (path, "/event") == NULL)
		return FALSE;

	g_debug ("Found input accel at %s", g_udev_device_get_sysfs_path (device));
	return TRUE;
}
Esempio n. 27
0
static void dump_device_and_parent(GUdevDevice * device, guint indent)
{
	const gchar *const *list;
	const gchar *const *iter;
	GUdevDevice *parent;
	char propstr[500];
	guint32 namelen = 0, i;

	println(indent, "------------------------------------------------------");
	println(indent, "%-20s %s", _("Name:"), g_udev_device_get_name(device));
	println(indent, "%-20s %s", _("Type:"), g_udev_device_get_devtype(device));
	println(indent, "%-20s %s", _("Subsystem:"), g_udev_device_get_subsystem(device));
	println(indent, "%-20s %s", _("Number:"), g_udev_device_get_number(device));
	println(indent, "%-20s %s", _("Path:"), g_udev_device_get_sysfs_path(device));
	println(indent, "%-20s %s", _("Driver:"), g_udev_device_get_driver(device));
	println(indent, "%-20s %lld", _("Sequential Number:"), (long long int)g_udev_device_get_seqnum(device));
	println(indent, "%-20s %s", _("Device File:"), g_udev_device_get_device_file(device));

	println(indent, " ");
	println(indent, _("Properties:"));

	/* Get longest property name length for alignment */
	list = g_udev_device_get_property_keys(device);
	for (iter = list; iter && *iter; iter++) {
		if (strlen(*iter) > namelen)
			namelen = strlen(*iter);
	}
	namelen++;

	for (iter = list; iter && *iter; iter++) {
		strcpy(propstr, *iter);
		strcat(propstr, ":");
		for (i = 0; i < namelen - strlen(*iter); i++)
			strcat(propstr, " ");
		strcat(propstr, g_udev_device_get_property(device, *iter));
		println(indent + 2, "%s", propstr);
	}

	println(indent, " ");

	parent = g_udev_device_get_parent(device);
	if (parent) {
		dump_device_and_parent(parent, indent + 4);
		g_object_unref(parent);
	}
}
Esempio n. 28
0
/**
 * fu_provider_udev_client_remove:
 **/
static void
fu_provider_udev_client_remove (FuProviderUdev *provider_udev, GUdevDevice *device)
{
	FuProviderUdevPrivate *priv = GET_PRIVATE (provider_udev);
	FuDevice *dev;
	g_autofree gchar *id = NULL;

	/* interesting device? */
	if (g_udev_device_get_property (device, "FWUPD_GUID") == NULL)
		return;

	/* already in database */
	id = fu_provider_udev_get_id (device);
	dev = g_hash_table_lookup (priv->devices, id);
	if (dev == NULL)
		return;
	fu_provider_device_remove (FU_PROVIDER (provider_udev), dev);
}
Esempio n. 29
0
/**
 * cd_sensor_client_remove:
 **/
static void
cd_sensor_client_remove (CdSensorClient *sensor_client,
			 GUdevDevice *device)
{
	CdSensor *sensor;
	const gchar *device_file;
	const gchar *device_path;
	const gchar *tmp;
	guint i;

	/* interesting device? */
	tmp = g_udev_device_get_property (device, "COLORD_SENSOR_KIND");
	if (tmp == NULL)
		goto out;

	/* actual device? */
	device_file = g_udev_device_get_device_file (device);
	if (device_file == NULL)
		goto out;

	/* get data */
	device_path = g_udev_device_get_sysfs_path (device);
	g_debug ("removing color management device: %s [%s]",
		 device_path, device_file);
	for (i = 0; i < sensor_client->priv->array_sensors->len; i++) {
		sensor = g_ptr_array_index (sensor_client->priv->array_sensors, i);
		if (g_strcmp0 (cd_sensor_get_device_path (sensor), device_path) == 0) {
			g_debug ("emit: removed");
			g_signal_emit (sensor_client, signals[SIGNAL_SENSOR_REMOVED], 0, sensor);
			g_ptr_array_remove_index_fast (sensor_client->priv->array_sensors, i);
			goto out;
		}
	}

	/* nothing found */
	g_warning ("removed CM sensor that was never added");
out:
	return;
}
static void
telit_custom_init_step (TelitCustomInitContext *ctx)
{
    GUdevDevice *port;

    /* If cancelled, end */
    if (g_cancellable_is_cancelled (ctx->cancellable)) {
        mm_dbg ("telit: no need to keep on running custom init in (%s)",
                mm_port_get_device (MM_PORT (ctx->port)));
        goto out;
    }

    /* Try to get a port configuration from the modem: usb interface 00
     * is always linked to an AT port
     */
    port = mm_port_probe_peek_port (ctx->probe);
    if (!ctx->getportcfg_done &&
        g_strcmp0 (g_udev_device_get_property (port, "ID_USB_INTERFACE_NUM"), "00") == 0) {

        if (ctx->getportcfg_retries == 0)
            goto out;
        ctx->getportcfg_retries--;

        mm_port_serial_at_command (
            ctx->port,
            "AT#PORTCFG?",
            2,
            FALSE, /* raw */
            FALSE, /* allow_cached */
            ctx->cancellable,
            (GAsyncReadyCallback)getportcfg_ready,
            ctx);
        return;
    }

out:
    g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
    telit_custom_init_context_complete_and_free (ctx);
}