Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
	int blight, connector_id;
	const char *path;
	struct udev *udev;
	struct udev_enumerate *e;
	struct udev_list_entry *entry;
	struct udev_device *drm_device;

	if (argc < 3) {
		printf("Please add connector_id and brightness values from 0-255\n");
		return 1;
	}

	connector_id = atoi(argv[1]);
	blight = atoi(argv[2]);

	udev = udev_new();
	if (udev == NULL) {
		printf("failed to initialize udev context\n");
		return 1;
	}

	e = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(e, "drm");
	udev_enumerate_add_match_sysname(e, "card[0-9]*");

	udev_enumerate_scan_devices(e);
	drm_device = NULL;
	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
		path = udev_list_entry_get_name(entry);
		drm_device = udev_device_new_from_syspath(udev, path);
		break;
	}
Ejemplo n.º 2
0
int
wgbm_get_default_fd_for_pattern(const char *pattern)
{
    struct udev *ud;
    struct udev_enumerate *en;
    struct udev_list_entry *devices, *entry;
    const char *path, *filename;
    struct udev_device *device;
    int fd;

    ud = udev_new();
    en = udev_enumerate_new(ud);
    udev_enumerate_add_match_subsystem(en, "drm");
    udev_enumerate_add_match_sysname(en, pattern);
    udev_enumerate_scan_devices(en);
    devices = udev_enumerate_get_list_entry(en);

    udev_list_entry_foreach(entry, devices) {
        path = udev_list_entry_get_name(entry);
        device = udev_device_new_from_syspath(ud, path);
        filename = udev_device_get_devnode(device);
        fd = open(filename, O_RDWR | O_CLOEXEC);
        udev_device_unref(device);
        if (fd >= 0) {
            udev_enumerate_unref(en);
            udev_unref(ud);
            return fd;
        }
    }
Ejemplo n.º 3
0
static int loopback_list_get(MountPoint **head) {
        _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
        struct udev_list_entry *item = NULL, *first = NULL;
        _cleanup_udev_unref_ struct udev *udev = NULL;
        int r;

        assert(head);

        udev = udev_new();
        if (!udev)
                return -ENOMEM;

        e = udev_enumerate_new(udev);
        if (!e)
                return -ENOMEM;

        r = udev_enumerate_add_match_subsystem(e, "block");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysname(e, "loop*");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysattr(e, "loop/backing_file", NULL);
        if (r < 0)
                return r;

        r = udev_enumerate_scan_devices(e);
        if (r < 0)
                return r;

        first = udev_enumerate_get_list_entry(e);
        udev_list_entry_foreach(item, first) {
                MountPoint *lb;
                _cleanup_udev_device_unref_ struct udev_device *d;
                char *loop;
                const char *dn;

                d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
                if (!d)
                        return -ENOMEM;

                dn = udev_device_get_devnode(d);
                if (!dn)
                        continue;

                loop = strdup(dn);
                if (!loop)
                        return -ENOMEM;

                lb = new0(MountPoint, 1);
                if (!lb) {
                        free(loop);
                        return -ENOMEM;
                }

                lb->path = loop;
                LIST_PREPEND(mount_point, *head, lb);
        }
Ejemplo n.º 4
0
static char *
get_render_node_from_id_path_tag(struct udev *udev,
                                 char *id_path_tag,
                                 char another_tag)
{
   struct udev_device *device;
   struct udev_enumerate *e;
   struct udev_list_entry *entry;
   const char *path, *id_path_tag_tmp;
   char *path_res;
   char found = 0;
   UDEV_SYMBOL(struct udev_enumerate *, udev_enumerate_new,
               (struct udev *));
   UDEV_SYMBOL(int, udev_enumerate_add_match_subsystem,
               (struct udev_enumerate *, const char *));
   UDEV_SYMBOL(int, udev_enumerate_add_match_sysname,
               (struct udev_enumerate *, const char *));
   UDEV_SYMBOL(int, udev_enumerate_scan_devices,
               (struct udev_enumerate *));
   UDEV_SYMBOL(struct udev_list_entry *, udev_enumerate_get_list_entry,
               (struct udev_enumerate *));
   UDEV_SYMBOL(struct udev_list_entry *, udev_list_entry_get_next,
               (struct udev_list_entry *));
   UDEV_SYMBOL(const char *, udev_list_entry_get_name,
               (struct udev_list_entry *));
   UDEV_SYMBOL(struct udev_device *, udev_device_new_from_syspath,
               (struct udev *, const char *));
   UDEV_SYMBOL(const char *, udev_device_get_property_value,
               (struct udev_device *, const char *));
   UDEV_SYMBOL(const char *, udev_device_get_devnode,
               (struct udev_device *));
   UDEV_SYMBOL(struct udev_device *, udev_device_unref,
               (struct udev_device *));

   e = udev_enumerate_new(udev);
   udev_enumerate_add_match_subsystem(e, "drm");
   udev_enumerate_add_match_sysname(e, "render*");

   udev_enumerate_scan_devices(e);
   udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
      path = udev_list_entry_get_name(entry);
      device = udev_device_new_from_syspath(udev, path);
      if (!device)
         continue;
      id_path_tag_tmp = udev_device_get_property_value(device, "ID_PATH_TAG");
      if (id_path_tag_tmp) {
         if ((!another_tag && !strcmp(id_path_tag, id_path_tag_tmp)) ||
             (another_tag && strcmp(id_path_tag, id_path_tag_tmp))) {
            found = 1;
            break;
         }
      }
      udev_device_unref(device);
   }
Ejemplo n.º 5
0
/**
 * @brief Create a new net object
 * @param name The name of the underlying device (eth0, br1, etc)
 * @return A newly allocated net object, or NULL on failure
 *
 * This function creates a new net object based on @p name.
 * Only the most minimal lookups are performed at creation in order
 * to save memory.
 */
Eeze_Net *
eeze_net_new(const char *name)
{
   const char *syspath = NULL;
   const char *idx;
   _udev_enumerate *en;
   _udev_list_entry *devs, *cur;
   _udev_device *device = NULL;
   Eeze_Net *net;

   net = eina_hash_find(eeze_nets, name);
   if (net)
     {
        EINA_REFCOUNT_REF(net);
        return net;
     }

   en = udev_enumerate_new(udev);
   udev_enumerate_add_match_sysname(en, name);
   udev_enumerate_add_match_subsystem(en, "net");
   udev_enumerate_scan_devices(en);
   devs = udev_enumerate_get_list_entry(en);
   udev_list_entry_foreach(cur, devs)
     {
        const char *devname, *test;

        devname = udev_list_entry_get_name(cur);
        test = strrchr(devname, '/');
        if (strcmp(++test, name)) continue;
        device = _new_device(devname);
        syspath = eina_stringshare_add(name);
        break;
     }
   if (!device) return NULL;
   net = calloc(1, sizeof(Eeze_Net));
   if (!net) return NULL;
   EINA_REFCOUNT_INIT(net);
   net->device = device;
   net->syspath = syspath;
   net->name = eina_stringshare_add(name);
   idx = udev_device_get_sysattr_value(net->device, "ifindex");
   net->index = atoi(idx);
   eina_hash_add(eeze_nets, name, net);
   udev_enumerate_unref(en);
   return net;
}
Ejemplo n.º 6
0
int read_fpga_status() {
  struct udev *udev;
  struct udev_enumerate *enumerate;
  struct udev_list_entry *device;
  struct udev_device *dev;
  const char *path;
  long prog_done = 0;

  udev = udev_new();
  if (!udev) {
    fprintf(stderr, "ERROR: udev_new() failed\n");
    return -1;
  }

  // Enumerate devcfg
  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_sysname(enumerate, XDEV_CFG_NAME);
  udev_enumerate_scan_devices(enumerate);
  device = udev_enumerate_get_list_entry(enumerate);

  // Did not find a device, lets try a different name
  if (!device)
  {
    fprintf(stderr, "ERROR: Could not find FPGA configuration device!\n");
    return -1;
  }

  // List should have only one entry
  if (udev_list_entry_get_next(device) != 0)
  {
    fprintf(stderr, "ERROR: Found more than one FPGA configuration device!\n");
    return -1;
  }

  // Create udev device
  path = udev_list_entry_get_name(device);
  dev = udev_device_new_from_syspath(udev, path);

  prog_done = (int)atol(udev_device_get_sysattr_value(dev, "prog_done"));

  udev_enumerate_unref(enumerate);
  udev_unref(udev);

  return(prog_done);
}
Ejemplo n.º 7
0
int
rw_netlink_get_pci_addr(const char *ifname, rw_pci_address_t *pci_addr)
{
  struct udev *udev = NULL;
  struct udev_enumerate *enumerate = NULL;
  struct udev_list_entry *devices, *dev_list_entry;
  int ret = -1;
  
  udev = udev_new();
  if (!udev) {
    ret = -1;
    goto ret;
  }

  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "net");
  udev_enumerate_add_match_sysname(enumerate, ifname);
  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);
  
  udev_list_entry_foreach(dev_list_entry, devices) {
    const char *path;
    
    path = udev_list_entry_get_name(dev_list_entry);
    ret = rw_sys_populate_pci_from_path(path, pci_addr);
    if (!ret){
      break;
    }
  }

ret:
  if (enumerate){
    udev_enumerate_unref(enumerate);
  }
  if (udev){
    udev_unref(udev);
  }
  return ret;
}
Ejemplo n.º 8
0
static int get_js_number(struct udev_device *udevice)
{
	struct udev_list_entry *devices, *dev_list_entry;
	struct udev_enumerate *enumerate;
	struct udev_device *hid_parent;
	const char *hidraw_node;
	const char *hid_id;
	int number = 0;

	hid_parent = udev_device_get_parent_with_subsystem_devtype(udevice,
								"hid", NULL);

	/*
	 * Look for HID_UNIQ first for the correct behavior via BT, if
	 * HID_UNIQ is not available it means the USB bus is being used and we
	 * can rely on HID_PHYS.
	 */
	hid_id = udev_device_get_property_value(hid_parent, "HID_UNIQ");
	if (!hid_id)
		hid_id = udev_device_get_property_value(hid_parent,
							"HID_PHYS");

	hidraw_node = udev_device_get_devnode(udevice);
	if (!hid_id || !hidraw_node)
		return 0;

	enumerate = udev_enumerate_new(udev_device_get_udev(udevice));
	udev_enumerate_add_match_sysname(enumerate, "js*");
	udev_enumerate_scan_devices(enumerate);
	devices = udev_enumerate_get_list_entry(enumerate);

	udev_list_entry_foreach(dev_list_entry, devices) {
		struct udev_device *input_parent;
		struct udev_device *js_dev;
		const char *input_id;
		const char *devname;

		devname = udev_list_entry_get_name(dev_list_entry);
		js_dev = udev_device_new_from_syspath(
						udev_device_get_udev(udevice),
						devname);

		input_parent = udev_device_get_parent_with_subsystem_devtype(
							js_dev, "input", NULL);
		if (!input_parent)
			goto next;

		/* check if this is the joystick relative to the hidraw device
		 * above */
		input_id = udev_device_get_sysattr_value(input_parent, "uniq");

		/*
		 * A strlen() check is needed because input device over USB
		 * have the UNIQ attribute defined but with an empty value.
		 */
		if (!input_id || strlen(input_id) == 0)
			input_id = udev_device_get_sysattr_value(input_parent,
								 "phys");

		if (!input_id)
			goto next;

		if (!strcmp(input_id, hid_id)) {
			number = atoi(udev_device_get_sysnum(js_dev));

			/* joystick numbers start from 0, leds from 1 */
			number++;

			udev_device_unref(js_dev);
			break;
		}
next:
		udev_device_unref(js_dev);
	}

	udev_enumerate_unref(enumerate);

	return number;
}
Ejemplo n.º 9
0
static int get_js_number(struct udev_device *udevice)
{
	struct udev_list_entry *devices, *dev_list_entry;
	struct udev_enumerate *enumerate;
	struct udev_device *hid_parent;
	const char *hidraw_node;
	const char *hid_phys;
	int number = 0;

	hid_parent = udev_device_get_parent_with_subsystem_devtype(udevice,
								"hid", NULL);

	hid_phys = udev_device_get_property_value(hid_parent, "HID_PHYS");
	hidraw_node = udev_device_get_devnode(udevice);
	if (!hid_phys || !hidraw_node)
		return 0;

	enumerate = udev_enumerate_new(udev_device_get_udev(udevice));
	udev_enumerate_add_match_sysname(enumerate, "js*");
	udev_enumerate_scan_devices(enumerate);
	devices = udev_enumerate_get_list_entry(enumerate);

	udev_list_entry_foreach(dev_list_entry, devices) {
		struct udev_device *input_parent;
		struct udev_device *js_dev;
		const char *input_phys;
		const char *devname;

		devname = udev_list_entry_get_name(dev_list_entry);
		js_dev = udev_device_new_from_syspath(
						udev_device_get_udev(udevice),
						devname);

		input_parent = udev_device_get_parent_with_subsystem_devtype(
							js_dev, "input", NULL);
		if (!input_parent)
			goto next;

		/* check if this is the joystick relative to the hidraw device
		 * above */
		input_phys = udev_device_get_sysattr_value(input_parent,
									"phys");
		if (!input_phys)
			goto next;

		if (!strcmp(input_phys, hid_phys)) {
			number = atoi(udev_device_get_sysnum(js_dev));

			/* joystick numbers start from 0, leds from 1 */
			number++;

			udev_device_unref(js_dev);
			break;
		}
next:
		udev_device_unref(js_dev);
	}

	udev_enumerate_unref(enumerate);

	return number;
}